Documentation
¶
Overview ¶
Package auth carries the caller's identity through a request: the key it presented, the backup key every agent of a server shares or the admin key, and the agent id each agent declares.
Index ¶
- Constants
- Variables
- func Agent(ctx context.Context) (string, bool)
- func Bearer(ctx context.Context) (string, bool)
- func Stream(authenticate Authenticator) grpc.StreamServerInterceptor
- func StreamInterceptor(secret string) grpc.StreamServerInterceptor
- func Unary(authenticate Authenticator) grpc.UnaryServerInterceptor
- func UnaryInterceptor(secret string) grpc.UnaryServerInterceptor
- func WithPrincipal(ctx context.Context, p *Principal) context.Context
- type Authenticator
- type Credentials
- type FailureLimit
- type Principal
Constants ¶
const (
// AgentHeader carries the agent id the caller declares.
AgentHeader = "goback-agent"
)
Variables ¶
var ErrForbidden = errors.New("not allowed for this caller")
ErrForbidden is returned when the principal may not do what it asked.
var ErrUnauthenticated = errors.New("no caller identity")
ErrUnauthenticated is returned when a request carries no principal.
Functions ¶
func Stream ¶
func Stream(authenticate Authenticator) grpc.StreamServerInterceptor
Stream runs authenticate before every streaming call.
func StreamInterceptor ¶
func StreamInterceptor(secret string) grpc.StreamServerInterceptor
StreamInterceptor is UnaryInterceptor for streaming calls.
func Unary ¶
func Unary(authenticate Authenticator) grpc.UnaryServerInterceptor
Unary runs authenticate before every unary call.
func UnaryInterceptor ¶
func UnaryInterceptor(secret string) grpc.UnaryServerInterceptor
UnaryInterceptor rejects calls that do not present secret and attaches the declared agent as the principal of the ones that do.
Types ¶
type Authenticator ¶
Authenticator decides who an incoming call is from and returns the context to handle it with, or a status error refusing it.
func Keys ¶ added in v1.96.0
func Keys(backup, admin string) Authenticator
Keys authenticates callers presenting the backup or the admin key as bearer token and attaches the agent they declare as the principal, an Admin one for the admin key. An empty admin key admits no admin.
func LimitFailures ¶ added in v1.96.0
func LimitFailures(authenticate Authenticator, limit FailureLimit) Authenticator
LimitFailures refuses the calls of a peer address that has used up its failures with ResourceExhausted, without checking what key they carry, until the limit lets it try again. A failure is a call authenticate answers Unauthenticated.
func SharedSecret ¶
func SharedSecret(secret string) Authenticator
SharedSecret authenticates callers presenting secret as bearer token and attaches the agent they declare as the principal.
type Credentials ¶
type Credentials struct {
Secret string
AgentID string
// Plaintext allows the secret onto a connection nothing encrypts,
// where anyone on the path can read it and everything it uploads.
// It is for a store on the same machine, nothing further.
Plaintext bool
}
Credentials sends the shared secret and the agent id with every call and refuses to do so over a plaintext connection unless Plaintext says otherwise.
func (Credentials) GetRequestMetadata ¶
GetRequestMetadata implements credentials.PerRPCCredentials.
func (Credentials) RequireTransportSecurity ¶
func (c Credentials) RequireTransportSecurity() bool
RequireTransportSecurity implements credentials.PerRPCCredentials.
type FailureLimit ¶ added in v1.96.0
type FailureLimit struct {
Burst int
Every time.Duration
// Forwarded names the peer by the last x-forwarded-for entry a call
// carries, which is the one a proxy in front appended, rather than by
// the proxy's own address.
Forwarded bool
}
FailureLimit is how often a peer address may fail to authenticate: Burst times at once, then once every Every.
type Principal ¶
type Principal struct {
AgentID string
Admin bool
// Bounded marks a caller that may only add to what the store keeps:
// it escrows the store key only where no copy of it is kept, and
// changes a set's retention only to a policy that keeps at least as
// much.
Bounded bool
}
Principal is who is calling: the agent id the caller declared, and whether it presented the admin key.
func FromContext ¶
FromContext returns the request's principal, if any.