Skip to content

fix: a policy's exclude covers its includer's subtree, wherever it sits in includes - #729

Merged
sini merged 1 commit into
mainfrom
fix/policy-exclude-reach
Oct 15, 2026
Merged

sini merged 1 commit into
mainfrom
fix/policy-exclude-reach

Conversation

@sini

@sini sini commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

This is the second excludes gap: den.lib.policy.exclude <aspect>, returned by a policy that sits in an aspect's includes, was ignored. It was traced from a nix-config host: a microVM guest whose tailscale aspect, pulled in through a role, still declared its age secret.

den.aspects.role.includes = [ den.aspects.feat ];
den.policies.drop-feat = { host, ... }: [ (den.lib.policy.exclude den.aspects.feat) ];
den.aspects.igloo.includes = [ den.policies.drop-feat den.aspects.role ];
# feat's nixos content and quirk emits still applied

The aspect-level form, den.aspects.igloo.excludes = [ den.aspects.feat ], already worked through the role.

#728 is the other gap: a schema-included parametric aspect losing its identity. That's a different cause in a different file. The two PRs are independent and don't conflict.

Root cause

Two problems, both in how a policy's exclude was registered.

  1. Timing. A policy in includes is only registered during the include walk (register-aspect-policy). It fires at the scope's dispatch-policies, after the aspect's static includes have already passed gate → check-constraint. The trace shows check feat with no entry, then register-constraint owner=policy identity=feat.
  2. Reach. Even if it registered in time, the entry records the policy's own include chain as ownerChain, and filterByScope applies a subtree exclude only under that chain. It would cover only what the policy itself includes. (issue-540-exclude-guard passes only because its include and exclude come from one policy.)

Fix

registerConstraints (nix/lib/aspects/fx/aspect/children.nix) already registers an aspect's own excludes before its includes are walked. It now does the same for the policies in that aspect's includes:

  • It evaluates each one against the scope's context: scopeContexts plus the aspect's scope handlers, and self, as dispatch binds it.
  • It registers their exclude effects as subtree constraints alongside the aspect's own.

The result is the same timing and the same reach as excludes = [ … ].

A policy whose required arguments the scope doesn't supply yet is skipped here and left to its dispatch, which behaves as before. The later dispatch re-registers the same exclude, which is harmless.

Tests

New file templates/ci/modules/deadbugs/policy-exclude-reaches-includer-subtree.nix:

  • Exclusion cases: a direct include; through a role with the policy first; through a role with the policy last.
  • Quirk emits: dropped too.
  • Controls:
    • the aspect-level excludes through a role;
    • a sibling host that includes the role without the policy keeps the aspect, so the exclude stays the includer's.
check main this PR
new test file 2/6 (the 4 exclusion cases fail) 6/6
nix-config's independent file features/exclude-nested-role.nix (branch test/policy-exclude-reach, 658f9a8) not run 6/6
full templates/ci suite (local) not run 1303/1303

Cost

Each policy listed in an aspect's includes is now evaluated once more, at constraint registration, in addition to its dispatch. Only its exclude effects are used. I didn't measure the cost.

…ts in includes

A policy listed in an aspect's includes fired only at the scope's dispatch.
By then the aspect's static includes had already passed the gate, and the
exclude it registered carried the policy's own include chain, so it reached
only what the policy itself included. policy.exclude therefore removed nothing
the includer pulled in, directly or through a role.

registerConstraints now also evaluates the policies in the aspect's includes
against the scope's context and registers their exclude effects beside the
aspect's own excludes: before any include is gated, with the includer's subtree
as reach. A policy whose arguments the scope does not supply yet is left to its
dispatch.
@github-actions github-actions Bot added the allow-ci allow all CI integration tests label Oct 15, 2026
@sini
sini enabled auto-merge (squash) October 15, 2026 16:02
@sini
sini merged commit c2e6a8e into main Oct 15, 2026
@sini
sini deleted the fix/policy-exclude-reach branch October 15, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

allow-ci allow all CI integration tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants