Skip to content

fix(k8s): the argo cd and grafana credential sync revokes and mints a token only when the service refused the old one, and reports every other failure #2156

Closed

Description

@dan-petty

What happened

k8s/credentials.py turns every failure of the Argo CD and Grafana token flows into None or False, so its caller cannot tell a refused token from a service that did not answer. The failure branches also have no test: the coverage run of CI at f4d7066 missed 72 of 337 statements in the module.

The effect on Grafana:

  1. verify_grafana_token returns False for any status other than 200 and for any exception, a timeout or a 502 too.
  2. _sync_grafana_credentials then mints a new token.
  3. _create_grafana_sa_token first revokes every token of the devops-cli service account.

So one failed read of /api/org makes the sync revoke tokens that still work. Argo CD has the same shape: a failed verify leads to a new session token.

Other swallowed causes:

  • mint_argocd_token, mint_grafana_token, _find_or_create_grafana_sa, _revoke_grafana_sa_tokens and _create_grafana_sa_token catch Exception and log at debug level only.
  • _resolve_existing_token and _resolve_service_url catch Exception around the settings and keyring reads.
  • _verify_argocd_token and _verify_grafana_token are aliases of the public functions, kept as old names.

What should happen

  • A verify tells three outcomes apart: the service accepted the token, the service refused it (401 or 403), or the check failed (another status, or a request error).
  • The sync mints a new token, and revokes old ones, only when the service refused the old token. When the check failed, the sync keeps the token and reports the failure with its cause.
  • A failed mint, account lookup or revoke reaches the sync result with its cause, and the command shows it.
  • Each handler catches only the errors that its call raises (AGENTS.md rule 11), and no handler hides a failure.

Evidence

At b170358:

  • src/devops_cli/k8s/credentials.py:389-456: the two verify functions; :419-421 and :454-456 catch Exception.
  • :503-554: the sync functions mint after any failed verify.
  • :279-297: _create_grafana_sa_token calls _revoke_grafana_sa_tokens before it creates a token.
  • :236-238, :260-262, :275-276, :295-297, :335-337, :481-483, :498-499: broad handlers.
  • :459-460: the aliases.
  • tests/fixtures/swallowed_failures_ceilings.json: src/devops_cli/k8s/credentials.py is at 11.

Acceptance criteria

  • Tests first: a 502 and a timeout at the Grafana verify leave the stored token and send no revoke and no create request. A 401 makes the sync mint a new token. The same three cases hold for Argo CD.
  • Tests cover a failed mint, a failed account lookup, a failed revoke and an undecodable secret field, and each test checks the reported cause.
  • No handler in k8s/credentials.py catches Exception. The swallowed-failures ceiling of the module goes down to the count that is left.
  • _verify_argocd_token and _verify_grafana_token are deleted.
  • HTTP goes through an httpx2.MockTransport given to the client, or refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's HTTP fake if it has landed. kubectl goes through process_fake. The keyring goes through the shared keyring fake. No test patches a devops_cli name (docs/TESTING.md).
  • uv run devops ci passes.

Related: #1322 (k8s/ tests on edge fakes), #1318 (the keyring seam; credentials.py imports the private _keyring_set), #1381 (these clients move onto the egress-checked factory), #1314 (the HTTP seam).

Source: #1322

Activity

  1. added
    source/agent
    type/bug
    on Oct 24, 2026
  2. dan-petty commented on Oct 24, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.

  3. added 3 commits that reference this issue on Oct 25, 2026
    45012fd
    78114c1
    ebee748
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

    source/agenttype/bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions