Skip to main content

Module jwt_ops

Module jwt_ops 

Source
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 RequestCtx extractor 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-server as a dependency.

Functions§

get_name
Extract the name claim from a JWT token.
get_preferred_username
Extract the preferred_username claim from a JWT token.
get_roles
Extract the realm_access.roles claim from a JWT token.
get_string_claim
Extract a top-level string claim (e.g. sub) from a JWT token.
has_role
Returns true when the token’s realm_access.roles claim contains role. Any JWT-decode failure or missing claim returns false — callers want a yes/no answer, and downstream BearerToken extraction is the auth boundary that surfaces the underlying 401.
is_user_admin
Returns true when the token’s realm_access.roles claim contains the PA_ADMIN role. Errors decoding the JWT are swallowed and treated as “not admin”.