The identity JWT

A route can tell its service who is calling with a signed JWT: the gateway signs a short token for each request it forwards, and the service checks it against public keys the gateway publishes. The service needs no secret, no account table and no call back to anybody.

JWT or Signed JWT

The Auth forward list of a route offers both. Choose Signed JWT (signed-jwt in the API): the gateway signs the token with its own keys, and the service proves it came from the gateway before believing a word of it.

JWT (jwt) sends the same claims in an unsigned token (alg none). Any caller able to reach the service directly can write one, so it is only for a service that cannot be reached except through the gateway and that merely decodes the token - a quick test, or a library that cannot verify a signature. When in doubt, Signed JWT.

Set it up

Prerequisite: a route to the service, in Infra > Routes.

  1. Open the route, section Identity: tick the facts the service needs (username, email, roles, tenant...) and, under As, the claim name each travels under.
  2. Section Auth forward: Mechanism Signed JWT. Pick the Algorithm (ES256, recommended), the Token TTL, and an Audience the service will check (orders-api). Save.
  3. Click Preview, beside the mechanism: it shows the token a service would receive for a sample caller.
  4. On the Routes screen, open the OIDC / JWT drawer (beside Global) and copy Discovery (internal), for instance http://meerkat:7070/.well-known/openid-configuration.
  5. Configure the service with that address and the audience (examples below), deploy it, and call the route as a signed-in user: the service now knows who is calling.

What the service receives

The token arrives as Authorization: Bearer ..., and any Authorization the client sent is removed first, so a caller cannot forge one. It carries:

Claim What it holds
iss the issuer: the gateway's internal issuer, the internal plane's full name (see The issuer), or the route's own Issuer when it writes one
sub the caller's account id
aud the route's Audience, or its name when the field is empty: set one when the service checks for a value of its own, or so that renaming the route does not change its tokens. The same rule as an OIDC client's audience: any text up to 255 characters, spaces inside included, no control character
iat, exp when it was signed, and when it stops being valid: two minutes later by default, set per route
your claims the attributes the route chose to send - username, e-mail, roles, capabilities, tenant - under the names you gave them

A decoded payload, for a route orders-api that sends username, email, roles and tenant:

{
  "iss": "http://meerkat-internal.shop.svc.cluster.local:7070",
  "sub": "usr_123",
  "aud": "orders-api",
  "iat": 1764583200,
  "exp": 1764583320,
  "username": "jdoe",
  "email": "jdoe@example.com",
  "roles": "ROLE_USER,billing-reader",
  "tenant": "acme"
}

The algorithm is ES256 by default (recommended), EdDSA, or RS256 for a library that knows nothing else.

Preview, beside the mechanism in Auth forward, shows the real thing before any traffic: a token signed by the gateway's key for a sample user, the algorithm and key id, and its claims decoded.

The Auth forward section of Orders API on Signed JWT, its Preview open: the Authorization header the service receives, ES256 with the key id, and the decoded claims

The shape of the roles

The roles attribute carries one expression, read as a pipeline from left to right. The same expression shapes the roles header, a JWT claim and an OIDC claim; a result that is a JSON array lands in a claim as an array.

Verb What it does
.Keep "tag:BILLING" "ROLE_USER" keeps the roles carrying a catalogue tag, or named
.Drop ... the opposite: everything except those
.Declared the roles the route's application declares in its spec, mapped on Endpoint security: those the caller holds, under the application's names
cutHead "ROLE_", cutTail, addHead, addTail reshape each name
lower, upper change the case
join ",", json the result: a separated list, or a JSON array

Without an expression a route sends every role, comma-separated ({{join "," .Roles}}), or, once it maps the roles its application declares, {{.Roles | .Declared | join ","}} (see Per-endpoint security). .Keep, .Drop and .Declared read catalogue names, so they go before any verb that reshapes them.

The expression is Go's text/template, so it can also decide: a selection that keeps nothing is false, and if, else if, else turn a set of roles into the single value an application wants. Grafana's tenant role, from three roles tagged grafana:

{{if .Roles | .Keep "ROLE_ADMIN" "grafana-admin"}}Admin{{else if .Roles | .Keep "grafana-editor"}}Editor{{else}}Viewer{{end}}

More shapes, with the application they were written for, are in Fitting an application.

How a service verifies it

