Patching Docker base images from GitHub to EKS

The simplest way to keep a Docker app on Amazon EKS patched: Dependabot spots a new base image digest, GitHub Actions rebuilds and pushes to ECR, and EKS rolls out the new image.

Published

Tags:

When AWS republishes amazonlinux:2023 with security patches, nothing happens to your running app. Here’s the simplest flow I know that fixes that, for a repo acme/example deployed to Amazon EKS.

Base image update to EKS: AWS republishes amazonlinux:2023 with a new digest, Dependabot opens a pull request, merging to main runs GitHub Actions, which builds, pushes to a private ECR repo and bumps the EKS Deployment, whose worker nodes pull the image to run Pods Excalidraw source: open it at excalidraw.com

This diagram will evolve, so please send feedback, or a pull request with your changes.

1. Dependabot spots the new base image

Pin the base image by digest:

FROM public.ecr.aws/amazonlinux/amazonlinux:2023@sha256:…

Without the digest, FROM …:2023 never changes, so Dependabot has nothing to bump. With it, Dependabot opens a pull request when the 2023 tag points at a new digest:

# .github/dependabot.yml
version: 2
updates:
  - package-ecosystem: docker
    directory: /
    schedule:
      interval: weekly

Weekly means a patch can take a week to ship; use daily if that’s too slow. Renovate does the same, and pays off once you have many repos.

2. GitHub Actions builds, pushes and deploys

Merging the pull request to main runs the workflow. It assumes an IAM role through OIDC, so there are no long-lived AWS keys:

# .github/workflows/deploy.yml
on:
  push:
    branches: [main]
permissions:
  id-token: write
  contents: read
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: aws-actions/configure-aws-credentials@v6
        with:
          role-to-assume: arn:aws:iam::123456789012:role/github-acme-example
          aws-region: eu-west-1
      - uses: aws-actions/amazon-ecr-login@v2
        id: ecr
      - run: |
          image=${{ steps.ecr.outputs.registry }}/acme/example:${{ github.sha }}
          docker build -t "$image" .
          docker push "$image"
          aws eks update-kubeconfig --name prod
          kubectl set image deployment/example example="$image"

The role needs an EKS access entry to run kubectl. Helm or Argo CD can replace the last two lines.

3. ECR: immutable tags, scanning and retention

On the private acme/example repository, turn on:

{
  "rules": [
    {
      "rulePriority": 1,
      "description": "Expire untagged images after 14 days",
      "selection": {
        "tagStatus": "untagged",
        "countType": "sinceImagePushed",
        "countUnit": "days",
        "countNumber": 14
      },
      "action": { "type": "expire" }
    },
    {
      "rulePriority": 2,
      "description": "Keep the last 30 tagged images",
      "selection": {
        "tagStatus": "tagged",
        "tagPatternList": ["*"],
        "countType": "imageCountMoreThan",
        "countNumber": 30
      },
      "action": { "type": "expire" }
    }
  ]
}

ECR applies it within 24 hours and logs each expiry in CloudTrail. Keep enough images to roll back to.

4. EKS pulls and rolls out

kubectl set image updates the Deployment, and each worker node’s kubelet pulls the new image with the node IAM role. The AmazonEC2ContainerRegistryPullOnly managed policy is enough. Kubernetes then replaces the old Pods with new containers, running the patched base.