Skip to content

Commit fd5c7cb

Browse files
authored
Merge pull request #4467 from ChengyuZhu6/manifest-push-fix
manifest: fix manifest push error on cross-registry
2 parents 6aa6b72 + 1626805 commit fd5c7cb

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

cmd/nerdctl/manifest/manifest_push_linux_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,29 @@ func TestManifestPush(t *testing.T) {
118118
"output": expectedDigest,
119119
}),
120120
},
121+
{
122+
Description: "reject-cross-registry-sources",
123+
Require: require.Not(nerdtest.Docker),
124+
Setup: func(data test.Data, helpers test.Helpers) {
125+
targetRef := fmt.Sprintf("%s:%d/%s",
126+
registryTokenAuthHTTPSRandom.IP.String(), registryTokenAuthHTTPSRandom.Port, "test-list-push:v1")
127+
helpers.Ensure("manifest", "create", "--insecure", targetRef+"-cross", manifestRef)
128+
},
129+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
130+
targetRef := fmt.Sprintf("%s:%d/%s",
131+
registryTokenAuthHTTPSRandom.IP.String(), registryTokenAuthHTTPSRandom.Port, "test-list-push:v1")
132+
return helpers.Command("manifest", "push", "--insecure", targetRef+"-cross")
133+
},
134+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
135+
return &test.Expected{
136+
ExitCode: 1,
137+
Errors: []error{errors.New(data.Labels().Get("error"))},
138+
}
139+
},
140+
Data: test.WithLabels(map[string]string{
141+
"error": "cannot use source images from a different registry than the target image:",
142+
}),
143+
},
121144
},
122145
}
123146
testCase.Run(t)

pkg/cmd/manifest/push.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ func pushIndividualManifests(ctx context.Context, resolver remotes.Resolver, man
135135
return fmt.Errorf("failed to parse manifest reference %s: %w", manifest.Ref, err)
136136
}
137137

138+
if manifestRef.Domain != targetDomain {
139+
return fmt.Errorf("cannot use source images from a different registry than the target image: %s != %s", manifestRef.Domain, targetDomain)
140+
}
141+
138142
var targetManifestRef string
139143
if manifestRef.Domain != targetDomain {
140144
targetManifestRef = fmt.Sprintf("%s/%s@%s", targetDomain, manifestRef.Path, manifest.Descriptor.Digest)

0 commit comments

Comments
 (0)