Repository navigation
Add the default_session_user server setting - #110179
Conversation
When a client connects with an empty user name, the server now authenticates it as the configured default session user instead of the hardcoded `default`: - HTTP: the `user` parameter, `X-ClickHouse-User` header and Basic credentials; - native protocol: an empty user name in the `Hello` packet is now accepted instead of being rejected; - MySQL and PostgreSQL wire protocols: an empty user name in the handshake; - gRPC: an empty `user_name` in the query info; - web terminal: an omitted user field in the auth message. Setting the value to an empty string prohibits connections without a user name. Interserver connections never use the default session user: they identify themselves with a special marker instead of a user name and are authenticated by the cluster secret and the initial user. Composable protocol endpoints (the `protocols` section) can override the setting per endpoint with a `default_session_user` key, so different listening ports can serve different anonymous users; the endpoint is restarted on config reload when the value changes. Co-Authored-By: Claude Fable 5 <[email protected]>
pymysql substitutes the OS user name for an empty user name on the client side, and users with a plaintext password (even an empty one) are asked for it with `AuthenticationCleartextPassword` over the PostgreSQL protocol. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
|
Workflow [PR], commit [b3ff303] Summary: ✅
AI ReviewSummaryThe PR adds the Final Verdict✅ Approve LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 475/499 (95.19%) · Uncovered code |
…tting With the `default_session_user` server setting, an HTTP request that passes an `X-ClickHouse-Key` header without an `X-ClickHouse-User` header no longer has an empty user name (which was previously rejected with `Code: 516`); instead it authenticates as the default session user (`default` by default). As the `default` user uses `no_password`, the supplied key is ignored and the query succeeds, so the expected output for that line becomes `1`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…EQUIRED_PASSWORD The earlier update assumed the `default` user uses `no_password` and would ignore the supplied key. In the stateless-test configuration the `default` user has an empty password (`<password></password>` in `programs/server/users.xml`), so a non-empty `X-ClickHouse-Key` without a user name authenticates as `default` and fails the password check. Because the user name is `default` and interactive Basic authentication is enabled for the request, `AccessControl::authenticate` remaps `AUTHENTICATION_FAILED` (516) to `REQUIRED_PASSWORD` (194). Verified against a local server built from this branch. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…terminal The `/webterminal` WebSocket handler seeded its default user directly from the global `default_session_user` server setting, so a composable HTTP endpoint with its own `<default_session_user>` (or an empty one to disable anonymous logins) authenticated anonymous WebSocket sessions as the wrong user. The per-endpoint override was already threaded into the regular HTTP handlers through `HTTPHandlerConnectionConfig`, but `WebTerminalRequestHandler` never received it. Plumb the override into `WebTerminalRequestHandler` (via a creator lambda in `addDefaultHandlersFactory`, like the dynamic query handler) and seed `auth_user` from it when present. An empty override leaves `auth_user` empty, so an auth message without a "user" field fails authentication, matching the "prohibit anonymous connections" semantics of the other protocols. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…g reload The reload check in `updateServers` marked a listener dirty when *any* `default_session_user` in the `impl` chain changed, even when a closer module already overrode it and the effective value for the endpoint was unchanged. That restarted the listener on config reload for no behavioral change whenever a shadowed base module was edited. Mirror the lookup used by `buildProtocolStackFromConfig`: the value closest to the endpoint wins. A new `getEffectiveDefaultSessionUser` helper walks the chain with "first value wins" semantics, and the reload path now restarts the endpoint only when the effective value actually differs between the previous and the new config. This also correctly detects the case where the override is removed from a closer module and the effective value falls back to a base module's value. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ration test `test_default_session_user` previously exercised only the query protocols, so the anonymous-user contract on the web terminal and the config-reload path was unproven. Add `test_webterminal_default_session_user`: a `/webterminal` WebSocket auth message without a "user" field must authenticate as the endpoint's per-endpoint `default_session_user` (a new `http_webterminal` endpoint), verified via `system.session_log`, while an explicit user name is unaffected. Add `test_config_reload_default_session_user`: in a single `SYSTEM RELOAD CONFIG`, change one endpoint's own (effective) value and a shadowed base value. The endpoint whose effective value changed is restarted and serves the new user, the endpoint whose effective value did not change keeps its user, and the trace log confirms only the former was reloaded for `default_session_user`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…eb terminal rules and the keeper Prometheus factory Two authenticated-HTTP-side paths ignored the per-endpoint `default_session_user` override: 1. A composable HTTP endpoint that exposes the web terminal via a custom `handlers` section (a `rule` with `handler.type = webterminal`) built `WebTerminalRequestHandler` without the override, so an omitted-user WebSocket session authenticated as the global default user (and an empty per-endpoint override did not disable anonymous access). The custom `webterminal` rule now uses the same creator-lambda pattern as `addDefaultHandlersFactory`, passing the override. 2. `createKeeperPrometheusHandlerFactory` dropped the override, so with `prometheus_keeper_metrics_only` a composable `type = prometheus` listener built its handlers with `connection_config.default_session_user == nullopt`. The optional is now threaded through into `createPrometheusHandlerFactoryImpl`, matching `createPrometheusHandlerFactory`. Note that the keeper factory serves only the `Metrics` protocol, which is exposed without authentication (`MetricsImpl` does not create a session), so this threading has no runtime effect today; it keeps the two Prometheus factory entry points symmetric.
…etheus endpoints in the integration test Adds `test_custom_webterminal_rule_default_session_user`: a composable HTTP endpoint (port 8128) that serves the web terminal through a custom `http_handlers` section referencing a `webterminal` rule, and asserts that a WebSocket auth message without a `user` field logs in as the endpoint's `default_session_user` (proving the override reaches the custom rule). Adds `test_prometheus_keeper_metrics_default_session_user`: two composable `type = prometheus` endpoints (ports 9108/9109) served through the keeper-metrics-only factory. Since the `Metrics` protocol is exposed without authentication, both scrapes succeed anonymously regardless of the endpoint's `default_session_user` (including an empty override); the test documents this scope boundary and guards against metrics exposition accidentally requiring authentication.
…` handlers The comments in `users.xml`, `users.yaml.example` and the user settings doc said that an omitted user name always falls back to `default`, which is now governed by the `default_session_user` server setting. The composable protocols doc implied that `default_session_user` applies to all `prometheus` handlers, while the metrics exposition endpoints (including Keeper metrics-only endpoints) never authenticate and ignore the setting. Co-Authored-By: Claude Fable 5 <[email protected]>
Pulls in #110260, the fix for the flaky test `02346_text_index_bug108519_qcc_skip_index` under randomized `materialize_statistics_on_insert`, which was the only failing test in https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110179&sha=b2143caac05dd213da79134fa637667a64d5efd5&name_0=PR Co-Authored-By: Claude Fable 5 <[email protected]>
… fixed-user HTTP handlers An HTTP handler with configured credentials (the `user` key inside `handler` of an `http_handlers` rule, or the `user` key of a `prometheus` protocol) authenticates as the configured user via `AlwaysAllowCredentials` regardless of the request, so a request without a user name must not be resolved through the default session user: with `default_session_user` set to an empty string, the empty-name check used to throw `AUTHENTICATION_FAILED` before the configured credentials were applied, breaking fixed-user handlers as soon as anonymous logins were disabled. The configured user name is already checked at the top of `authenticateUserByHTTP`. Covered by the new integration test `test_fixed_user_handler_with_anonymous_logins_disabled`: a `predefined_query_handler` with a fixed user on a composable endpoint with an empty `default_session_user` override serves a request without credentials as the configured user, while the default handlers on the same endpoint keep rejecting anonymous requests. The setting description and the composable protocols documentation are clarified accordingly. Addresses a review finding on #110179 Co-Authored-By: Claude Fable 5 <[email protected]>
The review noted that `test_default_session_user` did not exercise the gRPC path of the setting. gRPC is not a composable protocol, so only the global setting applies to it: a query without a user name runs as the global default session user, and an explicitly specified user is not affected. The pre-generated protobuf modules are copied from `test_grpc_protocol/pb2`, following the `test_session_log` pattern. Addresses a review note on #110179 Co-Authored-By: Claude Fable 5 <[email protected]>
`assert_login_success` only checked whether a matching `LoginSuccess` row had ever existed in `system.session_log`, so a row left by an earlier test logging in the same user on the same interface (e.g. `explicit_user` over HTTP) could satisfy a later web terminal assertion even if the WebSocket path regressed. The helper is now a context manager that compares the count of matching rows before and after the wrapped action. Co-Authored-By: Claude Fable 5 <[email protected]>
…oaden access The empty user name is resolved to the configured value before authentication, so the substituted user's password, network, and other access checks apply as usual: an empty user name is an alias for the configured user name, and accepting it on the native, MySQL, and PostgreSQL protocols (which previously rejected it) grants no access beyond what specifying the same user name explicitly already gives. Co-Authored-By: Claude Fable 5 <[email protected]>
# Conflicts: # programs/server/Server.cpp
alexey-milovidov
left a comment
There was a problem hiding this comment.
Ok. Reviewed all the code. Approved.
… reloader test_config_reload_prometheus_handlers_switch_to_fixed_user failed twice on master on Integration tests (amd_msan, 1/8) with the endpoint's <default_session_user> restart line missing from the server log. A listener's restart decision in updateServers compares the incoming config against the config recorded by the previous reload. SYSTEM RELOAD CONFIG is not the only reloader: the background ConfigReloader polls every config_reload_interval_ms (default 2000 ms) through the same updater, keyed on the config file's mtime, which replace_in_config's sed -i bumps. When a poller tick lands between a test's config edit and its explicit reload, the poller consumes the difference and records the edited config; the explicit reload then compares an edited config against an edited config, decides nothing changed, and logs nothing. In the failing run the three "will reload" lines carry no query id and run on the poller thread 352 ms before the test's SYSTEM RELOAD CONFIG, which logged no listener lines at all. The <default_session_user> variant is lost rather than merely late, because it is gated on the handler set consuming the setting, which the same edit removes. Pin config_reload_interval_ms to one hour for the module's three instances, so SYSTEM RELOAD CONFIG is the only reloader and the one-edit-set-to-one-reload assumption these tests already make actually holds. This follows the existing idiom in test_zookeeper_connection_log and test_shard_names. The same change also repairs three "assert not contains_in_log" sites, which were passing vacuously under this race: a negative assertion is satisfied whenever the poller already consumed the edit, so it failed silently open. No polling scheme could fix those, only removing the competing reloader. Forcing the race (a 50 ms poller and a 1 s gap between the two edits) reproduces the exact CI assertion 20 times out of 20, with the line absent from the whole server log. With this change under the same forcing, 20 of 20 pass and the line appears attributed to the reload query's own query id. The full module is 29 of 29 green. Related: ClickHouse#110179
|
@alexey-milovidov #110179 is merged, so this is my last note here. I promised above to open a fix PR for the Keeper Nothing has moved on master, and my earlier line numbers have drifted, so at One word unblocks it: NuRaft now, wait for #99123, or leave it as known. I can also file a tracking issue so it does not only live in a merged pull request, but I will not open one unless you want it. |
|
@groeneai write a test when user in |
|
Acknowledged. I will add the case to |
|
The name is not validated when the configuration is loaded, since it is resolved through |
…d in the users configuration `default_session_user` substitutes a configured user name whenever a client connects without one. Its integration suite covered the setting naming a declared user on every interface, and the empty-string reject mode on every interface, but not the value naming a user that is absent from the users configuration: the ordinary typo, and the state a server is in whenever the shipped default `default` is used while the `default` user has been removed from the users configuration. The one existing nonexistent-user assertion supplies the name from the client in the native Hello, so no substitution happens on that path and the setting is not exercised. Nothing validates the name earlier. The only config-time check on the setting concerns the interserver protocol, so the server starts normally and the failure is deferred to connect time: the name is substituted for the empty user name and then authenticated like any other, and `AccessControl::authenticate` reports `AUTHENTICATION_FAILED` under the configured name, which HTTP answers with 403. That is the setting's own documented contract, an empty user name being merely an alias for the configured user name, so the connection stays subject to the substituted user's authentication. The test points the global `default_session_user` of the module's otherwise-idle `node2` at a name absent from `configs/users.xml` and makes one anonymous HTTP request plus one explicit-user control. `node2` no longer mounts `configs/config.xml`, whose endpoints nothing on that node uses; it keeps the cluster definition the interserver test needs and the reload-interval pin the fixture asserts. Requested by @ fm4v in ClickHouse#110179 (comment) Co-Authored-By: Claude Opus 5 <[email protected]>
Adds a way to configure which user is assumed when a client connects without specifying a user name, instead of the hardcoded
default.default_session_user(defaultdefault), is applied when the user name is empty: an HTTP request without theuserparameter andX-ClickHouse-Userheader (including Basic credentials with an empty username and a key without a user), a native protocolHellopacket with an empty user name (previously rejected, now accepted), MySQL and PostgreSQL handshakes with an empty user name, a gRPC query withoutuser_name, an Arrow Flight call without anauthorizationheader (or with Basic credentials with an empty user name), and the web terminal auth message without a user field. Setting the value to an empty string prohibits connections without a user name. HTTP handlers with a fixed user (theuserkey insidehandlerof anhttp_handlersrule, or theuserkey of aprometheusprotocol) authenticate as their configured user and ignore the setting, including the empty reject mode.protocolssection) can override the setting per endpoint with adefault_session_userkey, so different listening ports can serve different anonymous users. The key is looked up from the endpoint's module throughimplreferences, and the endpoint is restarted on config reload when the value changes.default_session_useron aninterservercomposable protocol is rejected as a configuration error.The
NativeProtocol.mdspecification and the composable protocols documentation are updated accordingly. Covered by the new integration testtest_default_session_user(all protocols including gRPC and Arrow Flight, per-endpoint overrides, the explicit reject mode, fixed-user handlers on an endpoint with the reject mode, and a two-node cluster with a secret verifying that remote queries still run as the initiating user).Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added the
default_session_userserver setting: the user to authenticate as when a client connects without specifying a user name (previously hardcoded todefault; the native, MySQL, and PostgreSQL protocols now accept an empty user name instead of rejecting it, and Arrow Flight honors the setting instead of its own hardcodeddefault). Composable protocol endpoints in theprotocolssection can override it per endpoint with adefault_session_userkey, so different listening ports can serve different anonymous users. Setting it to an empty string prohibits connections without a user name. Interserver connections never use the default session user.Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/110179]