Skip to content

Commit 3f47430

Browse files
mottetm-rochemottetm
authored andcommitted
Allow to pull/push artifacts without TLS
If applied, this commit will introduce a new `--insecure-repository` flag to the following commands: `push artifacts`, `pull artifact`, `diff artifact` and `list artifacts`. When used the flag will lead to the option `crane.Insecure` being passed to the `crane` client allowing the use of insecure repositories. Signed-off-by: Matthieu Mottet <[email protected]>
1 parent 7b551b0 commit 3f47430

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

cmd/flux/diff_artifact.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
oci "github.com/fluxcd/pkg/oci/client"
2525
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
26+
"github.com/google/go-containerregistry/pkg/crane"
2627
"github.com/spf13/cobra"
2728

2829
"github.com/fluxcd/flux2/v2/internal/flags"
@@ -42,6 +43,7 @@ type diffArtifactFlags struct {
4243
creds string
4344
provider flags.SourceOCIProvider
4445
ignorePaths []string
46+
insecure bool
4547
}
4648

4749
var diffArtifactArgs = newDiffArtifactArgs()
@@ -57,6 +59,7 @@ func init() {
5759
diffArtifactCmd.Flags().StringVar(&diffArtifactArgs.creds, "creds", "", "credentials for OCI registry in the format <username>[:<password>] if --provider is generic")
5860
diffArtifactCmd.Flags().Var(&diffArtifactArgs.provider, "provider", sourceOCIRepositoryArgs.provider.Description())
5961
diffArtifactCmd.Flags().StringSliceVar(&diffArtifactArgs.ignorePaths, "ignore-paths", excludeOCI, "set paths to ignore in .gitignore format")
62+
diffArtifactCmd.Flags().BoolVar(&diffArtifactArgs.insecure, "insecure-registry", false, "allows the remote artifact to be pulled without TLS")
6063
diffCmd.AddCommand(diffArtifactCmd)
6164
}
6265

