Repository navigation
Restrict server-managed S3 credentials in user queries (chokepoint, alternative to #104889) - #106855
Conversation
Add a session setting `s3_allow_server_credentials_in_user_queries` (default off in clickhouse-server, no effect in clickhouse-local). When off, S3 access driven by user SQL cannot resolve the server's own ambient credentials (environment, IMDS, IRSA, `role_arn` STS, AWS config files, or the GCP OAuth metadata service) at the single credential-resolution chokepoint; a request with no explicit keys and no NOSIGN is refused with ACCESS_DENIED. Covers the `s3`/`s3Cluster` functions, the `S3`/`S3Queue` engines, named collections, dynamic S3 disks, BACKUP/RESTORE TO S3, DataLake reads, and Glue/BigLake catalogs. A constraint can pin it for untrusted users. Operator- provisioned static credentials in config are intentionally out of scope. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ntial requests Refine the restriction so it refuses a user-query S3 request only when it explicitly asks for a server-managed credential mechanism (`use_environment_credentials = 1`, a `role_arn`, or `http_client = gcp_oauth`) without usable explicit keys. A request that asks for none of them is sent unsigned (anonymous) instead of being rejected, so anonymous access to public buckets keeps working without an explicit `NOSIGN`. This is safe because the provider chain already returns before adding any environment/IMDS/instance-profile/AWS config-file provider under the restriction, so the server's own credentials are never resolved regardless. Drop the `04325` no-credentials case that asserted the old reject-everything behavior. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
… metadata A persistent `S3`/`S3Queue` table whose S3 credentials are server-managed (resolved when the table was created) would fail to load after a server restart, because the table load re-creates the S3 client and the restriction was re-applied in the load context. Skip the restriction for `FORCE_ATTACH`/`FORCE_RESTORE` (server startup and RESTORE), mirroring the dynamic-disk `isLoadingFromExistingMetadata` skip: the credentials were already validated at CREATE time. A user-issued `ATTACH` still uses `LoadingStrictnessLevel::ATTACH` and is re-validated, so it cannot bypass the check. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
These tests exercise S3 access that uses server-managed credentials (environment, a `from_env` value, or no credentials at all with the default `use_environment_credentials`), which user queries can no longer use by default. Enable `s3_allow_server_credentials_in_user_queries` on the relevant instances/profiles, the same way the earlier batch of tests was adapted: test_storage_s3 (restricted_dummy, s3_max_redirects), test_s3_cluster, test_allowed_url_from_config, test_mask_sensitive_info, test_restore_external_engines, and test_disk_configuration (including the privileged `from_env` disk profile). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [bbd49b1] Summary: ❌
AI ReviewSummaryThis PR hardens S3-related user SQL by blocking server-managed credentials across table functions, engines, backups, dynamic disks, and Findings❌ Blockers
Final VerdictNot ready. The |
…sses role_arn Address review of the S3 user-credential restriction: - Named collections default `use_environment_credentials` to 0 (was 1), so a collection that only specifies a URL reads anonymously instead of authenticating with the server's own cloud identity. A collection can opt back in with `use_environment_credentials = 1`; the `s3` table function / disks keep the built-in default, and `<s3><use_environment_credentials>0</...>` makes table-function reads anonymous globally (as ClickHouse Cloud already ships). - `getCredentialsProvider` skips the `role_arn` STS assume-role wrapper when `no_sign_request` is set, so NOSIGN truly bypasses credential resolution instead of running STS on top of the anonymous provider. The setting description is updated accordingly. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ions A `BACKUP`/`RESTORE TO S3(named_collection)` inherited `use_environment_credentials` from the global `<s3>` config (default 1), so a URL-only backup collection authenticated with the server's own identity and was refused under the restriction, unlike the `s3` table function whose named-collection default is now 0. Carry the collection's `use_environment_credentials` (defaulting to 0 for named collections) through BackupReaderS3/BackupWriterS3; the explicit url/key form leaves it unset and keeps the server `<s3>` config default. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…eries override StorageObjectStorageQueue is constructed with the global context (args.getContext()), so a `CREATE ... ENGINE = S3Queue(...) SETTINGS s3_allow_server_credentials_in_user_queries = 1` override did not reach the S3 client and the queue was rejected, unlike the `S3` engine. Apply the creating query's session/profile settings onto the storage context, mirroring registerStorageObjectStorage. Add a stateless regression. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ic disks Two consistency fixes for the S3 user-credential restriction so the forms the credential chokepoint already accepts are also reachable from user SQL: - Named collections now accept and propagate the explicit Google Application Default Credentials triple (`google_adc_client_id`, `google_adc_client_secret`, `google_adc_refresh_token`). With `http_client = gcp_oauth` this is a user-supplied credential, so the restriction allows it instead of minting a token from the server's GCP metadata service. - A dynamic S3 disk with an explicit `use_environment_credentials = 0` and no `role_arn` is now allowed: it asks for no server-managed credential and goes unsigned, matching the anonymous behavior of any other user query. Bare no-credential disks (default `use_environment_credentials = 1`), `role_arn` without explicit keys, and `gcp_oauth` without an explicit ADC triple are still refused. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Two more consistency fixes for the explicit Google ADC form under the S3 user-credential restriction: - `getCredentialsProvider` built an anonymous provider for `http_client = gcp_oauth` (the real authentication is a bearer token at the HTTP layer), but the STS assume-role wrapper still ran for any non-empty `role_arn`. A stale `role_arn` alongside an explicit ADC triple would attempt `AssumeRole` on top of the anonymous provider instead of using the ADC directly. Skip the wrapper for `gcp_oauth`, the same way it is skipped for `no_sign_request`. - `S3BackupClientCreator` copied `http_client`/`service_account`/ `metadata_service`/`request_token_path` into the client configuration but not the Google ADC triple, so `BACKUP`/`RESTORE TO S3` with `gcp_oauth` plus an explicit ADC in the server `<s3>` config reached the restriction as `gcp_oauth` without ADC and was rejected. Propagate the three ADC auth settings, matching the object-storage client builder. Co-Authored-By: Claude Opus 4.8 <[email protected]>
… into s3-restrict-server-credentials
… a flag The previous S3Queue credential-override fix passed a freshly created context copy to the storage as its own context. `StorageObjectStorageQueue` holds that context weakly through `WithContext`, and the background streaming `threadFunc` calls `getContext` on it, so once the transient copy was destroyed the task threw `Context has expired` (a logical error) on every poll. Because the change was in `createQueueStorage`, it affected every S3Queue and AzureQueue table, so the error surfaced in unrelated tests whose servers also ran queue background tasks. Keep passing the persistent global context (`args.getContext()`) to the storage, and pass the effective `s3_allow_server_credentials_in_user_queries` value from the CREATE query as a separate flag. The constructor applies it to a transient context used only to build the object storage client (which copies the context into its own credential refresher), so the per-session override still reaches the S3 client without leaving the storage holding an expiring context. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106855&sha=dec44ba4d6a84822290bad9abf0bf73b6f4f009c&name_0=PR Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ections Two follow-ups to the explicit Google ADC support in S3 named collections: - The query secret masker only recognized `secret_access_key` for `s3`/`S3` named-collection arguments, so `google_adc_client_secret` and `google_adc_refresh_token` supplied as overrides stayed visible in formatted queries and the query log. The S3 named-collection masking now hides the span covering every secret-bearing key present (`secret_access_key` and the two ADC secrets); a non-secret named argument in between is hidden too, which is safe. This applies to the `s3`/`S3` table function, the `S3` table and database engines, and `BACKUP`/`RESTORE TO S3(named_collection)`. - The backup named-collection parser carried only the key pair, `role_arn`, `role_session_name`, `no_sign_request`, and `use_environment_credentials`, so a collection with `http_client = gcp_oauth` plus an explicit ADC triple dropped those before `BackupReaderS3`/`BackupWriterS3` built `S3Settings` and the allowed explicit-ADC case could not work for `BACKUP`/`RESTORE TO S3`. Propagate `http_client` and the ADC triple from the collection as well. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…-credentials # Conflicts: # src/Backups/BackupIO_S3.cpp # src/Backups/BackupIO_S3.h # src/Backups/registerBackupEngineS3.cpp # src/Coordination/KeeperSnapshotManagerS3.cpp # src/IO/S3/tests/gtest_aws_s3_client.cpp
|
Hi @Algunenano — while reviewing this PR I found the following:
Happy to discuss — close anything that's wrong or already addressed. |
The load_data() step reads public clickhouse-datasets S3 files via the s3() table function. After ClickHouse#106855 the server rejects such reads with Code 497 (ACCESS_DENIED) because they fall back to server-managed credentials, which are now disallowed in user queries by default. The datasets are public, so read them with NOSIGN. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…for internal create Resolve conflicts against 26.6: - Keep `getBearerToken`; the `OneLakeCatalog::getAuthHeaders` user-agent override (#108117) is not in 26.6 and is unrelated to this fix. - Drop `allow_server_credentials_in_user_queries` and `is_loading_from_existing_metadata` from the `DatabaseDataLake` constructor call; both come from #106855, which is not backported to 26.6 and whose credential restriction is deliberately left out. - Thread the existing `internal` flag from `InterpreterCreateQuery` through `DatabaseFactory` (the plumbing from 274f167, without the S3 credential restriction). Required by `lazy_init` for internal creates; both 26.6 call sites, `loadMetadata` and `RestorerFromBackup`, already set the flag. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The `arm_tidy` build flagged two issues in `Credentials.cpp`: a duplicate `#include <IO/S3/Client.h>` (already included inside `#if USE_AWS_S3`) and a manual `max_retries` clamp that should use `std::min`. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106855&sha=66039ce735fe8dda61a386b8b70ef6972243939a&name_0=PR&name_1=Build%20%28arm_tidy%29 PR: ClickHouse#106855 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
A backup named collection with an explicit temporary (STS) key triplet dropped the `session_token`, so the request was signed without it. Thread the collection's `session_token` into the named-collection auth override and on into the S3 client creation, matching the `s3` table function and `S3` engine. PR: ClickHouse#106855 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The restriction was skipped when loading an object-storage table or S3 queue from existing metadata (server startup / RESTORE), on the assumption the credentials were validated at CREATE time. But the stored definition can be re-bound to a mutable source afterwards: a named collection created URL-only can later be set to `use_environment_credentials = 1` (or a server `<s3>` `role_arn` added), and on the next restart the skip would let the table silently regain the server identity, even though a user `CREATE`/`ATTACH` of the same definition would be refused. A user with `NAMED COLLECTION ADMIN` but no permission for the setting could thus escalate. Re-apply the restriction on load. A table that now resolves to server-managed credentials simply fails to build its client and becomes inaccessible after a restart instead of escalating; the server itself still starts. PR: ClickHouse#106855 Closes review threads: ClickHouse#106855 (comment) ClickHouse#106855 (comment) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
For persistent `S3`/`S3Queue` tables, enabling `s3_allow_server_credentials_in_user_queries` only per session or profile does not survive a restart: the table is revalidated with the startup context on reload, so one that relied on server-managed credentials becomes inaccessible after a restart. Document this and point operators to explicit credentials (or a server-wide setting) for durable access. PR: ClickHouse#106855 Closes review thread: ClickHouse#106855 (comment) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…stricted Re-applying the user-query S3 credential restriction when loading a persistent table from existing metadata (server startup or RESTORE) makes the server fail to start if the table resolves server-managed credentials -- including a table created before the restriction existed, or one whose named collection was later re-bound to `use_environment_credentials = 1`. Such a table cannot be migrated to explicit credentials before the upgrade, so a hard failure would brick startup. Add a server setting `s3_load_table_anonymously_if_credentials_restricted` (default true): when loading such a table, build an anonymous S3 client instead of throwing. The server starts, the table is inaccessible (its requests to a private bucket are denied) and never silently regains the server identity. Set it to 0 to fail loading instead. User `CREATE`/queries are unchanged -- still rejected with `ACCESS_DENIED`. PR: ClickHouse#106855 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
test_file_pruning_with_hive_style_partitioning[_2] restarts the old-version node onto the current binary and re-queries a bare-URL S3 table. A bare URL resolves the server's environment credentials, which are now restricted for user queries, and the old version cannot enable the override, so the table would be inaccessible after the restart. Give those tables explicit keys instead. PR: ClickHouse#106855 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
A Glue/BigLake `DataLakeCatalog` database loaded from existing metadata (server startup or RESTORE) was treated as allowed to use server-managed credentials -- the restriction was skipped on load. So a catalog created before this PR, or one whose server ambient identity changes later, would let untrusted users reach the server's IMDS/instance-profile/`role_arn`/GCP-metadata credentials after a restart, even at the new default. This is the same restart surface the PR closes for persistent `S3`/`S3Queue` tables. Re-apply the restriction on load. If the catalog then resolves restricted server-managed credentials and fails to build, leave it unavailable (the database is inaccessible and `getCatalog` reports a clear error; the server still starts) rather than escalating or aborting startup -- governed by the existing `s3_load_table_anonymously_if_credentials_restricted` server setting, mirroring the table behavior. A catalog given explicit credentials is unaffected and durable across restart. PR: ClickHouse#106855 Closes review thread: ClickHouse#106855 (comment) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…er-credentials Restrict server-managed S3 credentials in user queries (chokepoint, alternative to ClickHouse#104889)
The load_data() step reads public clickhouse-datasets S3 files via the s3() table function. After ClickHouse#106855 the server rejects such reads with Code 497 (ACCESS_DENIED) because they fall back to server-managed credentials, which are now disallowed in user queries by default. The datasets are public, so read them with NOSIGN. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ed as paths, two readings of one input Blind reviews of the pull requests that introduced nine bugs fixed later (ported in ClickHouse#131294-ClickHouse#131302) showed these gaps: - Data the server wrote itself and reads back (parts, patch parts, packed-file indexes, `ssd_cache` files) was treated as trusted, so out-of-bounds reads on it were dismissed or rated as Nits (ClickHouse#126553, ClickHouse#116007, ClickHouse#86095). - No prompt for overflow of sizes computed from user-controlled counts (`ColumnString::replicate`, ClickHouse#61075). - No prompt for names read from data that become paths (packed archive index, ClickHouse#93414). - A security check that reads its input differently from the consumer (first vs last repeated key, Boolean spellings), which the real review of ClickHouse#106855 missed. Also ask for a separate pass over parsers and security decisions in large pull requests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Alternative to #104889. Refines the approach first opened as #106794.
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, S3 named collections, dynamicdisk(type=s3, ...)definitions,BACKUP/RESTORE TO S3, DataLake table-data reads, andDataLakeCatalogdatabases (Glue, BigLake) 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, or the GCP OAuth metadata service.A request that asks for one of those server-managed sources (for example
use_environment_credentials = 1, arole_arn, orhttp_client = gcp_oauth) without supplying usable explicit credentials is rejected withACCESS_DENIED. A request that asks for none of them is sent unsigned (anonymous), the same as ifNOSIGNhad been given. Credentials the operator supplies explicitly are unaffected: keys passed in the query, static keys in a named collection (created via SQL or defined in config), and keys in the server<s3>config.use_environment_credentialsand how to change itWhether a credential-less request counts as "asking for environment credentials" is decided by
use_environment_credentials:0(it was1), so a collection that only specifies a URL reads anonymously instead of authenticating with the server's identity. This is one of the fixes the issue suggested. A collection can opt back in withuse_environment_credentials = 1.s3/s3Clustertable functions andS3/S3Queueengines use the built-in default (1) unless the server<s3>config overrides it. To make their credential-less reads anonymous by default, set it globally:s3('public-url')is refused and must useNOSIGN.Gated by a new session setting
s3_allow_server_credentials_in_user_queries(default off; no effect inclickhouse-local). A trusted administrative client enables it in its session or settings profile; it can be pinned for untrusted users with areadonlyconstraint and an explicit0value.CredentialsConfiguration::forbid_implicit_credentialsdefaults to true, so a newly added S3 entry point is fail-closed (denied server-managed credentials) unless it explicitly opts out.Loading existing tables on startup
Persistent
S3/S3Queuetables, dynamic S3 disks, andDataLakeCatalogdatabases are revalidated when reloaded from stored metadata (server startup orRESTORE). So that a single such object cannot abort startup, a definition that now resolves restricted server-managed credentials is loaded with an anonymous client instead: the server starts and the object stays in place but is inaccessible until its credentials resolve to a permitted source again. It never silently regains the server identity. This is controlled by a new server settings3_load_table_anonymously_if_credentials_restricted(default enabled); disabling it makes such a load abort startup instead.A table created only under a session/profile
s3_allow_server_credentials_in_user_queries = 1override can therefore become inaccessible after restart unless it has explicit credentials or the setting is enabled server-wide.Server-internal object-storage tables that the server itself creates in the
systemdatabase (named_<log>_s3/_s3queue) are exempt: they always take the anonymous-load fallback regardless of the server setting and are re-credentialed in place afterwards, so they never abort startup even in the hard-fail mode.Style differences from the other two PRs
getCredentialsProvider) plus one session-setting kill switch, fail-closed by default, instead of a per-field separation of user vs. server settings threaded through the configuration, auth-settings, and backup code. It intentionally covers less (noaccess_header/SSE stripping, no ARN redaction, no URI-aware endpoint matching), trading breadth for a small, contained change.use_environment_credentialsto0; and persistentS3/S3Queuetables loaded from existing metadata are no longer re-checked so they survive a restart.Backward-incompatible default
A credential-less user query that previously resolved the server's ambient credentials now either goes anonymous (named collections, or any path where the
<s3>config setsuse_environment_credentials = 0) or is refused withACCESS_DENIED(whereuse_environment_credentialsis still1) unless it usesNOSIGNor supplies explicit credentials. The old behaviour can be restored for a request withuse_environment_credentials = 1(ands3_allow_server_credentials_in_user_queriesenabled if the restriction is on). This should be deployed and back-ported carefully (Cloud first).Related: #104889
Related: #106794
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 no longer resolves the server's own cloud credentials (environment, IMDS/IRSA, instance profile, AWS config files,
role_arn-based STS, GCP OAuth metadata) by default; such a request must use explicit credentials orNOSIGN. Named collections now defaultuse_environment_credentialsto0. The previous behaviour can be restored per request withuse_environment_credentials = 1(or globally via the<s3>config) together with the new settings3_allow_server_credentials_in_user_queries(disabled by default). Explicitly supplied and operator-provisioned config credentials are unaffected. On server startup orRESTORE, a persistentS3/S3Queuetable, dynamic S3 disk, orDataLakeCatalogwhose definition resolves such credentials is loaded anonymously (inaccessible until re-credentialed) instead of aborting startup, controlled by the new server settings3_load_table_anonymously_if_credentials_restricted(enabled by default).Version info
26.7.1.570(included in26.7and later)