Connecting an application

Putting an application behind a route protects it. Making it know who is using it - their name, their rights - is the second half, and each application takes it its own way. These recipes cover a few common ones, one per family: read the one closest to yours.

First pick the mechanism, from what the application can do:

Mechanism What the application gets Choose it when Recipes
Headers one header per fact, on every request the application has a "trust the proxy" mode (an authentication header) Grafana, GeoServer
Signed JWT a short signed token on every request the service verifies a bearer token against a JWKS The identity JWT
OIDC (Enterprise) nothing on the request: the application signs in itself, through Meerkat the application only accepts an OpenID Connect provider RabbitMQ, DbGate

With Headers, nothing is declared beyond the route: in Identity, pick the facts and give each the header name the application reads; in Auth forward, mechanism Headers. Meerkat removes any copy of those headers a caller sent, so through the gateway they cannot be forged. With OIDC, declare a client and bind the route to it: see Meerkat as an OpenID provider.

The examples below use https://apps.example.com for the gateway's public address, a route per application under its own path, and meerkat for the gateway's name inside the cluster (the OIDC / JWT drawer writes the real one).

Both families rest on one promise: the application is reachable only through the gateway. A header is trusted because nobody else can set it; an application also reachable directly - a NodePort, an ingress of its own, a published port - trusts whoever reaches it that way. Keep its Service internal (ClusterIP), put nothing else in front of it, and where the platform allows, add a network policy that admits only the gateway.

Grafana, by headers

Mechanism: headers, read by Grafana's auth proxy.

Grafana side (environment variables; the same keys exist in grafana.ini under [auth.proxy] and [server]):

GF_SERVER_ROOT_URL=https://apps.example.com/grafana/
GF_SERVER_SERVE_FROM_SUB_PATH=true
GF_AUTH_PROXY_ENABLED=true
GF_AUTH_PROXY_HEADER_NAME=X-WEBAUTH-USER
GF_AUTH_PROXY_HEADER_PROPERTY=username
GF_AUTH_PROXY_AUTO_SIGN_UP=true
GF_AUTH_PROXY_HEADERS=Email:X-WEBAUTH-EMAIL Name:X-WEBAUTH-NAME Role:X-WEBAUTH-ROLE
GF_AUTH_PROXY_WHITELIST=10.42.0.0/16
GF_AUTH_SIGNOUT_REDIRECT_URL=https://apps.example.com/logout

