Skip to content

Commit 6fdd981

Browse files
stefanbergerlumjjb
authored andcommitted
images: Add list of Platforms to CheckAuthorization()
To be able to properly perform an authorization check on an image we need to know the platform to perform check when in cryptManifestList(). Extend the logic for cryptoOp == cryptoOpUnwrapOnly to skip over manifests that do not correspond to the local platform and return an error if no manifest was found that matches the local platform. The following projects seem NOT to be affect due to the change in the code path of CheckAuthorization() since they are not using it: - cri-o - nerdctl - skopeo - buildah - podman The impact on imgcrypt via ctr-enc is not so clear either since CheckAuthorization() is not called on the server side but by the ctr-enc client, thus can be modified easily. Resolves: #69 Signed-off-by: Stefan Berger <[email protected]>
1 parent f440058 commit 6fdd981

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

images/encryption/encryption.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ const (
5050
// LayerFilter allows to select Layers by certain criteria
5151
type LayerFilter func(desc ocispec.Descriptor) bool
5252

53+
// isLocalPlatform determines whether the given platform matches the local one
54+
func isLocalPlatform(platform *ocispec.Platform) bool {
55+
matcher := platforms.NewMatcher(*platform)
56+
57+
return matcher.Match(platforms.DefaultSpec())
58+
}
59+
5360
// IsEncryptedDiff returns true if mediaType is a known encrypted media type.
5461
func IsEncryptedDiff(ctx context.Context, mediaType string) bool {
5562
switch mediaType {
@@ -380,6 +387,9 @@ func cryptManifestList(ctx context.Context, cs content.Store, desc ocispec.Descr
380387
var newManifests []ocispec.Descriptor
381388
modified := false
382389
for _, manifest := range index.Manifests {
390+
if cryptoOp == cryptoOpUnwrapOnly && !isLocalPlatform(manifest.Platform) {
391+
continue
392+
}
383393
newManifest, m, err := cryptChildren(ctx, cs, manifest, cc, lf, cryptoOp, manifest.Platform)
384394
if err != nil || cryptoOp == cryptoOpUnwrapOnly {
385395
return ocispec.Descriptor{}, false, err
@@ -389,6 +399,9 @@ func cryptManifestList(ctx context.Context, cs content.Store, desc ocispec.Descr
389399
}
390400
newManifests = append(newManifests, newManifest)
391401
}
402+
if cryptoOp == cryptoOpUnwrapOnly {
403+
return ocispec.Descriptor{}, false, fmt.Errorf("No manifest found for local platform")
404+
}
392405

393406
if modified {
394407
// we need to update the index

0 commit comments

Comments
 (0)