Skip to content

fix(image): bake explicit substituters/keys instead of accept-flake-config - #782

Merged
c-vigo merged 2 commits into
feature/625-nix-claude-migrationfrom
bugfix/773-explicit-substituters
Jun 30, 2026
Merged

c-vigo merged 2 commits into
feature/625-nix-claude-migrationfrom
bugfix/773-explicit-substituters

Conversation

@c-vigo

@c-vigo c-vigo commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Problem

accept-flake-config = true was baked into the image's /etc/nix/nix.conf. That made any in-container nix run github:attacker/flake silently accept that flake's substituters/trusted-public-keys — the textbook Nix cache-redirection supply-chain attack (PR #670 roadmap thread A).

Fix

  • Remove accept-flake-config = true from the baked nix.conf.
  • Bake explicit substituters + trusted-public-keys so normal builds still hit the caches, while a foreign flake's nixConfig now requires a per-invocation --accept-flake-config.
  • Keep experimental-features and the empty build-users-group = (fix(image): set empty build-users-group in baked nix.conf #750) intact.

Keys/URLs are taken verbatim from the repo's existing source of truth, CONTRIBUTE.md:44-45 (the public vig-os Cachix cache + upstream cache.nixos.org). These are PUBLIC keys, safe to bake.

Baked /etc/nix/nix.conf — before / after

Before:

experimental-features = nix-command flakes
accept-flake-config = true
build-users-group =

After (verified by extracting the built image tarball's bootstrap layer):

experimental-features = nix-command flakes
substituters = https://cache.nixos.org https://vig-os.cachix.org
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= vig-os.cachix.org-1:yoOYRi3bvnM6ThxO0joLt7vtzhTfkq3r6jykeUMg7Bk=
build-users-group =

Cachix key source

vig-os.cachix.org-1:yoOYRi3bvnM6ThxO0joLt7vtzhTfkq3r6jykeUMg7Bk= — CONTRIBUTE.md:45 (the documented vig-os Cachix substituter setup). Not invented.

Tests

Extended tests/test_image.py::TestNixConfiguration (alongside the existing #749 build-users-group assertions) with three testinfra checks against the baked nix.conf:

  • test_nix_conf_does_not_accept_flake_config — asserts accept-flake-config = true is gone.
  • test_nix_conf_bakes_explicit_substituters — asserts both cache URLs present.
  • test_nix_conf_bakes_trusted_public_keys — asserts both public keys present.

Verification

  • nix flake check --accept-flake-config — all checks passed.
  • nix build .#devcontainerImage — succeeded, substituted from caches (no mass source rebuild); extracted the resulting tarball and confirmed the baked nix.conf matches the "after" block above.
  • nixfmt --check flake.nix, ruff check/format on the test, and pre-commit run --files ... — all relevant hooks pass.
  • The image-side testinfra assertions require a running container, so they run in image CI rather than locally.

Branch note

The originally-suggested security/ branch prefix is rejected by the repo's mandatory no-commit-to-branch hook (allowed types: feature|bugfix|hotfix|release|docs|test|refactor, plus chore/ and worktree/). A security fix maps to bugfix, so this PR is on bugfix/773-explicit-substituters.

Closes #773.

c-vigo added 2 commits June 30, 2026 14:59
…onfig

Baking accept-flake-config = true into /etc/nix/nix.conf let any
in-container `nix run github:attacker/flake` silently accept that
flake's substituters/trusted-public-keys, a cache-redirection
supply-chain trapdoor. Drop it and pin the trusted caches explicitly
(cache.nixos.org + the public vig-os Cachix cache) so normal builds
still substitute, while a foreign flake's nixConfig now requires a
per-invocation --accept-flake-config.

Refs: #773
@c-vigo
c-vigo merged commit ee9cfb7 into feature/625-nix-claude-migration Jun 30, 2026
10 checks passed
@c-vigo
c-vigo deleted the bugfix/773-explicit-substituters branch June 30, 2026 13:15
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.

1 participant