Everything a service needs is served on the internal plane, port 7070: the port the services behind the gateway call, never put behind an ingress. Nothing outside the cluster has a reason to read it, so nothing outside reaches it. It needs no token: it holds public keys only, which give no power, and a service has to read them before it holds anything at all. meerkat below is the gateway's name in our deployment files; the OIDC / JWT drawer writes the real one, asked of the runtime - on Kubernetes the Service's full name, such as http://meerkat-internal.shop.svc.cluster.local:7070, on Swarm or compose the service's. Once a certificate is placed on the internal plane, the same is served in HTTPS on 7443, and the drawer gives the https:// address; the services then trust the authority that signed it (TLS).

http://meerkat:7070/.well-known/openid-configuration
{
  "issuer": "http://meerkat:7070",
  "jwks_uri": "http://meerkat:7070/.well-known/jwks.json",
  "id_token_signing_alg_values_supported": ["ES256", "EdDSA", "RS256"],
  "subject_types_supported": ["public"]
}

One address, and the library learns from it both things it has to check: the issuer the tokens carry, and the keys they are signed with. Nothing to copy into the service's configuration by hand, and a key rotation reaches it on its own. jwks_uri is built from the address the caller used, so it names the gateway the way the service reaches it.

Libraries take it in one of two ways:

Two examples

A Node service, with the jose library (npm install jose):

import { createRemoteJWKSet, jwtVerify } from 'jose';

const issuer = 'http://meerkat-internal.shop.svc.cluster.local:7070'; // Issuer (internal)
const jwks = createRemoteJWKSet(new URL(issuer + '/.well-known/jwks.json'));

export async function caller(req) {
  const token = (req.headers.authorization || '').replace(/^Bearer /, '');
  const { payload } = await jwtVerify(token, jwks, { issuer, audience: 'orders-api' });
  return payload; // { sub, username, email, roles, tenant, ... }
}

A Spring Boot service, as an OAuth2 resource server (application.yml):

spring:
  security:
    oauth2:
      resourceserver:
        jwt:
          issuer-uri: http://meerkat-internal.shop.svc.cluster.local:7070
          audiences: orders-api

In both, a token signed by anybody else, for another route, or expired is refused before the service's code runs.

The JWKS, for a library that only takes keys

http://meerkat:7070/.well-known/jwks.json

The public half of the keys, as a standard JWKS - for a library that knows no discovery, such as jose's remote key set. The token's kid names the key, and the key carries its algorithm, so the service takes the algorithm from the key, never from the token's header. It then checks the issuer itself, against the one the drawer shows under Issuer (internal).

A PEM, for a service that cannot fetch anything

The OIDC / JWT drawer, beside Global on the Routes screen, shows each algorithm's public key as PEM. That key must be replaced by hand at every rotation, where the two addresses above follow it on their own.

The issuer

Every token says who issued it in iss, and a service checks it. A route's JWT goes to a service inside the cluster, which reads the keys on the internal plane: it carries the gateway's internal issuer, the internal plane's full name as the runtime names it - in Kubernetes the Service in front of it, https://<release>-internal.<namespace>.svc.cluster.local:7443 once a certificate is placed on it, http://...:7070 before. It is not typed: the OIDC / JWT drawer shows it under Issuer (internal), and the internal discovery document names it, the same whatever name a service used to read it - a JWT nobody asks for has to carry the one name every service learnt. A gateway that cannot ask its runtime (a bare binary) uses its public issuer instead.

A service that reads the issuer in the internal discovery follows by itself. A service that writes the issuer it expects in its own configuration must write that name - or the route writes the value the service expects: Issuer, under the audience in Auth forward, replaces the iss of that route's tokens.

The public name, chosen in Public address, is the issuer of the public door: the OpenID provider's tokens asked from outside the cluster.

The discovery document describes how to verify a token, not how to obtain one: for this mechanism the gateway signs one short token for each request it forwards, and there is nothing to exchange. A library that insists on authorization and token endpoints is one to point at the JWKS instead. An application that wants to sign its users in itself is a different case: with the OpenID provider (Enterprise edition), the same document then also names those endpoints.

Rotation

Renew keys, in the same drawer, makes a new pair for each algorithm and signs with it straight away. The previous public keys stay in the JWKS for ten minutes, so the tokens already signed keep verifying until they expire.

The JWKS is served with a cache of five minutes. A library that fetches the JWKS again when it meets an unknown kid - most of them do - follows a rotation at once. One that only trusts its cache can refuse new tokens for up to five minutes after a rotation: check how yours behaves before rotating in production.

Upgrading from an older version. The keys used to be served on the application port (8080). A service still reading http://...:8080/.well-known/jwks.json can no longer verify its tokens: point it at the internal plane, as above. Same keys, same tokens.

Read more