Skip to content

Commit e659cb9

Browse files
committed
Refactor Makefile to simplify push-all target and enhance backend logging for Kubernetes client initialization. Add debug logging for authentication header states and token handling, improving traceability during API requests.
1 parent aab86cd commit e659cb9

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ clean: ## Clean up all Kubernetes resources
7373

7474

7575

76-
push-all: build-all ## Push all images to registry
76+
push-all: ## Push all images to registry
7777
$(CONTAINER_ENGINE) tag $(FRONTEND_IMAGE) $(REGISTRY)/$(FRONTEND_IMAGE)
7878
$(CONTAINER_ENGINE) tag $(BACKEND_IMAGE) $(REGISTRY)/$(BACKEND_IMAGE)
7979
$(CONTAINER_ENGINE) tag $(OPERATOR_IMAGE) $(REGISTRY)/$(OPERATOR_IMAGE)

components/backend/handlers.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,21 @@ func getK8sClientsForRequest(c *gin.Context) (*kubernetes.Clientset, dynamic.Int
4949
token = rawFwd
5050
}
5151

52+
// Debug: basic auth header state (do not log token)
53+
hasAuthHeader := strings.TrimSpace(rawAuth) != ""
54+
hasFwdToken := strings.TrimSpace(rawFwd) != ""
55+
xfUser := c.GetHeader("X-Forwarded-User")
56+
xfPref := c.GetHeader("X-Forwarded-Preferred-Username")
57+
log.Printf("auth debug: path=%s method=%s tokenSource=%s tokenLen=%d hasAuthHeader=%t hasFwdToken=%t user=%q preferred=%q",
58+
c.FullPath(), c.Request.Method, tokenSource, len(token), hasAuthHeader, hasFwdToken, xfUser, xfPref)
59+
5260
if token != "" && baseKubeConfig != nil {
5361
cfg := *baseKubeConfig
5462
cfg.BearerToken = token
63+
// Ensure we do NOT fall back to the in-cluster SA token or other auth providers
64+
cfg.BearerTokenFile = ""
65+
cfg.AuthProvider = nil
66+
cfg.ExecProvider = nil
5567
cfg.Username = ""
5668
cfg.Password = ""
5769

@@ -62,14 +74,15 @@ func getK8sClientsForRequest(c *gin.Context) (*kubernetes.Clientset, dynamic.Int
6274

6375
// Best-effort update last-used for service account tokens
6476
updateAccessKeyLastUsedAnnotation(c)
77+
log.Printf("auth debug: built user-scoped clients ok (source=%s) for %s", tokenSource, c.FullPath())
6578
return kc, dc
6679
}
6780
// Token provided but client build failed – treat as invalid token
68-
log.Printf("Failed to build user-scoped k8s clients (source=%s) typedErr=%v dynamicErr=%v for %s", tokenSource, err1, err2, c.FullPath())
81+
log.Printf("Failed to build user-scoped k8s clients (source=%s tokenLen=%d) typedErr=%v dynamicErr=%v for %s", tokenSource, len(token), err1, err2, c.FullPath())
6982
return nil, nil
7083
} else {
7184
// No token provided
72-
log.Printf("No user token found for %s", c.FullPath())
85+
log.Printf("No user token found for %s (hasAuthHeader=%t hasFwdToken=%t)", c.FullPath(), hasAuthHeader, hasFwdToken)
7386
return nil, nil
7487
}
7588
// Unreachable

0 commit comments

Comments
 (0)