Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 4ed459f

Browse files
author
Ian Campbell
committed
Always obey --with-registry-auth, not claim.Parameters
Using `claim.Parameters` means that if the `install` was run using `--with-registry-auth` then all subsequent commands (`status`, `uninstall`, etc) would silently pass on the user's credentials (and it may not be the same user) Signed-off-by: Ian Campbell <[email protected]>
1 parent 07bb266 commit 4ed459f

File tree

7 files changed

+14
-31
lines changed

7 files changed

+14
-31
lines changed

internal/commands/cnab.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,14 @@ func addDockerCredentials(contextName string, contextStore store.Store) credenti
8181
}
8282
}
8383

84-
func shouldPopulateRegistryCreds(parameterValues map[string]interface{}) bool {
85-
v, ok := parameterValues[internal.ParameterShareRegistryCredsName]
86-
if !ok {
87-
return false
88-
}
89-
result, ok := v.(bool)
90-
if !ok {
91-
return false
92-
}
93-
return result
94-
}
95-
96-
func addRegistryCredentials(parameterValues map[string]interface{}, dockerCli command.Cli) credentialSetOpt {
84+
func addRegistryCredentials(shouldPopulate bool, dockerCli command.Cli) credentialSetOpt {
9785
return func(b *bundle.Bundle, creds map[string]string) error {
9886
if _, ok := b.Credentials[internal.CredentialRegistryName]; !ok {
9987
return nil
10088
}
10189

10290
registryCreds := map[string]types.AuthConfig{}
103-
if shouldPopulateRegistryCreds(parameterValues) {
91+
if shouldPopulate {
10492
for _, img := range b.Images {
10593
named, err := reference.ParseNormalizedNamed(img.Image)
10694
if err != nil {

internal/commands/cnab_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,14 @@ func TestShareRegistryCreds(t *testing.T) {
212212

213213
for _, c := range cases {
214214
t.Run(c.name, func(t *testing.T) {
215-
params := map[string]interface{}{
216-
internal.ParameterShareRegistryCredsName: c.shareCreds,
217-
}
218215
creds, err := prepareCredentialSet(
219216
&bundle.Bundle{
220217
Credentials: map[string]bundle.Location{internal.CredentialRegistryName: {}},
221218
Images: c.images,
222219
},
223220
addNamedCredentialSets(nil),
224221
addDockerCredentials("", nil),
225-
addRegistryCredentials(params, &registryConfigMock{configFile: &configfile.ConfigFile{
222+
addRegistryCredentials(c.shareCreds, &registryConfigMock{configFile: &configfile.ConfigFile{
226223
AuthConfigs: c.stored,
227224
}}))
228225
assert.NilError(t, err)

internal/commands/install.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ type installOptions struct {
1717
credentialOptions
1818
registryOptions
1919
pullOptions
20-
orchestrator string
21-
kubeNamespace string
22-
stackName string
23-
sendRegistryAuth bool
20+
orchestrator string
21+
kubeNamespace string
22+
stackName string
2423
}
2524

2625
type nameKind uint
@@ -61,7 +60,6 @@ func installCmd(dockerCli command.Cli) *cobra.Command {
6160
cmd.Flags().StringVarP(&opts.orchestrator, "orchestrator", "o", "", "Orchestrator to install on (swarm, kubernetes)")
6261
cmd.Flags().StringVar(&opts.kubeNamespace, "kubernetes-namespace", "default", "Kubernetes namespace to install into")
6362
cmd.Flags().StringVar(&opts.stackName, "name", "", "Installation name (defaults to application name)")
64-
cmd.Flags().BoolVar(&opts.sendRegistryAuth, "with-registry-auth", false, "Sends registry auth")
6563

6664
return cmd
6765
}
@@ -112,7 +110,7 @@ func runInstall(dockerCli command.Cli, appname string, opts installOptions) erro
112110
creds, err := prepareCredentialSet(bndl,
113111
addNamedCredentialSets(opts.credentialsets),
114112
addDockerCredentials(targetContext, dockerCli.ContextStore()),
115-
addRegistryCredentials(c.Parameters, dockerCli))
113+
addRegistryCredentials(opts.sendRegistryAuth, dockerCli))
116114
if err != nil {
117115
return err
118116
}

internal/commands/root.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ func (o *parametersOptions) addFlags(flags *pflag.FlagSet) {
6666
}
6767

6868
type credentialOptions struct {
69-
targetContext string
70-
credentialsets []string
69+
targetContext string
70+
credentialsets []string
71+
sendRegistryAuth bool
7172
}
7273

7374
func (o *credentialOptions) addFlags(flags *pflag.FlagSet) {
7475
flags.StringVar(&o.targetContext, "target-context", "", "Context on which the application is executed")
7576
flags.StringArrayVarP(&o.credentialsets, "credential-set", "c", []string{}, "Use a duffle credentialset (either a YAML file, or a credential set present in the duffle credential store)")
77+
flags.BoolVar(&o.sendRegistryAuth, "with-registry-auth", false, "Sends registry auth")
7678
}
7779

7880
type registryOptions struct {

internal/commands/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func runStatus(dockerCli command.Cli, claimName string, opts credentialOptions)
5050
creds, err := prepareCredentialSet(c.Bundle,
5151
addNamedCredentialSets(opts.credentialsets),
5252
addDockerCredentials(targetContext, dockerCli.ContextStore()),
53-
addRegistryCredentials(c.Parameters, dockerCli))
53+
addRegistryCredentials(opts.sendRegistryAuth, dockerCli))
5454
if err != nil {
5555
return err
5656
}

internal/commands/uninstall.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func runUninstall(dockerCli command.Cli, claimName string, opts credentialOption
4949
creds, err := prepareCredentialSet(c.Bundle,
5050
addNamedCredentialSets(opts.credentialsets),
5151
addDockerCredentials(targetContext, dockerCli.ContextStore()),
52-
addRegistryCredentials(c.Parameters, dockerCli))
52+
addRegistryCredentials(opts.sendRegistryAuth, dockerCli))
5353
if err != nil {
5454
return err
5555
}

internal/commands/upgrade.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ type upgradeOptions struct {
1717
registryOptions
1818
pullOptions
1919
bundleOrDockerApp string
20-
sendRegistryAuth bool
2120
}
2221

2322
func upgradeCmd(dockerCli command.Cli) *cobra.Command {
@@ -35,7 +34,6 @@ func upgradeCmd(dockerCli command.Cli) *cobra.Command {
3534
opts.registryOptions.addFlags(cmd.Flags())
3635
opts.pullOptions.addFlags(cmd.Flags())
3736
cmd.Flags().StringVar(&opts.bundleOrDockerApp, "bundle", "", "Override with new bundle or Docker App")
38-
cmd.Flags().BoolVar(&opts.sendRegistryAuth, "with-registry-auth", false, "Sends registry auth")
3937

4038
return cmd
4139
}
@@ -77,7 +75,7 @@ func runUpgrade(dockerCli command.Cli, installationName string, opts upgradeOpti
7775
creds, err := prepareCredentialSet(c.Bundle,
7876
addNamedCredentialSets(opts.credentialsets),
7977
addDockerCredentials(targetContext, dockerCli.ContextStore()),
80-
addRegistryCredentials(c.Parameters, dockerCli))
78+
addRegistryCredentials(opts.sendRegistryAuth, dockerCli))
8179
if err != nil {
8280
return err
8381
}

0 commit comments

Comments
 (0)