Skip to content

fix: keep other secret files out of image builds - #330

Merged
uniqueg merged 2 commits into
devfrom
fix/329-dockerignore-secrets
Nov 2, 2026
Merged

uniqueg merged 2 commits into
devfrom
fix/329-dockerignore-secrets

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Summary

.dockerignore excluded **/.env* but no other secret files, and all of cloud_registry/ is sent to the build. A local cloud_registry/server.pem would be copied into an image layer.

  • Excludes other common secret names at any depth, the same list as trs-filer (fix: keep local .env files out of image builds trs-filer#219): *.env, *.pem, *.key, SSH keys, *.p12, *.pfx, credentials*.json, .netrc, .git-credentials, .pypirc.
  • New test_context_without_secret_files checks them at the root and in included folders, and that similar source file names stay in.

No tracked file matches the new rules. No user or operator doc describes the build context, so no docs change.

Closes #329

Verification

  • Real docker build of a scratch image from all tracked files plus planted dummy secrets: none of the secrets reach the context, and all 25 tracked cloud_registry/ files do.
  • pytest tests/test_image_build.py -k 'secret_files or env_files or context_files', without the repo's conftest.py: 3 passed. The new test fails against the old .dockerignore.
  • ruff check and ruff format --check on the test pass.
  • The full test suite, mypy and the actual image build did not run locally. CI covers them.
  • CI on this PR: all checks pass, including the full test suite, mypy and the image build.

Declined review findings

  • More secret names, e.g. .npmrc, .pgpass, *.jks, .aws/, gcp-credentials.json (adversarial reviewer, low): a list of names can never be complete, and this one deliberately matches trs-filer. An allowlist of file types under cloud_registry/ would close the gap, but that is a design decision for both registries.

Open questions

None.

🤖 Generated with Claude Code

https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG

Summary by Sourcery

Exclude common secret files from Docker image build contexts while preserving legitimate source files with similar names.

Bug Fixes:

  • Prevent common secret files from being included in Docker build contexts, including nested files in cloud_registry/.

Tests:

  • Add coverage verifying secret files are excluded at the repository root and in included directories while similarly named source files remain included.

uniqueg and others added 2 commits November 2, 2026 19:54
Exclude common secret names at any depth from the build context, as
trs-filer does. All of cloud_registry/ is sent to the build, so a local
key or credentials file there would end up in an image layer.

Closes #329

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
@sourcery-ai

sourcery-ai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR hardens Docker image builds by extending .dockerignore with trs-filer-aligned patterns for common secret files at any depth, while adding context-level regression tests that validate nested exclusions without filtering legitimate source files.

File-Level Changes

Change Details Files
Expand Docker build-context exclusions to cover common secret files at any directory depth.
  • Add ignore patterns for environment files, certificates/keys, SSH keys, PKCS#12 archives, credential JSON files, and common credential files.
  • Keep the existing build-context behavior for non-secret source files with similar names.
.dockerignore
Add regression coverage for secret exclusion and source-file preservation.
  • Verify representative secret names are excluded at the repository root and within included cloud_registry subdirectories.
  • Verify source files such as keys.py, credentials.py, and tokens.pem.yaml remain in the context.
tests/test_image_build.py

Possibly linked issues


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

@codecov

codecov Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (f2232e5) to head (db0f4a3).
⚠️ Report is 1 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #330   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           22        22           
  Lines         2368      2368           
=========================================
  Hits          2368      2368           

☔ 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 2, 2026 19:05

@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 reviewed your changes and they look great!

Linked issues

#329 Exclude other secret files from image builds · 2 of 2 met

# Requirement Status Notes
1 Exclude the same common secret file names as trs-filer from image builds at any depth. ✅ Met .dockerignore adds patterns for .env files, PEM and key files, SSH keys, P12/PFX files, credentials JSON, .netrc, .git-credentials, and .pypirc.
2 Add a test for the exclusions. ✅ Met test_context_without_secret_files checks representative names at the root and in included folders, and verifies near-match source filenames remain included.

Sourcery assessment

Approved.


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

@uniqueg
uniqueg merged commit 9a6dc48 into dev Nov 2, 2026
48 of 56 checks passed
@uniqueg
uniqueg deleted the fix/329-dockerignore-secrets branch November 2, 2026 19:19
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.

Exclude other secret files from image builds

1 participant