Skip to content

Commit

Permalink
Merge pull request #973 from gianlucam76/helm-login
Browse files Browse the repository at this point in the history
(bug) login to private registries
  • Loading branch information
gianlucam76 authored Jan 24, 2025
2 parents f72b9d0 + d10a3cb commit 064a923
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
19 changes: 15 additions & 4 deletions controllers/handlers_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ func uninstallHelmCharts(ctx context.Context, c client.Client, clusterSummary *c
if err != nil && !errors.Is(err, driver.ErrReleaseNotFound) {
return nil, err
}

if currentRelease != nil && currentRelease.Status != string(release.StatusUninstalled) {
err = doUninstallRelease(ctx, clusterSummary, currentChart, kubeconfig, registryOptions, logger)
if err != nil {
Expand Down Expand Up @@ -1253,7 +1254,6 @@ func getRegistryClient(namespace string, registryOptions *registryClientOptions,
}
return registry.NewClient(options...)
}

return registry.NewRegistryClientWithTLS(os.Stderr, "", "", registryOptions.caPath,
registryOptions.skipTLSVerify, registryOptions.credentialsPath, settings.Debug)
}
Expand Down Expand Up @@ -2511,6 +2511,10 @@ func createFileWithCredentials(ctx context.Context, c client.Client, clusterName
return "", err
}

if secret.Type != corev1.SecretTypeDockerConfigJson {
return "", nil
}

if secret.Data == nil {
return "", errors.New(fmt.Sprintf("secret %s/%s referenced in HelmChart section contains no data",
namespace, credSecretRef.Name))
Expand Down Expand Up @@ -2636,7 +2640,7 @@ func doLogin(ctx context.Context, c client.Client, registryOptions *registryClie
return err
}

username, password, host, err := getUsernameAndPasswordFromSecret(registryURL, secret)
username, password, hostname, err := getUsernameAndPasswordFromSecret(registryURL, secret)
if err != nil {
return err
}
Expand All @@ -2646,8 +2650,15 @@ func doLogin(ctx context.Context, c client.Client, registryOptions *registryClie
return err
}

options := []registry.LoginOption{registry.LoginOptBasicAuth(username, password)}
return registryClient.Login(host, options...)
cfg := &action.Configuration{
RegistryClient: registryClient,
}

return action.NewRegistryLogin(cfg).Run(os.Stderr, hostname, username, password,
action.WithCertFile(""),
action.WithKeyFile(""),
action.WithCAFile(registryOptions.caPath),
action.WithInsecure(registryOptions.skipTLSVerify))
}

// usernameAndPasswordFromSecret derives authentication data from a Secret to login to an OCI registry. This Secret
Expand Down
1 change: 1 addition & 0 deletions controllers/handlers_helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ var _ = Describe("Hash methods", func() {
Data: map[string][]byte{
"config.json": credentialsBytes,
},
Type: corev1.SecretTypeDockerConfigJson,
}

caByte := []byte(randomString())
Expand Down

0 comments on commit 064a923

Please sign in to comment.