-
Notifications
You must be signed in to change notification settings - Fork 781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proxy: Policy verification of OCI Image before pulling #2029
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,7 @@ import ( | |
"github.com/containers/image/v5/manifest" | ||
ocilayout "github.com/containers/image/v5/oci/layout" | ||
"github.com/containers/image/v5/pkg/blobinfocache" | ||
"github.com/containers/image/v5/signature" | ||
"github.com/containers/image/v5/transports" | ||
"github.com/containers/image/v5/transports/alltransports" | ||
"github.com/containers/image/v5/types" | ||
|
@@ -95,7 +96,8 @@ import ( | |
// 0.2.3: Added GetFullConfig | ||
// 0.2.4: Added OpenImageOptional | ||
// 0.2.5: Added LayerInfoJSON | ||
const protocolVersion = "0.2.5" | ||
// 0.2.6: Policy Verification before pulling OCI | ||
const protocolVersion = "0.2.6" | ||
|
||
// maxMsgSize is the current limit on a packet size. | ||
// Note that all non-metadata (i.e. payload data) is sent over a pipe. | ||
|
@@ -266,6 +268,23 @@ func (h *proxyHandler) openImageImpl(args []any, allowNotFound bool) (replyBuf, | |
return ret, err | ||
} | ||
|
||
unparsedTopLevel := image.UnparsedInstance(imgsrc, nil) | ||
policy, err := signature.DefaultPolicy(h.sysctx) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was there a specific reason not to use That would also immediately handle |
||
if err != nil { | ||
return ret, err | ||
} | ||
policyContext, err := signature.NewPolicyContext(policy) | ||
if err != nil { | ||
return ret, err | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
allowed, err := policyContext.IsRunningImageAllowed(context.Background(), unparsedTopLevel) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here'd what we want is a new API like |
||
if !allowed || err != nil { | ||
return ret, err | ||
RishabhSaini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
if !allowed && err == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is dead code AFAICS. The code has already returned |
||
return ret, fmt.Errorf("policy verification failed unexpectedly") | ||
} | ||
|
||
// Note that we never return zero as an imageid; this code doesn't yet | ||
// handle overflow though. | ||
h.imageSerial++ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I think this is OK for now, maybe it makes sense to cache this in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, cache the
PolicyContext
(as long as it is used from a single thread).(Right now that does not make a difference, but a branch caching the imported keys in a native format inside a
PolicyContext
is floating around.)