Skip to content

feat(cloud): add experimental cloud init for claimable organizations - #1531

Draft
balanza wants to merge 7 commits into
mainfrom
feature-claimable-org-init
Draft

balanza wants to merge 7 commits into
mainfrom
feature-claimable-org-init

Conversation

@balanza

@balanza balanza commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Adds cloud init, which creates an unclaimed ClickHouse Cloud organization via the unauthenticated POST /v1/claimable endpoint. The command is gated behind the experimental-claimable Cargo feature.

Part of APIS-27.

API library (clickhouse-cloud-api)

  • ClaimableOrganization / ClaimableOrganizationApiKey models. They are Deserialize-only, so keySecret can never be serialized by accident. ClaimableOrganizationLimits is free-form JSON.
  • claimable_organization_create, which sends no Authorization header (security: []).
  • CLAIMABLE_ORGANIZATION_CREATE operation metadata, with no required permissions.
  • The vendored OpenAPI snapshot gets /v1/claimable and its schemas: organizationId, apiKey and expiresAt are required, limits is optional. The Rust response fields stay Option<T>, following the all-Option response policy. The CLI checks that the required fields are present.

CLI (clickhousectl)

  • cloud init [--region] runs before credential resolution, so it is fully unauthenticated. --org-id/--org-name/--api-key/--api-secret are rejected.
  • Saves the returned API key, API URL and expires_at to the project's .clickhouse/credentials.json. The key secret never appears on stdout or stderr.
  • Runs once per project. A TOCTOU-safe check rejects it when API key credentials already exist (already_initialized).
  • New CloudErrorCodes: already_initialized, claimable_unavailable.
  • Subprocess + wiremock tests cover the happy path, the JSON shape, the already-initialized guard, a 503 (claimable_unavailable), and a 403 that writes no credentials.

…able_organization_create

Add models for the POST /v1/claimable unauthenticated endpoint:
- ClaimableOrganization, ClaimableOrganizationApiKey (Deserialize-only;
  no Serialize so key_secret can never be accidentally serialised),
  ClaimableOrganizationLimits = serde_json::Value
- claimable_organization_create client method that bypasses self.request()
  and sends no Authorization header (security: [] in the spec)
- CLAIMABLE_ORGANIZATION_CREATE OperationMetadata constant (required_permissions: &[])
- Vendored OpenAPI snapshot updated with /v1/claimable path and schemas

Part of APIS-27.
…able feature flag

Add `cloud init` to create an unclaimed ClickHouse Cloud organisation:
- experimental_claimable Cargo feature gates the CLI command; library
  types compile unconditionally
- Credentials.expires_at: Option<jiff::Timestamp> (informative, not gated)
- save_claimable_credentials stores api_key, api_secret, api_url, expires_at;
  organisation_id is not stored (inferrable from cloud auth status / whoami)
- Bypass block in cloud/mod.rs runs before credential resolution so the
  command is fully unauthenticated
- check_already_initialized is TOCTOU-safe: preflight outside the lock,
  re-check inside
- AlreadyInitialized and ClaimableUnavailable CloudErrorCode variants
- key_secret never appears on stdout or stderr
- Subprocess + wiremock tests: happy path, JSON shape, already-initialized
  guard, 503 claimable_unavailable, 403 no-credentials-written

Closes APIS-27.
@balanza
balanza force-pushed the feature-claimable-org-init branch from cb43fa4 to 8d40a8b Compare November 24, 2026 20:47
@balanza
balanza requested a balanced review from Copilot November 24, 2026 21:30

Copilot AI 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.

🟡 Changes recommended

The anonymous claimable request can still send a caller-supplied default Authorization header, violating its no-credentials guarantee.

5 open issues
What changed in this PR

Adds experimental cloud init onboarding for claimable ClickHouse Cloud organizations, extending the API client and CLI’s project credential flow.

Changes:

  • Adds claimable-organization models, a creation method, operation metadata, and OpenAPI definitions.
  • Introduces feature-gated cloud init [--region] with credential persistence, initialization guards, and structured output.
  • Adds parsing and subprocess tests, plus integration-test classifier mappings.
