Using Jwts for Microservices Communication Service-to-service

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams set up using jwts for microservices communication service to service with signed tokens. One service sends a signed JSON token, and the next service checks the signature. Most teams start by sharing one signing key across every backend app. That approach makes setup fast for small systems. Still, wide permissions let any single compromised service call every other internal API. When a token holds broad roles, one bad request can change critical data. How using jwts for microservices comm

Service-to-Service Authentication + Crisis Communication Protocols: the complete guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free white paper. No spam. Unsubscribe anytime.

Teams set up using jwts for microservices communication service to service with signed tokens. One service sends a signed JSON token, and the next service checks the signature. Most teams start by sharing one signing key across every backend app. That approach makes setup fast for small systems. Still, wide permissions let any single compromised service call every other internal API. When a token holds broad roles, one bad request can change critical data.

How using jwts for microservices communication service to service works

A JSON Web Token holds three parts: a header, a payload, and a signature. In a backend system, an identity server creates and signs this token. The calling service asks the identity server for a token before sending data. The identity server checks the caller identity and returns a short-lived signed token. The payload holds claims like the caller ID, target audience, and allowed roles. The calling service puts this token in the request header for the target service.

When the target service gets the request, it reads the token header first. It uses a public key to check the math on the token signature. It never needs to call the identity server during this local check. Next, the target service checks the expiration time and the target audience claim. If the audience matches and the time is valid, the request moves forward. This design keeps network calls fast across many small backend services.

How teams manage signing keys and scopes

Teams must pick between shared secret keys and public-private key pairs. Shared secret keys are simple, but every service holds the exact same secret. If one app leaks that secret, an attacker can forge tokens for everything. Public-private key pairs fix this big risk for growing engineering teams. Only the central identity server holds the private key that signs new tokens. Other backend apps only hold the public key to check incoming signatures.

Teams also use scopes and claims to narrow down what a service can do. A billing service should only hold claims that allow payment updates. It should not hold claims that allow deleting user accounts in another app. Teams must rotate their signing keys on a regular schedule to stay safe. Automated key endpoints let services fetch new public keys without restarting any apps.

Service-to-Service Authentication + Crisis Communication Protocols: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native token checks solve and what they miss

Signed tokens prove which service sent a request without slow database lookups. They stop outside attackers from calling internal endpoints without a valid signature. Audience claims also stop a token meant for one app from working elsewhere. This native setup handles service identity well across large cloud networks.

Still, token checks only decide which app can walk through the front door. Once a service passes the token check, the token does not inspect live payloads. It cannot stop a trusted service from running a bad database query. It also cannot mask sensitive fields like emails, phone numbers, or card numbers. If an engineer debugs a live service, static service tokens do not log actions. Teams still need a way to control individual requests and protect raw data.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev sits inline in the protocol beside each supported service as an open-source proxy, a sidecar for your database or API. For every query or command an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human approval.

First, hoop.dev guardrails block banned queries before they run or hold risky ones for review, and hoop.dev data masking rewrites matched sensitive values in responses in memory. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Should microservices share a single symmetric signing key?

No, sharing one secret key across services creates a high security risk. If one service gets breached, attackers can sign tokens for every other app. Use a private key on your auth server and public keys on target services.

How long should a service-to-service token stay valid?

Keep internal service tokens short, often between five and fifteen minutes. Short life spans shrink the window of risk if a token leaks in logs. Apps can fetch a fresh token in the background before the old one expires.

Should services pass user tokens or mint new service tokens?

Pass user context only when the target service checks specific user permissions. Even then, exchange the outside token for a fresh internal token with narrow scopes. Never pass broad external tokens straight through every internal backend app.

Save the open-source gateway.

hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.