Skip to content

feat(http): expose cluster administration over HTTP - #2651

Open
Azorlogh wants to merge 1 commit into
mainfrom
claude/en-3289-cluster-admin-http-de1ede
Open

Azorlogh wants to merge 1 commit into
mainfrom
claude/en-3289-cluster-admin-http-de1ede

Conversation

@Azorlogh

@Azorlogh Azorlogh commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Adds HTTP routes under /v3/_/cluster for the operator ClusterService operations:

Route RPC Scope
POST /v3/_/cluster/leadership/transfer TransferLeadership ledger:WriteCluster
POST /v3/_/cluster/learners AddLearner ledger:WriteCluster
POST /v3/_/cluster/learners/{nodeId}/promote PromoteLearner ledger:WriteCluster
DELETE /v3/_/cluster/nodes/{nodeId}[?force=true] RemoveNode ledger:WriteCluster
POST /v3/_/cluster/drain, POST /v3/_/cluster/drain/end BeginDrain, EndDrain ledger:WriteCluster
GET /v3/_/cluster/drain GetDrainStatus ledger:ReadCluster
POST /v3/_/cluster/compactions/{primary,secondary} CompactPrimary, CompactSecondary ledger:WriteCluster

Each handler calls the in-process ClusterService, so leader forwarding, drain preflight, membership checks and validation are the gRPC ones. Maintenance mode is already reachable as the setMaintenanceMode variant of POST /v3/_/apply; it is documented, not duplicated.

Why

HTTP parity for cluster administration (api-parity epic). Linked ticket: EN-3289.

Product / operational motivation

  • Need: operators driving the ledger over HTTP must be able to transfer leadership, change membership, drain and compact without a gRPC client.
  • Current limitation: these operations exist only on ClusterService gRPC and ledgerctl.
  • Requirement / constraint: same scopes, forwarding, drain capability checks, full-width uint64 node IDs and error semantics as gRPC; no protobuf, persisted-format or protocol-revision change.
  • Evidence / durable documentation: docs/technical/architecture/subsystems/api/http-api.md#cluster-administration-over-http, docs/technical/contributing/api-comparison.md#cluster-administration-over-http, openapi.yml.

Technical decision

  • Decision: Backend embeds a ClusterAdmin interface (the subset of clusterpb.ClusterServiceServer used), wired to the existing gRPC server implementation. Errors go through the gRPC adapter's known-error mapping (extracted as KnownErrorStatus), then a status-to-HTTP rendering that keeps the gRPC status class, message and ledger reason (RAFT_NODE_REMOVAL_COMMITTED, RAFT_NODE_NOT_IN_CLUSTER).
  • Why proportionate: reusing the RPC implementation avoids a second copy of forwarding and drain preflight; the in-process call skips only the gRPC interceptors, whose scope check the HTTP route guard replaces.
  • Alternatives considered: calling node/membership directly from HTTP (duplicates forwarding and preflight); a loopback gRPC client (extra hop, auth plumbing); a dedicated maintenance route (duplicates POST /v3/_/apply).

Risk

MEDIUM: new write surface for destructive cluster operations. Mitigated by the RPC's own fixed scopes (default mapping: ledger:admin only), strict input validation, and the shared gRPC implementation.

Validation

  • bash scripts/agent-check
  • AI_REVIEW_BASE_SHA=7affc2ac5 bash scripts/agent-check-pr (race: adapter/grpc, adapter/http, bootstrap; Schemathesis 66/75 operations, the 9 cluster routes excluded)
  • Targeted tests: handler tests per route, TestClusterAdmin_ErrorMapping (local and forwarded errors), TestClusterNodeID_Decoding, TestOpenAPI_ClusterAdmin (requests and responses against openapi.yml), route-scope exhaustiveness rows
  • Full suite / broader validation: N/A

Architecture / behavior impact

  • Additive HTTP routes only. gRPC services, messages, field numbers, persisted formats and pkg/grpcprotocol.Version (40) are unchanged. The v2-to-v3 endpoint map is unchanged: no v2 operation maps to these routes.
  • classifyError is unchanged; cluster handlers use their own status rendering.
  • A 503 after a membership or drain request (including a deadline or cancellation, mapped to Unavailable as on gRPC) does not prove non-commit; retry guidance is documented per operation.
  • Schemathesis excludes ^/v3/_/cluster/: those operations would drain or reconfigure its single-node server.
  • Audit manifests updated: api-boundary-contracts, authentication-authorization-boundaries, raft-membership-leadership.

