Skip to content

Commit 1f945d7

Browse files
backend: Tests failing
1 parent b1598c3 commit 1f945d7

File tree

2 files changed

+6
-37
lines changed

2 files changed

+6
-37
lines changed

backend/cmd/headlamp.go

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ type HeadlampConfig struct {
8787
baseURL string
8888
oidcScopes []string
8989
proxyURLs []string
90-
compiledProxyURLs []glob.Glob
9190
cache cache.Cache[interface{}]
9291
kubeConfigStore kubeconfig.ContextStore
9392
multiplexer *Multiplexer
@@ -622,7 +621,7 @@ func createExternalProxyHandler(config *HeadlampConfig) http.HandlerFunc {
622621
return
623622
}
624623

625-
if !config.isURLAllowed(url.String()) {
624+
if !isURLAllowed(config.proxyURLs, url.String()) {
626625
logger.Log(logger.LevelError, nil, err, "no allowed proxy url match, request denied")
627626
http.Error(w, "no allowed proxy url match, request denied ", http.StatusBadRequest)
628627

@@ -642,8 +641,9 @@ func getProxyURL(r *http.Request) string {
642641
return proxyURL
643642
}
644643

645-
func (c *HeadlampConfig) isURLAllowed(targetURL string) bool {
646-
for _, g := range c.compiledProxyURLs {
644+
func isURLAllowed(proxyURLs []string, targetURL string) bool {
645+
for _, proxyURL := range proxyURLs {
646+
g := glob.MustCompile(proxyURL)
647647
if g.Match(targetURL) {
648648
return true
649649
}
@@ -899,30 +899,6 @@ func buildOIDCRedirectURL(config *HeadlampConfig, cluster, token string) string
899899
return redirectURL + fmt.Sprintf("auth?cluster=%s&token=%s", cluster, token)
900900
}
901901

902-
func (c *HeadlampConfig) compileProxyURLs() error {
903-
if len(c.proxyURLs) == 0 {
904-
return nil
905-
}
906-
907-
c.compiledProxyURLs = make([]glob.Glob, 0, len(c.proxyURLs))
908-
for _, pattern := range c.proxyURLs {
909-
pattern = strings.TrimSpace(pattern)
910-
911-
if pattern == "" {
912-
continue
913-
}
914-
915-
g, err := glob.Compile(pattern)
916-
if err != nil {
917-
return fmt.Errorf("invalid proxy URL pattern %q: %w", pattern, err)
918-
}
919-
920-
c.compiledProxyURLs = append(c.compiledProxyURLs, g)
921-
}
922-
923-
return nil
924-
}
925-
926902
func parseClusterAndToken(r *http.Request) (string, string) {
927903
cluster := ""
928904
re := regexp.MustCompile(`^/clusters/([^/]+)/.*`)

backend/cmd/server.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func main() {
4444
kubeConfigStore := kubeconfig.NewContextStore()
4545
multiplexer := NewMultiplexer(kubeConfigStore)
4646

47-
serverConfig := &HeadlampConfig{
47+
StartHeadlampServer(&HeadlampConfig{
4848
useInCluster: conf.InCluster,
4949
kubeConfigPath: conf.KubeConfigPath,
5050
skippedKubeContexts: conf.SkippedKubeContexts,
@@ -80,14 +80,7 @@ func main() {
8080
StdoutTraceEnabled: conf.StdoutTraceEnabled,
8181
SamplingRate: conf.SamplingRate,
8282
},
83-
}
84-
85-
if err := serverConfig.compileProxyURLs(); err != nil {
86-
logger.Log(logger.LevelError, nil, err, "Failed to compile proxy URL patterns")
87-
os.Exit(1)
88-
}
89-
90-
StartHeadlampServer(serverConfig)
83+
})
9184
}
9285

9386
func runListPlugins() {

0 commit comments

Comments
 (0)