@@ -82,7 +85,13 @@ func diffArtifactCmdRun(cmd *cobra.Command, args []string) error {
8285
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
8386
defer cancel()
8487

85-
ociClient := oci.NewClient(oci.DefaultOptions())
88+
opts := oci.DefaultOptions()
89+
90+
if diffArtifactArgs.insecure {
91+
opts = append(opts, crane.Insecure)
92+
}
93+
94+
ociClient := oci.NewClient(opts)
8695

8796
if diffArtifactArgs.provider.String() == sourcev1.GenericOCIProvider && diffArtifactArgs.creds != "" {
8897
logger.Actionf("logging in to registry with credentials")

cmd/flux/list_artifact.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222

23+
"github.com/google/go-containerregistry/pkg/crane"
2324
"github.com/spf13/cobra"
2425

2526
oci "github.com/fluxcd/pkg/oci/client"
@@ -34,6 +35,7 @@ type listArtifactFlags struct {
3435
regexFilter string
3536
creds string
3637
provider flags.SourceOCIProvider
38+
insecure bool
3739
}
3840

3941
var listArtifactArgs = newListArtifactFlags()
@@ -60,6 +62,7 @@ func init() {
6062
listArtifactsCmd.Flags().StringVar(&listArtifactArgs.regexFilter, "filter-regex", "", "filter tags returned from the oci repository using regex")
6163
listArtifactsCmd.Flags().StringVar(&listArtifactArgs.creds, "creds", "", "credentials for OCI registry in the format <username>[:<password>] if --provider is generic")
6264
listArtifactsCmd.Flags().Var(&listArtifactArgs.provider, "provider", listArtifactArgs.provider.Description())
65+
listArtifactsCmd.Flags().BoolVar(&listArtifactArgs.insecure, "insecure-registry", false, "allows the remote artifacts list to be fetched without TLS")
6366

6467
listCmd.AddCommand(listArtifactsCmd)
6568
}
@@ -78,7 +81,13 @@ func listArtifactsCmdRun(cmd *cobra.Command, args []string) error {
7881
return err
7982
}
8083

81-
ociClient := oci.NewClient(oci.DefaultOptions())
84+
ociOpts := oci.DefaultOptions()
85+
86+
if listArtifactArgs.insecure {
87+
ociOpts = append(ociOpts, crane.Insecure)
88+
}
89+
90+
ociClient := oci.NewClient(ociOpts)
8291

8392
if listArtifactArgs.provider.String() == sourcev1.GenericOCIProvider && listArtifactArgs.creds != "" {
8493
logger.Actionf("logging in to registry with credentials")

cmd/flux/pull_artifact.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"os"
2323

2424
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
25+
"github.com/google/go-containerregistry/pkg/crane"
2526
"github.com/spf13/cobra"
2627

2728
"github.com/fluxcd/flux2/v2/internal/flags"
@@ -43,6 +44,7 @@ The command can read the credentials from '~/.docker/config.json' but they can a
4344
type pullArtifactFlags struct {
4445
output string
4546
creds string
47+
insecure bool
4648
provider flags.SourceOCIProvider
4749
}
4850

@@ -58,6 +60,7 @@ func init() {
5860
pullArtifactCmd.Flags().StringVarP(&pullArtifactArgs.output, "output", "o", "", "path where the artifact content should be extracted.")
5961
pullArtifactCmd.Flags().StringVar(&pullArtifactArgs.creds, "creds", "", "credentials for OCI registry in the format <username>[:<password>] if --provider is generic")
6062
pullArtifactCmd.Flags().Var(&pullArtifactArgs.provider, "provider", sourceOCIRepositoryArgs.provider.Description())
63+
pullArtifactCmd.Flags().BoolVar(&pullArtifactArgs.insecure, "insecure-registry", false, "allows artifacts to be pulled without TLS")
6164
pullCmd.AddCommand(pullArtifactCmd)
6265
}
6366

@@ -83,7 +86,13 @@ func pullArtifactCmdRun(cmd *cobra.Command, args []string) error {
8386
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
8487
defer cancel()
8588

86-
ociClient := oci.NewClient(oci.DefaultOptions())
89+
opts := oci.DefaultOptions()
90+
91+
if pullArtifactArgs.insecure {
92+
opts = append(opts, crane.Insecure)
93+
}
94+
95+
ociClient := oci.NewClient(opts)
8796

8897
if pullArtifactArgs.provider.String() == sourcev1.GenericOCIProvider && pullArtifactArgs.creds != "" {
8998
logger.Actionf("logging in to registry with credentials")

cmd/flux/push_artifact.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ type pushArtifactFlags struct {
115115
output string
116116
debug bool
117117
reproducible bool
118+
insecure bool
118119
}
119120

120121
var pushArtifactArgs = newPushArtifactFlags()
@@ -137,6 +138,7 @@ func init() {
137138
"the format in which the artifact digest should be printed, can be 'json' or 'yaml'")
138139
pushArtifactCmd.Flags().BoolVarP(&pushArtifactArgs.debug, "debug", "", false, "display logs from underlying library")
139140
pushArtifactCmd.Flags().BoolVar(&pushArtifactArgs.reproducible, "reproducible", false, "ensure reproducible image digests by setting the created timestamp to '1970-01-01T00:00:00Z'")
141+
pushArtifactCmd.Flags().BoolVar(&pushArtifactArgs.insecure, "insecure-registry", false, "allows artifacts to be pushed without TLS")
140142

141143
pushCmd.AddCommand(pushArtifactCmd)
142144
}
@@ -266,6 +268,10 @@ func pushArtifactCmdRun(cmd *cobra.Command, args []string) error {
266268
logger.Actionf("pushing artifact to %s", url)
267269
}
268270

271+
if pushArtifactArgs.insecure {
272+
opts = append(opts, crane.Insecure)
273+
}
274+
269275
ociClient := client.NewClient(opts)
270276
digestURL, err := ociClient.Push(ctx, url, path,
271277
client.WithPushMetadata(meta),

0 commit comments

Comments
 (0)