Table of contents
Passing User Identity to Your Backend (x-user/x-user-roles/x-groups)
This page explains how your backend finds out who is making a request once ProxyAuth has authenticated them - the x-user, x-user-roles, and x-groups headers, how they're set, and why a client can never forge them.
The short version
For any route with required_login: true, once a request passes authentication, ProxyAuth adds up to three headers before forwarding to your backend:
x-user: alice
x-user-roles: admin,billing
x-groups: ops,admins
Your backend reads these headers to know who's calling, without needing to validate a token, a cookie, or talk to ProxyAuth itself - by the time a request reaches your backend, identity has already been established and injected.
x-user-roles/x-groups are forwarded regardless of whether roles/groups were the reason the request was let through in the first place - see Group- and Role-Based Access Control for how routes.yml's username/groups/roles can now also gate access, not just describe it for the backend.
Where this happens
inject_header(), in network/proxy.rs, runs on every authenticated request, right before it's sent to the backend:
pub fn inject_header(mut builder: Builder, username: &str, config: &AppConfig) -> Builder {
if username.is_empty() {
return builder;
}
// x-user: the authenticated username
builder = builder.header("x-user", username);
// x-user-roles: that user's roles, comma-joined, if they have any -
// an O(1) average-case lookup via roles_index, not a scan over
// every account.
if let Some(roles) = config.roles_for_username(username) {
let roles_str = roles.join(",");
if let Ok(val) = hyper::header::HeaderValue::from_str(&roles_str) {
builder = builder.header("x-user-roles", val);
}
}
// x-groups: same idea, via groups_index.
if let Some(groups) = config.groups_for_username(username) {
let groups_str = groups.join(",");
if let Ok(val) = hyper::header::HeaderValue::from_str(&groups_str) {
builder = builder.header("x-groups", val);
}
}
builder
}
x-useris set whenever a request has a resolved, authenticated username - i.e., its token/cookie was successfully validated.x-user-rolesis only set if that user has aroleslist configured (see therolesfield on a User object inconfig.json). Norolesconfigured -> the header simply isn't added at all, rather than being sent empty.x-groupsworks the same way, forgroups.- Both are joined with a comma - parse them on your backend with a simple
split(',').
Where username comes from
This only runs for routes with required_login: true (see routes.yml Reference). The username is resolved from whichever credential the request actually carried:
Authorization: Bearer <token> --+
+--> validated --> username
session_token cookie --+
If neither is present, or validation fails, the request is rejected before it ever reaches inject_header() - there's no path where an unauthenticated request reaches the backend with a stale or empty identity header.
Why a client can't spoof these headers themselves
This is the part worth understanding clearly, since it's what makes the whole mechanism trustworthy: ProxyAuth strips x-user, x-user-roles, and x-groups from the incoming client request before doing anything else, then adds its own - a client-supplied value is simply discarded, never forwarded.
if !is_hop_by_hop_header(key_str)
&& key_str != "authorization"
&& key_str != "user-agent"
&& key_str != "x-user" // <- client-sent x-user is dropped here
&& key_str != "x-user-roles" // <- client-sent x-user-roles is dropped here
&& key_str != "x-groups" // <- client-sent x-groups is dropped here
{
// ... only then is a header copied through from the client
}
Then, separately and afterward, inject_header() adds ProxyAuth's own x-user/x-user-roles/x-groups based on the validated token - not on anything the client sent. So even if a client sends its own x-user: admin header hoping to impersonate someone, it never reaches your backend; only the headers ProxyAuth computed from a successfully validated session do.
Practical implication for your backend: you can trust x-user/x-user-roles/x-groups unconditionally as long as requests only ever reach your backend through ProxyAuth - see the next section for why that assumption needs to be enforced at the network level too.
The one thing this doesn't protect against: bypassing ProxyAuth entirely
Header stripping protects against a client going through ProxyAuth and trying to sneak in a fake identity header. It does not protect against a client reaching your backend directly, bypassing ProxyAuth altogether - if your backend is reachable on the network without going through ProxyAuth, nothing stops someone from connecting straight to it and setting x-user: admin themselves, since your backend has no independent way to know the header wasn't set by ProxyAuth.
This means your backend must not be reachable except through ProxyAuth. In practice:
- Put your backend on a private network/internal address that ProxyAuth can reach but the public internet can't.
- If backend and ProxyAuth run on the same host, bind the backend to
127.0.0.1rather than0.0.0.0. - In containerized/Kubernetes setups, use network policies so only ProxyAuth's pod/service can reach the backend's pod/service.
This is the same "trusted boundary" assumption every reverse-proxy-injected-identity pattern relies on (it's how X-Forwarded-User works with nginx/Apache auth modules, and how Pomerium's/Authelia's own identity headers work too) - the header is only meaningful because the network guarantees it can only have been set by the proxy in front of you.
Example: reading identity in your backend
# Flask example
@app.route("/whoami")
def whoami():
user = request.headers.get("x-user")
roles = request.headers.get("x-user-roles", "").split(",") if request.headers.get("x-user-roles") else []
groups = request.headers.get("x-groups", "").split(",") if request.headers.get("x-groups") else []
return {"user": user, "roles": roles, "groups": groups}
// Express example
app.get("/whoami", (req, res) => {
const user = req.headers["x-user"];
const roles = req.headers["x-user-roles"]?.split(",") ?? [];
const groups = req.headers["x-groups"]?.split(",") ?? [];
res.json({ user, roles, groups });
});
No token validation, no calling back to ProxyAuth, no shared secret needed on the backend side - the headers are the trust boundary, backed by the network isolation described above.
What's not covered by this mechanism
- Public routes (
required_login: false) never getx-user/x-user-roles/x-groupsat all - there's no authenticated identity to inject. - Fine-grained per-resource permissions aren't part of this -
x-user-roles/x-groupsgive you the user's role/group names; deciding what each one can actually do inside your app is still your backend's responsibility. ProxyAuth's own access control stops at the route level (username/groups/roles/allow_methodsinroutes.yml- see Group- and Role-Based Access Control), not at the level of individual resources within your app. - This isn't a JWT - there's no signature your backend can independently verify; the guarantee is entirely network-boundary-based, not cryptographic. If you need a cryptographically verifiable identity token instead of a trusted header, that's not what this mechanism provides. (If you specifically need per-request cryptographic proof instead, see Anti-Replay Protection - a different, opt-in mechanism, not a replacement for this one.)
See also
- routes.yml Reference -
required_login,username/groups/roles, and how a route requires authentication in the first place. - config.json Reference - the
roles/groupsfields on a user entry. - Group- and Role-Based Access Control - how
groups/rolescan now also gate route access, not just populate these headers. - How a Token Is Built and Verified - what "a successfully validated session" actually means before
usernameis ever resolved.
📖 Wiki Home · 💻 Source Code · 🐛 Report an Issue · 📜 License
Found an error or something outdated on this page? Open an issue or submit a PR against the wiki repository.