auth

package
v1.64.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package auth carries the caller's identity through a request: the one secret every agent of a server shares, and the agent id each agent declares.

Index

Constants

View Source
const (

	// AgentHeader carries the agent id the caller declares.
	AgentHeader = "goback-agent"
)

Variables

View Source
var ErrForbidden = errors.New("not allowed for this caller")

ErrForbidden is returned when the principal may not do what it asked.

View Source
var ErrUnauthenticated = errors.New("no caller identity")

ErrUnauthenticated is returned when a request carries no principal.

Functions

func Agent

func Agent(ctx context.Context) (string, bool)

Agent returns the agent id the incoming call declares, if any.

func Bearer

func Bearer(ctx context.Context) (string, bool)

Bearer returns the bearer token of the incoming call, if any.

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.

func WithPrincipal

func WithPrincipal(ctx context.Context, p *Principal) context.Context

WithPrincipal attaches the principal to the context.

Types

type Authenticator

type Authenticator func(ctx context.Context) (context.Context, error)

Authenticator decides who an incoming call is from and returns the context to handle it with, or a status error refusing it.

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

func (c Credentials) GetRequestMetadata(context.Context, ...string) (map[string]string, error)

GetRequestMetadata implements credentials.PerRPCCredentials.

func (Credentials) RequireTransportSecurity

func (c Credentials) RequireTransportSecurity() bool

RequireTransportSecurity implements credentials.PerRPCCredentials.

type Principal

type Principal struct {
	AgentID string
}

Principal is who is calling: the agent id the caller declared.

func FromContext

func FromContext(ctx context.Context) (*Principal, bool)

FromContext returns the request's principal, if any.

func Require

func Require(ctx context.Context) (*Principal, error)

Require returns the principal or ErrUnauthenticated.

func (*Principal) AuthorizeCommit

func (p *Principal) AuthorizeCommit(c *proto.Commit) error

AuthorizeCommit checks that a commit names the principal's agent.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL