Skip to content

feat(cloud): point agent help at cloud access request for writes - #1503

Open
sdairs wants to merge 9 commits into
feature-access-requestfrom
feature-access-request-agent-help
Open

sdairs wants to merge 9 commits into
feature-access-requestfrom
feature-access-request-agent-help

Conversation

@sdairs

@sdairs sdairs commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

What

With experimental-access-negotiation compiled in, the CONTEXT FOR AGENTS help now sends an agent on a read-only OAuth login to cloud access request when it needs a write, and no longer tells it to log in with an API key.

#1495 added this pointer to the write-gate error. In practice agents rarely reach that error: root help, cloud --help and cloud auth status already tell them OAuth is read-only and that writes need an API key, so they stop and ask the user for one before trying a write. This PR changes what those screens say.

Why on top of feature-access-request

Same reason as #1495: cloud access exists only under #[cfg(feature = "experimental-access-negotiation")], so help that names it has to sit behind the same gate. Every string changed here is cfg-selected. A default build is unchanged: all 300 --help screens are byte-identical to the base commit.

Change (feature on only)

Screen Change
root Agent context rewritten: one line each on Postgres and ClickHouse, one sentence on cloud auth (OAuth is read-only. For writes, run cloud access request (the user approves it, requires OAuth)), and the typical flow now goes cloud auth signup -> cloud auth login -> cloud access request -> cloud service create. The "Check state first" line is replaced by Check auth status: cloud auth status.
cloud "API keys are read+write; OAuth is read-only and every write command fails on it" becomes OAuth is read-only: for writes, run `cloud access request` (the user approves it). The typical flow drops the API-key login. The cloud auth whoami line and the cloud auth status / --org-id line are removed; the second repeated the subcommand's description and the --org-id option text.
cloud service "Other commands need API key auth." becomes Other commands are writes: on OAuth, run `cloud access request` first.
cloud access request One line added at the top: "For writes on an OAuth login. The user approves or declines in their browser, so no go-ahead is needed first."
cloud access (description) "Get write access: request a short-lived key that the user approves"
cloud auth login API-key lines removed from the agent context; one pointer to cloud access request added. The --api-key/--api-secret flags and their option help are untouched.
cloud auth signup Next: is now cloud auth login.
cloud auth status output New write_access field in JSON, and a Write access: line in the table output, shown only while OAuth is the active source. It names cloud access roles and cloud access request --perms role:<UUID>.

Error messages are not changed.

Evidence

Agent runs on one task that needs a control-plane write and SQL writes, starting from a read-only OAuth login, with access requests approved automatically. 20 runs per row.

Requested access unprompted Finished
Base, Claude Code (Haiku) 0/20 0/20
Base, OpenCode (Haiku) 0/20 3/20
This PR, Claude Code (Sonnet) 20/20 20/20
This PR, OpenCode (Haiku) 20/20 20/20

The four unfinished runs all failed after approval, for reasons this PR does not address: three ran the CLI from another directory, where the saved key is not found and the CLI falls back to the OAuth login without saying so, and one requested a role without SQL access.

Not yet run against real Cloud with a person approving or declining.

