Repository navigation
Closed
Labels
Description
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:
verify_grafana_tokenreturnsFalsefor any status other than 200 and for any exception, a timeout or a 502 too._sync_grafana_credentialsthen mints a new token._create_grafana_sa_tokenfirst revokes every token of thedevops-cliservice 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_tokensand_create_grafana_sa_tokencatchExceptionand log at debug level only._resolve_existing_tokenand_resolve_service_urlcatchExceptionaround the settings and keyring reads._verify_argocd_tokenand_verify_grafana_tokenare 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-421and:454-456catchException.:503-554: the sync functions mint after any failed verify.:279-297:_create_grafana_sa_tokencalls_revoke_grafana_sa_tokensbefore 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.pyis 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.pycatchesException. The swallowed-failures ceiling of the module goes down to the count that is left. -
_verify_argocd_tokenand_verify_grafana_tokenare deleted. - HTTP goes through an
httpx2.MockTransportgiven to the client, or refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's HTTP fake if it has landed. kubectl goes throughprocess_fake. The keyring goes through the shared keyring fake. No test patches adevops_cliname (docs/TESTING.md). -
uv run devops cipasses.
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
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Oct 24, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.
The candidate fixes incorrect behavior in credential handling and token revocation logic.The issue causes incorrect token revocation and can lead to security problems.Fixes a critical bug in authentication that affects multiple services.Requires changes to error handling, tests, and credential management logic.Both items fix k8s related issues but the first deals with argo cd sync options while this one handles credential verification and token management.fix(k8s): the argo cd and grafana credential sync revokes and mints a…
fix(k8s): the argo cd and grafana credential sync revokes and mints a…
fix(k8s): the argo cd and grafana credential sync revokes and mints a…