Protecting other applications
Forward authentication
On this page
- Introduction
- How a request is checked
- The three things that must line up
- nginx
- Traefik and Caddy: point them at
/proxy/verify/redirect - Traefik
- Caddy
- Envoy
- Prove it works
- Who may reach which application
- An application on another domain
- Rules for one path
- A path that could mean two things is refused
- What the application receives
- Groups and a signed identity
- Programs: an access token instead of a cookie
- When the sign-in behind a token was not strong enough
- Session lifetime
Introduction
Some applications have a weak sign-in of their own, or none at all, such as n8n, a dashboard or an internal tool. They know nothing about OpenID Connect (OIDC), so they cannot send people to Signari themselves.
"Forward authentication" puts Signari in front of such an application. The reverse proxy that serves the application asks Signari about every request before serving it. An answer of 200 means let it through, and 401 means send the browser to sign in.
You register each protected host with signari proxy, and you set up the proxy
itself with one of the recipes on this page.
How a request is checked
Before the proxy serves anything, it makes a "subrequest": a request of its own to
Signari's /proxy/verify, carrying the browser's cookie. Signari answers 200 with
the person's identity, and only then does the proxy pass the request to the
application:
Textbrowser ──▶ nginx ──▶ (subrequest) ──▶ signari /proxy/verify │ │ │◀───── 200 + identity ────────┘ ▼ the app
The three things that must line up
A mistake in a forward-authentication set-up often produces no error. These are the parts to check, in the order they cause trouble.
1. Both hosts must share a parent domain. Signari's session cookie has the
__Host- prefix. That prefix forbids a Domain attribute, so the cookie is never
sent to another host. Forward authentication therefore issues a second, narrower
cookie, scoped to the parent domain. That only works if there is one, and
SIGNARI_PROXY_COOKIE_DOMAIN names it for the whole deployment:
| Issuer | Protected application | SIGNARI_PROXY_COOKIE_DOMAIN | |
|---|---|---|---|
auth.example.com | n8n.example.com | example.com | works |
auth.example.com | n8n.other.com | — | no shared parent: see a cookie of its own |
auth.localhost | n8n.localhost | localhost | works (local development) |
localhost:9443 | 127.0.0.1:8080 | — | different hosts, not parent/child |
signari proxy cookie -org <uuid> -host <h> -cookie <domain> gives one host a
parent domain of its own, instead of the deployment's. That domain must cover the
issuer too. A browser refuses a cookie for a domain that the address setting it is
not under. So such a domain is refused at sign-in, by the same check.
If you get this wrong, the browser loops. The proxy says 401, and Signari sets a cookie that the application's host never receives. Signari redirects back, and the proxy says 401 again. No component logs an error, because each one is working as configured.
Signari detects this at /proxy/start and refuses it with this message:
Textthe proxy cookie is scoped to "localhost", which "127.0.0.1" is not under, sothe browser would never send it back and would loop between the proxy and hereforever.
2. Every protected host must be registered. After sign-in, Signari sends the
browser back to the address in rd. That address comes from a header the proxy
set from the original request, so it is attacker-influenced. Signari uses an
allow-list of hosts, not a "same domain" pattern, because a hostname an attacker
controls under your domain would satisfy a pattern.
Register a host, list the hosts, and disable one, with signari proxy:
Shellsignari proxy add-host -org <org-uuid> -host n8n.example.comsignari proxy listsignari proxy disable-host -org <org-uuid> -host n8n.example.com # or enable-host, remove-host
You can do the same with PUT /admin/organizations/{orgID}/proxy-hosts in the
Admin API, or with proxy_hosts: in a configuration
file. Each change is audited, and bumps the configuration
version.
The host is written as the browser sends it, including a non-default port
(n8n.example.com:8443). It is lower-cased, and a scheme, path or query is refused,
not guessed at.
If a host is not registered, the person signs in and is then told the application they came from is not a registered protected host.
A host belongs to one organisation in the whole deployment. Registering a host
that another organisation already protects is refused. The Admin API answers
409 host_taken, and the command line and signari apply return an error.
The verify endpoint lets in people from the organisation that registered the host. If two organisations could both register it, the second one's administrator could let their own people into the first one's application. Their identity headers would carry whatever the second organisation said about them.
3. Identity headers must come from the auth response, never from the client.
The "auth response" is Signari's answer to the proxy's subrequest. If the proxy
reads identity from the client instead, and passes the client's X-Forwarded-User
through, anyone can claim to be anyone by setting a header.
Signari sends all five identity headers (X-Forwarded-User, X-Forwarded-Sub,
X-Forwarded-Email, X-Forwarded-Groups and X-Forwarded-Jwt) on every 200,
taken from the verified token. A header with nothing to say is sent empty: for
example, X-Forwarded-Email when the account has no address.
The empty header matters. Suppose a proxy copies a header from the auth response
only when the response carries it. If the header were left out, the client's own
X-Forwarded-Email would reach the application unchanged. A person with no address
on record could then claim any address. Check how your proxy behaves, instead of
relying on either assumption.
Signari cannot remove headers from the client's request. The proxy must read the
identity headers from the auth response, which is what auth_request_set does in
the nginx recipe below.
nginx
This recipe is for nginx 1.31.
Here is the nginx server block for one protected application, n8n at
n8n.example.com:
nginxserver { listen 443 ssl; server_name n8n.example.com; ssl_certificate /etc/nginx/tls.crt; ssl_certificate_key /etc/nginx/tls.key; # The subrequest nginx makes before serving anything. `internal` keeps it # unreachable from outside -- without it, a client could call this path # directly and read the identity headers Signari sets. location = /signari-auth { internal; proxy_pass https://auth.example.com/proxy/verify; proxy_pass_request_body off; proxy_set_header Content-Length ""; # What was originally asked for. Signari validates these against the # allow-list and uses them to build the URL to return to. proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header X-Forwarded-Uri $request_uri; proxy_set_header X-Forwarded-Method $request_method; } location / { auth_request /signari-auth; # THE LINES THAT MATTER. Identity is read from the auth RESPONSE and # then set on the upstream request. Without them nginx forwards whatever # the client sent, and authentication is a formality anyone can skip. auth_request_set $signari_user $upstream_http_x_forwarded_user; auth_request_set $signari_email $upstream_http_x_forwarded_email; auth_request_set $signari_sub $upstream_http_x_forwarded_sub; auth_request_set $signari_groups $upstream_http_x_forwarded_groups; auth_request_set $signari_jwt $upstream_http_x_forwarded_jwt; proxy_set_header X-Forwarded-User $signari_user; proxy_set_header X-Forwarded-Email $signari_email; proxy_set_header X-Forwarded-Sub $signari_sub; proxy_set_header X-Forwarded-Groups $signari_groups; proxy_set_header X-Forwarded-Jwt $signari_jwt; # On 401, send the browser to sign in. The target comes from the auth # response's Location header, which already carries the return URL. auth_request_set $signari_login $upstream_http_location; error_page 401 = @signari_login; proxy_pass http://n8n:5678; } location @signari_login { return 302 $signari_login; }}
Traefik and Caddy: point them at /proxy/verify/redirect
Traefik and Caddy hand a refusal from Signari to the browser as it is: the status,
the Location and the body. A browser follows Location only on a redirect.
nginx's recipe above turns the 401 into one, but Traefik and Caddy do not. A
person behind them sees an error page and is never sent to sign in.
/proxy/verify/redirect answers a browser loading a page (GET or HEAD,
accepting text/html) with 302 to sign in. It keeps the 401 for everything
else, so an API client is not handed a redirect to a page it cannot use.
The recipes below are for Traefik 3.1 and Caddy 2.8.
Check yours with signari proxy check. Its browser probe fails a set-up that
strands a browser on the 401.
Traefik
In Traefik, Signari is a forwardAuth middleware, which you attach to every
router:
YAMLhttp: middlewares: signari: forwardAuth: address: https://auth.example.com/proxy/verify/redirect # Traefik's own X-Forwarded-* headers, never the client's. Set to true, # Traefik keeps a client-supplied X-Forwarded-Host, and Signari # authorises whichever host that names. trustForwardHeader: false # Only these are copied from the auth response onto the upstream # request. Anything not listed here is NOT forwarded, which is the # behaviour you want -- it is an allow-list. authResponseHeaders: - X-Forwarded-User - X-Forwarded-Email - X-Forwarded-Sub routers: n8n: rule: Host(`n8n.example.com`) middlewares: [signari] # attach to EVERY router, not just this one service: n8n
Caddy
In Caddy, the forward_auth directive asks Signari before reverse_proxy serves
the application:
Caddyfilen8n.example.com { # https:// explicitly: without a scheme Caddy dials the auth server over # plain HTTP on port 80, carrying the proxy cookie in the clear. forward_auth https://auth.example.com { uri /proxy/verify/redirect copy_headers X-Forwarded-User X-Forwarded-Email X-Forwarded-Sub } reverse_proxy n8n:5678}
Envoy
Envoy uses its ext_authz filter, over HTTP. It relays a refusal to the browser as
Traefik and Caddy do, so it too points at /proxy/verify/redirect.
Envoy 1.31 differs from them in two ways. It adds the request's own path and query
to that path, asking at /proxy/verify/redirect/dashboard?tab=1. It also asks with
the request's own method.
Signari answers anything below the path, by any method. It reads what is asked
about from the X-Forwarded-* headers. Envoy sets none of its own, so the
configuration tells it to set them:
YAML- name: envoy.filters.network.http_connection_manager typed_config: "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager stat_prefix: app # Without these Envoy passes /a/../b on as it came, to Signari and to the app, # so a rule for one path can be asked about another. normalize_path: true merge_slashes: true route_config: { ... } # the application's routes http_filters: - name: envoy.filters.http.ext_authz typed_config: "@type": type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthz failure_mode_allow: false # Signari unreachable is a refusal, never a pass allowed_headers: patterns: [{exact: cookie}, {exact: accept}, {exact: authorization}] http_service: server_uri: {uri: "https://auth.example.com", cluster: signari, timeout: 3s} path_prefix: /proxy/verify/redirect authorization_request: headers_to_add: - {key: X-Forwarded-Host, value: "%REQ(:authority)%"} - {key: X-Forwarded-Uri, value: "%REQ(:path)%"} - {key: X-Forwarded-Method, value: "%REQ(:method)%"} - {key: X-Forwarded-Proto, value: "https"} authorization_response: # Copied onto the request to the app, replacing any the client sent. allowed_upstream_headers: patterns: [{exact: x-forwarded-user}, {exact: x-forwarded-email}, {exact: x-forwarded-sub}] # What a refusal gives the browser: where to sign in. allowed_client_headers: patterns: [{exact: location}, {exact: www-authenticate}] - name: envoy.filters.http.router typed_config: "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
In this example, signari is a cluster for Signari's address, with an
UpstreamTlsContext whose sni is its host name. allowed_headers belongs on
ExtAuthz itself. Envoy 1.31 still takes it inside authorization_request, and
warns that this is going.
Prove it works
Seeing a sign-in page in the browser does not show that every path is protected.
signari proxy check tests the set-up from outside, as an attacker would see it:
Shellsignari proxy check \ -app https://n8n.example.com \ -issuer https://auth.example.com \ -origin http://127.0.0.1:5678 # the app's own address
It probes as an anonymous attacker would, and exits non-zero on any finding. It needs no database, so you can run it from continuous integration (CI). You can also run it from outside your network, to see what an outside attacker can reach. It looks for:
- paths that slipped through: a rule on
/does not cover/restor/webhook, and the application does most of its work through those; - method bypasses: authentication written as a GET-only condition leaves writes open;
- identity-header injection: a request that merely claims to be a person;
- direct-to-origin bypass: the application still listening on its own port, where a request skips the proxy entirely;
- a sign-in that never arrives: the proxy hands a browser its 401 instead of a
redirect. Or, for a host that keeps a cookie of its
own,
/.signari/is not routed to Signari, or its redirect comes back rewritten. Nothing is open, and nobody can sign in, so it is reported asSTUCK.
A clean run covers only the paths and methods listed in the output, from the place it ran. The output says so.
Who may reach which application
A valid proxy cookie is not enough. On every request, the verify endpoint checks three things:
-
The host is one of the signed-in person's organisation's protected hosts, and it is enabled. The host comes from
X-Forwarded-Host, which the proxy must send (the configurations on this page do). Suppose a person from another organisation, an unregistered host or a disabled host is involved, or no host is named. Then the answer is403, and no identity headers are sent. -
The access policy allows it. A protected host is keyed
proxy:<host>, the way an application is keyed by its client ID. So this rule decides who reaches the payroll application:YAMLpolicies: - name: payroll-is-for-finance when: {client: "proxy:payroll.example.com"} require: {groups: [finance], mfa: true}
A refusal is
403, with the rule's message inX-Signari-Reason. -
Network, device and travel conditions are treated as unknown, so they refuse. The request that reaches the verify endpoint comes from the proxy, so its address is the proxy's own. A
from_networksrule checked against it would let everybody in from inside the office the proxy sits in.
The answer is 403 and not 401, because the person is signed in and may not
reach this application. A 401 would send them back to sign in. Signari would let
them through, and they would arrive here again, in a loop.
An application on another domain
A cookie can only be set for a domain that the address setting it is under. So the issuer cannot set one for an application on a domain they do not share. That application can keep a cookie of its own, set on its own address:
Shellsignari proxy cookie -org <uuid> -host n8n.other.com -cookie own
Its proxy has to route one more path to Signari, /.signari/, sending the
application's name in X-Forwarded-Host. It must also hand Signari's redirects back
unchanged. On nginx, add this alongside the location blocks above:
nginxlocation /.signari/ { proxy_pass https://auth.example.com; proxy_ssl_server_name on; # Without it, nginx rewrites the issuer's address in Signari's redirect to this # application's, and the browser goes round between here and /proxy/start. proxy_redirect off; proxy_set_header Host auth.example.com; proxy_set_header X-Forwarded-Host $http_host;}
This block is for nginx 1.31.8.
Without proxy_redirect off, no browser can sign in through this block. The
default in nginx rewrites Location: https://auth.example.com/proxy/start?… to
/proxy/start?…, which the browser then asks the application for. Its forward
authentication sends the browser back to the beginning, and the browser loops.
Nothing is exposed, so a check that only looks for open paths passes it.
signari proxy check follows the sign-in begun at the application's address one
step, and names this.
With a cookie of its own, the sign-in then goes like this:
- The proxy asks about a request with no cookie. The answer sends the browser to
https://n8n.other.com/.signari/proxy/begin, not to the issuer. - That sets a state cookie on the application's address and sends the browser to the issuer, carrying the state.
- The issuer signs the person in as usual. It sends them back to
/.signari/proxy/callbackwith a code that lasts a minute, for this host and this state. - There, the code is held to the state in the browser, the host, and a session that is still live. The proxy cookie is set on the application's address alone, and the browser goes back to the page it asked for.
Step 2 exists because a code in a URL works for whoever opens it. Without the state, someone could sign in, stop at the callback, and send the link to another person, who would then use the application as them. With the state, the code works only in the browser that started the sign-in.
A cookie set this way names its application, and is refused at any other, the same organisation's included. Everything else is as it was. The session is checked on every request, so signing out at the issuer ends it. It needs signing in once per application, instead of once per parent domain. A neighbouring application signs in on the same session, with no second password.
Registering a host this way changes what its proxy has to do, so do the two
together. Until /.signari/ is routed, the person is sent to a page the application
does not have.
Rules for one path
A host protects every path alike until it has rules. Rules are for the paths that this does not fit. Examples are a health check that must answer anybody, a metrics path nothing outside should reach, or a console held to more than the rest.
Rules are written in a file, one effect methods path line each, and the first rule
that matches decides:
Text# rules.txt: the first that matches decidespublic GET,HEAD /static/**public * /healthdeny * /metrics/**auth:console * /console/**
Set a host's rules from the file with signari proxy rules, or leave out -file to
show them:
Shellsignari proxy rules -org <uuid> -host grafana.example.com -file rules.txtsignari proxy rules -org <uuid> -host grafana.example.com # show them
You can do the same with "rules" on PUT /admin/organizations/{orgID}/proxy-hosts,
or with rules: under proxy_hosts: in a configuration file.
Each replaces the whole list, because the order is what it means. An empty list
clears it.
Each rule has one of three effects:
| Effect | |
|---|---|
public | Nobody has to be signed in. The application is told of nobody, even when somebody is: every identity header is sent empty |
deny | 403 for everybody, signed in or not |
auth | What every path no rule names gets, written out to take a path back from a wider rule after it, or with :name to hold it to more |
A path is matched whole. * stands for anything within one segment. **, alone in
a segment, stands for any number of segments, none included. So /static/** matches
/static, /static/ and /static/js/app.js, and not /staticfiles.
auth:console gives a path an access policy of its own, keyed
proxy:<host>#console, on top of the host's:
YAMLpolicies: - name: the-console-needs-a-second-factor when: {client: "proxy:grafana.example.com#console"} require: {groups: [ops], mfa: true}
A path that could mean two things is refused
Signari checks the rule, but the application serves the path, and the application
decides for itself what a path means. Where the two differ, a rule is a way past the
check. /static/../metrics matches /static/** at Signari, and is /metrics at the
application.
So on a host with rules, these are refused with 403, signed in or not, and never
compared:
- A dot segment, spelled out or encoded (
/a/../b,/a/%2e%2e/b). - An empty segment (
//admin). - An encoded slash or backslash, and a plain backslash.
- A path parameter (
/a;x/b). - Anything still encoded once decoded (
/a/%252e).
With the nginx, Traefik, Caddy and Envoy configurations on this page, each of those
is refused before the application sees it, signed in or not. Envoy's
normalize_path resolves some first. It then sends the resolved path to the
engine and the application alike, so the two still judge one path.
An application that uses paths like these cannot have rules on its host.
Signari handles upper and lower case for you. A deny or auth rule meets every
spelling of its path. So deny /admin/** refuses /ADMIN/users to an application
that serves it as /admin/users. A public rule meets only the spelling written,
so public /static/** does not open /STATIC/ to anybody. No spelling gets more
than the one the rule names.
Two things are still yours to get right.
First, a path is compared with its trailing slash. deny * /metrics leaves
/metrics/ open, which many applications serve as /metrics. So a deny is written
/metrics/**, which covers both and everything below.
Second, a rule depends on what the proxy reports. With rules on a host, a proxy
that sends no X-Forwarded-Uri is refused, not guessed at. If a proxy sends no
X-Forwarded-Method, every rule naming methods is read the strict way. A public
one does not apply, and a deny one does. The configurations on this page send
both.
Rules are read on every request, and take effect on commit. A disabled host opens nothing, whatever its rules say. A host is held by one organisation, so no organisation can write rules for another's application.
What the application receives
On every 200, the application receives these headers:
| Header | Contents |
|---|---|
X-Forwarded-User | the person's uuid |
X-Forwarded-Sub | the same uuid, for applications expecting sub |
X-Forwarded-Email | the email, or empty when the account has none (present either way, so a client-sent copy is overwritten) |
X-Forwarded-Groups | the groups released to this application that the person is in, comma-separated, or empty |
X-Forwarded-Jwt | a signed statement of the above, or empty |
The person's ID is sent instead of their email address, because an email address can change and can be reassigned. The universally unique identifier (UUID) is the stable identity.
Groups and a signed identity
Nothing about groups is sent until you say which groups an application may hear of, because a group's name says something about a person.
Release groups, or a signed identity, with signari proxy release:
Shellsignari proxy release -org <uuid> -host grafana.example.com -groups admins,viewerssignari proxy release -org <uuid> -host grafana.example.com -signed-identity on
Each flag keeps what the other set. -groups "" releases none. A name holding a
comma is refused, since the header is a comma-separated list.
The headers can be trusted only if nothing but the proxy can reach the application. Anything that reaches the application directly can send them itself.
With -signed-identity on, X-Forwarded-Jwt carries a JSON Web Token
(JWT). The application can check it for itself against this
issuer's keys:
JSON{"iss": "https://id.example.com", "aud": "https://grafana.example.com", "sub": "7c1e…", "email": "ada@example.com", "groups": ["admins"], "iat": 1793440000, "exp": 1793440060}
Check the signature against jwks_uri, that typ is proxy-identity+jwt, that
iss and aud are what you expect, and exp. The token lasts a minute and is made
afresh for every request. So it is proof of this request, and not something to keep.
Programs: an access token instead of a cookie
A script or a service has no browser to sign in with. When a request carries no
proxy cookie and does carry Authorization: Bearer, that token is checked instead.
Register the protected address as a resource that tokens can be issued for. The program then sends its token with each request:
Shellsignari resource add -org <uuid> -resource https://app.example.comcurl -H "Authorization: Bearer $TOKEN" https://app.example.com/report
The token's aud has to be https://<the host>, so ask for it with
resource=https://app.example.com. A token for anything else is refused, and that
includes one for the client itself or for another protected host.
What ends a token ends it here on the next request:
- revoking it;
- revoking its grant;
- ending its session;
- deactivating the person;
- disabling the client.
After that, the token goes through the same decision as a cookie. The host has to be one of the organisation's, and enabled, and the access policy has to allow it.
A client_credentials token passes as its client. So X-Forwarded-User is the
client ID, and X-Forwarded-Email is empty. To a policy it is a client in no
groups, so a rule requiring a group or a second factor refuses it.
When a request carries both, the cookie decides, because the application behind the
proxy may use Authorization for something of its own.
A "sender-constrained" token is bound to a key or a certificate: Demonstrating Proof of Possession (DPoP) or certificate-bound. Such a token is refused. What proves it is bound to the application's address, and only the application could check that, so a proxy would be taking it on trust.
Your proxy has to pass Authorization to /proxy/verify. nginx's auth_request
does, unless it has been told not to.
When the sign-in behind a token was not strong enough
A policy rule can ask for factors, such as mfa: true or
phishing_resistant: true. Suppose that is all a rule asks for, and the token's
sign-in did not give it.
Then the answer is a 401 with the challenge that RFC 9470, OAuth 2.0 Step Up
Authentication Challenge Protocol, defines:
TextHTTP/1.1 401 UnauthorizedWWW-Authenticate: Bearer error="insufficient_user_authentication", error_description="Sign in with a second factor to reach the reports.", acr_values="2"
The program sends the person to sign in again with acr_values=2, which asks for
two factors, and the token from that sign-in passes. phishing_resistant asks for
4, a device-bound key. A rule with factors_any_of gets the challenge without
acr_values, because no single value means "one of these factors".
Stepping up is a new sign-in, and it replaces the session. The token from before it then gets a 401 saying the session has ended. The program carries on with the token from the new sign-in.
A refusal that no sign-in would change stays a 403. Examples are a group the person
is not in, a network rule, or a deny. A token with no session behind it stands for
nobody who could sign in, so it also gets a 403. So does a browser, which the proxy
sends to sign in in its own way.
The 401 carries the same Location as any other refusal, so a proxy that turns
refusals into a sign-in goes on doing so. That also means a program sees the
challenge only if your proxy hands it the 401.
In nginx 1.31.8, auth_request passes a 401's WWW-Authenticate on by itself. So
do not add it again with add_header, which sends it twice.
The nginx recipe above, though, sends every 401 to sign in with error_page. Serve
programs from a location without that line.
Session lifetime
The proxy cookie lasts 30 minutes and is refreshed by the flow. Signari also rechecks the live session on every request, so signing out of Signari revokes proxy access immediately. Forward authentication cannot be used to outlive a sign-out.
The recheck also reads the person. A session whose person is no longer active is
refused, whichever path deactivated them, even when the deactivation ended no
session. One example is a System for Cross-domain Identity Management
(SCIM) PUT with "active": false.