Skip to content

Clear --jwt and the other credential options from the command line of clickhouse-client and clickhouse-keeper-client - #131963

Merged
PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:clear-credential-options-from-command-line
Nov 16, 2026
Merged

PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:clear-credential-options-from-command-line

Conversation

@groeneai

@groeneai groeneai commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #131191

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

clickhouse-client now clears the values of --jwt, --ssh-key-passphrase, --one-time-password and --oauth-client-secret from its command line, as it already did for --password, so they are no longer visible in ps and /proc/<pid>/cmdline. clickhouse-keeper-client now does the same for --password and --identity. Closes #131191.

Description

On 26.10.2.103 and 26.8.37.168, clickhouse-client --jwt <token> keeps the bearer token readable by every local user in ps / /proc/<pid>/cmdline for the whole run, while --password is cleared. Thanks to the reporter of #131191 for the analysis.

clearPasswordFromCommandLine only knew --password; the credential options added later were never added to it, and clickhouse-keeper-client never called it. It now zeroes the values of a fixed list of credential options (--password, --jwt, --ssh-key-passphrase, --one-time-password, --oauth-client-secret, --identity), given as --option value, --option=value or --option = value (clickhouse-keeper-client also --option:value), exact names only. It scans from the last argument, so the token is still cleared in --password --jwt <token> (--password without a value). clickhouse-keeper-client calls it after parsing its options. The values are consumed from copies made during parsing. clickhouse-benchmark (only --password) and clickhouse-local (no credential options) are unaffected.

Not covered, as for --password before: a password inside a connection string (clickhouse://user:password@host) and abbreviated or differently-cased option names the parsers also accept (such as --jw <token>, or --PASSWORD in clickhouse-keeper-client). A CLICKHOUSE_JWT environment variable, suggested in the issue, is a separate feature and is not added here (-C <file> with jwt: <token> already keeps the token off the command line); I can send it separately.

Validation: the new test reads /proc/<pid>/cmdline of clickhouse-client and clickhouse-keeper-client connected to a listener that never answers; it prints the secrets on master and passes with the fix (50 runs). Authentication with --password (also --password = <pw>), --ssh-key-passphrase and keeper --identity (also --identity:<user>:<pw>) still works.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/131963]

Version info

  • Merged into: 26.11.1.2469-master (included in 26.11 and later)

groeneai and others added 2 commits November 16, 2026 10:06
`clearPasswordFromCommandLine` zeroed only `--password VALUE` and
`--password=VALUE` in argv. The credential options added to clickhouse-client
later (`--ssh-key-passphrase`, `--jwt`, `--one-time-password`,
`--oauth-client-secret`) were never added to it, and clickhouse-keeper-client
(`--password`, `--identity user:password`) never called it, so these values
stayed readable by every local user in `ps` and `/proc/<pid>/cmdline` for the
whole run (measured on 26.10.2.103 and 26.8.37.168 for `--jwt`).

The function now zeroes the values of a fixed list of credential options, in
the `--option value` and `--option=value` forms, exact names only. A shared
list is safe because every caller rejects an unknown option during parsing,
before the call. The scan goes from the last argument to the first without
skipping: the client turns a `--password` followed by `-...` into
ask-password, so in `--password --jwt TOKEN` the "value" of `--password` is
`--jwt`, and the old forward scan zeroed it, skipped it and left TOKEN
visible. Backwards, each argument is matched on its original text before the
argument to its left can zero it.

clickhouse-keeper-client calls the function after `init`, where Poco has
already bound the option values into its configuration. All values are
consumed from copies made during parsing, so only the `ps` view changes.

Not covered, as for `--password` before: a password inside a connection
string, abbreviated option names, and Poco's `--option:value` spelling.

Closes: ClickHouse#131191

Co-Authored-By: Claude Opus 5.5 <[email protected]>
clickhouse-client fuses `--option = value` (three arguments) into
`--option=value`, so `--jwt = TOKEN` and `--password = SECRET` are accepted,
but only the lone `=` was zeroed and the value stayed visible in `ps`. When
the argument after an exact credential option name is `=` and one more
argument follows (the client's own fusion condition), that next argument is
zeroed instead.

Poco, used by clickhouse-keeper-client, also accepts `:` as the long-option
delimiter, so `--password:SECRET` and `--identity:user:SECRET` are accepted;
the value after `:` is now zeroed like the value after `=`. The boost-based
programs reject that spelling before the call.

Still not covered: a password inside a connection string, and abbreviated or
differently-cased option names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 2 rounds, 2 findings, 0 in the final round) plus my own review.

