Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions internal/handlers/helm_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package handlers

import (
"net/http"
"sync"

"github.com/elazarl/goproxy"

Expand All @@ -14,9 +13,8 @@ import (

// HelmRegistryHandler handles requests to helm registries, adding auth.
type HelmRegistryHandler struct {
credentials []helmRegistryCredentials
oidcCredentials map[string]*oidc.OIDCCredential
mutex sync.RWMutex
credentials []helmRegistryCredentials
oidcRegistry *oidc.OIDCRegistry
}

type helmRegistryCredentials struct {
Expand All @@ -28,8 +26,8 @@ type helmRegistryCredentials struct {
// NewHelmRegistryHandler returns a new HelmRegistryHandler.
func NewHelmRegistryHandler(creds config.Credentials) *HelmRegistryHandler {
handler := HelmRegistryHandler{
credentials: []helmRegistryCredentials{},
oidcCredentials: make(map[string]*oidc.OIDCCredential),
credentials: []helmRegistryCredentials{},
oidcRegistry: oidc.NewOIDCRegistry(),
}

for _, cred := range creds {
Expand All @@ -42,12 +40,8 @@ func NewHelmRegistryHandler(creds config.Credentials) *HelmRegistryHandler {
registry = cred.Host()
}

oidcCredential, _ := oidc.CreateOIDCCredential(cred)
if oidcCredential != nil {
if registry != "" {
handler.oidcCredentials[registry] = oidcCredential
logging.RequestLogf(nil, "registered %s OIDC credentials for helm registry: %s", oidcCredential.Provider(), registry)
}
// OIDC credentials are not used as static credentials.
if oidcCred, _, _ := handler.oidcRegistry.Register(cred, []string{"registry"}, "helm registry"); oidcCred != nil {
Comment on lines +43 to +44
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OIDCRegistry.Register returns (cred, key, registered) but this code only checks oidcCred != nil and ignores whether the credential was actually registered (e.g., missing/invalid registry/host). That can silently drop an OIDC-configured credential with no warning and make misconfigurations harder to diagnose. Consider switching the condition to use the registered boolean (and optionally log when oidcCred != nil but registered == false).

Suggested change
// OIDC credentials are not used as static credentials.
if oidcCred, _, _ := handler.oidcRegistry.Register(cred, []string{"registry"}, "helm registry"); oidcCred != nil {
// OIDC credentials are not used as static credentials once successfully registered.
if _, _, registered := handler.oidcRegistry.Register(cred, []string{"registry"}, "helm registry"); registered {

Copilot uses AI. Check for mistakes.
continue
}

Expand All @@ -69,7 +63,7 @@ func (h *HelmRegistryHandler) HandleRequest(req *http.Request, ctx *goproxy.Prox
}

// Try OIDC credentials first
if oidc.TryAuthOIDCRequestWithPrefix(&h.mutex, h.oidcCredentials, req, ctx) {
if h.oidcRegistry.TryAuth(req, ctx) {
return req, nil
}

Expand Down
Loading