Skip to content

fix: re-fetch OIDC token on 401 to handle token expiry during retries - #1682

Merged
ccwienk merged 1 commit into
masterfrom
refetch-token-on-401-to-avoid-oidc-token-ttl
Jul 31, 2026
Merged

fix: re-fetch OIDC token on 401 to handle token expiry during retries#1682
ccwienk merged 1 commit into
masterfrom
refetch-token-on-401-to-avoid-oidc-token-ttl

Conversation

@Michael5601

Copy link
Copy Markdown
Contributor

The github-auth action fetched the OIDC token once upfront before the token exchange retry loop. With high retry counts and long backoff, the loop can run longer than the 5-minute OIDC token TTL, causing the exchange to fail with a 401 even though the infrastructure issue has self-healed.

The fix fetches the OIDC token once upfront and only re-fetches it when the token exchange returns a 401, keeping the number of OIDC token requests minimal. All other 4xx errors fail immediately since retrying the same request won't help. Transient errors (5xx, timeouts, 408, 429) continue to retry with the same token.

As part of this change, sys.exit(1) calls inside the HTTP layer were replaced with typed HttpError and TransientError exceptions, allowing exchange_token to distinguish between error types and react accordingly.

Release note:

Re-fetches the OIDC token on 401 during token exchange retries, fixing authentication failures when retries span longer than the 5-minute OIDC token lifetime.

@gardener-prow gardener-prow Bot added do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. cla: yes Indicates the PR's author has signed the cla-assistant.io CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 28, 2026
@Michael5601
Michael5601 force-pushed the refetch-token-on-401-to-avoid-oidc-token-ttl branch from 23dcfdf to a06bd74 Compare July 28, 2026 13:52
@ccwienk

ccwienk commented Jul 29, 2026

Copy link
Copy Markdown
Member

check/fix linter-error

Comment thread .github/actions/github-auth/get-token.py Outdated
@Michael5601
Michael5601 force-pushed the refetch-token-on-401-to-avoid-oidc-token-ttl branch from a06bd74 to 74b9413 Compare July 29, 2026 11:52
@Michael5601
Michael5601 requested a review from ccwienk July 29, 2026 11:53
Comment thread .github/actions/github-auth/get-token.py
@Michael5601
Michael5601 force-pushed the refetch-token-on-401-to-avoid-oidc-token-ttl branch from 74b9413 to fd1b841 Compare July 30, 2026 08:19
@Michael5601
Michael5601 requested a review from ccwienk July 30, 2026 08:21
@ccwienk

ccwienk commented Jul 31, 2026

Copy link
Copy Markdown
Member

/kind bug

@ccwienk ccwienk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All comments addressed, looks good.

@gardener-prow gardener-prow Bot added the kind/bug Bug label Jul 31, 2026
@ccwienk

ccwienk commented Jul 31, 2026

Copy link
Copy Markdown
Member

/lgtm

@gardener-prow gardener-prow Bot added lgtm Indicates that a PR is ready to be merged. and removed do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Jul 31, 2026
@gardener-prow

gardener-prow Bot commented Jul 31, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ccwienk

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@gardener-prow

gardener-prow Bot commented Jul 31, 2026

Copy link
Copy Markdown

LGTM label has been added.

DetailsGit tree hash: 123e1ba965f0f3699c26d36a705ec8ebbb7faa5b

@gardener-prow gardener-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 31, 2026
@ccwienk
ccwienk merged commit dc66a08 into master Jul 31, 2026
22 of 23 checks passed
@ccwienk
ccwienk deleted the refetch-token-on-401-to-avoid-oidc-token-ttl branch July 31, 2026 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Indicates the PR's author has signed the cla-assistant.io CLA. kind/bug Bug lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants