Documentation
¶
Overview ¶
Package jwtauth is the hub's attach-time authentication: it issues and verifies the HMAC-SHA256 JWTs peers present, holds the signing secret so it can be rotated live (Secret), and enforces the whole check in front of the tunnel handler (Guard). The token's subject is the peer id the hub uses as the tunnel key.
Index ¶
Constants ¶
const ( // wrongly-signed token. ReasonUnauthorized = "unauthorized" // ReasonInvalidName is a valid token naming a peer the proxy could // never address. ReasonInvalidName = "invalid-peer-name" // ReasonBlocked is a valid token for a denylisted peer. ReasonBlocked = "blocked" )
The reasons a RejectHook is called with.
Variables ¶
var ErrUnauthenticated = errors.New("unauthenticated")
ErrUnauthenticated is returned by PeerFrom for a context the guard never stamped, which can only happen if the handler is mounted without it.
Functions ¶
func Issue ¶
Issue mints a signed JWT for peer, valid for ttl. tunnelURL is carried in the audience claim: it is the hub the token is for, and the peer reads it (unverified, it holds no key) to know where to dial. That makes the signed token the whole join token, with no envelope around it.
Types ¶
type Blocker ¶
Blocker is the peer-id denylist the guard consults on every attach. The ban is on the identity, not one token, so a blocked peer stays out even holding a valid, unexpired token.
type Guard ¶
type Guard struct {
Secret *Secret
Blocked Blocker
OnReject RejectHook
}
Guard is the attach-time gate in front of the hub's tunnel handler: it verifies the Bearer JWT, refuses unroutable and blocked peers, and stamps the peer id onto the request context for PeerFrom.
guard := jwtauth.Guard{Secret: secret, Blocked: blocks, OnReject: metrics.RecordReject}
mux.Handle("/", guard.Middleware(attach.NewHandler(registry, jwtauth.PeerFrom, logger)))
Only Secret is required: without a Blocker nothing is denylisted (every valid token attaches), and without a RejectHook refusals are simply not counted.
type RejectHook ¶
RejectHook observes refused attaches with a low-cardinality reason, which makes it a metric counter's attribute as-is.
type Secret ¶
type Secret struct {
// contains filtered or unexported fields
}
Secret is the hub's JWT signing secret, held behind an atomic pointer so the console's rotate-secret can swap it live — invalidating every issued token — without a process restart. Every read goes through Get, so the next verification after a rotate already uses the new secret.