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 - #2210

Merged
dan-petty merged 1 commit into
mainfrom
fix/2156-credential-sync-remints-on-refusal
Oct 25, 2026
Merged

dan-petty merged 1 commit into
mainfrom
fix/2156-credential-sync-remints-on-refusal

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Summary

The Argo CD and Grafana credential sync now mints a new token, and revokes old ones, only when the service refused the stored token. It reports every other failure with its cause.

Before this change, src/devops_cli/k8s/credentials.py changed each failure of the token flows into None or False:

  • verify_grafana_token returned False for a timeout or a 502 too. The sync then minted a new token, and the Grafana mint first revoked each token of the devops-cli service account. Thus one failed read of /api/org revoked tokens that were valid.
  • verify_argocd_token took HTTP 200 as acceptance. But Argo CD answers /api/v1/session/userinfo with HTTP 200 for each caller, and sets loggedIn: false for a token that it refuses (AuthFuncOverride and GetUserInfo in server/session/session.go of argoproj/argo-cd). Thus the sync kept each refused Argo CD token.
  • The mint, the account lookup, the revoke, the token create and the settings and keyring reads caught Exception and logged at debug level only. A failed kubectl read, an output that is not JSON and an undecodable field all became "not found".

What changes:

  • A check returns True (accepted) or False (refused: HTTP 401 or 403, or Argo CD loggedIn not true), and raises StackCredentialError with the cause when the check fails (another status, an answer that is not JSON, or a request error).
  • The sync keeps the stored token when the check fails. Each failed step reaches the result as a CredentialSync with its cause. devops k8s sync-secrets shows each cause and then exits with status 1. deploy-stack shows the same lines.
  • get_or_mint_argocd_token gives a failed mint to devops argo. get_or_mint_grafana_auth keeps the admin password as the fallback of devops grafana, and logs a warning with the cause.
  • No handler in the module catches Exception. The swallowed-failures ceiling of the module goes from 11 to 0. The aliases _verify_argocd_token and _verify_grafana_token are deleted.
  • tests/test_k8s_credentials.py now tests the module through its edges only: kubectl through process_fake, HTTP through stub_web, the keyring through mock_keyring. No test in it patches a devops-cli name. StubWeb gets respond (an answer for one method and URL) and fail (a transport error for a URL). The module coverage from its own tests is 99%.

Evidence: on origin/main 527558f the new test file has 42 failed and 11 passed tests. The 11 that pass test behavior that does not change. On this branch all 53 pass.

Follow-up

Item

Closes #2156

Change: openspec/changes/archive/2026-10-25-2156-credential-sync-remints-on-refusal/

Comment thread src/devops_cli/k8s/credentials.py Fixed
@dan-petty
dan-petty force-pushed the fix/2156-credential-sync-remints-on-refusal branch from c8e2cff to 45012fd Compare October 25, 2026 00:42
@dan-petty
dan-petty marked this pull request as ready for review October 25, 2026 00:49
@dan-petty
dan-petty force-pushed the fix/2156-credential-sync-remints-on-refusal branch from 45012fd to 78114c1 Compare October 25, 2026 14:58
… token only when the service refused the old one, and reports every other failure

The token checks of Argo CD and Grafana now tell three outcomes apart.
The service accepts the token, the service refuses it (HTTP 401 or 403,
or from Argo CD HTTP 200 with `loggedIn: false`), or the check fails
(another status, an answer that is not JSON, or a request error).

The sync mints a new token, and the Grafana mint revokes the old
tokens, only after a refusal. A failed check keeps the stored token.
Each failed check, mint, account lookup, revoke, token create, kubectl
read, Secret field decode and keyring store reaches the sync result with
its cause. `devops k8s sync-secrets` shows each cause and then exits
with status 1.

Argo CD answers `/api/v1/session/userinfo` with HTTP 200 for each
caller (`AuthFuncOverride` in `server/session/session.go`), so the old
check accepted each refused Argo CD token.

No handler in `k8s/credentials.py` catches `Exception`, and the
swallowed-failures ceiling of the module goes from 11 to 0. The tests
of the module use the edge fakes (`process_fake`, `stub_web`,
`mock_keyring`) and patch no devops-cli name. `StubWeb` gets `respond`
and `fail`.

Closes #2156
@dan-petty
dan-petty force-pushed the fix/2156-credential-sync-remints-on-refusal branch from 78114c1 to ebee748 Compare October 25, 2026 16:16
@dan-petty
dan-petty merged commit 1bb164b into main Oct 25, 2026
17 checks passed
@dan-petty
dan-petty deleted the fix/2156-credential-sync-remints-on-refusal branch October 25, 2026 16:24
dan-petty pushed a commit that referenced this pull request Oct 26, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.6.0](v0.5.0...v0.6.0)
(2026-10-26)


