Skip to content

build: pick up OS security updates in images - #749

Merged
uniqueg merged 7 commits into
devfrom
build/os-security-updates
Nov 9, 2026
Merged

uniqueg merged 7 commits into
devfrom
build/os-security-updates

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Summary

FOCA's images inherit fixable OS vulnerabilities from their pinned python:3.X-slim-trixie base images, currently zlib1g 1:1.3.dfsg+really1.3.1-1+b1 (CVE-2026-76844 and CVE-2026-85091, high; CVE-2026-27171, medium). The fix (+deb13u1) is in trixie-security, but not in any upstream base image yet, not even the latest python:3.13-slim-trixie digest (sha256:e48f59cd..., checked 2026-11-08), so a digest bump doesn't help.

The base stage of docker/Dockerfile now installs all pending Debian updates instead of upgrading apt alone (#697):

RUN apt-get update --error-on=any && \
    DEBIAN_FRONTEND=noninteractive \
        apt-get upgrade -y --with-new-pkgs --no-install-recommends \
            -o Dpkg::Options::=--force-confdef \
            -o Dpkg::Options::=--force-confold && \
    if apt-get -s dist-upgrade | grep '^Inst '; then \
        echo "Updates kept back (listed above), see docker/Dockerfile" >&2; \
        exit 1; \
    fi && \
    rm -rf /var/lib/apt/lists/*
  • --error-on=any fails the build if a package index can't be fetched. Without it, apt-get update exits 0 on fetch errors and the upgrade silently does nothing; this happened in a local build (the Python 3.12 image kept apt 3.0.3 and zlib1g +b1).
  • --with-new-pkgs installs updates that need new packages instead of keeping them back.
  • The guard fails the build if updates are still kept back (e.g. ones that need a package removed). The build doesn't run dist-upgrade: letting the base image remove packages on its own could break the image silently, so a maintainer decides.
  • The dpkg options keep locally modified configuration files without a prompt, so builds can't hang or fail on one.

So OS fixes reach FOCA's images, and every image built on them (proTES, cloud-registry, trs-filer, Pubgrade, Pubgrade-Sidecar), with the next build, without a Dockerfile change per advisory. As a trade-off, builds of the same commit at different times may differ in their OS packages. This includes release images, which are rebuilt at tag time. The docs say so.

The test of the base stage (tests/test_image_requirements.py) now checks the general upgrade step. Docs are updated: getting started (Docker), deployment (image scans), contributing (image scan, base images, release flow), and the 0.22.0 release notes (Security).

After 0.22.0 is released and downstream images move to it, the temporary Trivy ignores of the zlib1g findings in Pubgrade-Sidecar and cloud-registry (expiring 2026-11-30) can be removed.

Closes #747

Verification

  • pytest tests/test_image_requirements.py: 18 passed. The new test failed before the Dockerfile change.
  • ruff check, ruff format --check, mypy: pass. mkdocs build --strict: passes.
  • Built all five images locally with docker build --no-cache -f docker/Dockerfile --build-arg PY_IMAGE=3.X-slim-trixie . (3.11 to 3.15). All have apt 3.0.4 and zlib1g 1:1.3.dfsg+really1.3.1-1+deb13u1, and import foca works.
  • Trivy (aquasec/trivy:latest image --scanners vuln --ignore-unfixed --ignorefile .trivyignore.yaml):
  • CI on 0589443 (runs 42514975708 and 42514989123, after the dist-upgrade guard): all checks pass, 3 skipped as intended on PRs (Push image, Publish image, Trivy upload); Scan image passes for Python 3.11 to 3.15; no open code scanning alerts for the PR.

Reviews

adversarial-reviewer and quality-reviewer ran in round 1, and adversarial-reviewer ran again in round 2. All findings were fixed:

  • Round 1, medium: updates that need new packages were kept back silently; fixed with --with-new-pkgs.
  • Round 1, medium: the release notes and the Dockerfile comment listed different CVEs; aligned.
  • Round 1, medium: the test gave no message when the step was missing; added one.
  • Round 1, lows: dpkg conffile prompts, docs on uncached builds and release-rebuild drift, wrapping, and the user-facing reproducibility note.
  • Sourcery (3 medium threads): removals kept back, ignored index fetch errors, and the order of update and upgrade; fixed in 0589443 with the guard and an anchored test.
  • Round 2, lows: the wording of the conffile comment, and the test now checks only the command, not the comments that follow it.

Declined review findings

  • Round 1, low (adversarial): add a smoke run of the release digest in release.yml. That changes the release workflow, which is out of scope here. The OS package drift of release images is documented instead, and the release scan still gates publishing.

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Install available Debian OS updates during image builds so released security fixes reach FOCA and downstream images without per-advisory Dockerfile changes.

Bug Fixes:

  • Ensure container images receive all available Debian security and OS package updates during each build, including fixes not yet present in the pinned upstream base images.

Enhancements:

  • Make base-image upgrades fail clearly when package indexes cannot be fetched or updates remain held back, while avoiding interactive configuration prompts.
  • Update image requirements tests to validate the general OS upgrade step and document build-time package variability and release-image rebuild behavior.

Documentation:

  • Document that images install Debian updates at build time and may contain different OS package versions when rebuilt.

Tests:

  • Expand Dockerfile image requirement coverage to verify reliable, complete OS package upgrades.

uniqueg and others added 5 commits November 8, 2026 19:24
Upgrade all Debian packages in the base stage with apt-get upgrade
instead of single ones, so that the images get the fixes Debian has
released (e.g., zlib1g for CVE-2026-76844 and CVE-2026-85091) before
the upstream Python images have them. apt-get update fails if an index
can't be fetched, which would otherwise leave the packages as they are.

Refs #747

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #747

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Install updates that need new packages (--with-new-pkgs) instead of
keeping them back, and keep changed configuration files without a
dpkg prompt (--force-confdef, --force-confold), so that fixes aren't
left out silently and builds don't fail on a prompt.

Refs #747

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Limit the checks of the upgrade step to the command itself, without
the comments that follow it, and word the Dockerfile comment on
configuration files precisely.

Refs #747

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Configuration

Upgrade all Debian packages in the Docker base stage, fail on unavailable indexes or updates still kept back, and install new dependencies noninteractively so released OS fixes reach derived images.

  • docker/Dockerfile L31-51

Documentation

Explain that builds install available Debian updates and may therefore differ over time, including guidance for image scans, local builds, deployment, and releases.

  • docs/contributing/index.md L133-142, L179-181, L284-286
  • docs/deployment.md L473-477
  • docs/getting-started.md L127-131
  • docs/releases/0.22.0.md L17

Tests

Replace the apt-only Dockerfile check with assertions covering the general OS upgrade command, its failure behavior, and its noninteractive options.

  • tests/test_image_requirements.py L42-74

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Refs #747

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codecov

codecov Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (d5595dc) to head (0589443).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #749   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           74        74           
  Lines         9434      9434           
=========================================
  Hits          9434      9434           
Flag Coverage Δ
test_unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 8, 2026 19:18

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="docker/Dockerfile" line_range="43" />
<code_context>
+# modified in the base image keep their version, without a prompt
+RUN apt-get update --error-on=any && \
+    DEBIAN_FRONTEND=noninteractive \
+        apt-get upgrade -y --with-new-pkgs --no-install-recommends \
+            -o Dpkg::Options::=--force-confdef \
+            -o Dpkg::Options::=--force-confold && \
</code_context>
<issue_to_address>
**Vulnerable package remains in image**

When a Debian security update requires removing an installed package, `apt-get upgrade --with-new-pkgs` keeps the update back while exiting successfully, so the image retains the vulnerable package despite the expectation that pending updates are installed.

Use an upgrade command that permits removing installed packages and ensure the build fails if the security update cannot be applied.

Also at `docs/contributing/index.md:135-136`, `docs/deployment.md:474-476`.
</issue_to_address>

### Comment 2
<location path="tests/test_image_requirements.py" line_range="56" />
<code_context>
+    run = re.split(r"(?<!\\)\n", run, maxsplit=1)[0]
+    # Fails if an index can't be fetched, which would otherwise leave the
+    # packages as they are, without an error
+    assert re.search(r"\bapt-get update --error-on=any\b", run)
+    # Also updates that need new packages, which would be kept back otherwise
+    assert re.search(r"\bapt-get upgrade\b[^&]*\s--with-new-pkgs\b", run)
</code_context>
<issue_to_address>
**Failed index fetch is ignored**

When the Docker command suppresses `apt-get update`'s nonzero exit status before running the upgrade, `test_base_stage_upgrades_os_packages` checks for the update and upgrade text separately at lines 55 and 57, so it passes if the update's failure is suppressed and the upgrade continues using stale indexes.

Assert that the update and upgrade are chained so a failed update stops the build.
</issue_to_address>

### Comment 3
<location path="tests/test_image_requirements.py" line_range="58" />
<code_context>
+    # packages as they are, without an error
+    assert re.search(r"\bapt-get update --error-on=any\b", run)
+    # Also updates that need new packages, which would be kept back otherwise
+    assert re.search(r"\bapt-get upgrade\b[^&]*\s--with-new-pkgs\b", run)
+    # Without prompts, of debconf and of dpkg for changed configuration files
+    assert "DEBIAN_FRONTEND=noninteractive" in run
</code_context>
<issue_to_address>
**Upgrade uses stale package index**

When the Docker command places `apt-get upgrade` before `apt-get update` in the same step, `test_base_stage_upgrades_os_packages` independently searches for the update at line 55 and upgrade at line 57, so it passes if the upgrade runs before the update and misses fixes available from the refreshed index.

Assert that the update precedes the upgrade in the command.
</issue_to_address>

Linked issues

#747 build: pick up OS security updates in images · 3 of 4 met · 1 to check by hand

# Requirement Status Notes
1 Install all pending Debian updates in the base stage instead of upgrading single packages. ✅ Met The base stage runs apt-get update --error-on=any and apt-get upgrade --with-new-pkgs --no-install-recommends; it also handles configuration files noninteractively.
2 Update the test of the base stage. ✅ Met test_base_stage_upgrades_os_packages checks the update and upgrade command options and that the step is in the base stage.
3 Document the build-time Debian updates in the image documentation and release notes. ✅ Met The getting-started, deployment, and contributing docs, and the 0.22.0 release notes describe the updates and their availability at build time.
4 Have all Python-version images pass the CI scan with no fixable critical or high findings, including zlib1g. 👀 Check by hand (runtime) Verify the reported CI scan results for every Python version and confirm they show no fixable critical or high findings.

Sourcery assessment

Needs a human reviewer. 3 findings to address first, and the build now upgrades all available Debian packages, so an incompatible update could change runtime behavior or break an image. Published images retain those package versions after a code revert, but the bounded impact can be repaired by rebuilding and replacing the affected images.

Blocking findings: docker/Dockerfile:43, tests/test_image_requirements.py:56, tests/test_image_requirements.py:58


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread docker/Dockerfile Resolved
Comment thread tests/test_image_requirements.py Resolved
Comment thread tests/test_image_requirements.py Resolved
Fail the build if updates are still kept back after the upgrade (e.g.,
as they would remove packages), listing them, instead of leaving them
out silently, and check in the test that the update comes first and
stops the step on failure (Sourcery review).

Refs #747

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit b165cb9 into dev Nov 9, 2026
83 checks passed
@uniqueg
uniqueg deleted the build/os-security-updates branch November 9, 2026 00:38
@uniqueg uniqueg added this to the v0.22.0 milestone Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build: pick up OS security updates in images

1 participant