Beyond Static JWT: Choosing Financial-Grade K8s Service Authentication Across Cluster Boundaries
This article analyzes why static HS256 JWT secrets fail in financial Kubernetes environments, details K8s ServiceAccount token automation and rotation, explains secure cross-cluster authentication via gateway token exchange and SPIFFE mTLS, and compares native workload identity with Keycloak for a zero-static-secret architecture.
Reading font

Why Static Symmetric JWT Secrets Must Be Eliminated in Finance
Many projects start with HS256 static secrets because they are simple: gateway and microservices share one Kubernetes Secret, sender signs, receiver verifies. In high-security production this design has three structural flaws:
Verification key equals signing key (zero-barrier lateral forgery) : With HS256 the same key signs and verifies. If 30 services need to verify callers, all 30 hold the shared secret. Compromise of one edge service (e.g., reporting, notifications) leaks the secret, letting an attacker forge JWTs for any service and call core accounting APIs directly.
Static long-lived secrets and rotation paralysis : To avoid frequent config changes, static secrets often go months or years without rotation; issued machine tokens may have multi-month TTL. Emergency rotation requires synchronized update and rolling restart of all signers and verifiers — impractical under strict financial change windows, leading to "years without key rotation."
No holder binding (Bearer token replay) : Traditional static JWTs are bearer tokens. If a token leaks into gateway access logs, APM traces, or unencrypted internal networks, it can be replayed until expiry.
Figure 1 contrasts symmetric shared keys (verifier = signer) with asymmetric short-lived workload credentials (public/private key separation + audience binding).
To eliminate "single leak = full compromise," a financial-grade auth foundation must enforce two iron rules: first, the signing private key never leaves the control plane; workloads only hold public keys for verification ( RS256 / ES256). Second, abolish static long-lived credentials; every credential must bind to a specific workload instance and target audience ( aud) and support minute-level automatic rotation.
K8s ServiceAccount Authentication: What Is Auto-Injected vs. What Requires Code Changes
The common confusion: "Are credentials auto-injected? Does business code need to change?"
Accurate answer: Credential request, mount, and periodic refresh are 100% handled by Kubelet with zero business code involvement; but reading the credential into requests and verifying it on the receiver side depends on whether you use pure native SDK mode or push it down to a service mesh.
1. Platform-Automated Part: Projected Volume & 80% Lifetime Rotation
Pre-1.21 Kubernetes stored never-expiring SA tokens in etcd Secrets — now fully deprecated. Modern Kubernetes enables BoundServiceAccountTokenVolume (based on TokenRequest API) by default.
When a workload YAML declares a projected volume with a specific audience and expirationSeconds, Kubelet automatically manages the entire credential lifecycle:
apiVersion: v1
kind: Pod
metadata:
name: payment-caller
namespace: finance-core
spec:
serviceAccountName: payment-caller-sa
containers:
- name: app
image: registry.internal/finance/payment-caller:v2.4
volumeMounts:
- mountPath: /var/run/secrets/tokens
name: ledger-api-token
readOnly: true
volumes:
- name: ledger-api-token
projected:
sources:
- serviceAccountToken:
path: ledger-token
expirationSeconds: 1800
audience: "https://ledger-svc.finance-core.svc"Under this config the platform automatically does two critical things:
In-memory filesystem isolation : Kubelet requests a JWT signed with RS256 or ES256 via the API Server's TokenRequest endpoint. The token is never written to etcd; it is mounted directly into the node's memory-backed tmpfs and erased the moment the Pod is destroyed.
Silent auto-rotation : Kubelet renews the token at 80% of its lifetime (e.g., minute 24 of a 1800-second token, or minute 48 of the default 3600-second token) or when less than 24 hours remain, by requesting a new token from the API Server and atomically replacing the file at /var/run/secrets/tokens/ledger-token via symlink swap.
2. Parts Requiring Business Code or Mesh Cooperation: Hot Reload & Verification
Even though the file updates on disk, HTTP/gRPC requests won't automatically insert it into headers. Figure 2 shows the four-step loop from Kubelet issuance through tmpfs rotation to client presentation and server verification.
If the team does not adopt a service mesh and uses native SA tokens directly, business code (or a common base SDK) must handle three details:
Client must never read the file once at startup and cache it : The most common production pitfall. Developers often read the token once during init via os.ReadFile into a memory variable. At minute 31 the old token expires and all subsequent calls return 401 Unauthorized. The client SDK must re-read the mount path every minute or watch for filesystem updates (Go's client-go provides transport.NewBearerAuthWithRefreshRoundTripper with built-in timed re-read logic).
Receiver should prefer OIDC JWKS offline verification : The receiver (e.g., ledger-svc) gets Authorization: Bearer <token>. Kubernetes API Server exposes native OIDC discovery endpoints ( /.well-known/openid-configuration and /openid/v1/jwks). The receiver fetches and periodically caches the cluster's public key set (JWKS) at startup, then verifies signature, expiry, and strictly checks iss (issuer), sub (caller identity, format system:serviceaccount:finance-core:payment-caller-sa), and aud (must equal its own service identifier https://ledger-svc.finance-core.svc). Offline verification takes microseconds and adds zero load to the API Server.
High-sensitivity operations add TokenReview real-time validation : Offline JWKS verification has a small time window — if the caller Pod is deleted, its already-issued short-lived token still passes public-key verification for the remaining minutes. For core interfaces like large fund transfers, the receiver can call Kubernetes' TokenReview API to have the API Server check in real time whether the token's bound Pod UID is still alive, caching the result for 10–30 seconds to protect the API Server.
3. Eliminating Code Changes Entirely: Push Down to SPIFFE & Service Mesh
If you want business code completely unaware of token reading and verification, the industry standard is to push workload identity into the infrastructure layer — using the SPIFFE (Secure Production Identity Framework for Everyone) standard with a service mesh (e.g., Istio), or Kubernetes 1.37's GA PodCertificateRequest (KEP-4317) and ClusterTrustBundle (KEP-3257).
Under Istio (traditional sidecar or sidecar-less Ambient Mesh node-level ztunnel) or SPIRE:
The data-plane proxy automatically reads the local Projected Volume's K8s SA token, proves its container identity to the control plane ( istiod or SPIRE Server), and exchanges it for a very short-lived X.509-SVID certificate (the cert's SAN extension carries the standard identity spiffe://cluster.local/ns/finance-core/sa/payment-caller-sa).
When Service A calls Service B, the underlying Envoy or ztunnel proxy automatically establishes a mutual TLS (mTLS) encrypted channel and performs mutual certificate verification during the handshake.
Operators only write declarative AuthorizationPolicy resources to precisely control "which ServiceAccount in which Namespace may call which microservice path" — business code writes zero authentication logic.
Supporting External Cluster Services: Can We "Unconditionally Trust the Gateway"?
Real production environments rarely run 100% inside a single Kubernetes cluster. External core banking hosts, legacy VM apps, and partner callbacks all need to call internal services.
Many architects intuitively think: "Let the north-south API gateway authenticate external services; once a request passes the gateway, internal services just blindly trust whatever the gateway forwards."
1. Why "Gateway Verifies Once, Internal Network Runs Naked" Is Extremely Dangerous in Finance
This "hard shell, soft center" perimeter security model is a classic anti-pattern in Zero Trust and financial compliance audits, exposing two major attack surfaces:
Internal lateral bypass (East-West Bypass) : If the gateway authenticates the external caller but then strips the external credential and forwards a plain request (e.g., adding a custom X-Caller-Org: bank-partner-a header), and internal services trust that header simply because traffic comes from the internal network — then compromise of any edge Pod (e.g., a container serving static assets or marketing pages) lets an attacker directly call core accounting services from inside the cluster, manually forging X-Caller-Org: bank-partner-a and completely bypassing all API gateway defenses.
Confused Deputy problem : Even if internal services restrict connections via network policies or mTLS to "only allow the API gateway Pod to connect," if the gateway does not forward the original external caller's cryptographic credential or signature context, the backend core service only sees "request from gateway" and cannot independently verify "which external organization actually initiated the request, and whether the gateway misrouted due to a config error."
2. Financial-Grade Standard Solution: North-South Strong Auth + Gateway Token Exchange (RFC 8693) + East-West Dual-Layer Verification
The correct approach is not "blind trust" but a defense-in-depth system of "gateway boundary auth + token exchange + cluster-internal transport-layer and application-layer dual verification."
Figure 3 shows how the orange external domain at top passes through the boundary gateway for token conversion, then the green core services at bottom perform transport-layer and application-layer dual verification.
The cross-boundary call chain consists of three tightly coupled links:
First link (North-South ingress auth) : External services or front-end machines accessing the cluster boundary gateway must abandon static API Keys. Prefer mutual mTLS client certificate auth (following RFC 8705 certificate binding) or asymmetric private-key-signed JWT assertions (following RFC 7523 private_key_jwt spec) . The external system keeps its private key; the gateway or external identity provider stores only the public key certificate.
Second link (Gateway-layer token exchange: RFC 8693 Token Exchange / Transaction Token) : After verifying the external request, the API gateway never directly forwards the original long-lived external token, nor passes unsigned bare headers . Using its own key (or calling an internal token service), the gateway performs standard OAuth 2.0 Token Exchange (RFC 8693) or issues an IETF Transaction Token (Txn-Token) , generating an asymmetrically signed JWT with a very short TTL (e.g., 30–60 seconds) valid only for this internal call chain. The internal token's payload explicitly contains three critical fields: sub (Subject): records the real identity of the original external organization or service; act (Actor): records the gateway identity performing the proxy forwarding; aud (Audience): locks down the target internal microservice for this request.
Third link (Cluster-internal dual Zero Trust verification) : When the request reaches the core accounting service from the gateway, the core service executes two independent checks: Transport-layer verification (prevents internal bypass) : Via service mesh mTLS (or network policies + node certificates) verify the peer's SPIFFE ID is the legitimate gateway identity (e.g., spiffe://cluster.local/ns/ingress/sa/api-gateway). Any other Pod connecting directly is rejected at the TLS handshake. Application-layer verification (prevents privilege escalation & confused deputy) : The core service (or its sidecar's RequestAuthentication policy) uses the internal public key (JWKS) to verify the gateway-issued short-lived internal JWT, confirming the sub external caller has permission to access the current business interface.
Thus, even if an internal edge Pod is compromised, it lacks both the gateway's SPIFFE mTLS private key and the private key for signing internal transaction tokens — the internal lateral forgery path is completely blocked.
Native K8s SA / SPIFFE vs. Keycloak: Advantages, Limits, and Integration
Teams often struggle with another core choice: "Since Keycloak is a mature open-source IAM/IdP, should we fully adopt Keycloak or just use native K8s SA and SPIFFE?"
To decide correctly, first recognize these two technologies operate at completely different layers of a Zero Trust architecture.
1. Fundamental Difference: Infrastructure Identity (Who Am I) vs. Business Authorization & Federation (What Can I Do)
Kubernetes SA / SPIFFE (Workload Identity Layer) : Solves "Who is this process or container?" . Its core advantage is eliminating the "Secret Zero Problem" . Because the container runs under the direct view of Kubelet and the OS kernel, the platform can verify container authenticity via process namespace, cgroup, and Pod UID and automatically inject short-lived credentials — no human-preplaced first secret needed. But its limitation is clear: it issues infrastructure-level identities (only Namespace and ServiceAccount name), lacking business-level fine-grained permission scopes, commercial tenant attributes, and cannot directly issue identities to third-party partners without Kubelet.
Keycloak (OAuth2/OIDC Authorization & Federation Layer) : Solves "What business permissions does this caller have?" plus unified auth management across heterogeneous platforms and human/machine mixed calls. Keycloak provides full Client management, Scope permission mapping, multi-tenant Realm isolation, token exchange, and audit logs. But if you forcibly apply traditional Keycloak Client Credentials for internal Kubernetes microservice-to-microservice calls, you immediately hit two pits: 1. Initial secret resurrected (Credential Zero) : Traditional mode requires each microservice to present a static client_secret to Keycloak when requesting a token. How to securely place that secret in the Pod and rotate it? You're back to static password management. 2. Centralized stateful component availability bottleneck : Keycloak is a heavy stateful system dependent on relational DB and distributed cache. If hundreds of internal microservices hit Keycloak on every east-west call, or frequently call introspection endpoints, Keycloak jitter or DB pool exhaustion becomes an instant cluster-wide single point of failure (SPOF).
2. Cutting-Edge Best Practice: Layered Autonomy + Keyless Federation (Workload Identity Federation)
In modern financial cloud-native architecture, native workload identity (K8s SA / SPIFFE) and Keycloak are not mutually exclusive alternatives but a "golden combination: internal network uses platform-native identity, cross-boundary uses Keycloak federation exchange" .
Especially when a cluster-internal service genuinely needs an OAuth2 Access Token with complex business Scopes from Keycloak (e.g., to call a cross-department centralized gateway or external compliance interface), leverage Keycloak's native Federated JWT Client Authentication (RFC 7523-based federated client auth) to completely eliminate client_secret:
Configure Keycloak to trust K8s OIDC public keys : In Keycloak's Client authentication settings, change the auth method from traditional Client Id and Secret to Signed Jwt, and configure trust for the Kubernetes cluster's exposed JWKS public key endpoint.
Use K8s SA Token directly to exchange for business token : The Pod stores no Keycloak password. The business container reads the Kubelet-auto-mounted, hourly-rotated ServiceAccount JWT and sends it as client_assertion to Keycloak's /token endpoint:
curl -X POST "https://idp.internal.bank/realms/finance/protocol/openid-connect/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials" \
-d "client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer" \
-d "client_assertion=$(cat /var/run/secrets/tokens/keycloak-assertion-token)" \
-d "scope=settlement:write ledger:read"Full-chain zero static secrets : Keycloak verifies the client_assertion using K8s public keys, confirming it was issued by the cluster API Server for that specific Pod, then returns an OAuth2 Access Token with business permissions like settlement:write. The entire chain has zero static passwords written to disk.
Full-Scenario Selection Matrix & Evolution Roadmap
To help teams decide based on current ops capacity and architecture stage, Figure 4 compares four mainstream solutions across four dimensions: key distribution & rotation mechanism, code intrusion level, and applicable boundaries (note Row 1's red-marked static symmetric key anti-pattern vs. the three dynamic credential approaches' evolution relationship).
For teams currently using static symmetric JWT Secrets and wanting to evolve toward financial-grade high-security architecture, the following phased smooth migration path is recommended to avoid business disruption from a big-bang rewrite:
Phase 1 (Stop bleeding & decouple public/private keys, 1–2 weeks) : If full call-chain refactor isn't immediately possible, first switch static HS256 symmetric signing to RS256 or ES256 asymmetric signing. Only allow the gateway or a dedicated auth service to hold the private key for issuing tokens; all downstream business microservices mount only public keys (or fetch JWKS) for read-only verification, and enforce aud (target audience) checks. This step only changes config and verification key loading logic, instantly severing the biggest threat: "edge service leaks key → can forge any identity cluster-wide."
Phase 2 (Switch cluster-internal east-west to dynamic workload identity, 2–4 weeks) : - If team infrastructure is lean, service count under ~15: directly enable Kubernetes Projected ServiceAccount Token , wrap periodic file re-read logic in common RPC/HTTP client, receiver verifies offline via cluster OIDC JWKS. - If many services, multi-language heterogeneity, or want to fully free business devs: introduce Istio (recommend evaluating lower-overhead Ambient mode) or SPIRE , using automatically issued short-lived X.509-SVID certs for cluster-wide mutual mTLS and AuthorizationPolicy access control.
Phase 3 (North-south gateway token exchange & Keycloak keyless federation, on demand) : For external bank front-end machines, partners, and cross-cluster calls, deploy Keycloak as boundary authorization center. External callers access API gateway via mutual mTLS or private-key JWT; gateway performs RFC 8693 Token Exchange to issue short-lived internal transaction tokens for internal propagation; internal services needing Keycloak-protected external resources uniformly use K8s SA Token as client_assertion for federated token exchange, ultimately achieving a cluster-internal-and-external "zero static secret" financial-grade security closed loop.
For questions about attribution, corrections or content rights, please contactand we will review it promptly.