### Features

* **k8s:** devops k8s doctor checks the gitea stack: tunnel host,
anonymous refusal, clone url, registry token and no egress
([#2200](#2200))
([4af6ea6](4af6ea6)),
closes [#2187](#2187)
* **telemetry:** centralized loki logql streamer, prometheus sparklines
& trace waterfalls (tab-telemetry)
([#2213](#2213))
([5d368c8](5d368c8)),
closes [#691](#691)
* **telemetry:** send devops-cli logs with trace ids to Loki
([#2224](#2224))
([28c1607](28c1607)),
closes [#813](#813)


### Bug Fixes

* **ai:** a transient rag lookup failure is not cached, so the same
query recovers as soon as the backend answers
([#2222](#2222))
([6f49beb](6f49beb))
* **ai:** rag chunks stay under the embedder's real token limit, not a
four-characters-per-token estimate
([#2221](#2221))
([a21ad61](a21ad61))
* **cli:** devops --dry-run on a command group given only its own
options
([de49122](de49122))
* **cli:** devops --dry-run on a command group given only its own
options previews it instead of crashing with IndexError
([#2259](#2259))
([de49122](de49122))
* **cli:** drop devcontainer k8s auto-deploy for printed deploy-stack
command ([#2227](#2227))
([9278d3e](9278d3e))
* **config:** service clients use only configured urls and never fall
back to an unconfigured localhost default
([#2219](#2219))
([5b3817d](5b3817d))
* **git:** git output the code parses is read NUL-separated, and git
outcomes come from exit codes
([#2257](#2257))
([db1d234](db1d234))
* **github:** devops pr check-readiness on a branch with no open pull
request exits with a clean error
([#2270](#2270))
([0a1b312](0a1b312))
* **github:** project sync's board lookup and field provisioning fail
closed on a failed read
([#2272](#2272))
([40138f4](40138f4))
* **k8s:** argo cd sync honours --prune and --force, rollout promote and
abort reach the status subresource, and teardown's argo check fails
closed ([#2246](#2246))
([7f3743b](7f3743b))
* **k8s:** authenticate service proxy with client auth settings and
stream typed pod watch
([#2242](#2242))
([1be8a79](1be8a79))
* **k8s:** dcgm-exporter's memory request and limit fit its measured
footprint ([#2264](#2264))
([4776f63](4776f63))
* **k8s:** deploy-stack decides helm recovery from helm's json status
and adopts existing resources with --take-ownership
([#2243](#2243))
([c5dbafc](c5dbafc))
* **k8s:** send LogQL to Loki unchanged and restrict kubectl fallback
([#2228](#2228))
([29743af](29743af)),
closes [#1431](#1431)
* **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 ([#2210](#2210))
([1bb164b](1bb164b))
* **mcp:** an mcp tool stops at its timeout, also when its command runs
in-process
([#2269](#2269))
([6cf8ff0](6cf8ff0))
* **review:** a dependency advisory that admission rejects is not
reported ([#2217](#2217))
([4326906](4326906))
* **review:** a dependency advisory the base revision's pins already
have is listed as pre-existing
([#2268](#2268))
([00b3572](00b3572))
* **review:** a scanner finding that names a kubernetes object the
reviewed commit lacks is rejected as object-not-in-commit
([#2225](#2225))
([e69a4ff](e69a4ff)),
closes [#1352](#1352)
* **roadmap:** delete intake's refine hook; the cross-job rule is the
one same-round refine trigger
([#2262](#2262))
([90fc109](90fc109))
* **roadmap:** intake files and places a candidate that the model judges
a duplicate, and names the possible original, instead of dropping or
closing it
([#2223](#2223))
([050620d](050620d))
* **roadmap:** the roadmap service logs each failed job's own error with
its repository, and a configuration error without a traceback
([#2229](#2229))
([96238be](96238be))
* **security:** the pluto, popeye and gitleaks adapters read what those
tools actually write
([#2220](#2220))
([6789a80](6789a80))
* **security:** vault leases requires --revoke and lease registry
rebuilds on credential changes
([#2271](#2271))
([efab944](efab944))
* **telemetry:** grafana aggregate lines sum and average the lines
shown, read as dashed reference lines, and reach calls in flight
([#2215](#2215))
([2084172](2084172))
* **telemetry:** wait for background exporter threads on client shutdown
([#2274](#2274))
([e6b86b2](e6b86b2)),
closes [#2273](#2273)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants