Repository navigation
feat(remote): add support for policy.json allow/deny - #1013
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1013 +/- ##
==========================================
- Coverage 82.40% 82.31% -0.09%
==========================================
Files 67 70 +3
Lines 4949 5304 +355
==========================================
+ Hits 4078 4366 +288
- Misses 535 581 +46
- Partials 336 357 +21 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
2c3dc9a to
f782b54
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR adds comprehensive support for the containers-policy.json format, enabling image access control policies based on allow/deny rules. The implementation includes policy management, evaluation, and integration with repository operations.
Key changes:
- Implements policy evaluation with support for insecure accept, reject, and signature verification requirements (placeholders)
- Adds policy integration to Repository struct with enforcement in Fetch, Push, and Resolve operations
- Provides comprehensive test coverage including unit tests, integration tests, and edge case handling
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| registry/remote/repository.go | Adds Policy field and checkPolicy method integration |
| registry/remote/repository_policy_test.go | Tests policy enforcement in repository operations |
| registry/remote/policy/policy.go | Core policy management with load/save/validation |
| registry/remote/policy/evaluator.go | Policy evaluation engine for image access decisions |
| registry/remote/policy/requirement.go | Policy requirement types and JSON marshaling |
| registry/remote/policy/policy_test.go | Comprehensive policy functionality tests |
| registry/remote/policy/requirement_test.go | Tests for requirement validation and types |
| registry/remote/policy/edge_cases_test.go | Edge case and error condition testing |
| registry/remote/policy/example_test.go | Example usage and documentation tests |
| docs/policy.md | Documentation for the policy package |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
f6bd8e2 to
39e9cd5
Compare
0860b2b to
719ca4b
Compare
sabre1041
left a comment
There was a problem hiding this comment.
No additional comments other than what @shizhMSFT shared
… allow/deny Signed-off-by: Terry Howe <[email protected]>
|
Resolved all of those comments with a slight tweak to the comment for IdentityMatchExact which I think is a bit better go style. |
Signed-off-by: Terry Howe <[email protected]>
Move policy code from internal/configuration to registry/remote/policy as a public package so SDK users can create and manage policies. Add platform-specific default path handling so GetDefaultPolicyPath only falls back to /etc/containers/policy.json on Linux. Use interfaces for signature verification instead of direct implementation. Signed-off-by: Terry Howe <[email protected]>
e58fa3e to
ae07713
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 9 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
shizhMSFT
left a comment
There was a problem hiding this comment.
Caution
This review was generated by GitHub Copilot using Claude Opus 4.6, mimicking the review style of shizhMSFT. This is not the real shizhMSFT — it is an AI-generated review persona. Please treat these comments as AI-assisted suggestions, not authoritative human feedback.
Good progress on addressing the previous comments — the package move to public and cross-platform support are welcome. However, there are several spec compliance issues that need attention before this can be merged. Always follow the spec since the spec is the standard.
Key concerns:
-
Scope matching does not follow the spec.
GetRequirementsForImageonly performs exact match and transport-default fallback. Per containers-policy.json(5), for thedocker:transport, scopes are matched as prefixes of the fully expanded form — a scopedocker.io/libraryshould matchdocker.io/library/nginx:latest. Wildcard subdomain matching (*.example.com) is also required. This is a fundamental correctness issue. -
signedByfield schema deviates from the spec. The spec says: "Exactly one of keyPath, keyPaths and keyData must be present." The implementation (a) accepts any combination instead of exactly one, and (b) adds akeyDatasfield with aSignedByKeyDatastruct type that does not exist in the spec. -
sigstoreSignedis missing several spec-defined fields. Thepkiconfiguration,keyPaths,rekorPublicKeyPaths, andrekorPublicKeyDatasare all absent. If we choose not to implement them yet, this should be explicitly documented and the parser should reject unknown/unsupported fields rather than silently ignoring them. -
FulcioConfig.Validate()is incomplete. Per the spec, whenfulciois present, bothoidcIssuerandsubjectEmailare mandatory. The current validation only checks for CA path/data.
See inline comments for additional issues.
- Implement longest-prefix scope matching with wildcard subdomain support in GetRequirementsForImage per containers-policy.json spec - Enforce exactly one key source in PRSignedBy (keyPath, keyPaths, or keyData) per spec - Remove non-spec SignedByKeyData struct and KeyDatas field from PRSignedBy - Change PRSigstoreSigned.KeyDatas to []string per spec - Remove non-spec SigstoreKeyData struct - Require OIDCIssuer and SubjectEmail in FulcioConfig.Validate per spec - Validate that Policy.Default is non-empty per spec - Use 0600/0700 file permissions in Save for security policy files - Remove duplicate Load function, keep only LoadPolicy - Unexport policy path constants (policyConfUserDir, etc.) - Use errdef.ErrMissingReference sentinel for nil policy error Signed-off-by: Terry Howe <[email protected]>
Add checkPolicy to all Repository, blobStore, and manifestStore methods that make network requests. Previously only Fetch, Push, and Resolve were covered. Newly covered operations: - Content: FetchReference, PushReference - Metadata: Exists, Tags, Referrers, Predecessors - Mutating: Delete, Tag, Mount Also fixes scope to use fully-qualified form (registry/repository) for correct policy.json matching, and adds context-key deduplication to prevent double-checking when Repository methods delegate to sub-stores. Signed-off-by: Terry Howe <[email protected]>
shizhMSFT
left a comment
There was a problem hiding this comment.
LGTM and let's go for a faster development path.
Support for policy.json allow/deny https://man.archlinux.org/man/containers-policy.json.5.en