Skip to content

Commit 5157133

Browse files
author
Ankita Thomas
committedAug 10, 2020
skip TLS option for pulling indexes
1 parent 018a040 commit 5157133

File tree

7 files changed

+42
-13
lines changed

7 files changed

+42
-13
lines changed
 

‎cmd/opm/index/add.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func addIndexAddCmd(parent *cobra.Command) {
5353
if err := indexCmd.MarkFlagRequired("bundles"); err != nil {
5454
logrus.Panic("Failed to set required `bundles` flag for `index add`")
5555
}
56-
indexCmd.Flags().Bool("skip-tls", false, "skip TLS certificate verification for container image registries while pulling bundles")
56+
indexCmd.Flags().Bool("skip-tls", false, "skip TLS certificate verification for container image registries while pulling bundles or index")
5757
indexCmd.Flags().StringP("binary-image", "i", "", "container image for on-image `opm` command")
5858
indexCmd.Flags().StringP("container-tool", "c", "", "tool to interact with container images (save, build, etc.). One of: [docker, podman]")
5959
indexCmd.Flags().StringP("build-tool", "u", "", "tool to build container images. One of: [docker, podman]. Defaults to podman. Overrides part of container-tool.")

‎cmd/opm/index/delete.go

+7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func newIndexDeleteCmd() *cobra.Command {
4141
indexCmd.Flags().StringP("pull-tool", "p", "", "tool to pull container images. One of: [none, docker, podman]. Defaults to none. Overrides part of container-tool.")
4242
indexCmd.Flags().StringP("tag", "t", "", "custom tag for container image being built")
4343
indexCmd.Flags().Bool("permissive", false, "allow registry load errors")
44+
indexCmd.Flags().Bool("skip-tls", false, "skip TLS certificate verification for container image registries while pulling index")
4445

4546
if err := indexCmd.Flags().MarkHidden("debug"); err != nil {
4647
logrus.Panic(err.Error())
@@ -91,6 +92,11 @@ func runIndexDeleteCmdFunc(cmd *cobra.Command, args []string) error {
9192
return err
9293
}
9394

95+
skipTLS, err := cmd.Flags().GetBool("skip-tls")
96+
if err != nil {
97+
return err
98+
}
99+
94100
logger := logrus.WithFields(logrus.Fields{"operators": operators})
95101

96102
logger.Info("building the index")
@@ -108,6 +114,7 @@ func runIndexDeleteCmdFunc(cmd *cobra.Command, args []string) error {
108114
Operators: operators,
109115
Tag: tag,
110116
Permissive: permissive,
117+
SkipTLS: skipTLS,
111118
}
112119

113120
err = indexDeleter.DeleteFromIndex(request)

‎cmd/opm/index/deprecate.go

+7
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func newIndexDeprecateTruncateCmd() *cobra.Command {
5757
indexCmd.Flags().StringP("pull-tool", "p", "", "tool to pull container images. One of: [none, docker, podman]. Defaults to none. Overrides part of container-tool.")
5858
indexCmd.Flags().StringP("tag", "t", "", "custom tag for container image being built")
5959
indexCmd.Flags().Bool("permissive", false, "allow registry load errors")
60+
indexCmd.Flags().Bool("skip-tls", false, "skip TLS certificate verification for container image registries while pulling index")
6061
if err := indexCmd.Flags().MarkHidden("debug"); err != nil {
6162
logrus.Panic(err.Error())
6263
}
@@ -105,6 +106,11 @@ func runIndexDeprecateTruncateCmdFunc(cmd *cobra.Command, args []string) error {
105106
return err
106107
}
107108

109+
skipTLS, err := cmd.Flags().GetBool("skip-tls")
110+
if err != nil {
111+
return err
112+
}
113+
108114
logger := logrus.WithFields(logrus.Fields{"bundles": bundles})
109115

110116
logger.Info("deprecating bundles from the index")
@@ -122,6 +128,7 @@ func runIndexDeprecateTruncateCmdFunc(cmd *cobra.Command, args []string) error {
122128
Tag: tag,
123129
Bundles: bundles,
124130
Permissive: permissive,
131+
SkipTLS: skipTLS,
125132
}
126133

127134
err = indexDeprecator.DeprecateFromIndex(request)

‎cmd/opm/index/export.go

+7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func newIndexExportCmd() *cobra.Command {
4646
}
4747
indexCmd.Flags().StringP("download-folder", "f", "downloaded", "directory where downloaded operator bundle(s) will be stored")
4848
indexCmd.Flags().StringP("container-tool", "c", "none", "tool to interact with container images (save, build, etc.). One of: [none, docker, podman]")
49+
indexCmd.Flags().Bool("skip-tls", false, "skip TLS certificate verification for container image registries while pulling index")
4950
if err := indexCmd.Flags().MarkHidden("debug"); err != nil {
5051
logrus.Panic(err.Error())
5152
}
@@ -75,6 +76,11 @@ func runIndexExportCmdFunc(cmd *cobra.Command, args []string) error {
7576
return err
7677
}
7778

79+
skipTLS, err := cmd.Flags().GetBool("skip-tls")
80+
if err != nil {
81+
return err
82+
}
83+
7884
logger := logrus.WithFields(logrus.Fields{"index": index, "package": packageName})
7985

8086
logger.Info("export from the index")
@@ -86,6 +92,7 @@ func runIndexExportCmdFunc(cmd *cobra.Command, args []string) error {
8692
Package: packageName,
8793
DownloadPath: downloadPath,
8894
ContainerTool: containertools.NewContainerTool(containerTool, containertools.NoneTool),
95+
SkipTLS: skipTLS,
8996
}
9097

9198
err = indexExporter.ExportFromIndex(request)

‎cmd/opm/index/prune.go

+7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func newIndexPruneCmd() *cobra.Command {
4141
indexCmd.Flags().StringP("container-tool", "c", "podman", "tool to interact with container images (save, build, etc.). One of: [docker, podman]")
4242
indexCmd.Flags().StringP("tag", "t", "", "custom tag for container image being built")
4343
indexCmd.Flags().Bool("permissive", false, "allow registry load errors")
44+
indexCmd.Flags().Bool("skip-tls", false, "skip TLS certificate verification for container image registries while pulling index")
4445

4546
if err := indexCmd.Flags().MarkHidden("debug"); err != nil {
4647
logrus.Panic(err.Error())
@@ -95,6 +96,11 @@ func runIndexPruneCmdFunc(cmd *cobra.Command, args []string) error {
9596
return err
9697
}
9798

99+
skipTLS, err := cmd.Flags().GetBool("skip-tls")
100+
if err != nil {
101+
return err
102+
}
103+
98104
logger := logrus.WithFields(logrus.Fields{"packages": packages})
99105

100106
logger.Info("pruning the index")
@@ -109,6 +115,7 @@ func runIndexPruneCmdFunc(cmd *cobra.Command, args []string) error {
109115
Packages: packages,
110116
Tag: tag,
111117
Permissive: permissive,
118+
SkipTLS: skipTLS,
112119
}
113120

114121
err = indexPruner.PruneFromIndex(request)

‎go.sum

-3
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,8 @@ github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de
358358
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
359359
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
360360
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
361-
github.com/grpc-ecosystem/grpc-health-probe v0.2.1-0.20181220223928-2bf0a5b182db h1:UxmGBzaBcWDQuQh9E1iT1dWKQFbizZ+SpTd1EL4MSqs=
362-
github.com/grpc-ecosystem/grpc-health-probe v0.2.1-0.20181220223928-2bf0a5b182db/go.mod h1:uBKkC2RbarFsvS5jMJHpVhTLvGlGQj9JJwkaePE3FWI=
363361
github.com/grpc-ecosystem/grpc-health-probe v0.3.2 h1:daShAySXI1DnGc8U9B1E4Qm6o7qzmFR4aRIJ4vY/TUo=
364362
github.com/grpc-ecosystem/grpc-health-probe v0.3.2/go.mod h1:izVOQ4RWbjUR6lm4nn+VLJyQ+FyaiGmprEYgI04Gs7U=
365-
github.com/grpc/grpc-go v1.30.0 h1:3ttCZRhSqhlKmQ6UrrTukz9LjJF/Bi8RuRo8rlyxKhA=
366363
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4=
367364
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
368365
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=

‎pkg/lib/indexer/indexer.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (i ImageIndexer) AddToIndex(request AddToIndexRequest) error {
6969
return err
7070
}
7171

72-
databasePath, err := i.extractDatabase(buildDir, request.FromIndex)
72+
databasePath, err := i.extractDatabase(buildDir, request.FromIndex, request.SkipTLS)
7373
if err != nil {
7474
return err
7575
}
@@ -120,6 +120,7 @@ type DeleteFromIndexRequest struct {
120120
OutDockerfile string
121121
Tag string
122122
Operators []string
123+
SkipTLS bool
123124
}
124125

125126
// DeleteFromIndex is an aggregate API used to generate a registry index image
@@ -131,7 +132,7 @@ func (i ImageIndexer) DeleteFromIndex(request DeleteFromIndexRequest) error {
131132
return err
132133
}
133134

134-
databasePath, err := i.extractDatabase(buildDir, request.FromIndex)
135+
databasePath, err := i.extractDatabase(buildDir, request.FromIndex, request.SkipTLS)
135136
if err != nil {
136137
return err
137138
}
@@ -231,6 +232,7 @@ type PruneFromIndexRequest struct {
231232
OutDockerfile string
232233
Tag string
233234
Packages []string
235+
SkipTLS bool
234236
}
235237

236238
func (i ImageIndexer) PruneFromIndex(request PruneFromIndexRequest) error {
@@ -240,7 +242,7 @@ func (i ImageIndexer) PruneFromIndex(request PruneFromIndexRequest) error {
240242
return err
241243
}
242244

243-
databasePath, err := i.extractDatabase(buildDir, request.FromIndex)
245+
databasePath, err := i.extractDatabase(buildDir, request.FromIndex, request.SkipTLS)
244246
if err != nil {
245247
return err
246248
}
@@ -279,22 +281,22 @@ func (i ImageIndexer) PruneFromIndex(request PruneFromIndexRequest) error {
279281
}
280282

281283
// extractDatabase sets a temp directory for unpacking an image
282-
func (i ImageIndexer) extractDatabase(buildDir, fromIndex string) (string, error) {
284+
func (i ImageIndexer) extractDatabase(buildDir, fromIndex string, skipTLS bool) (string, error) {
283285
tmpDir, err := ioutil.TempDir("./", tmpDirPrefix)
284286
if err != nil {
285287
return "", err
286288
}
287289
defer os.RemoveAll(tmpDir)
288290

289-
databaseFile, err := i.getDatabaseFile(tmpDir, fromIndex)
291+
databaseFile, err := i.getDatabaseFile(tmpDir, fromIndex, skipTLS)
290292
if err != nil {
291293
return "", err
292294
}
293295
// copy the index to the database folder in the build directory
294296
return copyDatabaseTo(databaseFile, filepath.Join(buildDir, defaultDatabaseFolder))
295297
}
296298

297-
func (i ImageIndexer) getDatabaseFile(workingDir, fromIndex string) (string, error) {
299+
func (i ImageIndexer) getDatabaseFile(workingDir, fromIndex string, skipTLS bool) (string, error) {
298300
if fromIndex == "" {
299301
return path.Join(workingDir, defaultDatabaseFile), nil
300302
}
@@ -306,7 +308,7 @@ func (i ImageIndexer) getDatabaseFile(workingDir, fromIndex string) (string, err
306308
var rerr error
307309
switch i.PullTool {
308310
case containertools.NoneTool:
309-
reg, rerr = containerdregistry.NewRegistry(containerdregistry.WithLog(i.Logger))
311+
reg, rerr = containerdregistry.NewRegistry(containerdregistry.SkipTLS(skipTLS), containerdregistry.WithLog(i.Logger))
310312
case containertools.PodmanTool:
311313
fallthrough
312314
case containertools.DockerTool:
@@ -458,6 +460,7 @@ type ExportFromIndexRequest struct {
458460
Package string
459461
DownloadPath string
460462
ContainerTool containertools.ContainerTool
463+
SkipTLS bool
461464
}
462465

463466
// ExportFromIndex is an aggregate API used to specify operators from
@@ -471,7 +474,7 @@ func (i ImageIndexer) ExportFromIndex(request ExportFromIndexRequest) error {
471474
defer os.RemoveAll(workingDir)
472475

473476
// extract the index database to the file
474-
databaseFile, err := i.getDatabaseFile(workingDir, request.Index)
477+
databaseFile, err := i.getDatabaseFile(workingDir, request.Index, request.SkipTLS)
475478
if err != nil {
476479
return err
477480
}
@@ -592,6 +595,7 @@ type DeprecateFromIndexRequest struct {
592595
OutDockerfile string
593596
Bundles []string
594597
Tag string
598+
SkipTLS bool
595599
}
596600

597601
// DeprecateFromIndex takes a DeprecateFromIndexRequest and deprecates the requested
@@ -603,7 +607,7 @@ func (i ImageIndexer) DeprecateFromIndex(request DeprecateFromIndexRequest) erro
603607
return err
604608
}
605609

606-
databasePath, err := i.extractDatabase(buildDir, request.FromIndex)
610+
databasePath, err := i.extractDatabase(buildDir, request.FromIndex, request.SkipTLS)
607611
if err != nil {
608612
return err
609613
}

0 commit comments

Comments
 (0)
Please sign in to comment.