feat: add notation policy init command - #1364
Open
ChrisJr404 wants to merge 1 commit into
Open
Conversation
Scaffolds a starter trustpolicy.oci.json from flags so new users don't have to hand-write one. Mirrors the existing blob policy init, minus the --global flag (OCI policies scope by registry, not a global toggle) and adds --registry-scope which defaults to the wildcard "*". Validates the generated document before writing and won't clobber an existing policy without --force. Also documents the subcommand in specs/cmd/policy.md. Signed-off-by: Chris (ChrisJr404) <11917633+ChrisJr404@users.noreply.github.com>
ChrisJr404
requested review from
NiazFK,
gokarnm,
priteshbandi,
rgnote,
shizhMSFT,
toddysm,
vaninrao10 and
yizha1
as code owners
August 17, 2026 23:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
notation policy initso new users can scaffold a validtrustpolicy.oci.jsonfrom flags instead of hand-writing one from the spec, which closes #653.It follows the same shape as the existing
notation blob policy init, so the flags and prompts should feel familiar. The differences are OCI-specific: there's no--global(OCI policy statements scope by registry rather than a global toggle), and there's a new--registry-scopeflag that's repeatable and defaults to the wildcard"*"so a fresh policy applies to every registry until the user narrows it. The generated statement usessignatureVerification.level: strict. It runsOCIDocument.Validate()before writing, so a bad--trusted-identityDN or an illegal wildcard-plus-scope combination fails without touching the config. If a policy already exists it prompts before overwriting, and--forceskips the prompt.I updated
specs/cmd/policy.mdin the same PR since the discussion asked for the CLI spec to define the experience first. Happy to split the spec out into its own PR to land ahead of the code if that's the process you'd prefer.Tested with
go test ./cmd/notation/...(all pass). Newinit_test.gocovers the happy path (file written, parses, validates, default wildcard scope), rejection of an invalid registry-scope combo, and--forceoverwriting an existing file. Also ran the built binary end to end against a throwawayXDG_CONFIG_HOME: default wildcard init, a--registry-scopevariant, the overwrite prompt cancelling onN, and--force. One open question for reviewers: I leftinitnon-interactive (flag-driven) to match the blob command; let me know if you'd rather it prompt for the trust store / identity when they're omitted.