Skip to content

[Security] Empty API key silently disables all HTTP auth #424

@santoshkumarradha

Description

@santoshkumarradha

Summary

When config.APIKey is empty, APIKeyAuth silently becomes a no-op, so a production deployment that forgets to set AGENTFIELD_API_KEY runs with no HTTP authentication and emits no warning.

Context

The first lines of APIKeyAuth at auth.go:26 are if config.APIKey == "" { c.Next(); return }. A mis-injected secret, a misconfigured Kubernetes secret mount, or an accidental environment variable omission silently disables all auth for every API route. There is no startup log, no metric, and no health-check signal indicating auth is off. This has caused production outages in similar systems when ops teams deployed without noticing the missing env var.

Scope

In Scope

  • Either: fail server startup when API auth is configured but the key is empty (preferred).
  • Or: require an explicit AGENTFIELD_INSECURE_DISABLE_AUTH=true (or equivalent config flag) to allow the no-op, and emit a WARN log on every request when it is active, plus a loud startup log.
  • Whichever path is chosen, make it explicit and auditable.

Out of Scope

  • Changing how keys are validated once present.
  • Forcing API keys to meet complexity requirements — that is a separate concern.
  • Modifying the admin token middleware (tracked in S7).

Files

  • control-plane/internal/server/middleware/auth.go:26 — replace silent no-op with explicit startup guard or insecure-mode flag
  • control-plane/internal/config/config.go — add InsecureDisableAuth bool field if taking the explicit-flag route
  • control-plane/cmd/agentfield-server/main.go — add startup validation that rejects empty API key unless insecure mode is explicitly set
  • control-plane/internal/server/middleware/auth_test.go — test: empty API key with no insecure flag causes startup error (or middleware panics with clear message)

Acceptance Criteria

  • Server refuses to start (or middleware refuses to register) when APIKey is empty and no explicit insecure-mode flag is set
  • If insecure mode is explicitly enabled, a WARN-level log is emitted at startup and optionally on each unauthenticated request
  • Existing tests that configure a non-empty API key are unaffected
  • Tests pass (go test ./control-plane/...)
  • Linting passes (make lint)

Notes for Contributors

Severity: MEDIUM

Look at how AdminTokenAuth (S7) is fixed — apply the same pattern here so both middleware pieces are consistent. The startup-validation approach (fail in main.go or server.go before routes are registered) is generally easier to test than a middleware-level panic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:control-planeControl plane server functionalitybugSomething isn't workingsecuritySecurity vulnerability

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions