← Back to list

ECR-creds-refresher

kubernetes operator

Dejanu Alex · 2025-12-21 18:04 · 8 claps · 1.8 min read
#kubernetes #kubernetes-operator #devops #k8s #elastic-container-service
Open on Medium ↗
Wiki topics: ☁️ · DevOps & Cloud

ECR-creds-refresher

kubernetes operator

Generally, the following are the main methods to authenticate to a private registry in order to be able to pull images from it:

In this particular case, the motivation was that I had to authenticate to AWS Elastic Container Registry private repositories, and couldn’t modify the aforementioned cluster configurations. Therefore ecr-creds-refresher operator was the natural workaround.

Pre-requisites

Before obtaining the ECR authentication authorization token ( aws ecr get-login-password --region REGION | docker login --username AWS --password-stdin AWS_ACCOUNT_ID.dkr.ecr.REGION.amazonaws.com) ensure that you have an AWS user/role with the required ECR permissions and valid AWS credentials (such as AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, or temporary credentials when assuming a role).

Demo

When attempting to spin up a pod based on an image from the private ECR repo :

kubectl run test \
--image=255656399702.dkr.ecr.us-east-1.amazonaws.com/os/alpine:latest \
--image-pull-policy=Always -- sleep 5

The pod will fail with ImagePullBackOff

ImagePullBackOff

ImagePullBackOff

To fix this, we need:

  • A secret that holds the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
  • A mechanism to obtain the authentication token. ⚠️ Important note: An authentication token is used to access any Amazon ECR registry that your IAM principal **has access to and is valid for 12 hours**.

The second point is exactly what the ecr-creds-refresher will do for us, more concretely:

  • Upon startup, it will read the AWS credentials from the configured secret (which can be in any namespace).
  • Watches for ECRPullSecret custom resources (CRs), on CR Creation/Update/Resume, will fetch the ECR token from AWS, update the secret that holds the token, and patch the default ServiceAccount in the desired namespaces.
  • Last but not least, the operator does a periodic refresh of the ECR token and updates all secrets in the desired namespaces.

By desired namespace, I mean the namespaces in which we want to run pods that use images from private ECR repositories (this is easily configurable using the operator CustomResource).

CR

CR

Operator demo and repo here 🔄 : ecr-creds-refresher

[embed]


메타데이터
post_id
f74ec7b87cb8
slug
ecr-creds-refresher-f74ec7b87cb8
url
https://medium.com/@dejanualex/ecr-creds-refresher-f74ec7b87cb8
canonical_url
https://medium.com/@dejanualex/ecr-creds-refresher-f74ec7b87cb8
author_url
https://medium.com/@dejanualex
status
ok
fetched_at
2026-06-21 07:44:09