auth/utils: ensure registry credentials are always fresh#1244
Merged
Conversation
Member
Author
|
Note: We already do this for other operations that are known to be long-running, like reconciling YAML on remote clusters: Lines 126 to 160 in 3f9f27f |
Member
Author
|
Integration tests are running:
Edit: All passed! |
Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
cd04af0 to
bf1b9c7
Compare
Member
Author
|
I have deployed this change through a source-controller release candidate in my EKS clusters (where all my sources are OCIRepository) and they are all healthy. Will keep it there until I can switch to the 2.9 release. |
stefanprodan
approved these changes
Jun 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a bug (not a vuln!), but I have never seen it happen, there are no user reports that I'm aware of.
Long-running operations using artifact registry credentials for multiple OCI/HTTP calls can hit 401, since credentials are statically resolved by
auth.GetArtifactRegistryCredentials(). That function returns a user+pass pair immediately (due to howauth/{aws|azure|gcp}are implemented for ECR/ACR/GAR). In other words, theAuthorize()method of the returnedauthn.Authenticatorwill return a cached user+pass pair that never changes. This fix delays the call toauth.GetArtifactRegistryCredentials()to happen on demand insideauthn.Authenticator.Authorize(), which ensures that multiple calls will always return a fresh credential. This is becauseauth.GetArtifactRegistryCredentials()has a smart cache inside that keeps track of the credential lifetime. This makes it never return an expired credential, as a new one is created when the cached one is expired (the cache knows when).This fix is super good for
flux-mirror sync, which callsauth/utills.GetArtifactRegistryCredentials()(not the low-level one fromauth) for ECR/ACR/GAR only once during the process startup and hands theauthn.Authenticatoroff togo-containerregistry. Before this fix,go-containerregistrywould callAuthorize()again internally upon a 401 and get the same credentials acquired during process startup. This PR causesAuthorize()to return valid creds on every call.I don't think SC or IRC would ever hit this bug, since their operations are not super long. The reconcilers just perform a handful of calls, and no OCI artifact is large enough that it takes 2-digit minutes to reconcile. But this PR fixes the whole thing anyway.