Skip to content
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

feat: Support signing bundles during copy #3204

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/porter/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ If the source bundle is a digest reference, destination must be a tagged referen
cmd.Flag("force").Annotations = map[string][]string{
"viper-key": {"force-overwrite"},
}
f.BoolVar(&opts.SignBundle, "sign-bundle", false, "Sign the bundle using the configured signing plugin")

return &cmd
}
1 change: 1 addition & 0 deletions docs/content/docs/references/cli/bundles_copy.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ porter bundles copy [flags]
--force Force push the bundle to overwrite the previously published bundle
-h, --help help for copy
--insecure-registry Don't require TLS for registries
--sign-bundle Sign the bundle using the configured signing plugin
--source string The fully qualified source bundle, including tag or digest.
```

Expand Down
1 change: 1 addition & 0 deletions docs/content/docs/references/cli/copy.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ porter copy [flags]
--force Force push the bundle to overwrite the previously published bundle
-h, --help help for copy
--insecure-registry Don't require TLS for registries
--sign-bundle Sign the bundle using the configured signing plugin
--source string The fully qualified source bundle, including tag or digest.
```

Expand Down
21 changes: 20 additions & 1 deletion pkg/porter/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type CopyOpts struct {
Destination string
InsecureRegistry bool
Force bool
SignBundle bool
}

// Validate performs validation logic on the options specified for a bundle copy
Expand Down Expand Up @@ -98,9 +99,27 @@ func (p *Porter) CopyBundle(ctx context.Context, opts *CopyOpts) error {

bunRef.Reference = destinationRef

_, err = p.Registry.PushBundle(ctx, bunRef, regOpts)
bunRef, err = p.Registry.PushBundle(ctx, bunRef, regOpts)
if err != nil {
return span.Error(fmt.Errorf("unable to copy bundle to new location: %w", err))
}

if opts.SignBundle {
for _, invImage := range bunRef.Definition.InvocationImages {
relocInvImage := bunRef.RelocationMap[invImage.Image]
span.Debugf("signing invocation image %s...", relocInvImage)
err = p.Signer.Sign(ctx, relocInvImage)
if err != nil {
return span.Errorf("failed to sign image %s: %w", relocInvImage, err)
}
}

span.Debugf("signing bundle %s", bunRef.Reference.String())
err = p.Signer.Sign(ctx, bunRef.Reference.String())
if err != nil {
return span.Errorf("failed to bundle %s: %w", bunRef.Reference.String(), err)
}
}

return nil
}
Loading