# Sev Finding Verdict Evidence / action
1 ❌ --option = value (accepted by clickhouse-client, Client.cpp:1656-1669) left the value visible AGREE, fixed the value after a lone = is zeroed; test case added, fails on master
2 💡 clickhouse-keeper-client's --option:value (Poco's second delimiter) stayed visible AGREE, fixed : accepted after the exact name; test case added, fails on master
3 💡 Changelog category should be Bug Fix DISAGREE the same mechanism for --password (#11665) is an Improvement; clearing argv is a best-effort mitigation
4 💡 Connection-string password and abbreviated option names stay visible DISAGREE separate parsers (ConnectionString.cpp, prefix lookup), unchanged since --password; stated in the description

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-48:20261116-105001

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @antonio2368, could you review this? It extends clearPasswordFromCommandLine from --password to the other credential options (--jwt, --ssh-key-passphrase, --one-time-password, --oauth-client-secret, --identity) and calls it from clickhouse-keeper-client after its options are parsed, so these values are no longer visible in ps.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes: 05813_clear_credentials_from_command_line fails on every run with the master binary (the secrets are printed) and passes with the fix.
b Root cause explained? clearPasswordFromCommandLine only zeroed --password; later credential options were never added, and clickhouse-keeper-client never called it.
c Fix matches root cause? Yes: the existing function covers the missing options and keeper-client calls it; no new mechanism.
d Test intent preserved / new tests added? New test for every listed option as --opt value, --opt=value and --opt = value, --password without a value, and keeper-client incl. --opt:value; 01317_no_password_in_command_line still passes.
e Both directions demonstrated? Yes: master FAIL, fix OK with the same command; the token is also visible on official 26.10.2.103 and 26.8.37.168.
f Fix is general across code paths? All callers: client/local, benchmark (only --password), keeper-client (new call). No other program takes a credential option.
g Fix generalizes across inputs (params/datatypes/wrappers)? --opt value, --opt=value, --opt = value (client), --opt:value (keeper-client), empty value, an option as the last argument, --password --jwt <token>; non-credential options stay untouched. Not covered: connection-string password, abbreviated or differently-cased names.
h Backward compatible? (maintainer-approved exception only) Yes: display only; values are parsed into copies first (authentication with --password, --ssh-key-passphrase and keeper --identity verified).
i Invariants and contracts preserved? Every write stays inside an existing argument; each argument is matched on its original text (backward scan); argv[0] is never touched.

Session id: cron:clickhouse-impl-slot-7:20261116-103800

@clickhouse-gh

clickhouse-gh Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [42c4337]

Summary: ✅


AI Review

Summary

Extends clearPasswordFromCommandLine to additional credential options and calls it from clickhouse-keeper-client after parsing. No actionable findings at commit 42c4337d9c20f46093f13adc2b850a446e2fd1e9. The added stateless test covers the supported spellings; 373 focused cases passed locally under ASan and UBSan.

Missing context / blind spots
  • ⚠️ Full ClickHouse binaries were unavailable locally, so the end-to-end stateless test and authentication checks were not rerun. Runtime evidence for these paths comes from the author's recorded validation.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Nov 16, 2026
@PedroTadim PedroTadim self-assigned this Nov 16, 2026
@clickhouse-gh clickhouse-gh Bot added can be tested Allows running workflows for external contributors comp-cli clickhouse-client (interactive CLI) and client library. labels Nov 16, 2026

@clickhouse-gh clickhouse-gh Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI review approves this commit, see the AI Review comment.

@clickhouse-gh

clickhouse-gh Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 42c4337d9 with master afc888dae (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

8 translation units recompiled, 15 s compile time in total, 8 of them have a recent master baseline.

Job report

@PedroTadim
PedroTadim enabled auto-merge November 16, 2026 14:06
@PedroTadim
PedroTadim added this pull request to the merge queue Nov 16, 2026
Merged via the queue into ClickHouse:master with commit eb82d56 Nov 16, 2026
570 of 572 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 16, 2026
zvonand added a commit to Altinity/ClickHouse that referenced this pull request Nov 19, 2026
Antalya 26.8 Backport of ClickHouse#131963 - Clear `--jwt` and the other credential options from the command line of `clickhouse-client` and `clickhouse-keeper-client`
zvonand added a commit to Altinity/ClickHouse that referenced this pull request Nov 20, 2026
Antalya 25.8 Backport of ClickHouse#131963 - Clear `--jwt` and the other credential options from the command line of `clickhouse-client` and `clickhouse-keeper-client`
zvonand added a commit to Altinity/ClickHouse that referenced this pull request Nov 20, 2026
Stable 26.3 Backport of ClickHouse#131963 - Clear `--jwt` and the other credential options from the command line of `clickhouse-client` and `clickhouse-keeper-client`
zvonand added a commit to Altinity/ClickHouse that referenced this pull request Nov 20, 2026
Stable 26.8 Backport of ClickHouse#131963 - Clear `--jwt` and the other credential options from the command line of `clickhouse-client` and `clickhouse-keeper-client`
zvonand added a commit to Altinity/ClickHouse that referenced this pull request Nov 20, 2026
Antalya 26.3 Backport of ClickHouse#131963 - Clear `--jwt` and the other credential options from the command line of `clickhouse-client` and `clickhouse-keeper-client`
zvonand added a commit to Altinity/ClickHouse that referenced this pull request Nov 21, 2026
Stable 25.8 Backport of ClickHouse#131963 - Clear `--jwt` and the other credential options from the command line of `clickhouse-client` and `clickhouse-keeper-client`
VighneshPath pushed a commit to VighneshPath/ClickHouse that referenced this pull request Nov 23, 2026
…ptions-from-command-line

Clear `--jwt` and the other credential options from the command line of `clickhouse-client` and `clickhouse-keeper-client`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-cli clickhouse-client (interactive CLI) and client library. pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clickhouse-client: --jwt value stays visible in ps and the process list

3 participants