sarkyboy commited on
Commit
79cc701
·
1 Parent(s): fd8a939

chore: remove debug logs from auth middleware

Browse files
src/internal/api/handlers/management/handler.go CHANGED
@@ -53,17 +53,8 @@ type Handler struct {
53
  func NewHandler(cfg *config.Config, configFilePath string, manager *coreauth.Manager) *Handler {
54
  envSecret, _ := os.LookupEnv("MANAGEMENT_PASSWORD")
55
  // DEBUG: Print raw env secret length and hex
56
- fmt.Printf("[DEBUG-AUTH] NewHandler: Raw Env MANAGEMENT_PASSWORD len=%d\n", len(envSecret))
57
- if len(envSecret) > 0 {
58
- fmt.Printf("[DEBUG-AUTH] NewHandler: Raw Env Secret Hex: %x\n", envSecret)
59
- }
60
  envSecret = strings.TrimSpace(envSecret)
61
- fmt.Printf("[DEBUG-AUTH] NewHandler: Trimmed Env Secret len=%d, value(masked)=%s***\n", len(envSecret), func() string {
62
- if len(envSecret) > 3 {
63
- return envSecret[:3]
64
- }
65
- return "short"
66
- }())
67
 
68
  h := &Handler{
69
  cfg: cfg,
@@ -208,7 +199,6 @@ func (h *Handler) Middleware() gin.HandlerFunc {
208
  }
209
  }
210
  if secretHash == "" && envSecret == "" {
211
- fmt.Printf("[DEBUG-AUTH] %s: No auth configured (Hash empty, Env empty)\n", clientIP)
212
  c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"error": "remote management key not set"})
213
  return
214
  }
@@ -241,11 +231,8 @@ func (h *Handler) Middleware() gin.HandlerFunc {
241
  candidates = append(candidates, qk)
242
  }
243
 
244
- fmt.Printf("[DEBUG-AUTH] %s: Found %d candidate keys\n", clientIP, len(candidates))
245
-
246
  if len(candidates) == 0 {
247
  if !localClient {
248
- fmt.Printf("[DEBUG-AUTH] %s: No key provided (Headers empty, Query empty)\n", clientIP)
249
  fail()
250
  }
251
  c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "missing management key"})
@@ -259,7 +246,6 @@ func (h *Handler) Middleware() gin.HandlerFunc {
259
  if envSecret != "" {
260
  for _, provided := range candidates {
261
  if subtle.ConstantTimeCompare([]byte(provided), []byte(envSecret)) == 1 {
262
- fmt.Printf("[DEBUG-AUTH] %s: Env Secret Match! (candidate len=%d)\n", clientIP, len(provided))
263
  authenticated = true
264
  break
265
  }
@@ -271,7 +257,6 @@ func (h *Handler) Middleware() gin.HandlerFunc {
271
  for _, provided := range candidates {
272
  err := bcrypt.CompareHashAndPassword([]byte(secretHash), []byte(provided))
273
  if err == nil {
274
- fmt.Printf("[DEBUG-AUTH] %s: Hash Match! (candidate len=%d)\n", clientIP, len(provided))
275
  authenticated = true
276
  break
277
  }
@@ -293,7 +278,6 @@ func (h *Handler) Middleware() gin.HandlerFunc {
293
 
294
  // If we get here, all candidates failed
295
  if !localClient {
296
- fmt.Printf("[DEBUG-AUTH] %s: All %d candidates failed validation.\n", clientIP, len(candidates))
297
  fail()
298
  }
299
  c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "invalid management key"})
 
53
  func NewHandler(cfg *config.Config, configFilePath string, manager *coreauth.Manager) *Handler {
54
  envSecret, _ := os.LookupEnv("MANAGEMENT_PASSWORD")
55
  // DEBUG: Print raw env secret length and hex
56
+ envSecret, _ := os.LookupEnv("MANAGEMENT_PASSWORD")
 
 
 
57
  envSecret = strings.TrimSpace(envSecret)
 
 
 
 
 
 
58
 
59
  h := &Handler{
60
  cfg: cfg,
 
199
  }
200
  }
201
  if secretHash == "" && envSecret == "" {
 
202
  c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"error": "remote management key not set"})
203
  return
204
  }
 
231
  candidates = append(candidates, qk)
232
  }
233
 
 
 
234
  if len(candidates) == 0 {
235
  if !localClient {
 
236
  fail()
237
  }
238
  c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "missing management key"})
 
246
  if envSecret != "" {
247
  for _, provided := range candidates {
248
  if subtle.ConstantTimeCompare([]byte(provided), []byte(envSecret)) == 1 {
 
249
  authenticated = true
250
  break
251
  }
 
257
  for _, provided := range candidates {
258
  err := bcrypt.CompareHashAndPassword([]byte(secretHash), []byte(provided))
259
  if err == nil {
 
260
  authenticated = true
261
  break
262
  }
 
278
 
279
  // If we get here, all candidates failed
280
  if !localClient {
 
281
  fail()
282
  }
283
  c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "invalid management key"})