authz

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package authz decides who may do what (security.md "Authorization", PHASE1 step 10).

Users get roles per tenant, optionally limited to one CA. Instance admins manage users and unseal the server; that alone gives no rights in a tenant. The services check permissions themselves (the CA engine, the keyring), so the API, the UI, ACME and the agent can't bypass them.

Index

Constants

View Source
const StepUpWindow = 5 * time.Minute

StepUpWindow is how long a fresh second factor counts.

Variables

View Source
var (
	ErrDenied         = errors.New("permission denied")
	ErrStepUpRequired = errors.New("confirm this action with your second factor first")
)

Errors. Both are refusals the caller can fix; the API maps ErrStepUpRequired to a prompt for the second factor.

View Source
var Roles = []Role{Viewer, Operator, Admin}

Roles lists the valid roles.

Functions

func NeedsStepUp

func NeedsStepUp(p Permission) bool

NeedsStepUp reports whether p needs a fresh second factor.

func ValidRole

func ValidRole(r Role) bool

ValidRole reports whether r is a tenant role.

Types

type Binding

type Binding struct {
	Tenant string
	CA     string
	Role   Role
}

Binding is one role of a user in a tenant; CA "" covers the whole tenant.

type Kind

type Kind string

Kind says where a principal comes from.

const (
	// KindUser: signed in through the web UI or the API.
	KindUser Kind = "user"
	// KindConsole: a command on the server itself (myownpki ...). Whoever runs
	// it can read the data directory anyway; it may do everything.
	KindConsole Kind = "console"
	// KindSystem: the server's own jobs (CRL renewal, checkpoints).
	KindSystem Kind = "system"
)

Kinds.

type Permission

type Permission string

Permission is one thing a principal may do.

const (
	ReadPKI      Permission = "pki.read"           // CAs, certificates, CRL status
	ReadAudit    Permission = "audit.read"         // the tenant audit log: user names and IPs are personal data
	IssueCert    Permission = "certificate.issue"  // also renew
	RevokeCert   Permission = "certificate.revoke" // step-up
	DownloadKey  Permission = "key.download"       // a server-generated private key; step-up
	ManageCA     Permission = "ca.manage"          // create, import, renew, retire, update, revoke, install; step-up
	UploadCRL    Permission = "crl.upload"         // the offline root's CRL; step-up
	ManageTenant Permission = "tenant.manage"      // tenant settings
)

Tenant permissions.

const (
	Unseal      Permission = "system.unseal" // and seal; the passphrase is the stronger proof, no step-up
	ManageUsers Permission = "user.manage"   // users, roles, 2FA reset, unlock; step-up
)

Instance permissions: instance admins only.

type Principal

type Principal struct {
	Kind          Kind
	UserID        string
	Username      string
	InstanceAdmin bool
	Bindings      []Binding
	// StepUpAt is the last fresh second factor of this session; zero = none.
	StepUpAt time.Time
	// ViaToken: the request carries an API token. A token never satisfies
	// step-up (step 18): those actions need a person with a fresh code.
	ViaToken bool
}

Principal is the authenticated caller.

func Console

func Console() *Principal

Console returns the principal of a command run on the server.

func System

func System(job string) *Principal

System returns the principal of the server's own jobs.

func (*Principal) CanIssueSomewhere

func (p *Principal) CanIssueSomewhere() bool

CanIssueSomewhere tells whether p may issue at one CA at least (or is the console) – for previews that belong to no CA yet.

func (*Principal) Check

func (p *Principal) Check(perm Permission, res Resource, now time.Time) error

Check returns nil if p may do perm on res at now, an error wrapping ErrDenied or ErrStepUpRequired otherwise. A nil principal is denied.

func (*Principal) FreshStepUp

func (p *Principal) FreshStepUp(now time.Time) error

FreshStepUp checks only the step-up of a signed-in user – for changes to the own account (a new or removed passkey) that need no role.

type Resource

type Resource struct {
	Tenant string
	CA     string
}

Resource is what an action touches. CA "" is an action on the whole tenant (for example creating a CA): only a tenant-wide role allows it.

type Role

type Role string

Role is a tenant role.

const (
	Viewer   Role = "viewer"
	Operator Role = "operator"
	Admin    Role = "admin"
)

Roles, from least to most.

type TokenStepUpError

type TokenStepUpError struct {
	Action string
}

TokenStepUpError refuses an action that needs step-up to an API token. It is a denial (ErrDenied), not a prompt: no POST /auth/step-up can ever make a token fresh, so step-up-required would send a script in circles.

func (*TokenStepUpError) Error

func (e *TokenStepUpError) Error() string

func (*TokenStepUpError) Unwrap

func (e *TokenStepUpError) Unwrap() error

Unwrap makes errors.Is(err, ErrDenied) true.

Jump to

Keyboard shortcuts

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