Meerkat side:

  1. A route on /grafana/** to the Grafana service, path kept as is (Grafana serves from the sub-path).
  2. Identity: username as X-WEBAUTH-USER, email as X-WEBAUTH-EMAIL, fullname as X-WEBAUTH-NAME.
  3. Auth forward: mechanism Headers.
  4. The role. Grafana wants one of Viewer, Editor, Admin. In Application > Roles, declare three roles tagged grafana (grafana-admin, grafana-editor, grafana-viewer). In the route's Security section, put them in its access rule beside ROLE_ADMIN. Then add to Identity the attribute roles as X-WEBAUTH-ROLE, with the expression:
{{if .Roles | .Keep "ROLE_ADMIN" "grafana-admin"}}Admin{{else if .Roles | .Keep "grafana-editor"}}Editor{{else}}Viewer{{end}}

One route serves everybody, each with their level. See The shape of the roles.

The Grafana route's Identity section: username as X-WEBAUTH-USER, with REMOTE_USER and X-Remote-User sent beside it, fullname as X-WEBAUTH-NAME, email as X-WEBAUTH-EMAIL, and roles as X-WEBAUTH-ROLE through the expression, each with the value a sample caller gets

Check it: click Preview in the route's Auth forward: it lists the headers a sample caller would send (X-WEBAUTH-USER: jdoe...). Then open https://apps.example.com/grafana/ signed in: Grafana shows your name in its profile menu, with no Grafana sign-in page.

Traps:

GeoServer, by headers

Mechanism: headers, read by GeoServer's HTTP Header authentication filter.

GeoServer side (web administration, Security > Authentication):

  1. Authentication Filters, Add new, HTTP Header. Name it (gateway), and set Request header attribute to a name nobody would guess, such as X-Gw-Auth-7f3c9a - GeoServer's own documentation calls it a shared secret between the proxy and GeoServer.
  2. Role source: either User group service (GeoServer's own users and roles, matched on the name), or Request header with a second header carrying the roles, separated by ;.
  3. Filter Chains: in each chain the browser and the clients use (web, rest, gwc, default), add the new filter before anonymous, and remove basic and form where people should only arrive through the gateway.
  4. Settings > Global, Proxy Base URL: https://apps.example.com/geoserver, so the capabilities documents name the public address.

Meerkat side:

  1. A route on /geoserver/** to the GeoServer service.
  2. Identity: username as X-Gw-Auth-7f3c9a (the same name). With roles from a header, roles as the roles header, shaped to GeoServer's form, for instance {{.Roles | .Keep "tag:GEOSERVER" | join ";"}} for the roles you tagged for it, named as GeoServer names them (ROLE_ADMINISTRATOR...).
  3. Auth forward: mechanism Headers.

Check it: Preview in Auth forward shows the header and its value for a sample caller. Then open https://apps.example.com/geoserver/web/ signed in: GeoServer shows you as logged in, under your username.

Traps:

RabbitMQ management, through the OpenID provider

Mechanism: OIDC (Enterprise). The management UI signs in through Meerkat with PKCE, then calls the management API with its access token through the same route.

Meerkat side:

  1. The issuer: the application plane's public name, declared in Domains & TLS, Application tab - here apps.example.com, so https://apps.example.com.
  2. A client rabbitmq-ui, without a secret (the UI is browser code), and Audience rabbitmq (RabbitMQ's resource_server_id). A client declares no redirect URI: the UI's callback page is under the route's path, which is what the provider accepts.
  3. A route on /rabbitmq/** to the management port (15672), mechanism OIDC, client rabbitmq-ui, claims preferred_username from username and a roles claim. Two levels are two routes on the same path and client: the first for your RabbitMQ administrators with roles fixed to admin, the second for the others with roles fixed to viewer.

RabbitMQ side (rabbitmq.conf):

auth_backends.1 = rabbit_auth_backend_oauth2
# during the switch only, so the existing accounts still work:
auth_backends.2 = rabbit_auth_backend_internal

auth_oauth2.resource_server_id = rabbitmq
auth_oauth2.issuer = https://apps.example.com
auth_oauth2.preferred_username_claims.1 = preferred_username
auth_oauth2.additional_scopes_key = roles
auth_oauth2.scope_aliases.admin = rabbitmq.tag:administrator rabbitmq.read:*/* rabbitmq.write:*/* rabbitmq.configure:*/*
auth_oauth2.scope_aliases.viewer = rabbitmq.tag:monitoring rabbitmq.read:*/*

management.path_prefix = /rabbitmq
management.oauth_enabled = true
management.oauth_client_id = rabbitmq-ui
management.oauth_scopes = openid profile
# during the switch only: keeps the username and password form
management.oauth_disable_basic_auth = false

Check it: Try a sign-in on the rabbitmq-ui client's row, for one of your RabbitMQ administrators, shows the first route letting them in and roles: admin in the access token. Then open https://apps.example.com/rabbitmq/ and click Click here to log in: you are signed in without a password.

Traps:

DbGate, through the OpenID provider

Mechanism: OIDC (Enterprise). DbGate's server runs the sign-in and keeps a secret.

Meerkat side:

  1. The issuer: the public name apps.example.com, so https://apps.example.com.
  2. A route on /dbgate/** to DbGate, mechanism OIDC, client dbgate, claim preferred_username from username (and email, name if you like).
  3. The client dbgate, with its secret Given by the application: when DbGate's chart writes it in a Kubernetes Secret (dbgate-oidc, key client-secret, read by DbGate as OAUTH_CLIENT_SECRET), choose that key in the field's list - it is offered because DbGate's pod behind the route reads it - and Meerkat reads it at each sign-in: nobody copies it. Without a chart that writes one, Generated by Meerkat, copied into DbGate's configuration before saving. DbGate comes back under /dbgate/, the route's path: nothing to declare.

DbGate side (environment variables):

WEB_ROOT=/dbgate
OAUTH_AUTH=https://apps.example.com/meerkat/oidc/authorize
OAUTH_TOKEN=http://meerkat:7070/meerkat/oidc/token
OAUTH_LOGOUT=https://apps.example.com/logout
OAUTH_CLIENT_ID=dbgate
OAUTH_CLIENT_SECRET=...      # from the Secret dbgate-oidc, key client-secret
OAUTH_SCOPE=openid profile
OAUTH_LOGIN_FIELD=preferred_username
LOGIN_PERMISSIONS_alice=*
LOGIN_PERMISSIONS_bob=~*, widgets/database

Traps:

Read more