Secrets lifecycle¶
How to keep credentials and tokens out of logs, images, and the wrong process—and how to rotate JWT and OIDC signing material without taking unrelated dependencies offline.
For architecture and token placement, see Security architecture and Auth recipes. For gateway and JSON logging, see Observability. For TLS and HSTS at the edge, see Production TLS and edge headers. For query-string tokens (URL sessions, email links, redaction), see URL sessions, query tokens, and email links (security).
Principles¶
Never bake secrets into images. Build args and
DockerfileENVfor production secrets leak in layer history; inject at runtime (Kubernetes Secret, cloud secret manager → env or mounted file, CI/CD sealed secrets).Do not log secrets. Avoid printing
os.environ, full header dicts, or exception messages that echo user-controlledAuthorizationbodies. Usefluxlit.logging.redactwhen copying headers into logs or debug output.Scope secrets to the process that needs them. Long-lived IdP client secrets belong in the FastAPI / gateway environment, not in patterns that expose them to untrusted Streamlit widgets (see Security architecture).
Kubernetes and cloud patterns¶
Kubernetes: mount
Secretas files under/var/run/secrets/...or map keys to env vars on the Pod; useenvFromonly where every key is intended for the container. Prefer workload identity (IAM, GCP SA) for fetching short-lived tokens over long-lived API keys in env.AWS / GCP / Azure: use the platform secret store and inject into the task at rollout; rotate by new secret version + rolling restart rather than editing running pods in place.
Local / dev:
.envis fine for developer machines; keep.envout of Docker context (the default.dockerignorefromfluxlit buildalready lists.env).
Logs and observability¶
Gateway access logs and custom middleware can accidentally record Authorization, cookies, or API keys. When building structured logs:
Prefer allowlists of field names; never dump
request.headerswholesale into production indexes.Use
fluxlit.logging.redacthelpers when you must log a subset of headers for support.
See Observability for JSON formatter examples and correlation IDs.
JWT and OIDC secret rotation¶
JWKS (asymmetric / IdP keys)¶
When using FLUXLIT_JWT_JWKS_URL (or an equivalent URL in JWTAuthConfig), verification keys come from the IdP.
IdP key rotation is controlled by the issuer: new keys appear in JWKS with a new
kid; old keys remain until signing stops.FluxLit’s JWT path fetches JWKS as configured—ensure network egress to the JWKS URL from the gateway and watch cache / TTL behavior if you customize HTTP clients; after IdP rotation, stale caches can cause short 401 bursts until refreshed.
OIDC client secret rotation: update the secret at the IdP, then update
OIDC_CLIENT_SECRET(or your env) and roll replicas so Streamlit child processes inherit the new env.
BFF signing secrets¶
FLUXLIT_OIDC_BFF_SECRET (and similar) protect cookies or server-side exchanges. Rotate like HS256: deploy new value, roll processes, coordinate with any sticky session or multiple replica constraints documented in Security architecture.
For recipe-level wiring, see Auth recipes.