Review focus

  • handleClusterError / clusterStatusClass in internal/adapter/http/cluster_admin.go: which status messages are passed through.
  • KnownErrorStatus extraction in internal/adapter/grpc/server.go (behavior-preserving move).

Known concerns

  • CreateCheckpoint is not exposed here; it belongs with the backup/restore HTTP work.

Add /v3/_/cluster routes for leadership transfer, learner addition and
promotion, node removal, drain begin/end/status and primary/secondary
compaction. Each handler calls the in-process ClusterService so leader
forwarding, drain preflight and validation match gRPC, and requires the
RPC's fixed scope (ledger:ReadCluster / ledger:WriteCluster).

Node errors are normalized through the gRPC adapter's known-error mapping
(extracted as KnownErrorStatus) so local and forwarded failures render the
same HTTP status, reason and message. Node IDs accept JSON integers or
decimal strings at full uint64 width.

Maintenance mode stays on POST /v3/_/apply. Schemathesis excludes the new
routes because they reconfigure its single-node server. Protobuf, persisted
formats and service revision 40 are unchanged.
@strix-security

strix-security Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Strix Security Review

✅ No open security findings.

PR summary: Adds HTTP routes under `/v3/_/cluster` for the cluster administration RPCs (leadership transfer, learner add/promote, node removal, drain begin/end/status, primary and secondary compaction), each calling the in-process `ClusterService` implementation behind the matching `ledger:ReadCluster` / `ledger:WriteCluster` scope guard. It also extracts the gRPC adapter's typed-error mapping into `KnownErrorStatus` and renders those statuses as HTTP codes with their ledger reasons.

Review summary

Reviewed the nine new /v3/_/cluster routes, the clusterNodeID / body decoders, the error-rendering path (handleClusterError, clusterStatusClass, the writeErrorClass extraction), the KnownErrorStatus move in the gRPC adapter, and the ClusterAdmin wiring through DefaultBackend and bootstrap. No security defect survived validation: every route sits behind the global authentication middleware with the same granular scope its gRPC twin enforces, the caller's bearer token is carried on the request context and re-attached to the outgoing peer call so the leader re-evaluates the same scope, request bodies are decoded strictly under the existing body-size cap, and the status rendering stays within messages the gRPC surface already returns to the same caller while unclassified failures are sanitized. Two leads from the shared scope/token-handling code were examined and rejected as pre-existing behaviour that this change does not widen.

Ruled out (2)
  • Can a token satisfy the new cluster-route scope guards by asserting the granular scope name directly, bypassing a deliberately narrow scope mapping?
    The granular-scope pass-through is documented pre-existing behaviour shared with the gRPC ClusterService, which already enforced the identical fixed cluster scope on every RPC these routes expose, so a token carrying that scope was equally admitted over gRPC before this change.
  • Does the difference between HTTP and gRPC handling of duplicate or non-Bearer Authorization headers let a caller cross a privilege boundary on the new routes?
    The header parsing is unchanged pre-existing code shared by every authenticated route, and the service verifies the JWT and derives scopes from the token it reads, so the claimed identity differential requires a misconfigured fronting proxy rather than a path this change adds.

Review 1 on this PR · 48c9984 · requested Nov 25 15:50 UTC when the PR was opened


Reviewed by Strix
Re-run review · Configure security review settings · Try a deeper review with @strix-security /deep

@NumaryBot NumaryBot added the risk: high NumaryBot classified this pull request as high risk. label Nov 25, 2026
@NumaryBot NumaryBot added bot-reviewed NumaryBot completed its review workflow for the current head. review-approved The DINESH review gate is satisfied for the current head. labels Nov 25, 2026
NumaryBot

This comment was marked as outdated.

@NumaryBot NumaryBot added review-approved The DINESH review gate is satisfied for the current head. and removed review-approved The DINESH review gate is satisfied for the current head. labels Nov 25, 2026

@NumaryBot NumaryBot 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.

The required automated review completed with no remaining findings.

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

bot-reviewed NumaryBot completed its review workflow for the current head. review-approved The DINESH review gate is satisfied for the current head. risk: high NumaryBot classified this pull request as high risk.

Development

Successfully merging this pull request may close these issues.

2 participants