Skip to content

Commit 74e196e

Browse files
committed
Add --insecure-registry to porter build command
When porter builds a bundle, we lookup the repository digest of any referenced images. Previously we did that with Pull, which always allowed connections to insecure registries. Now that we are executing a HEAD request instead to get the digest, instead of pulling the image with PullImage, we can be more explicit like we are with the publish commnad. I have added --insecure-registry to porter build, so that the bundle author can decide when building if they want to allow connections to an insecure registry (http or self-signed certificates). Signed-off-by: Carolyn Van Slyck <[email protected]>
1 parent 36ed299 commit 74e196e

File tree

7 files changed

+16
-5
lines changed

7 files changed

+16
-5
lines changed

cmd/porter/bundle.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ The docker driver builds the bundle image using the local Docker host. To use a
9191
"Do not use the Docker cache when building the bundle's invocation image.")
9292
f.StringArrayVar(&opts.Customs, "custom", nil,
9393
"Define an individual key-value pair for the custom section in the form of NAME=VALUE. Use dot notation to specify a nested custom field. May be specified multiple times. Max length is 5,000 characters when used as a build argument.")
94+
f.BoolVar(&opts.InsecureRegistry, "insecure-registry", false,
95+
"Don't require TLS when pulling referenced images")
9496

9597
// Allow configuring the --driver flag with build-driver, to avoid conflicts with other commands
9698
cmd.Flag("driver").Annotations = map[string][]string{

docs/content/cli/build.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ porter build [flags]
4242
-d, --dir string Path to the build context directory where all bundle assets are located. Defaults to the current directory.
4343
-f, --file string Path to the Porter manifest. The path is relative to the build context directory. Defaults to porter.yaml in the current directory.
4444
-h, --help help for build
45+
--insecure-registry Don't require TLS when pulling referenced images
4546
--name string Override the bundle name
4647
--no-cache Do not use the Docker cache when building the bundle's invocation image.
4748
--no-lint Do not run the linter

docs/content/cli/bundles_build.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ porter bundles build [flags]
4242
-d, --dir string Path to the build context directory where all bundle assets are located. Defaults to the current directory.
4343
-f, --file string Path to the Porter manifest. The path is relative to the build context directory. Defaults to porter.yaml in the current directory.
4444
-h, --help help for build
45+
--insecure-registry Don't require TLS when pulling referenced images
4546
--name string Override the bundle name
4647
--no-cache Do not use the Docker cache when building the bundle's invocation image.
4748
--no-lint Do not run the linter

pkg/porter/build.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ type BuildOptions struct {
3535
// Custom is the unparsed list of NAME=VALUE custom inputs set on the command line.
3636
Customs []string
3737

38+
// InsecureRegistry allows connecting to an unsecured registry or one without verifiable certificates.
39+
InsecureRegistry bool
40+
3841
// parsedCustoms is the parsed set of custom inputs from Customs.
3942
parsedCustoms map[string]string
4043
}

pkg/porter/generateManifest.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ func (p *Porter) generateInternalManifest(ctx context.Context, opts BuildOptions
6464
}
6565
}
6666

67+
regOpts := cnabtooci.RegistryOptions{
68+
InsecureRegistry: opts.InsecureRegistry,
69+
}
70+
6771
// find all referenced images that does not have digest specified
6872
// get the image digest for all of them and update the manifest with the digest
6973
err = e.WalkNodes(ctx, "images.*", func(ctx context.Context, nc *yqlib.NodeContext) error {
@@ -88,7 +92,7 @@ func (p *Porter) generateInternalManifest(ctx context.Context, opts BuildOptions
8892
return span.Errorf("failed to parse image %s reference: %w", img.Repository, err)
8993
}
9094

91-
digest, err := p.getImageDigest(ctx, ref)
95+
digest, err := p.getImageDigest(ctx, ref, regOpts)
9296
if err != nil {
9397
return span.Error(err)
9498
}
@@ -117,7 +121,7 @@ func (p *Porter) generateInternalManifest(ctx context.Context, opts BuildOptions
117121
}
118122

119123
// getImageDigest retrieves the repository digest associated with the specified image reference.
120-
func (p *Porter) getImageDigest(ctx context.Context, img cnab.OCIReference) (digest.Digest, error) {
124+
func (p *Porter) getImageDigest(ctx context.Context, img cnab.OCIReference, regOpts cnabtooci.RegistryOptions) (digest.Digest, error) {
121125
ctx, span := tracing.StartSpan(ctx, attribute.String("image", img.String()))
122126
defer span.EndSpan()
123127

@@ -130,7 +134,6 @@ func (p *Porter) getImageDigest(ctx context.Context, img cnab.OCIReference) (dig
130134
img = refWithTag
131135
}
132136

133-
regOpts := cnabtooci.RegistryOptions{}
134137
imgSummary, err := p.Registry.GetImageMetadata(ctx, img, regOpts)
135138
if err != nil {
136139
return "", err

pkg/porter/generateManifest_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ func Test_getImageLatestDigest(t *testing.T) {
173173
p.TestRegistry.MockGetImageMetadata = tc.mockGetImageMetadata
174174
}
175175

176-
digest, err := p.getImageDigest(context.Background(), ref)
176+
regOpts := cnabtooci.RegistryOptions{}
177+
digest, err := p.getImageDigest(context.Background(), ref, regOpts)
177178
if tc.wantErr != "" {
178179
require.ErrorContains(t, err, tc.wantErr)
179180
return

tests/smoke/airgap_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func TestAirgappedEnvironment(t *testing.T) {
8383
})
8484

8585
// Build the test bundle separate from publish so we best validate that we aren't pulling referenced images during build anymore
86-
test.RequirePorter("build")
86+
test.RequirePorter("build", insecureFlag)
8787

8888
// Validate that the referenced bundle is not in the local docker cache and that build did not pull it
8989
err = shx.RunE("docker", "image", "inspect", localRefWithDigest)

0 commit comments

Comments
 (0)