Skip to content

Fetch a new access token after a 401 from Venafi Cloud - #853

Open
wallrj-cyberark wants to merge 1 commit into
masterfrom
agent-reauth-on-401
Open

wallrj-cyberark wants to merge 1 commit into
masterfrom
agent-reauth-on-401

Conversation

@wallrj-cyberark

Copy link
Copy Markdown
Contributor

The agent caches its Venafi Cloud access token until about a minute before it expires. It kept reusing that token even after the server rejected it with 401. This PR drops the cached token on a 401, so the next retry fetches a new one.

Why now?

The server is about to start answering 401 when a token is for the wrong sub-TSG. This happens when a cluster moves to another sub-TSG while the agent holds a token for the old one. Today an agent in that state fails every upload until its token expires, which can take about 15 minutes. With this change it recovers on the next retry, 30 seconds later.

Older agents still recover on their own once the token expires, so upgrading is not required.

Testing

TestVenafiCloudClient_ReauthenticatesOn401 checks that a 401 on upload causes a second token request, and that the next upload succeeds.

Test runs
  • go test ./pkg/client/ -race passes, with KUBEBUILDER_ASSETS set for the VenafiConnection tests.
  • With the fix reverted, the new test fails: only one token is requested.

[with Claude]

- The Venafi Cloud client cached its access token until shortly before
  it expired, and reused it even after the server rejected it with 401.
- When a cluster moves to another sub-TSG, the old token is no longer
  accepted. The agent then failed every upload until the token expired.
- Drop the cached token on a 401, so the next retry fetches a new one.

Co-authored-by: Georgi Yanev <georgi.yanev@cyberark.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Richard Wall <richard.wall@cyberark.com>
@wallrj-cyberark
wallrj-cyberark marked this pull request as ready for review November 17, 2026 13:29
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.

1 participant