Repository navigation
Restrict server-managed S3 credentials in user queries (alternative to #104889) - #106794
Algunenano wants to merge 4 commits into
Conversation
|
Workflow [PR], commit [b733b58] Summary: ❌
AI ReviewSummaryThis PR adds a central guard to stop user-originated S3 access from resolving server-managed credentials. The provider-chain guard is useful, but several request-secret and lifecycle paths still bypass the intended per-user policy, so the hardening is incomplete. Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block Minimum required actions: close the remaining secret-forwarding paths, fix or explicitly redesign the cross-user cache behavior, make Glue honor the intended setting semantics, and add the focused regressions above. |
| @@ -190,16 +210,7 @@ class S3BackupClientCreator | |||
| settings.auth_settings[S3AuthSetting::server_side_encryption_customer_key_base64], | |||
There was a problem hiding this comment.
This still forwards server-configured SSE material into user-driven BACKUP/RESTORE TO S3 requests when restrict_credentials is true. settings.auth_settings was loaded from the server <s3> config and endpoint config, so server_side_encryption_customer_key_base64/server_side_encryption_kms_config can be sent to a user-controlled S3 endpoint even though the PR promises that restricted user SQL cannot inherit server SSE material. Please pass empty SSE values under restrict_credentials, the same way S3StorageParsedArguments::fromAST clears them for the s3/S3 paths.
Adds the session setting `s3_allow_server_credentials_in_user_queries` (default off). When off in clickhouse-server, S3 access from user SQL (`s3`/`s3Cluster`, the `S3`/`S3Queue` engines, named collections, dynamic `disk(type=s3, ...)`, `BACKUP`/`RESTORE TO S3`, and Glue/DataLake catalogs) may not resolve the server's own ambient credentials: environment variables, instance metadata (IMDS), IRSA, ECS, instance profile, SSO, AWS config/ credentials files, `role_arn`-based STS assume-role (without explicit keys), or the GCP OAuth metadata service. Such a request is rejected with `ACCESS_DENIED` unless it supplies explicit credentials or uses NOSIGN. Credentials supplied explicitly in the query, or operator-provisioned static credentials in named collections or the `<s3>` config, are unaffected. Enforced at a single credential-resolution chokepoint (`getCredentialsProvider`) plus a static check for dynamic S3 disks in `getDiskConfigurationFromAST` (skipped when loading existing metadata). `CredentialsConfiguration::forbid_implicit_credentials` defaults to true (fail closed); server-internal callers (server disks, Keeper snapshots) opt out explicitly. `gcp_oauth` is matched case-insensitively and refused unless a complete explicit ADC triple is given. clickhouse-local is unaffected. The setting can be enabled per session/profile for a trusted administrative client and pinned for untrusted users with an explicit value plus a readonly constraint (the explicit value is required so an old `compatibility` version cannot restore the previous default). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
A restricted user query must not use the server's AWS shared-credentials file (the profile provider) when there are no explicit keys and no env/IMDS credentials; it is rejected with ACCESS_DENIED and works once the setting is enabled. The server's own data disk is unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
These tests exercise user-facing S3 access that intentionally uses server-managed credentials (IMDS, environment, role_arn STS, gcp_oauth, or auth headers from the `<s3>` config). Enable `s3_allow_server_credentials_in_user_queries` for them, via the default settings profile or per-query, so they keep passing under the new default. Covers test_s3_imds, test_storage_gcp_auth, test_s3_access_headers, test_e2e_catalogs, test_storage_delta, test_database_glue, and test_storage_s3. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
e02cafb to
b3ec892
Compare
|
|
||
| /// A Glue catalog is created by user SQL (`CREATE DATABASE ... ENGINE = DataLakeCatalog`), so it must | ||
| /// not be able to reuse the server's own credentials. | ||
| creds_config.forbid_implicit_credentials = getContext()->shouldRestrictUserQueryS3Credentials(); |
There was a problem hiding this comment.
getContext here is the global context because DatabaseDataLake::getCatalog constructs GlueCatalog with Context::getGlobalContextInstance. That makes the new session/profile setting ineffective for Glue: CREATE/SELECT with SETTINGS s3_allow_server_credentials_in_user_queries = 1 still reads the global default and rejects aws_role_arn/ambient credentials, which contradicts the PR contract and the updated tests. If this is moved to the caller's context, please also avoid caching a credentials provider created under one user's setting in catalog_impl, otherwise the first caller's allow/deny state leaks to later users. The restriction needs to be evaluated against the current query/user context when Glue credentials are resolved/refreshed.
BigLakeCatalog::retrieveGoogleCloudAccessToken fell back to the GCP metadata service when no complete ADC triple was configured, and even after an explicit ADC token request failed, letting user SQL mint a token with the server's own identity. Now an explicit ADC triple is used and fails closed (no metadata fallback), and the metadata-service path is refused when user queries are restricted. Glue and BigLake catalogs are constructed once with the global server context and cached/shared, so the per-session setting cannot enable their server-managed credentials; the setting documentation now states that such catalogs require explicit credentials. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
| /// DataLake table reads) is driven by user SQL, so it must not use the server's own credentials. | ||
| /// Server disks use the server's own credentials. User-created dynamic S3 disks are handled earlier, | ||
| /// in getDiskConfigurationFromAST. | ||
| credentials_configuration.forbid_implicit_credentials = !for_disk_s3 && context->shouldRestrictUserQueryS3Credentials(); |
There was a problem hiding this comment.
This only gates the AWS/GCP credential providers; restricted user SQL still inherits server-configured request secrets below. auth_settings.getHeaders at line 217 can append <access_header> from the server <s3> config when no explicit access key is set, and lines 255-256 still forward server-configured SSE-C/KMS settings into the client. That means SELECT * FROM s3('https://attacker/...') can still make ClickHouse send operator-provisioned auth headers/SSE material to a user-controlled endpoint even with s3_allow_server_credentials_in_user_queries = 0; the integration-test comments already treat <access_header> as server-managed and blocked by default. Please clear server-originated headers/SSE material, or reject the request, whenever forbid_implicit_credentials is true while preserving headers explicitly supplied in the query.
|
|
||
| This prevents an authenticated user from making the server access S3 with its own (ambient) credentials (server-side credential hijacking). Credentials supplied explicitly — in the query, or as static keys in a named collection (whether created via SQL or defined in config) or in the server `<s3>` config — are not affected by this setting. | ||
|
|
||
| A trusted administrative client may need server-managed credentials for legitimate operations (for example, attaching system tables on an `s3_plain_rewritable` disk via SQL). Enable this setting in that client's session or settings profile to permit it. |
There was a problem hiding this comment.
This per-session allow model does not hold for DatabaseS3 cached tables. A trusted session can read db.file with s3_allow_server_credentials_in_user_queries = 1; DatabaseS3::getTableImpl then stores the resulting StorageS3 in loaded_tables, and later untrusted sessions return that cached storage before any current-context credential check, reusing the client/provider created with server credentials. That makes the allow setting bleed across sessions for user-controlled S3 database reads. Please avoid caching DatabaseS3 tables materialized with server-managed credentials, include the credential policy in the cache key, or recreate/revalidate the S3 client for the current query context before returning a cached table.
|
#106855 is more complete |
Alternative to #104889.
Restricts S3 access that originates from user SQL so it cannot make the server authenticate to S3 with the server's own cloud identity. By default, the
s3/s3Clustertable functions, theS3/S3Queueengines, named collections, dynamicdisk(type=s3, ...)definitions,BACKUP/RESTORE TO S3, and Glue/DataLake catalogs may no longer resolve server-managed credentials: environment variables, instance metadata (IMDS), IRSA, ECS, instance profile, SSO, AWS config/credentials files,role_arn-based STS assume-role (without explicit keys), or the GCP OAuth metadata service (http_client = gcp_oauthwithout an explicit ADC triple). Such a request is rejected withACCESS_DENIEDunless it supplies explicit credentials or usesNOSIGN.Credentials that the operator provisions explicitly — static keys in a named collection (whether created via SQL or defined in config) or in the
<s3>config — keep working as before; this change only blocks resolving the server's own (ambient) credentials from user SQL.This is gated by a new session setting
s3_allow_server_credentials_in_user_queries(default off). A trusted administrative client can enable it in its session or settings profile (pinned with areadonlyconstraint and an explicit value for untrusted users); it has no effect inclickhouse-local.CredentialsConfiguration::forbid_implicit_credentialsdefaults to true so a newly added S3 entry point is denied server-managed credentials unless it explicitly opts in.Compared to #104889 this takes a smaller, more central approach (a single credential-resolution chokepoint plus a session-setting kill switch), which is easier to back-port. It does not include #104889's ARN redaction, URI-aware endpoint matching, config-reload credential revocation, or the
BACKUP ON CLUSTERendpoint-authorization handshake.Related: #104889
Closes: https://github.com/ClickHouse/clickhouse-private/issues/54202
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
S3 access originating from user SQL can no longer resolve the server's own cloud credentials (environment, IMDS/IRSA, instance profile, AWS config files,
role_arn-based STS, GCP OAuth metadata). Explicitly supplied credentials and operator-provisioned named-collection/config credentials are unaffected. Controlled by the new settings3_allow_server_credentials_in_user_queries(disabled by default).