Expand description
JWT claim extractors used by the audit and authorization paths.
Decodes a bearer token (with or without the Bearer prefix),
tolerates both URL-safe and standard Base64 encodings, and
returns named claims as String. All failures map to
MantaError::JwtMalformed with a structured message; the
HTTP layer maps that to a 401.
§Security caveat
These helpers do not verify the JWT signature. Claims are extracted on trust, which is sound only for a token whose origin is known:
- In manta-server, authorization reads the exchanged token, which
the
RequestCtxextractor got from the site’s own identity provider over TLS a moment earlier (that provider verified the caller’s CSCS token first). Never use these helpers to authorize on the caller-supplied CSCS token itself. - In manta-cli, the claims of the CLI’s own CSCS token are only
displayed (
config show), never trusted for access.
TODO: verify the caller’s CSCS token in manta-server (signature
against the CSCS Keycloak’s JWKS, plus iss, aud, exp). One
issuer, so one cached key set; needs the audience question settled
with IAM first.
Statics§
- PA_
ADMIN - Keycloak role name that grants full admin access. Owned here so
every workspace crate that decodes JWTs can read it without
pulling
manta-serveras a dependency.
Functions§
- get_
name - Extract the
nameclaim from a JWT token. - get_
preferred_ username - Extract the
preferred_usernameclaim from a JWT token. - get_
roles - Extract the
realm_access.rolesclaim from a JWT token. - get_
string_ claim - Extract a top-level string claim (e.g.
sub) from a JWT token. - has_
role - Returns
truewhen the token’srealm_access.rolesclaim containsrole. Any JWT-decode failure or missing claim returnsfalse— callers want a yes/no answer, and downstreamBearerTokenextraction is the auth boundary that surfaces the underlying 401. - is_
user_ admin - Returns
truewhen the token’srealm_access.rolesclaim contains thePA_ADMINrole. Errors decoding the JWT are swallowed and treated as “not admin”.