feat: implement AWS ECR credentials loader in Kubernetes keychains#3864
feat: implement AWS ECR credentials loader in Kubernetes keychains#3864Nachiket-Roy wants to merge 12 commits into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Nachiket-Roy The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
|
|
Welcome @Nachiket-Roy! It looks like this is your first PR to knative/func 🎉 |
|
Hi @Nachiket-Roy. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
There was a problem hiding this comment.
Pull request overview
This PR adds programmatic AWS ECR authentication support to the Kubernetes keychain credential loader pipeline, aligning it with the existing GCR and ACR loaders so image push/pull can automatically resolve ECR credentials.
Changes:
- Add ECR registry hostname detection (
isECRRegistry) and wire an ECR credential loader usingamazon-ecr-credential-helperviaauthn.NewKeychainFromHelper. - Return
creds.ErrCredentialsNotFoundwhen the loader should not apply (non‑ECR registries) to allow other loaders to proceed. - Add unit tests for ECR registry detection and basic loader behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pkg/k8s/keychains.go | Implements ECR registry detection and an ECR credential loader using the AWS ECR credential helper. |
| pkg/k8s/keychains_test.go | Adds tests for ECR registry detection and ECR loader fallback behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
/ok-to-test |
|
The semaphore introduces a cross-registry blocking problem. Consider:
After just 2 timeouts — potentially for completely unrelated registries — all ECR credential lookups are dead until one of the leaked goroutines' The semaphore doesn't prevent the goroutine leak (the leaked goroutine holds the slot until I'd suggest dropping it. The goroutine leak is inherent to |
|
The caching here is more complex than it needs to be. The ECR helper already has its own file-based credential cache ( The only value of caching at this layer is avoiding repeated 5-second timeout hangs when credentials aren't configured. For that, a TTL'd var failedRegistries sync.Map
// early return
if _, ok := failedRegistries.Load(registry); ok {
return oci.Credentials{}, creds.ErrCredentialsNotFound
}
// after the lookup, only cache "no credentials" errors (not timeouts)
if errors.Is(resErr, creds.ErrCredentialsNotFound) {
failedRegistries.Store(registry, struct{}{})
}No TTL is needed — if AWS credentials aren't configured, they won't appear mid-process. The closure scoping already ensures the state is fresh per Alternatively, drop the cache entirely. The 5-second timeout is bounded, the helper caches its own successes, and |
|
Removing
The only argument for keeping it is avoiding the goroutine spawn for non-ECR registries, but that's a micro-optimization around the goroutine pattern itself. |
|
My PR in aws ecr was merged. |
|
@matejvasek will update my pr in few hours. |
…credential loader
…chronous lookup and semaphore
426d4a5 to
463f3c7
Compare
Summary
This change adds programmatic AWS Elastic Container Registry (ECR) authentication support when resolving OCI registry keychains, aligning it with the existing GCP (Google Container Registry) and Azure (ACR) patterns. Previously, the ECR credentials loader was left unimplemented (GetECRCredentialLoader returned an empty slice), which prevented automatic, programmatic ECR credential resolution when pushing/pulling images in Kubernetes keychains workflows.
What changes were made?
public.ecr.awsas well as private registry formats across various AWS partitions.GetECRCredentialLoader): Leveraged the officialamazon-ecr-credential-helper/ecr-loginlibrary programmatically, wrapped viaauthn.NewKeychainFromHelper().io.Discardand ensured that if no ambient credentials exist,creds.ErrCredentialsNotFoundis returned, letting subsequent credential loaders in the chain attempt authentication.Testing
pkg/k8s/keychains_test.go)Closes : #3863