File Description
scripts/​tests/​test_classify_install_integration.py Covers the new CLI test mapping.
scripts/​tests/​test_classify_cloud_integration.py Covers claimable API file mappings.
scripts/​classify-install-integration.py Classifies the new CLI test file.
scripts/​classify-cloud-integration.py Marks claimable files as having no live suite.
crates/​clickhousectl/​tests/​cloud/​main.rs Registers feature-gated initialization tests.
crates/​clickhousectl/​tests/​cloud/​init.rs Tests requests, output, credential persistence, and errors.
crates/​clickhousectl/​src/​main.rs Rejects credential and organization flags for initialization.
crates/​clickhousectl/​src/​cloud/​permissions.rs Supports unauthenticated command declarations.
crates/​clickhousectl/​src/​cloud/​output.rs Adds initialization-specific error codes.
crates/​clickhousectl/​src/​cloud/​mod.rs Dispatches initialization before credential resolution.
crates/​clickhousectl/​src/​cloud/​init.rs Implements organization creation and result handling.
crates/​clickhousectl/​src/​cloud/​credentials.rs Stores claimable credentials and expiry metadata.
crates/​clickhousectl/​src/​cloud/​cli.rs Defines the command, flag restrictions, and help.
crates/​clickhousectl/​src/​cli.rs Updates command-order and help-structure tests.
crates/​clickhousectl/​Cargo.toml Adds the experimental feature gate.
crates/​clickhouse-cloud-api/​src/​models/​claimable.rs Defines deserialize-only claimable response models.
crates/​clickhouse-cloud-api/​src/​models.rs Exports the new models.
crates/​clickhouse-cloud-api/​src/​meta/​operations.rs Registers claimable creation metadata.
crates/​clickhouse-cloud-api/​src/​client/​claimable.rs Implements the claimable creation request.
crates/​clickhouse-cloud-api/​src/​client.rs Registers the claimable client module.
crates/​clickhouse-cloud-api/​clickhouse_cloud_openapi.json Adds the endpoint and response schemas.

Review effort: Balanced

serde_json::Value::String(r.to_owned()),
);
}
let resp = self.http.post(url).json(&body).send().await?;
Comment on lines +27923 to +27924
"operationId": "claimableOrganizationCreate",
"parameters": [],
return Err(err);
}

let resolved_base_url = resolve_base_url(base_url);
Comment on lines +19 to +20
#[cfg(feature = "experimental-claimable")]
mod init;
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

AI review gate — Draft pull request — AI review not started

  • Cursor Bugbot does not review draft pull requests, so the gate cannot pass yet.

What to do:

  • Mark the pull request Ready for review. Bugbot then reviews it.
  • The bot re-runs this gate automatically when you mark the pull request ready or the review lands; or comment /ai-gate check.

Re-run the gate with “Re-run jobs” after an approval or a finished review. A push re-runs it automatically.

Copilot AI 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.

🟡 Changes recommended

Initialization can retain an existing same-API organization pin, causing subsequent commands to use newly created credentials against the wrong organization.

5 open issues
3 previously missed issues

In code that hasn't changed since last review

Medium severity Clear credential expiry when replacing API credentials

crates/​clickhousectl/​src/​cloud/​credentials.rs:167

After cloud init followed by cloud auth login --api-key ... --api-secret ..., set_api_credentials replaces the pair and API URL but retains this expires_at. The file then associates one organization's expiry with unrelated credentials. Clear expires_at whenever ordinary login replaces the pair.

Medium severity Reject empty API key credentials before saving

crates/​clickhousectl/​src/​cloud/​init.rs:115

The required-field checks accept empty keyId or keySecret strings. These are saved and init reports success, but Credentials::api_credentials explicitly rejects empty strings, so subsequent commands cannot use the new key and another init bypasses the already-initialized guard. Reject an empty pair before persisting it.

Medium severity Preserve 401 auth classification for CLI exit handling

crates/​clickhousectl/​src/​cloud/​init.rs:164

A 401 is converted into a generic CloudError here, so cloud_error_to_top_level produces exit 1 instead of the CLI's required auth exit 4. Attaching an auth failure classification does not set CloudError.kind. Preserve the 401/auth distinction as the existing converter in cloud/client.rs:1342-1346 does, while keeping 403 generic.

1 resolved since last review

Review effort: Balanced

return Err(err);
}

let resolved_base_url = resolve_base_url(base_url);

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.

2 participants