Skip to content

Commit d10a3cb

Browse files
committed
(bug) login to private registries
If the Secret with credentials is of type kubernetes.io/dockerconfigjson create the credentials file and pass to Helm registry. Otherwise expects secret to contain username and password and use just those to login
1 parent f72b9d0 commit d10a3cb

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

controllers/handlers_helm.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ func uninstallHelmCharts(ctx context.Context, c client.Client, clusterSummary *c
363363
if err != nil && !errors.Is(err, driver.ErrReleaseNotFound) {
364364
return nil, err
365365
}
366+
366367
if currentRelease != nil && currentRelease.Status != string(release.StatusUninstalled) {
367368
err = doUninstallRelease(ctx, clusterSummary, currentChart, kubeconfig, registryOptions, logger)
368369
if err != nil {
@@ -1253,7 +1254,6 @@ func getRegistryClient(namespace string, registryOptions *registryClientOptions,
12531254
}
12541255
return registry.NewClient(options...)
12551256
}
1256-
12571257
return registry.NewRegistryClientWithTLS(os.Stderr, "", "", registryOptions.caPath,
12581258
registryOptions.skipTLSVerify, registryOptions.credentialsPath, settings.Debug)
12591259
}
@@ -2511,6 +2511,10 @@ func createFileWithCredentials(ctx context.Context, c client.Client, clusterName
25112511
return "", err
25122512
}
25132513

2514+
if secret.Type != corev1.SecretTypeDockerConfigJson {
2515+
return "", nil
2516+
}
2517+
25142518
if secret.Data == nil {
25152519
return "", errors.New(fmt.Sprintf("secret %s/%s referenced in HelmChart section contains no data",
25162520
namespace, credSecretRef.Name))
@@ -2636,7 +2640,7 @@ func doLogin(ctx context.Context, c client.Client, registryOptions *registryClie
26362640
return err
26372641
}
26382642

2639-
username, password, host, err := getUsernameAndPasswordFromSecret(registryURL, secret)
2643+
username, password, hostname, err := getUsernameAndPasswordFromSecret(registryURL, secret)
26402644
if err != nil {
26412645
return err
26422646
}
@@ -2646,8 +2650,15 @@ func doLogin(ctx context.Context, c client.Client, registryOptions *registryClie
26462650
return err
26472651
}
26482652

2649-
options := []registry.LoginOption{registry.LoginOptBasicAuth(username, password)}
2650-
return registryClient.Login(host, options...)
2653+
cfg := &action.Configuration{
2654+
RegistryClient: registryClient,
2655+
}
2656+
2657+
return action.NewRegistryLogin(cfg).Run(os.Stderr, hostname, username, password,
2658+
action.WithCertFile(""),
2659+
action.WithKeyFile(""),
2660+
action.WithCAFile(registryOptions.caPath),
2661+
action.WithInsecure(registryOptions.skipTLSVerify))
26512662
}
26522663

26532664
// usernameAndPasswordFromSecret derives authentication data from a Secret to login to an OCI registry. This Secret

controllers/handlers_helm_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,7 @@ var _ = Describe("Hash methods", func() {
929929
Data: map[string][]byte{
930930
"config.json": credentialsBytes,
931931
},
932+
Type: corev1.SecretTypeDockerConfigJson,
932933
}
933934

934935
caByte := []byte(randomString())

0 commit comments

Comments
 (0)