ADR-007: CLI/API/UI Parity

Status

Accepted — 2026-03-27; Amended — 2026-08-24 (Amendment 1: human-only authorization surfaces, #1417); 2026-09-17 (Amendment 2: as built — command tree, dependencies, container image; Amendment 3: as built — CLI Architecture, #2154)

Amended by ADR-049 (2026-09-30), effective 2026-10-12: Amendment 4 (canopy-cli on canopy-identity’s device flow; Amendment 1 retired). Amended 2026-11-15: Amendment 5 (offline file checks; what the CLI may not link, #3384).

Context

Canopy exposes three interaction surfaces: a REST API (consumed by program services and integrations), a worker portal UI (canopy-web), and an applicant portal UI (canopy-portal). Without a CLI, the only way to script operations, automate testing, or perform ad-hoc queries is by hand-crafting HTTP requests with curl and a Keycloak token.

OpenStack demonstrated that CLI/API/UI parity — where every operation available in one surface is available in all three — enables:

  1. Scriptable automation — batch operations, data migration, CI/CD integration

  2. Developer productivity — faster iteration than navigating a UI for every test

  3. Operational parity — on-call staff can investigate and act without a browser

  4. Incremental testability — CLI commands become the foundation for integration test scripts

  5. Accessibility — screen reader users and keyboard-only operators get full access via the CLI

The OpenStack CLI (openstack) is the model: a thin client over the REST API using clap-style subcommands, profile-based configuration, and table/json output formatting.

Decision

Every operation exposed by any Canopy service’s REST API must also be available as a canopy CLI subcommand. The CLI is a first-class interface, not a convenience wrapper. New API endpoints ship with corresponding CLI commands in the same MR or the immediately following one.

CLI Architecture

  • Binary: tools/canopy-cli/ — a standalone Rust binary using clap and reqwest

  • Library crate: tools/canopy-cli/src/lib.rs exports Cli, Commands, subcommand types, ApiClient, output, and config modules so integration tests can drive the CLI programmatically

  • API client: ApiClient wraps reqwest::Client with bearer token injection. All CLI commands call the REST API — no direct database access, no bypassing service boundaries

  • Profile config: ~/.config/canopy/profiles.toml stores named profiles with service URLs and Keycloak settings. --profile flag (default: default). Auto-created on first run.

  • Auth: canopy login acquires a Keycloak token via ROPC grant and stores it in ~/.config/canopy/tokens/. canopy token show displays the current token. All other commands auto-refresh expired tokens.

  • Output: --format table|json (global flag, default table). Table output uses tabled crate. JSON output is raw API response for piping to jq.

  • Shell completions: canopy completion bash|zsh|fish|powershell

Command Structure

Commands mirror the API structure:

canopy login
canopy token show|refresh

canopy person create|list|get|update|delete
canopy household create|get|add-member|remove-member
canopy person add-income|add-asset|add-expense|add-address

canopy application create|list|get|update|withdraw
canopy application waive-interview|complete-interview

canopy rules list|get|create|update|delete|import|evaluate

canopy eligibility determine|get-determination|list-determinations

canopy snap evaluate
canopy tanf evaluate
canopy medicaid evaluate
canopy caps evaluate
canopy wic evaluate

canopy enrollment list|get
canopy renewal list|get|process

canopy notice list|get
canopy appeal file|list|get|schedule-hearing|record-decision

canopy report generate|list|export

canopy security events|alerts|nist-controls
canopy security chain-status|chain-verify|chain-attest

canopy completion bash|zsh|fish|powershell

The security chain- trio replaced the original security verify-chain command when the chain surface was unified under /v1/security/chain/ (#1205, ADR-014 Amendment 9; GET /v1/security/verify-chain is deleted): chain-status --family <audit|fti> [--service <canopy-tanf|canopy-medicaid>] (exits non-zero on the fail-closed 503 arm), chain-verify --family … [--service …] [--loop <tail|scrub|family-full>] [--wait] (202 job handle; --wait polls the job to done/error), and chain-attest --event-id <uuid> --family … [--service …] (exits non-zero when not attested). Both families are ACTIVE: the fti arguments (--family fti --service canopy-{tanf,medicaid}) are served live since MR-3 of #1206 — the CLI forwards them unchanged (honest passthrough, per this ADR’s thin-client rule), and a dormant fti target (until #1279) comes back as the server’s typed 503, parsed and named by the same fail-closed exit path.

Parity Enforcement

  • Every plan that adds API endpoints must include a "CLI commands" section in its Steps listing the corresponding canopy subcommands

  • The canopy-cli Cargo.toml depends on no internal crates except via the HTTP API — it is a pure REST client

  • Integration tests can use the CLI library crate to drive end-to-end scenarios

Consequences

  • Every service plan must account for CLI command additions — this increases scope slightly but ensures no operation is UI-only

  • The CLI binary ships in the Docker image alongside service binaries for operational use

  • The tools/canopy-cli/ directory grows incrementally as services are implemented — it is never "done" until all services are complete

  • Shell completion support enables discoverability without documentation

Alternatives Considered

No CLI (rejected)

Rely on curl + API documentation. Rejected because scripting with curl requires managing tokens, constructing JSON payloads, and parsing responses manually — too slow for development and operations.

GraphQL endpoint (rejected)

A single GraphQL endpoint would provide query flexibility but adds complexity, doesn’t solve the scripting problem (still need a client), and conflicts with the per-service isolation model (ADR-001).

TUI (deferred)

A terminal UI (like k9s for Kubernetes) could provide a richer interactive experience. Deferred — the CLI is the priority; a TUI can wrap the same ApiClient later.

Amendment 1 (2026-08-24, #1417): human-only authorization surfaces are a documented parity exception

The post-C1 authorization model (ADR-043 §C, #1443) created a surface class parity cannot reach without weakening the fleet’s authorization controls: endpoints whose HUMAN arm accepts only an exchanged user-context bearer minted by an azp-allowlisted exchanger, and whose service arm is refused at an in-handler human projection. The first member is POST /v1/applications/{id}/documents/{document_id}/scan-override (#1006, #1443): the release must name its accountable human, so a bare service token 403s at the releasing_supervisor projection and a direct worker login — exactly what canopy login's ROPC grant produces (broad audience) — 403s at the receiver contract.

The canopy CLI holds exactly those two credential shapes, and MUST: making the CLI an authorized exchanger would add a user-context-minting client to every receiver’s authorized_exchanger_azps allowlist, widening the fleet’s most sensitive control for a scripting convenience.

Decision: such endpoints are documented CLI-unsupported, with the worker portal — whose canopy-web-exchanger is the audited, allowlisted minting path — as the sole human path. Members are enumerated here and noted in the CLI help of the nearest sibling command:

  • POST /v1/applications/{id}/documents/{document_id}/scan-override (sibling: canopy application document-rescan).

Revisiting this (e.g. a CLI device-flow client with its own exchanger azp) is a maintainer security decision to be taken deliberately, never a parity default.

Amendment 2 (2026-09-17) — as built

Status unchanged (still Accepted). This amendment records where the shipped CLI differs from the 2026-03 text above; the Decision and Consequences are not edited.

  • Command tree. The live command list is canopy --help — the Command enum in tools/canopy-cli/src/main.rs, one module per command under tools/canopy-cli/src/cmd/. It differs from the §Command Structure tree in both directions: enrollment, appeal and report were never built (no such command module exists), while document, interview, verification, determine, income, asset, expense and address exist and are not drawn. The parity gaps (appeals, reporting, enrollment) are not tracked by this ADR.

  • Dependencies. tools/canopy-cli/Cargo.toml depends on the wire-contract crates canopy-contracts-eligibility, canopy-contracts-persons, canopy-contracts-security, canopy-contracts-snap and on canopy-common (the shared HTTP helper). No service, database or message-queue crate is a dependency, so the CLI still reaches services only over HTTP; the §Parity Enforcement sentence "depends on no internal crates" reads as-built as "depends on no crate that bypasses the HTTP boundary".

  • Container image. Dockerfile builds the workspace minus canopy-portal (the CLI included) but its runtime stage copies only the service binaries and canopy-seed; no canopy-cli binary is copied. The Consequence "ships in the Docker image alongside service binaries" is therefore not as built. Whether the binary joins the image or is distributed separately is a maintainer decision outside this record. Erratum (2026-09-18, #2099): the runtime stage now copies the canopy binary to /app/canopy beside the service binaries; the Consequence is as built.

Amendment 3 (2026-09-17, #2154) — as built: CLI Architecture

Status unchanged (still Accepted). Three §CLI Architecture claims above are not as built and Amendment 2 does not record them; this amendment does, and the Decision text is not edited.

  • Library exports. tools/canopy-cli/Cargo.toml declares two targets, the canopy binary (src/main.rs) and the canopy_cli library (src/lib.rs), and lib.rs exports only the auth, client (ApiClient), cmd, config and output modules. The clap tree is the binary’s: pub struct Cli is tools/canopy-cli/src/main.rs:22, the Command enum (there is no Commands) is main.rs:36, and every Parser / Subcommand derive in the crate is in main.rs — the library contributes only the flattened cmd::person::DemographicArgs and the output::Format value enum. No other crate can therefore name Cli, parse an argv or call Cli::command(); the binary does so itself for canopy completion and in its own #[cfg(test)] module. The §Parity Enforcement sentence holds one level down: integration tests drive the command layer function by function (canopy_cli::cmd::<module>::<command>(&ApiClient, Format), as tests/cli_test.rs does), and a test of the command tree itself runs the built binary.

  • Token refresh. Nothing refreshes a token. auth::load_token reads ~/.config/canopy/tokens/<profile>.json and deserialises it; every authenticated arm of main hands the stored access_token to ApiClient::new as it is — or, for the nine crypto-shred commands (the four canopy-persons ones and the five determination redacts), after the RFC 8693 audience exchange in auth::exchanged_client, which is minted from that same stored token — and ApiClient sends it as the bearer on every request with no 401 handling. StoredToken::is_valid is called only by canopy token show (cmd/token.rs), which prints Valid: yes or Valid: EXPIRED; StoredToken.refresh_token is stored by parse_token_response and read nowhere; the crate’s only token-endpoint calls are auth::login and auth::login_service — reached only through canopy login user|service, the sole callers of auth::store_token — and auth::exchange_for_audience, an exchange for an exact audience, not a renewal. TokenAction has only Show: the canopy token refresh of §Command Structure was never built. An expired token is sent as-is, the service’s refusal surfaces through output::check_status as HTTP <status>: <detail>, and the remedy is a fresh canopy login.

  • Table output. --format table is tab-joined text, not the tabled crate. output::print_list prints the column names joined by tabs, a dash rule per column and each row’s values joined by tabs; output::print_detail prints one right-aligned key: value line per field. tools/canopy-cli/Cargo.toml has no tabled dependency; the workspace pin tabled = "0.17" in the root Cargo.toml [workspace.dependencies] has no consumer and no Cargo.lock entry.

Building any of the three — the clap tree in the library so Cli::command() is testable in-process, a refresh-token grant before authenticated calls, a tabled renderer — is a separate maintainer decision outside this record.

Amendment 4 (2026-10-12, #2883, ADR-049) — canopy-cli signs in with the device flow

Status unchanged (still Accepted). ADR-049 D7 moves canopy-cli onto canopy-identity’s RFC 8628 device flow, and its plan I3g (SW12) wired it. The parity Decision stands. This amendment records how the CLI now authenticates, what it reaches, and what that does to Amendments 1–3. The Decision text is not edited.

  • Sign-in (§CLI Architecture’s Auth bullet). canopy login starts a device flow at canopy-identity and prints a verification URI and a user code. A signed-in worker approves the code on canopy-web’s /device page under a step-up, and the CLI polls until the approval opens a native session (ADR-049 D7, Amendments 9 and 21). The session’s refresh credential is bound by DPoP to a device key, and both live in an owner-only store per profile, <config dir>/canopy/identity/<profile> (Amendment 23, O4). canopy logout revokes and removes the session. canopy token <SERVICE> prints one service’s token.

  • Gone: the password grant, canopy login service, the CLI-side RFC 8693 audience exchange, canopy token show, and the notice mark-read verb (#2805).

  • Tokens. Every command sends through the profile’s device client (tools/canopy-cli/src/session.rs). Each call’s token comes from a refresh grant for its target, which rotates the stored credential (Amendment 9, N6). The token is a delegation token naming the worker, with act [canopy-cli], one audience and at most 300 s of life. A receiver’s refusal of the bearer is re-minted and resent once (canopy_auth::send_with_retry). This retires Amendment 3’s "Nothing refreshes a token".

  • Profiles. A profile in profiles.toml names canopy-identity’s issuer identifier (identity_issuer) and an optional ca_file, beside the service URLs, and no Keycloak settings. devstack is a reserved profile, derived from the running devstack’s .ports.env on every run, and the global --devstack switch is gone.

  • Reach. canopy-cli is a native client in the compiled call graph, with delegation-only edges to 14 services: appeals, applications, caps, eligibility, medicaid, notices, persons, renewals, reporting, rules, security, snap, tanf and wic (CANOPY_CLI in crates/canopy-auth/src/identity_policy/call_graph.rs). A route admits the CLI’s token when its admission’s user arm admits the worker’s roles, from any actor or through an arm listing canopy-cli.

  • Amendment 1 retires. The scan-override route admits a supervisor’s or admin’s delegation from any actor (services/canopy-applications/src/api/documents_scan.rs), canopy-cli’s included, so it is no longer a parity exception. No canopy command calls it yet, which makes it a parity gap like Amendment 2’s, not an exception.

  • Amendment 2’s gaps narrow. canopy appeal and canopy ipv cover appeals' operator routes, and canopy report covers reporting’s routes except the overpayment summary only canopy-web reads (#2886). enrollment still has no command.

Amendment 5 (2026-11-15, #3384) — canopy-cli may carry offline file checks

Status unchanged (still Accepted). The parity Decision stands: every API operation is a command, and a command reaches a service only over HTTP. This amendment admits a second kind of command and states what the CLI still may not link. The Decision text is not edited.

  • Offline file checks. canopy-cli may carry a command that only reads files the operator names: no token, no profile, no network and no database. It has no API operation or UI page to be at parity with, so it is outside §Parity Enforcement. canopy config check <pack-dir> --federal <federal-dir> is the first: it runs the pack checks of canopy-pack-check on a working copy of a configuration repository (Offline commands). Such a command runs before the session is opened (dispatch, tools/canopy-cli/src/main.rs), as canopy completion does.

  • What the CLI links. canopy-cli links no service crate (no package under services/), nor canopy-db, canopy-mq, the AMQP client lapin or the database driver (sqlx, sqlx-core, sqlx-postgres), directly or through another crate. A unit test, canopy_cli_links_no_database_message_queue_or_service_crate (tools/canopy-cli/src/dependency_boundary.rs), reads the crate's normal dependencies from cargo tree -p canopy-cli, which resolves features for the CLI alone, and fails naming any such package. Through canopy-pack-check the CLI gains zen-engine and canopy-zen-exact, which evaluate decisions in-process and open nothing.

  • No sqlx. Since #3414 canopy-cli resolves and ships without sqlx: canopy-types and canopy-common carry it only behind a sqlx feature the CLI does not enable, and the test above refuses it. Cargo unifies features across the packages of one build, so the shipped canopy is built in a cargo invocation of its own (cargo build -p canopy-cli --bin canopy --target-dir target/car-cli, on the car, in the release job and in cargo xtask dev start), and the staging step refuses a canopy whose symbols name sqlx_core or sqlx_postgres (xtask/src/devstack_binaries/build.rs). Amendment 2's "No service, database or message-queue crate is a dependency" reads, as built, as the list above.

  • Not here. A job that needs a direct database connection or key material belongs to a separate canopy-admin (#3399), not to canopy-cli, by the maintainer's ruling of 2026-11-14.

Amendment 6 (2026-11-24, #3399) — an operator’s tool is never an xtask verb; work below the API is canopy-manage’s

Status unchanged (still Accepted). Amendment 5’s last bullet names the tool for direct-database and key-material jobs canopy-admin. By the maintainer's ruling of 2026-11-24 it is canopy-manage, matching the sibling project's craig-manage; that bullet is otherwise unchanged.

  • Three tools, three users. cargo xtask is the developer's task runner: it needs a checkout and a toolchain, has no release version and links test fixtures. It carries nothing an operator runs against a deployment. Work that goes through a service's API is canopy-cli's. Work below the API, on a database or on key material, is canopy-manage's (tools/canopy-manage; canopy-manage Reference).

  • No default target. A canopy-manage job is told where to write or what to connect to, and refuses to start otherwise. Nothing in it reads a devstack's files.

  • Released with the services. The binary ships in the service image at the services' version. It links no test library and no service crate; a unit test, canopy_manage_links_no_test_library_and_no_service (tools/canopy-manage/src/dependency_boundary.rs), reads its resolved dependencies and refuses either.

  • No alias. A verb that moves leaves xtask in the change that moves it. A unit test in xtask, every_xtask_command_a_page_names_exists, fails when a page outside plans/ and adrs/ names a cargo xtask command xtask does not have.

  • As built. canopy-manage carries gen-signing-keys, migrate apply, rewrap-keks and identity check, moved from xtask, and gen-client-key, new. A second xtask test, no_operator_page_sends_an_operator_to_xtask, holds the operator pages: an xtask command one of them names must be on a list of developer verbs, each with its reason, and by sub-verb where only some of a verb's are a developer's.

Edit this page · default