Skip to content
Merged
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 {
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