Skip to content

Pin the hardened base images and refresh them through the CI upgrade - #76023

Merged
vatsrahul1001 merged 20 commits into
mainfrom
mirror-hardened-images-more-often
Oct 30, 2026
Merged

vatsrahul1001 merged 20 commits into
mainfrom
mirror-hardened-images-more-often

Conversation

@potiuk

@potiuk potiuk commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

CI reproducibility

CI and PROD images were built on the moving tags of our ghcr.io mirror of the Docker Hardened Images. Docker rebuilds those tags in place, so every mirror refresh changed the image every build started from. Nothing changed in the repository, and the full CI had not run on the new image. A CI run could pass or fail depending only on when it ran, and rebuilding the same commit later produced a different image.

The breakage of "Test examples of PROD image building" is an example (run). The mirrored base had libbz2-1.0 1.0.8-6+dhi2, while the dhi.io apt repository had already moved to a bzip2 that needs 1.0.8-6+deb13u0+dhi2, so build-essential could not be installed (docker-hardened-images/catalog#689). Docker fixed it only in the images of its current Python patch releases.

Base images pinned to what the CI passed on

  • Builds use a digest, not a tag. BASE_IMAGE is ghcr.io/apache/airflow/base/python:<tag>@sha256:<digest> for breeze-built CI and PROD images and for the Dockerfile / Dockerfile.ci defaults. The digests live in dev/breeze/src/airflow_breeze/files/hardened_python_image_digests.json, covering Python 3.11–3.14 on Debian 13 and 12.
  • Only the upgrade moves the pins. "Upgrade important CI environment" (breeze ci upgrade, upgrade_important_versions.py) reads the current digests from the mirror, rewrites the pins file and every reference that already carries a digest, and opens the upgrade PR. A new base image reaches the builds only after the full CI has passed on it.
  • This PR moves the images to Docker's current Python patch releases (3.11.18, 3.12.16, 3.13.18, 3.14.8), whose images carry the fixed package numbering.
  • Pinned digests stay tagged. The mirror tags every mirrored and every pinned digest as <tag>-<digest12>, so the image a pin or an open upgrade PR refers to never becomes untagged.
  • Local rebuilds follow the pins. The pins file is in FILES_FOR_REBUILD_CHECK, so a changed pin also changes the CI image sources hash and makes breeze rebuild.

Mirroring

  • The mirror refreshes every six hours instead of weekly, from main only. main mirrors every Python version an active release branch still builds on (ALL_PYTHON_MAJOR_MINOR_VERSIONS), so release branches need no mirror runs of their own.
  • A tag that moves past its pin starts the main upgrade check, so the pins follow Docker's rebuilds within hours. The dhi.io apt repository moves together with the images, and a pin left behind for long stops matching what apt installs. The scheduled Mon/Wed/Fri upgrade check stays as the backstop.
  • Every upgrade mirrors first. The upgrade check workflow runs the mirror in a job of its own and waits for it, so the token that may dispatch workflows never reaches the job running the upgraded third-party tools. A local breeze ci upgrade does the same, after checking that the gh credentials may dispatch apache/airflow workflows (--no-mirror-base-images skips it). An upgrade of main tells the mirror not to start a second main upgrade.

Python version

  • AIRFLOW_PYTHON_VERSION is no longer written into files. It is empty by default: the hardened flavor takes Python from BASE_IMAGE, and a version passed that does not match it fails the build. Breeze passes the patch release of the image it builds on, and the docs examples no longer set it.
  • The legacy flavor has patch releases of its own. It compiles Python from python.org, which publishes a patch release days before the hardened images do (python.org is at 3.14.10, the hardened images at 3.14.8). The upgrade fills legacy_python_versions.json from python.org, skipping release directories that only hold pre-releases, and breeze passes those versions for legacy builds, so a new python.org release rebuilds the legacy images instead of reusing a cached layer. A direct docker build of the legacy flavor accepts MAJOR.MINOR and builds the latest release of that line.

apt prefers Docker's packages

The hardened images keep stock Debian's sources beside dhi.io, and apt took whichever offered the higher version, mixing Debian builds into an image whose dependencies Docker built (docker-hardened-images/catalog#610). /etc/apt/preferences.d/airflow-prefer-dhi ranks dhi.io at 999 - above Debian, below 1000, so it never forces a downgrade. The PostgreSQL repository the image adds for postgresql-client is ranked at 1001, so apt takes PGDG's libpq5, which postgresql-client-18 needs and dhi.io does not carry. The preferences stay in the image, so images extending it get the same behaviour.

One command before a release

The release manager runs one command, which mirrors the base images and then upgrades the branch, before a beta and before the test-to-stable PR (dev/README_RELEASE_AIRFLOW.md):

  • breeze workflow-run upgrade-check --branch main before a beta: runs the upgrade check workflow, which opens the [main] upgrade PR, and waits for it.
  • breeze workflow-run upgrade-check --branch vX-Y-test before the test-to-stable PR: runs the upgrade in the release manager's checkout and pushes it straight to vX-Y-test, the head of that PR. It runs locally because the release branch rules let only committers push there without CI having passed. It never switches, resets or cleans the checkout: when it is not at the tip of the branch or has local changes, it fails and says what to do.

--branch defaults to the branch breeze comes from and completes to the branches that have an upgrade check workflow.

Runners

A build-info job on ubuntu-slim picks the runners the way CI does: self-hosted RunsOn runners in apache/airflow, public runners when the repository variable USE_PUBLIC_RUNNERS is true. The upgrade, which builds the CI image and runs every hook, gets the CI image build class (8+16 CPUs, 32+64 GB). The mirror, which only copies manifests between registries, gets the smallest (2+4 CPUs, 8+16 GB). The job that only dispatches the mirror and waits for it stays on ubuntu-slim. The breeze action gets a free-space input, as freeing disk space needs swap control and docker, which ubuntu-slim does not have and the jobs there do not need.

Every other build-info job moves to ubuntu-slim as well (CI AMD/ARM, the release, constraints, docs-publishing and image-cache workflows): they only install breeze and run selective checks, so they drop the sudo workspace cleanup and the disk cleanup. The fork CI gate job already ran there.

Not covered

Only the base image is pinned. Packages installed with apt during the build still come from the live repositories. Neither Docker nor the third-party repositories we use offer snapshots we could pin to, and pinning individual package versions would fail as soon as a repository drops a superseded version.

Checks run

  • uv run --project dev/breeze pytest dev/breeze/tests/test_ci_upgrade.py dev/breeze/tests/test_workflow_commands.py dev/breeze/tests/test_gh_workflow_utils.py dev/breeze/tests/test_mirror_base_images.py dev/breeze/tests/test_build_prod_params.py: 95 passed.
  • uv run --project scripts pytest scripts/tests/ci/prek/test_upgrade_important_versions.py: 41 passed.
  • prek run --from-ref main --stage pre-commit: passed, except lychee-docker, lint-dockerfile and shellcheck, which were skipped because they need a local Docker daemon. They run in CI.
  • Not run: the mirror and upgrade workflows themselves, and the python.org lookup in a direct legacy docker build.

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Claude Code (Opus 5) following the guidelines


🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ 3 job(s) of attempt 1 were stopped because AWS reclaimed their EC2 Spot instances. These are not test failures.

RunsOn re-runs them automatically when the run finishes; no action is needed.

potiuk and others added 7 commits October 30, 2026 13:42
Docker rebuilds the hardened images in place and moves the dhi.io apt
repository on at the same time. With a weekly mirror, the base images
Airflow builds on lag the repository by up to a week, and any apt
install whose dependencies were rebuilt in between fails: build-essential
currently cannot be installed because the mirrored base has an older
libbz2 than the bzip2 the repository offers
(docker-hardened-images/catalog#689). Mirroring copies manifests between
registries without pulling layers, so running it several times a day is
cheap.

Generated-by: Claude Opus 5
Building on the mirror's moving tags made CI non-reproducible: any
refresh of the mirror changed the image every build started from,
without a change in the repository and without the full CI having run
on it. A CI run could pass or fail depending only on when it ran, and
rebuilding the same commit later gave a different image.

The images now build on a digest, and only the upgrade check moves it,
in a PR that must pass the full CI before the new base is used. The
mirror refreshes every six hours and triggers that upgrade check when it
moves a tag past its pin, so the pins follow Docker's rebuilds - and the
dhi.io apt repository moving with them - within hours rather than drift
behind it. Every pinned and mirrored digest keeps a tag of its own, so a
pinned image never becomes untagged.

The hardened images keep stock Debian's apt sources beside dhi.io, and
apt took whichever offered the higher version, mixing Debian builds into
an image whose dependencies were built by Docker. dhi.io is now
preferred whenever it publishes the package.

Generated-by: Claude Opus 5
Docker renumbered its builds ("1.0.8-6+dhi2" became
"1.0.8-6+deb13u0+dhi2", which sorts lower) and its apt repository moved
to the new numbers before its images did. Every package depending on a
renumbered build - bzip2, libffi-dev, libgpg-error-dev among them - is
then uninstallable, because apt will not replace the image's
higher-numbered copy with the repository's lower-numbered one, and the
CI image build fails (docker-hardened-images/catalog#689). Every package
in the image comes from dhi.io, so letting its repository decide their
versions is safe, and it keeps the build working through such a
renumbering.

Generated-by: Claude Opus 5
Docker stops rebuilding a Python patch release once it publishes the
next, so the 3.11.17, 3.12.15 and 3.13.16 images still carry the old
package numbering that the dhi.io apt repository has moved past, and
installing packages on them fails (docker-hardened-images/catalog#689).
Docker fixed it in the images of the current patch releases.

Generated with the Python part of the upgrade check, which also pins
the new images to the digests the mirror serves for them.

Generated-by: Claude Opus 5
At priority 1001 the Package:* dhi.io preference forces dhi.io's build even as a downgrade, so apt keeps dhi.io's libpq5 17.11 and postgresql-client-18 (which needs libpq5 >= 18.6 from PGDG) cannot be installed. Below 1000 the preference still favours dhi.io for the packages it publishes but lets apt take a newer version from another repository to satisfy a dependency. The forced "downgrade" the >1000 priority handled no longer arises now the base image is pinned to a digest CI has passed on.
install_postgres adds the PGDG repository, but the hardened image's Package:* dhi.io preference outranks Debian's default, so apt kept dhi.io's libpq and postgresql-client-18 (which needs a newer libpq5 than dhi.io carries) failed with held broken packages. Pinning the PostgreSQL origin above the dhi.io preference lets apt take libpq from PGDG to satisfy the client.
vatsrahul1001 and others added 11 commits October 30, 2026 13:42
The docker-stack docs spellcheck rejects the British spelling favours in build.rst; use the US spelling there and in the matching install-script comments.
Docker publishes hardened Python patch releases often, and every one of them
had to be repeated in the Dockerfiles, the docs examples and the reference
docs, although the hardened flavor takes Python from the base image anyway.
Passing a version that disagrees with the base image now fails the build
instead of producing an image with the wrong label.

The legacy flavor compiles Python from python.org sources, which get a patch
release days before the hardened images do. It gets patchlevels of its own,
which the upgrade check moves, so a new python.org release changes its build
argument and rebuilds the legacy images instead of reusing a cached layer.

Generated-by: Claude Opus 5
The base images and Python patch releases are pinned, and only the upgrade
check moves the pins, to images the mirror already has. A release cut
without running both could ship base images and Python patch releases that
are days or weeks old, missing security fixes Docker and python.org have
already published.

Generated-by: Claude Opus 5
A server error for the newest release fell through to an older one, and the
upgrade check would then have downgraded the legacy Python pin.

Generated-by: Claude Opus 5
The mirror is the same registry for every branch, and a release branch's
upgrade check pins the newest patch release, which main's run mirrors anyway.
Runs from release branches only duplicated main's. Main mirrors the full
list of Python versions an active release branch still builds on, so a
version main has dropped keeps being refreshed while a release branch uses it.

Generated-by: Claude Opus 5
Release managers run the mirror and the upgrade check before every release,
and need to know both finished before they go on. The commands wait for the
runs and fail when one does not succeed, and the upgrade check defaults to
the branch breeze comes from.

Generated-by: Claude Opus 5
The upgrade check pins the images the mirror serves, so a check run against
a stale mirror pins stale images, and remembering to mirror first was one
more manual step before every release. The check now runs the mirror on
main itself, locally as well as in CI, and fails early, before dispatching
anything, when the gh credentials cannot dispatch workflows. The release
process runs it before every beta and before every test-to-stable sync.

Generated-by: Claude Opus 5
A main upgrade check that mirrors first would otherwise have the mirror
start another main upgrade as soon as a tag moved past its pin, and the two
would force-push over each other's PR. An explicit --github-token is also
handed to the mirror's gh calls, which do not see the upgrade's command
environment.

Generated-by: Claude Opus 5
The upgrade job runs the third-party tools and hooks it upgrades, with a
token that may push. Giving that token "actions: write" as well would let
any of that code dispatch, re-run or cancel workflows. A separate job that
only dispatches the mirror holds that permission now, and the upgrade job
waits for it.

Generated-by: Claude Opus 5
Before a beta the upgrade goes through a PR to main, but before a
test-to-stable PR it belongs on the release branch itself, the head of
that PR, so the PR's CI tests it. The release branch rules let only
committers push there without CI having passed, so that upgrade runs in
the release manager's checkout. It refuses to run on a checkout that is
not at the tip of the branch or has local changes, instead of resetting
it and losing them.

Generated-by: Claude Opus 5
Staging with "git add ." took only the current directory, so running the
release-branch upgrade from a subdirectory could push part of it.

Generated-by: Claude Opus 5
@potiuk
potiuk force-pushed the mirror-hardened-images-more-often branch from 1f37210 to 7e6dc7c Compare October 30, 2026 12:44
@potiuk potiuk changed the title Pin the hardened base images to digests the CI has passed on Pin the hardened base images and refresh them through the CI upgrade Oct 30, 2026
The mirror and upgrade check ran on public runners whatever they did. The
upgrade builds the CI image and runs every hook, so it gets the CI image
build class of the self-hosted runners, while the mirror only copies
manifests and gets the smallest one. A build-info job on ubuntu-slim picks
the runners the way CI does, and the job that only dispatches the mirror
and waits stays on ubuntu-slim too. Freeing disk space needs swap control
and docker, which ubuntu-slim does not have and jobs there do not need, so
the breeze action can skip it.

Generated-by: Claude Opus 5
Build-info jobs only install breeze and run selective checks, yet each
took a full public runner, cleaned its workspace with sudo and freed disk
space, none of which a fresh ubuntu-slim container needs.

Generated-by: Claude Opus 5
@vatsrahul1001
vatsrahul1001 merged commit 4843535 into main Oct 30, 2026
291 of 295 checks passed
@vatsrahul1001
vatsrahul1001 deleted the mirror-hardened-images-more-often branch October 30, 2026 13:52
@github-actions

Copy link
Copy Markdown
Contributor

Backport failed to create: v3-4-test. View the failure log Run details

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
❌ v3-4-test Commit Link

You can attempt to backport this manually by running:

cherry_picker 4843535 v3-4-test

This should apply the commit to the v3-4-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.

After you have resolved the conflicts, you can continue the backport process by running:

cherry_picker --continue

If you don't have cherry-picker installed, see the installation guide.

vatsrahul1001 added a commit that referenced this pull request Oct 30, 2026
…#76038)

* Refresh the hardened base image mirror every six hours

Docker rebuilds the hardened images in place and moves the dhi.io apt
repository on at the same time. With a weekly mirror, the base images
Airflow builds on lag the repository by up to a week, and any apt
install whose dependencies were rebuilt in between fails: build-essential
currently cannot be installed because the mirrored base has an older
libbz2 than the bzip2 the repository offers
(docker-hardened-images/catalog#689). Mirroring copies manifests between
registries without pulling layers, so running it several times a day is
cheap.

Generated-by: Claude Opus 5

* Pin the hardened base images to digests the CI has passed on

Building on the mirror's moving tags made CI non-reproducible: any
refresh of the mirror changed the image every build started from,
without a change in the repository and without the full CI having run
on it. A CI run could pass or fail depending only on when it ran, and
rebuilding the same commit later gave a different image.

The images now build on a digest, and only the upgrade check moves it,
in a PR that must pass the full CI before the new base is used. The
mirror refreshes every six hours and triggers that upgrade check when it
moves a tag past its pin, so the pins follow Docker's rebuilds - and the
dhi.io apt repository moving with them - within hours rather than drift
behind it. Every pinned and mirrored digest keeps a tag of its own, so a
pinned image never becomes untagged.

The hardened images keep stock Debian's apt sources beside dhi.io, and
apt took whichever offered the higher version, mixing Debian builds into
an image whose dependencies were built by Docker. dhi.io is now
preferred whenever it publishes the package.

Generated-by: Claude Opus 5

* Let dhi.io's package versions win over the image's own

Docker renumbered its builds ("1.0.8-6+dhi2" became
"1.0.8-6+deb13u0+dhi2", which sorts lower) and its apt repository moved
to the new numbers before its images did. Every package depending on a
renumbered build - bzip2, libffi-dev, libgpg-error-dev among them - is
then uninstallable, because apt will not replace the image's
higher-numbered copy with the repository's lower-numbered one, and the
CI image build fails (docker-hardened-images/catalog#689). Every package
in the image comes from dhi.io, so letting its repository decide their
versions is safe, and it keeps the build working through such a
renumbering.

Generated-by: Claude Opus 5

* Move the base images to Docker's current Python patch releases

Docker stops rebuilding a Python patch release once it publishes the
next, so the 3.11.17, 3.12.15 and 3.13.16 images still carry the old
package numbering that the dhi.io apt repository has moved past, and
installing packages on them fails (docker-hardened-images/catalog#689).
Docker fixed it in the images of the current patch releases.

Generated with the Python part of the upgrade check, which also pins
the new images to the digests the mirror serves for them.

Generated-by: Claude Opus 5

* Compare the registry host exactly in the mirror test

Generated-by: Claude Opus 5

* Lower the dhi.io apt pin below 1000 so dependencies can resolve

At priority 1001 the Package:* dhi.io preference forces dhi.io's build even as a downgrade, so apt keeps dhi.io's libpq5 17.11 and postgresql-client-18 (which needs libpq5 >= 18.6 from PGDG) cannot be installed. Below 1000 the preference still favours dhi.io for the packages it publishes but lets apt take a newer version from another repository to satisfy a dependency. The forced "downgrade" the >1000 priority handled no longer arises now the base image is pinned to a digest CI has passed on.

* Rank the PostgreSQL apt repository above the dhi.io preference

install_postgres adds the PGDG repository, but the hardened image's Package:* dhi.io preference outranks Debian's default, so apt kept dhi.io's libpq and postgresql-client-18 (which needs a newer libpq5 than dhi.io carries) failed with held broken packages. Pinning the PostgreSQL origin above the dhi.io preference lets apt take libpq from PGDG to satisfy the client.

* Use US spelling favors to pass the docs spellcheck

The docker-stack docs spellcheck rejects the British spelling favours in build.rst; use the US spelling there and in the matching install-script comments.

---------

Co-authored-by: Rahul Vats <43964496+vatsrahul1001@users.noreply.github.com>

(cherry picked from commit 4843535)

Co-authored-by: Jarek Potiuk <jarek@potiuk.com>
vatsrahul1001 added a commit that referenced this pull request Oct 30, 2026
…#76038)

* Refresh the hardened base image mirror every six hours

Docker rebuilds the hardened images in place and moves the dhi.io apt
repository on at the same time. With a weekly mirror, the base images
Airflow builds on lag the repository by up to a week, and any apt
install whose dependencies were rebuilt in between fails: build-essential
currently cannot be installed because the mirrored base has an older
libbz2 than the bzip2 the repository offers
(docker-hardened-images/catalog#689). Mirroring copies manifests between
registries without pulling layers, so running it several times a day is
cheap.

Generated-by: Claude Opus 5

* Pin the hardened base images to digests the CI has passed on

Building on the mirror's moving tags made CI non-reproducible: any
refresh of the mirror changed the image every build started from,
without a change in the repository and without the full CI having run
on it. A CI run could pass or fail depending only on when it ran, and
rebuilding the same commit later gave a different image.

The images now build on a digest, and only the upgrade check moves it,
in a PR that must pass the full CI before the new base is used. The
mirror refreshes every six hours and triggers that upgrade check when it
moves a tag past its pin, so the pins follow Docker's rebuilds - and the
dhi.io apt repository moving with them - within hours rather than drift
behind it. Every pinned and mirrored digest keeps a tag of its own, so a
pinned image never becomes untagged.

The hardened images keep stock Debian's apt sources beside dhi.io, and
apt took whichever offered the higher version, mixing Debian builds into
an image whose dependencies were built by Docker. dhi.io is now
preferred whenever it publishes the package.

Generated-by: Claude Opus 5

* Let dhi.io's package versions win over the image's own

Docker renumbered its builds ("1.0.8-6+dhi2" became
"1.0.8-6+deb13u0+dhi2", which sorts lower) and its apt repository moved
to the new numbers before its images did. Every package depending on a
renumbered build - bzip2, libffi-dev, libgpg-error-dev among them - is
then uninstallable, because apt will not replace the image's
higher-numbered copy with the repository's lower-numbered one, and the
CI image build fails (docker-hardened-images/catalog#689). Every package
in the image comes from dhi.io, so letting its repository decide their
versions is safe, and it keeps the build working through such a
renumbering.

Generated-by: Claude Opus 5

* Move the base images to Docker's current Python patch releases

Docker stops rebuilding a Python patch release once it publishes the
next, so the 3.11.17, 3.12.15 and 3.13.16 images still carry the old
package numbering that the dhi.io apt repository has moved past, and
installing packages on them fails (docker-hardened-images/catalog#689).
Docker fixed it in the images of the current patch releases.

Generated with the Python part of the upgrade check, which also pins
the new images to the digests the mirror serves for them.

Generated-by: Claude Opus 5

* Compare the registry host exactly in the mirror test

Generated-by: Claude Opus 5

* Lower the dhi.io apt pin below 1000 so dependencies can resolve

At priority 1001 the Package:* dhi.io preference forces dhi.io's build even as a downgrade, so apt keeps dhi.io's libpq5 17.11 and postgresql-client-18 (which needs libpq5 >= 18.6 from PGDG) cannot be installed. Below 1000 the preference still favours dhi.io for the packages it publishes but lets apt take a newer version from another repository to satisfy a dependency. The forced "downgrade" the >1000 priority handled no longer arises now the base image is pinned to a digest CI has passed on.

* Rank the PostgreSQL apt repository above the dhi.io preference

install_postgres adds the PGDG repository, but the hardened image's Package:* dhi.io preference outranks Debian's default, so apt kept dhi.io's libpq and postgresql-client-18 (which needs a newer libpq5 than dhi.io carries) failed with held broken packages. Pinning the PostgreSQL origin above the dhi.io preference lets apt take libpq from PGDG to satisfy the client.

* Use US spelling favors to pass the docs spellcheck

The docker-stack docs spellcheck rejects the British spelling favours in build.rst; use the US spelling there and in the matching install-script comments.

---------

Co-authored-by: Rahul Vats <43964496+vatsrahul1001@users.noreply.github.com>

(cherry picked from commit 4843535)

Co-authored-by: Jarek Potiuk <jarek@potiuk.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants