Skip to content

feat(remote): add support for policy.json allow/deny - #1013

Merged
TerryHowe merged 5 commits into
oras-project:mainfrom
TerryHowe:feature-policy-json
Apr 1, 2026
Merged

TerryHowe merged 5 commits into
oras-project:mainfrom
TerryHowe:feature-policy-json

Conversation

@TerryHowe

@TerryHowe TerryHowe commented Oct 6, 2025 •

Copy link
Copy Markdown
Member

@codecov

codecov Bot commented Oct 6, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.24044% with 65 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.31%. Comparing base (34c4248) to head (1226889).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
registry/remote/policy/policy.go 70.70% 25 Missing and 4 partials ⚠️
registry/remote/repository.go 72.09% 12 Missing and 12 partials ⚠️
registry/remote/policy/requirement.go 92.00% 6 Missing and 4 partials ⚠️
registry/remote/policy/evaluator.go 96.42% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TerryHowe
TerryHowe force-pushed the feature-policy-json branch 2 times, most recently from 2c3dc9a to f782b54 Compare October 6, 2025 19:23
@Wwwsylvia
Wwwsylvia requested a review from Copilot October 10, 2025 11:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread registry/remote/policy/requirement.go Resolved
@shizhMSFT shizhMSFT changed the title Feature add support for policy.json allow/deny feat: add support for policy.json allow/deny Oct 10, 2025
@shizhMSFT shizhMSFT changed the title feat: add support for policy.json allow/deny feat(remote): add support for policy.json allow/deny Oct 10, 2025
@TerryHowe
TerryHowe force-pushed the feature-policy-json branch 3 times, most recently from f6bd8e2 to 39e9cd5 Compare October 28, 2025 18:09
@TerryHowe TerryHowe added the v3 Things belongs to version 3.x label Nov 17, 2025
@TerryHowe TerryHowe added this to the v3.0.0 milestone Nov 17, 2025
@TerryHowe
TerryHowe force-pushed the feature-policy-json branch 2 times, most recently from 0860b2b to 719ca4b Compare November 23, 2025 19:36
@TerryHowe
TerryHowe requested a review from sabre1041 as a code owner December 10, 2025 00:58
Comment thread registry/remote/repository.go Resolved
Comment thread registry/remote/repository.go Resolved
Comment thread registry/remote/policy/evaluator.go Resolved

@sabre1041 sabre1041 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No additional comments other than what @shizhMSFT shared

TerryHowe added a commit to TerryHowe/oras-go that referenced this pull request Feb 17, 2026
@TerryHowe

Copy link
Copy Markdown
Member Author

Resolved all of those comments with a slight tweak to the comment for IdentityMatchExact which I think is a bit better go style.

TerryHowe and others added 2 commits March 24, 2026 17:14
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]>
shizhMSFT

This comment was marked as duplicate.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread registry/remote/policy/policy.go Resolved
Comment thread registry/remote/policy/policy_test.go Resolved
Comment thread registry/remote/policy/policy_test.go Resolved
Comment thread registry/remote/repository.go Resolved
Comment thread registry/remote/repository.go Resolved
Comment thread registry/remote/repository.go Resolved
Comment thread registry/remote/policy/evaluator.go Resolved
Comment thread registry/remote/policy/policy_test.go Resolved
Comment thread registry/remote/policy/policy.go Resolved
shizhMSFT

This comment was marked as duplicate.

@shizhMSFT shizhMSFT left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Scope matching does not follow the spec. GetRequirementsForImage only performs exact match and transport-default fallback. Per containers-policy.json(5), for the docker: transport, scopes are matched as prefixes of the fully expanded form — a scope docker.io/library should match docker.io/library/nginx:latest. Wildcard subdomain matching (*.example.com) is also required. This is a fundamental correctness issue.

  2. signedBy field 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 a keyDatas field with a SignedByKeyData struct type that does not exist in the spec.

  3. sigstoreSigned is missing several spec-defined fields. The pki configuration, keyPaths, rekorPublicKeyPaths, and rekorPublicKeyDatas are 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.

  4. FulcioConfig.Validate() is incomplete. Per the spec, when fulcio is present, both oidcIssuer and subjectEmail are mandatory. The current validation only checks for CA path/data.

See inline comments for additional issues.

Comment thread registry/remote/policy/policy.go Resolved
Comment thread registry/remote/policy/requirement.go Resolved
Comment thread registry/remote/policy/requirement.go Resolved
Comment thread registry/remote/policy/requirement.go Resolved
Comment thread registry/remote/policy/requirement.go Resolved
Comment thread registry/remote/policy/requirement.go Resolved
Comment thread registry/remote/repository.go Resolved
Comment thread registry/remote/repository.go Resolved
Comment thread registry/remote/policy/evaluator.go Resolved
Comment thread registry/remote/policy/policy.go Resolved
- 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 shizhMSFT left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and let's go for a faster development path.

@TerryHowe
TerryHowe merged commit 8252f66 into oras-project:main Apr 1, 2026
9 checks passed
@TerryHowe
TerryHowe deleted the feature-policy-json branch October 16, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v3 Things belongs to version 3.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants