Expand description
Hasura’s authentication contract.
Hasura settles three things about a request before any query runs: whether the caller is authenticated at all, which role it is speaking as, and what session variables that role carries. The first is what makes the other two safe, and reading them apart is the fault this module exists to fix.
A caller that holds the admin secret is an administrator, and an
administrator may ask to be treated as someone else: X-Hasura-Role: user
alongside the secret says “answer as user would be answered”, and the
other x-hasura-* headers are that role’s session variables. Naming a role
is therefore something an authenticated caller does, not an alternative
to authenticating – a role header arriving on its own is an
unauthenticated request, and Hasura refuses it.
§Where this deliberately differs from Hasura
Hasura configured with no admin secret treats every caller as an
administrator, which means an unsecured deployment also lets any caller
name its own role and its own identity. This server does not: with no
secret configured, x-hasura-* headers are ignored entirely and session
variables come from a verified token, as they did before this module
existed. A policy reading a value the caller chose is not a policy, and the
failure is silent – the query succeeds, against the wrong rows.
Nothing is lost by it. Every case in Hasura’s corpus that names a role sends the secret beside it, because that is what Hasura’s own suite does.
Structs§
- Hasura
Auth Config - What this server was told about who may claim what.
- Hasura
Identity - Who the caller is, in Hasura’s sense of the word.
Enums§
- Secret
Outcome - What the admin secret alone can settle about a request.
- Token
Role - Who a verified token’s bearer speaks as.
Constants§
- ADMIN_
ROLE - The name a caller with the secret speaks as unless it asks for another.
- BACKEND_
ONLY_ HEADER - The header whose value is read as a boolean, and Hasura’s refusal for one that is not.
- ROLE_
NOT_ ALLOWED - Hasura’s wording for a caller that asked to be a role its token does not list.
- SECRET_
INVALID - Likewise.
- SECRET_
MISSING - Hasura’s own wording, which a migrating client may be matching on.
Functions§
- allowed_
roles - The roles a token allows its bearer to ask to be.
- backend_
only_ requested - Whether a caller asked for the fields a
backend_onlypermission hides. - boolean_
text - What Hasura reads as true and false in a header, and the words it uses when a header is neither.
- from_
admin_ secret - Settle what the admin secret says about a request.
- role_
for_ token - Settle which role a verified token speaks as, given what the caller asked for.
- role_
from_ claims - The role a verified token names, if it names one.
- session_
from_ claims - Collect
x-hasura-*claims from a verified token as session variables. - session_
from_ headers - Reduce
x-hasura-*headers to session variables. - unauthenticated
- The identity a request falls to when nothing authenticated it.
- unreadable_
boolean_ header - Whether a request carries that header with something unreadable in it.