Open points for review

  • Agent-context line cap. The cloud access request block is now 9 content lines against the standard's 8. This PR raises the cap to 9 for that one path in whole_command_tree_follows_help_structure. Folding one line of that block would be the cleaner fix; it is left as evaluated so the wording matches the runs above.
  • root_agent_context_status_commands_parse is compiled out when the feature is on, because the new root context no longer lists --json status commands.
  • Root help and main. feat(cli): name Postgres in root help, typical flows and search (#1493) #1494 changed the root agent context on main (it added a Postgres line). The feature-on root here has its own Postgres and ClickHouse lines, so merging main into feature-access-request will need the two reconciled.
  • cloud service in root. The ClickHouse line names cloud service; it should follow the rename if Rename cloud service to cloud clickhouse (ch), keep service as a hidden alias #1499 lands.
  • Other resource groups (postgres, query-api-endpoint, saved-query, backup, clickpipe, clickstack, udf) still say writes need API key auth. They should get the same one-line change as cloud service.

Checks

cargo fmt --all --check, cargo clippy -p clickhousectl --all-targets and cargo test -p clickhousectl pass with and without --features experimental-access-negotiation.

🤖 Generated with Claude Code


Note

Low Risk
Changes are cfg-gated help text and optional status output fields only; no change to default binaries or write-gate behavior.

Overview
When experimental-access-negotiation is enabled, CONTEXT FOR AGENTS help is rewritten so coding agents route write operations through cloud access request after a read-only OAuth login, instead of instructing them to log in with API keys. Root, cloud, cloud auth login/signup, cloud service, and cloud access request help are feature-gated; builds without the flag stay byte-identical.

cloud auth status now surfaces write_access (JSON and human output) when OAuth is the active credential, pointing agents at cloud access roles and cloud access request --perms role:<UUID>.

Help-structure tests allow 9 context lines for cloud access request only, and skip the root --json status-command parse test when the new root context no longer names those commands.

Reviewed by Cursor Bugbot for commit 970df53. Bugbot is set up for automated code reviews on this repo. Configure here.

balanza and others added 9 commits November 17, 2026 12:48
GET /v1/organizations/{organizationId}/roles answers differently by auth:
an API key gets the administrative catalog (RBACRole), a CLI user Bearer
token gets the roles that user may assign. Model the second as its own
method, organization_assignable_roles_get_list, with AssignableRole,
AssignableRolePolicy and AssignableRolePolicyTags.

The method refuses Basic clients locally with AuthMismatch instead of
falling back to the catalog. Fields stay Option, per the library's
compatibility policy, so callers can tell a missing policy list from an
empty one. The analyzer allowlists the extra typed helper for the
existing route.
…lane

Rename from_resolved to from_resolved_auth and pass the resolved auth
straight through. Normalize the saved OAuth API URL in for_oauth_tokens,
as every other construction path already does, so a record saved without
the /v1 suffix resolves the same base URL.

Extract print_client_diagnostics from the --debug block so a command that
builds its own client can report the same credential source and API URL.
`cloud access` lets an agent get a short-lived, narrowly scoped API key that
a human approves in the browser, instead of reusing a long-lived key. It is
compiled only with the new `experimental-access-negotiation` feature, so
published binaries carry none of it; CI runs clippy and tests with it on.

Identity: both subcommands refresh and use the OAuth user login
(`CloudClient::for_access`), never an API key, even when one outranks it.
The API URL is `--url`, else the one saved with the login. The organization
comes from the user's complete membership list: one is picked
automatically, otherwise `--org`/`--org-id` or `--org-name`. Selectors are
reparsed without clap's global propagation, which would otherwise hide a
conflict between values given at different command depths.

`cloud access roles` prints the assignable-role menu. Incomplete roles or
policies fail before any output instead of implying an empty permission
set.

`cloud access request` runs the authorization code flow with PKCE
(RFC 7636) over a loopback redirect (RFC 8252):

1. bind 127.0.0.1 (or [::1]) and file the request with the redirect URI,
   S256 challenge, CSRF state and an optional `--perms role:<UUID>`
   proposal;
2. print the approval URL to stderr and open the browser;
3. wait for the redirect, which carries the code or `error=access_denied`;
   the wait is bounded by the server's pending deadline and
   `--timeout-seconds` (default two minutes), and the request status is
   never read;
4. exchange code, verifier and redirect URI for the key, and save it to
   `.clickhouse/credentials.json`.

The handshake client never follows redirects, so the code and verifier
cannot be replayed to another origin. Server messages are bounded and
scrubbed of the code and verifier. Each HTTP operation is capped at 30
seconds. Filing and the exchange are not retried. JSON stdout contains only
the final result.

Docs live in the authentication reference, under an experimental heading,
rather than the README.
Serve dedicated approved and denied loopback pages styled like the
console's access-request confirmation view, with a 5-second countdown
that tries to close the tab.
Root, cloud, cloud service, access request, auth login/signup help and
the auth status write_access field. API-key login is no longer named
in agent context.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@cla-assistant

cla-assistant Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ balanza
✅ sdairs
❌ chloecdc
You have signed the CLA already but the status is still pending? Let us recheck it.

This branch has not been deployed

No deployments
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