Skip to content

securitypolicy tool: don't add the pause container to open-door policies - #2933

Merged
Maksim An (anmaxvl) merged 1 commit into
microsoft:mainfrom
veerun14:securitypolicy-allow-all-open-door
Sep 15, 2026
Merged

Maksim An (anmaxvl) merged 1 commit into
microsoft:mainfrom
veerun14:securitypolicy-allow-all-open-door

Conversation

@veerun14

Copy link
Copy Markdown
Contributor

Problem

internal/tools/securitypolicy unconditionally appends securitypolicy.DefaultContainerConfigs() (the pause container) to the container list on the Linux path, even when the input TOML sets allow_all = true.

securitypolicy.MarshalPolicy rejects that combination: an open-door policy must have no containers. So securitypolicy -c open-door.toml -t rego always fails — and it fails after doing the work of resolving and pulling the pause image, so the user waits on a registry round-trip for a guaranteed error.

Fix

Skip the default container configs when allow_all is set. The pause container is only meaningful for a policy that actually enumerates containers; an open-door policy enumerates none by definition.

  • The Windows path is unaffected — it never appended the default configs.
  • The -t fragment path is deliberately left alone. MarshalFragment takes no allowAll argument, so a fragment can never be open-door and the default configs remain correct there.

Testing

The package had no tests. Added main_test.go covering the three cases:

  • allow_all = true -> no containers appended
  • allow_all = false -> pause container appended
  • explicit containers + allow_all = false -> user containers preserved, pause appended

To make the rule testable without invoking the whole command, the container-list construction is extracted into linuxPolicyContainerConfigs. Behaviour is otherwise unchanged.

I negative-tested the new test by restoring the original bug: it fails as expected.

End to end, securitypolicy -c <open-door>.toml -t rego now succeeds and emits a policy at api_version 0.12.0 with 26 rules and no pause container.

The non-fragment linux path unconditionally appended
helpers.DefaultContainerConfigs() to config.Containers before calling
MarshalPolicy. MarshalPolicy rejects allow_all combined with a non-empty
container list, so `securitypolicytool -c <cfg> -t rego` with
`allow_all = true` always failed with "Invalid policy for open-door
enforcer" -- but only after pulling k8s.gcr.io/pause:3.1 and computing its
dm-verity root hash, so the failure was both guaranteed and slow.

The equivalent windows path does not append the default containers and works
correctly today.

Move the decision into linuxPolicyContainerConfigs and skip the append when
allow_all is set, so an open-door policy enumerates no containers. It now
generates in about a second with no registry access. Behaviour for every
other config is unchanged, and the fragment path is untouched: allow_all does
not apply to fragments, since MarshalFragment takes no allowAll argument.

Extracting the helper makes the rule testable; main_test.go locks it in, and
also asserts the underlying constraint that an open-door policy must not
enumerate containers. Verified that the new test fails against the previous
behaviour.

Also document open-door generation in the tool README, including that such a
policy is stamped with the generating hcsshim's api_version and lists exactly
that version's enforcement points, so it must not be checked in as a Base64
literal and reused across versions.

Signed-off-by: Veeraiah Chowdary Nuvvula <6164424+veerun14@users.noreply.github.com>
@veerun14
venuvvul (veerun14) requested a review from a team as a code owner September 15, 2026 02:46
@anmaxvl
Maksim An (anmaxvl) merged commit 1983948 into microsoft:main Sep 15, 2026
20 checks passed
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.

2 participants