Documentation
¶
Overview ¶
Package hello is the REST/JSON service the purser examples authenticate.
It is deliberately dull. The service is one GET returning who the caller is, because the interesting part of the examples is the credential that got them in, not what they asked for.
Nothing here is part of purser's exported API. It is internal to the module and exists so the server and client binaries share one wire contract rather than two hand-written ones that can disagree.
Index ¶
Constants ¶
const Path = "/hello"
Path is the one endpoint the service serves.
Variables ¶
This section is empty.
Functions ¶
func Authenticate ¶
Authenticate resolves the caller with a and puts it on the request context, or answers 401.
This is what purser's httpmw package will eventually provide. Until it does, every consumer writes these fifteen lines, so the example writes them where they can be read:
- The Caller and the AuthSource go on the context together. The source is taken from the authenticator that verified the request — a.Source() — and never from anything the client sent.
- An error means no identity. There is no partial success to fall through on, so the handler below never runs.
func Handler ¶
Handler serves Path from the Caller on the request context.
It assumes Authenticate ran ahead of it. A missing Caller is a wiring bug in the server, not an unauthenticated request, and is reported as one: returning a cheerful anonymous greeting instead would make an unauthenticated surface look like a working one.
Types ¶
type Fault ¶
type Fault struct {
Error string `json:"error"`
}
Fault is the error body.
It carries a category rather than the underlying error text. An authentication failure's detail — which field was missing, which matcher rejected — is for the server's log, not for the peer that failed it: a client that can enumerate why it was rejected can enumerate its way to a credential that is not.
type Greeting ¶
type Greeting struct {
// Greeting is the human-readable line.
Greeting string `json:"greeting"`
// Caller is purser.Caller.Identity — a SPIFFE ID under the SPIFFE
// profile, whatever SubjectSource names under the PKI one.
Caller string `json:"caller"`
// AuthSource is how the server authenticated the request. It comes
// from the authenticator that did the verifying, never from a
// request header.
AuthSource string `json:"auth_source"`
// Labels is the credential metadata purser attached — issuer DN and
// serial for PKI, trust domain and path for SPIFFE.
Labels map[string]string `json:"labels,omitempty"`
// ServedBy names the server instance, so a reader can tell which
// replica answered.
ServedBy string `json:"served_by"`
}
Greeting is the success body: the identity purser resolved, and the evidence it resolved it from.