Package vmtoken implements parsing and verification of signed GCE VM metadata tokens.
Intended to be used from a server environment (e.g. from a GAE), since it depends on a bunch of luci/server packages that require a properly configured context.
const Header = "X-Luci-Gce-Vm-Token"
Header is the name of the HTTP header where the GCE VM metadata token is expected.
Clear returns a new context without a GCE VM metadata token installed.
CurrentIdentity returns the identity of the VM stored in the current context.
Has returns whether the current context contains a valid GCE VM metadata token.
Hostname returns the hostname of the VM stored in the current context.
Matches returns whether the current context contains a GCE VM metadata token matching the given identity.
Middleware embeds a Payload in the context if the request contains a GCE VM metadata token.
Payload is extracted from a verified GCE VM metadata token.
It identifies a VM that produced the token and the target audience for the token (as it was supplied to the GCE metadata endpoint via 'audience' request parameter when generating the token).
Verify parses a GCE VM metadata token, verifies its signature and expiration time, and extracts interesting parts of it into Payload struct.
Does NOT verify the audience field. This is responsibility of the caller.
The token is in JWT form (three dot-separated base64-encoded strings). It is expected to be signed by Google OAuth2 backends using RS256 algo.
|client||Package client implements client-side fetch and transmission of signed GCE VM metadata tokens.|