auth

package
v2.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package auth is the identity port: who is making this request, and may they do what they are asking. The engine never sees a credential; it sees a Principal, which the HTTP layer puts on the context after an Authenticator has produced one. Authorization is a second port, so a deployment can plug in a policy without touching authentication.

The shape follows Kubernetes: an authenticator chain turns a request into a subject with groups (here Roles), and an authorizer decides on (subject, verb, resource). Cartograph ships the no-identity adapters an unauthenticated single-operator deployment needs; a deployment that puts Cartograph behind an authenticating proxy, or wires an OIDC provider, adds an Authenticator and keeps everything else.

Index

Constants

View Source
const (
	VerbRead  = "read"
	VerbWrite = "write"
)

Verbs an Action carries. Read is any safe method; Write is the rest.

Variables

View Source
var Anonymous = Principal{Subject: "", Anonymous: true}

Anonymous is the principal of a request nobody identified.

View Source
var ErrForbidden = errors.New("forbidden")

ErrForbidden is returned by an Authorizer that refuses an action.

View Source
var ErrUnauthenticated = errors.New("unauthenticated")

ErrUnauthenticated is returned by an Authenticator that requires a credential and found none, or a bad one.

Functions

func Authorize

func Authorize(z Authorizer, next http.Handler) http.Handler

Authorize is the one enforcement point: every request through the API is classified and put to the Authorizer, after the Authenticator has put a principal on the context. A refusal is 403 with the contract's problem shape; the handler never runs.

func Middleware

func Middleware(a Authenticator, next http.Handler) http.Handler

Middleware runs a on every request and puts the principal on the context. A request the authenticator refuses gets 401 and never reaches the handler.

func WithPrincipal

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

WithPrincipal returns a context carrying p.

Types

type Action

type Action struct {
	// Verb is read or write (the HTTP method's intent).
	Verb string
	// Kind and ID name the manifest, when the action concerns one.
	Kind string
	ID   string
}

Action is one thing a principal asks to do.

func ActionFor

func ActionFor(r *http.Request) Action

ActionFor classifies a request: its verb from the method, and the manifest it concerns from the path when the path names one (/manifests/{kind}/{id}...). Everything else (the goal tree, the snapshots list, the state manifest) is an action with no kind.

type AllowAll

type AllowAll struct{}

AllowAll permits every action. The default authorizer.

func (AllowAll) Authorize

Authorize returns nil.

type Authenticator

type Authenticator interface {
	Authenticate(r *http.Request) (Principal, error)
}

Authenticator turns a request into a Principal. Return Anonymous for a request that carries no identity when that is allowed; return ErrUnauthenticated to refuse it.

type Authorizer

type Authorizer interface {
	Authorize(ctx context.Context, p Principal, a Action) error
}

Authorizer decides whether a principal may perform an action.

type NoAuthentication

type NoAuthentication struct{}

NoAuthentication identifies nobody: every request is Anonymous. The default for a single-operator deployment on a trusted network.

func (NoAuthentication) Authenticate

func (NoAuthentication) Authenticate(*http.Request) (Principal, error)

Authenticate returns Anonymous.

type Principal

type Principal struct {
	// Subject is the stable identifier, what a version's Actor records.
	Subject string
	// Name is for display. Falls back to Subject.
	Name string
	// Roles are the groups the principal belongs to, for an Authorizer.
	Roles []string
	// Anonymous is true when no authenticator identified anyone.
	Anonymous bool
}

Principal is who a request runs as.

func PrincipalFrom

func PrincipalFrom(ctx context.Context) Principal

PrincipalFrom returns the principal on ctx, or Anonymous.

func (Principal) Actor

func (p Principal) Actor(fallback string) string

Actor is what a write records: the subject, or fallback for an anonymous principal (a vault's spec.operator, typically).

Directories

Path Synopsis
Package proxy is the Authenticator for a deployment behind an authenticating reverse proxy (oauth2-proxy, Pomerium, Authelia, an ingress with OIDC): the proxy verifies the person and forwards their identity in a header, and this adapter trusts that header.
Package proxy is the Authenticator for a deployment behind an authenticating reverse proxy (oauth2-proxy, Pomerium, Authelia, an ingress with OIDC): the proxy verifies the person and forwards their identity in a header, and this adapter trusts that header.
Package roles is a role-based Authorizer: principals in a write role may read and write, principals in a read role may read, everyone else is refused.
Package roles is a role-based Authorizer: principals in a write role may read and write, principals in a read role may read, everyone else is refused.

Jump to

Keyboard shortcuts

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