feat(sandboxd): require a bearer token via --auth-token-sha256

Merged
CH
2mo ago
+518-10

What this PR does / why we need it:

sandboxd authenticates no client. Anything that can reach :8080 or :9090 can run commands and read or write files as the daemon. NetworkPolicy is the intended boundary, but it does not cover every path. On GKE Dataplane V2 node-local traffic is admitted regardless of policy, and a missing or drifted namespace policy leaves the port open to neighbours.

This PR adds an optional bearer token:

  • --auth-token-sha256=<hex>: the SHA-256 digest of the token. Only the digest goes in the pod spec. The orchestrator mints a token per sandbox and keeps it in memory. A literal token in args or env would be copied into the pod spec, into objects derived from it (e.g. a Kueue Workload), and into the environment of every process sandboxd starts.
  • --auth-token-file=<path>: the token in a file, e.g. a mounted Secret. Set at most one of the two flags. An empty or missing file is a startup error.
  • When set, every gRPC call (unary and stream interceptors) and every REST request needs Authorization: Bearer <token>. Comparison is constant time over the SHA-256. Failures get UNAUTHENTICATED or 401 with WWW-Authenticate: Bearer.
  • GET /v1/health stays open for kubelet probes. /v1/metadata requires the token.
  • Unset leaves behaviour unchanged.

Out of scope: code inside the sandbox already has the API's reach, so the token does not defend against it. NetworkPolicy stays the primary boundary.

Includes tests (REST, gRPC unary and stream, health exemption, flag parsing, file loading), a USER_GUIDE section and OpenAPI bearerAuth.

Which issue(s) this PR is related to:

None filed.

Release Note

sandboxd: optional bearer-token client authentication via --auth-token-sha256 or --auth-token-file. /v1/health stays unauthenticated.

Summary by CodeRabbit

  • New Features
    • Added optional bearer-token authentication for gRPC and REST requests, configurable with a token digest or token file.
    • Requests with missing or invalid credentials are rejected; the REST health check remains accessible without a token.
    • Authentication remains disabled when neither option is configured.
  • Documentation
    • Added setup guidance, examples, and details on token handling and authentication behavior.