From 2f2d7baadb21d459ce3ba14919efd4dfc2032386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9=20Carasso=20dit=20Carson?= Date: Tue, 17 Nov 2026 15:49:48 -0800 Subject: [PATCH] feat(cloud): point agents at cloud access when a write hits read-only OAuth The OAuth write-gate error only mentioned long-lived API keys, so an agent on read-only OAuth that runs a write (e.g. `cloud service create`) never discovers the scoped `cloud access request` flow. Append a hint to that error, gated behind `experimental-access-negotiation` via a cfg-selected const so default binaries don't advertise commands they don't carry and both build configs stay warning-clean. Co-Authored-By: Claude Opus 4.8 --- crates/clickhousectl/src/cloud/mod.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/crates/clickhousectl/src/cloud/mod.rs b/crates/clickhousectl/src/cloud/mod.rs index 69045cf9..552149da 100644 --- a/crates/clickhousectl/src/cloud/mod.rs +++ b/crates/clickhousectl/src/cloud/mod.rs @@ -147,8 +147,7 @@ pub async fn run(args: CloudArgs, json: bool) -> Result<()> { // OAuth (Bearer) tokens are read-only. Block write commands early // to avoid fail loops where agents repeatedly hit 403 errors. if client.is_bearer_auth() && command.is_write_command() { - return Err(Error::AuthRequired( - "This command requires API key authentication. \ + const BASE: &str = "This command requires API key authentication. \ OAuth (browser login) provides read-only access.\n\n\ To authenticate with an API key:\n \ clickhousectl cloud auth login --api-key YOUR_KEY --api-secret YOUR_SECRET\n\n\ @@ -156,9 +155,19 @@ pub async fn run(args: CloudArgs, json: bool) -> Result<()> { export CLICKHOUSE_CLOUD_API_KEY=your-key\n \ export CLICKHOUSE_CLOUD_API_SECRET=your-secret\n\n\ Learn how to create API keys:\n \ - https://clickhouse.com/docs/cloud/manage/openapi?referrer=clickhousectl" - .into(), - )); + https://clickhouse.com/docs/cloud/manage/openapi?referrer=clickhousectl"; + // The scoped-access flow exists only when compiled with the + // `experimental-access-negotiation` feature, so a default binary must + // not advertise commands it does not carry. + #[cfg(feature = "experimental-access-negotiation")] + const ACCESS_HINT: &str = "\n\n\ + Or request a short-lived, human-approved scoped key, with no \ + long-lived API key to manage:\n \ + clickhousectl cloud access roles # list the roles you can request\n \ + clickhousectl cloud access request --perms role:"; + #[cfg(not(feature = "experimental-access-negotiation"))] + const ACCESS_HINT: &str = ""; + return Err(Error::AuthRequired(format!("{BASE}{ACCESS_HINT}"))); } // `service client` ends in an `exec()` of the local client, and its