From 1cf4feb0710db53cdd820635b9e37d87ada530f7 Mon Sep 17 00:00:00 2001 From: RishabhSaini Date: Thu, 29 Jun 2023 17:55:19 -0400 Subject: [PATCH] proxy: Policy verification of OCI Image before pulling Signed-off-by: RishabhSaini --- cmd/skopeo/proxy.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/cmd/skopeo/proxy.go b/cmd/skopeo/proxy.go index d15f3ee72b..ad3ff7d681 100644 --- a/cmd/skopeo/proxy.go +++ b/cmd/skopeo/proxy.go @@ -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,20 @@ func (h *proxyHandler) openImageImpl(args []any, allowNotFound bool) (replyBuf, return ret, err } + unparsedTopLevel := image.UnparsedInstance(imgsrc, nil) + policy, err := signature.DefaultPolicy(h.sysctx) + if err != nil { + return ret, err + } + policyContext, err := signature.NewPolicyContext(policy) + if err != nil { + return ret, err + } + allowed, err := policyContext.IsRunningImageAllowed(context.Background(), unparsedTopLevel) + if !allowed || err != nil { + return ret, err + } + // Note that we never return zero as an imageid; this code doesn't yet // handle overflow though. h.imageSerial++