Skip to content

Conversation

JelteF
Copy link
Collaborator

@JelteF JelteF commented Feb 3, 2025

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.

Copy link
Collaborator

@Y-- Y-- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link

@Bodobolero Bodobolero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but added some suggestions and questions

* local filesystem access.
*/
auto save_nestlevel = NewGUCNestLevel();
SetConfigOption("duckdb.disabled_filesystems", "", PGC_SUSET, PGC_S_SESSION);
Copy link

@Bodobolero Bodobolero Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I read some code comment or documentation that this GUC (disabled_filesystems) can only be disabled once but not re-enabled once it has been disabled.
Quote: Security-related configuration settings generally lock themselves for safety reasons.
I didn't test if it works or not.
Did you test that you could enable LocalFileSystem temporarily (for the session) as planned AFTEr it had been previously disabled globally (as a pg_duckdb GUC)?

Your non_superuser.out below shows that you did, which is great. Just wanted to verify that you really tested with "disabled_filesystems = LocalFileSystem" globally disabled as a GUC?

Copy link

@Bodobolero Bodobolero Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if a user uses another session at the same time while extension install is running (and GUC is set to disabled_filesystem = ""). Could the other session access LocalFilesystem concurrently - thus having an attack vector?
Note: depending on where the extension is downloaded from and how long it takes the time window could be long enough for the attack.

If the temporary GUC change is limited to single PostgreSQL backend process we should be fine. If it applies to all back-ends it would be a problem.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code comment to address these questions.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, makes sense now

…ation

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` and `duckdb.cache` 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.
@JelteF JelteF enabled auto-merge (squash) February 4, 2025 09:42
@JelteF JelteF merged commit 449618b into main Feb 4, 2025
5 checks passed
@JelteF JelteF deleted the security-changes branch February 4, 2025 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants