-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update security restrictions to allow non-superuser extension install…
…ation (#572) This updates a bunch of our security related code. For previous releases we needed to be very careful with allowing arbitrary SQL code to be executed in DuckDB because DuckDB queries could read all Postgres tables. This is not the case anymore since #466 was merged, because now any access to Postgres tables goes through the Postgres planner and executor instead of custom code. Lots of code wasn't updated with that new behaviour in mind though. 1. Allow running `duckdb.raw_query`, `duckdb.cache`, `duckdb.cache_info`, `duckdb.cache_delete` and `duckdb.recycle_db` as any user (with the duckdb role). 2. Allow running `duckdb.install_extension` as regular users, if required permissions are explicitly granted. This is not allowed by default for non-superusers because it's still considered a very high privilege. 3. Disallow running queries on tables with RLS enabled in a different place, so that it is checked for every Postgres table that DuckDB opens (also when using `duckdb.query`/`duckdb.raw_query`). 4. Add `duckdb.allow_community_extensions` setting.
- Loading branch information
Showing
14 changed files
with
231 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from .utils import Postgres | ||
|
||
import pytest | ||
import psycopg.errors | ||
import psycopg.sql | ||
|
||
|
||
def test_community_extensions(pg: Postgres): | ||
pg.create_user("user1", psycopg.sql.SQL("IN ROLE duckdb_group")) | ||
# Raw extension installation should not be possible non-superusers, because | ||
# that would allow installing extensions from community repos. | ||
with pg.cur() as cur: | ||
cur.sql("SET ROLE user1") | ||
print(cur.sql("SHOW ROLE")) | ||
cur.sql("SET duckdb.force_execution = false") | ||
with pytest.raises( | ||
psycopg.errors.InternalError, | ||
match="Permission Error: File system LocalFileSystem has been disabled by configuration", | ||
): | ||
cur.sql( | ||
"SELECT * FROM duckdb.raw_query($$ INSTALL avro FROM community; $$)" | ||
) | ||
|
||
# Even if such community extensions somehow get installed, it's not possible | ||
# to load them without changing allow_community_extensions. Not even for a | ||
# superuser. | ||
with pg.cur() as cur: | ||
cur.sql("SET duckdb.force_execution = false") | ||
cur.sql("SELECT * FROM duckdb.raw_query($$ INSTALL avro FROM community; $$)") | ||
with pytest.raises( | ||
Exception, | ||
match="IO Error: Extension .* could not be loaded because its signature is either missing or invalid and unsigned extensions are disabled by configuration", | ||
): | ||
cur.sql("SELECT * FROM duckdb.raw_query($$ LOAD avro; $$)") | ||
|
||
# But it should be possible to load them after changing that setting. | ||
with pg.cur() as cur: | ||
cur.sql("SET duckdb.allow_community_extensions = true") | ||
cur.sql("SET duckdb.force_execution = false") | ||
cur.sql("SELECT * FROM duckdb.raw_query($$ LOAD avro; $$)") | ||
|
||
# And that setting is only changeable by superusers | ||
with pg.cur() as cur: | ||
cur.sql("SET ROLE user1") | ||
with pytest.raises( | ||
psycopg.errors.InsufficientPrivilege, | ||
match='permission denied to set parameter "duckdb.allow_community_extensions"', | ||
): | ||
cur.sql("SET duckdb.allow_community_extensions = true") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.