Documentation
¶
Index ¶
- Constants
- Variables
- type Signer
- func (s *Signer) Duration() time.Duration
- func (s *Signer) Project(signingContext jwt.MapClaims) (jwt.MapClaims, error)
- func (s *Signer) Sign(signingContext jwt.MapClaims) (string, error)
- func (s *Signer) SignProjected(projected jwt.MapClaims) (string, error)
- func (s *Signer) SignScoped(signingContext jwt.MapClaims, grantedScopes []string) (string, error)
Constants ¶
const SubjectlessRemedy = "a credential that names nobody is not a supported configuration; " +
"fix the credential source so it supplies a subject -- add a `sub` key to the subject Secret, " +
"or return a non-empty `claims.sub` from the credential-check backend"
SubjectlessRemedy is the operator-facing half of every subject-less rejection: what to FIX, not what went wrong. Kept as one exported constant so the JWT mint, the PASETO mint, and both validation paths give an operator reading the logs the same instruction.
Variables ¶
var ErrNonExpiringToken = errors.New("refusing to sign a token that never expires: `exp` is missing, null, non-numeric or zero")
ErrSubjectlessCredential is the one error for a credential that names nobody. A subject-less credential is NOT a supported configuration: every gate in host-manager is keyed on who the caller is, so a token whose `sub` is empty is attributable to no one, authorizable against nothing, and auditable as nobody.
It is reachable, which is why this is a check and not a comment. jwt.MapClaims.GetSubject reports a MISSING `sub` as ("", nil) -- only a wrong-TYPED `sub` errors (golang-jwt v5 map_claims.go) -- so a credential source that vouches for a login without naming a subject silently produces `sub: ""`. Two real sources do exactly that:
- a subject Secret keyed only by `email` (internal/auth/roles.go): the matcher accepts `email == subject`, and the claims it returns are the Secret's data keys minus `password`, so no `sub` key exists at all;
- an http-lookup backend answering `{"ok":true}` or `{"ok":true,"claims":{}}` (internal/auth/lookup_http.go): the backend's `claims` object is returned verbatim, with an EMPTY MapClaims substituted when it is omitted.
LoginLocal never derives a subject from `username`, so nothing downstream repairs it.
It lives HERE, in the mint package, because this is where the empty subject is first manufactured and because internal/sign is the lowest package every token path can reach: internal/auth and internal/auth/apitoken both depend on it, and the dependency cannot run back. One sentinel means an operator grepping for one message finds every site that refused. ErrNonExpiringToken is returned when the final claim set would yield a token that never expires: `exp` missing, null, non-numeric, or zero. golang-jwt reads `exp: 0` as absent, and a verifier without WithExpirationRequired accepts an absent `exp` forever. The signer's default exp can only be lost this way through a projection override -- in practice a host ClaimMappings rule that writes `exp`. A past exp is NOT refused: an already-expired token is harmless. See kdex-tech/host-manager#227.
var ErrSubjectlessCredential = errors.New(
"subject-less credential: the credential source resolved without a `sub` claim")
Functions ¶
This section is empty.
Types ¶
type Signer ¶
type Signer struct {
// contains filtered or unexported fields
}
func NewSigner ¶
func NewSigner( audience string, duration time.Duration, issuer string, privateKey *crypto.Signer, kid string, mapper *dmapper.Mapper, ) (*Signer, error)
NewSigner creates a new signer.
func (*Signer) Duration ¶ added in v0.2.78
Duration returns the lifetime each signed token is valid for. Cache implementations should subtract a skew from this to ensure a cached token always has meaningful remaining life on hit.
func (*Signer) Project ¶ added in v0.2.78
Project derives the deterministic claim set that will be signed for a given signingContext. iat/exp/jti are deliberately omitted: they identify the token, not the identity, and putting them in the projection defeats the caller's ability to use the projection as a cache key.
The signer's audience is the AUTHORITATIVE outbound aud: Project is always called to re-issue a token for a SPECIFIC downstream target (the per-function FAT path in proxy.go), and re-using the inbound aud would make the issued token transferable to a different audience than the signer was configured for. Concretely: a user logs in at the host (aud=["https://<host>"]) and then calls a function; proxy.go builds a signer with audience=fn.Status.URL, but the previous logic reused the inbound host aud, so the function rejected the FAT with "token has invalid audience". Always use s.audience.
func (*Signer) Sign ¶
Sign is a convenience wrapper that runs Project then SignProjected. Direct callers that want to cache should call the two steps separately so the cache key reflects the deterministic projection rather than the raw inbound context (which routinely includes per-request headers like Traceparent that defeat the cache).
func (*Signer) SignProjected ¶ added in v0.2.78
SignProjected attaches the per-token identifiers (iat/exp/jti) to an already-projected claim set and signs it. Use this in tandem with Project when caching to skip the projection step on a cache hit.
The projection has the LAST WORD on every field — including iat/exp/jti. The original Sign emitted mapper output last via maps.Copy, and several call sites depend on that semantic (e.g. dev-mode tests that inject exp=-1 via a ClaimMappings rule to synthesize an expired token). Default iat/exp/jti are written first, then maps.Copy(outboundClaims, projected) overrides anything the projection already carries.
func (*Signer) SignScoped ¶ added in v0.4.15
SignScoped is Sign with OAuth scope confinement: it projects the context (which runs the ClaimMappings mapper and Compact), removes the scope-controlled claim families absent from grantedScopes, then signs. Confinement runs AFTER the mapper, so a ClaimMappings rule that injects into a scope-controlled family cannot smuggle it into a token whose scope did not grant it — regardless of which source claim the rule reads. Used by the primary subject mints (LoginLocal, mintTokensFromCode, mintTokensFromSubject); FAT projection, mint_token, OIDC exchange, and client_credentials keep raw Sign/Project. See kdex-tech/host-manager#140.