authz

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package authz provides multi-principal, RBAC-style access control for the control plane. It generalizes the legacy single static bearer token into a set of named principals, each with its own token, an allowed-profile glob list, and permission flags.

The zero value and a nil *Store both mean "RBAC not configured", allowing the caller to fall back to legacy single-token behavior.

Index

Constants

View Source
const EnvFile = "RUNEWARD_AUTHZ_FILE"

EnvFile is the environment variable that points at the RBAC principals file.

Variables

View Source
var ErrEmpty = errors.New("authz: store not configured")

ErrEmpty is returned by helpers that require a configured store. It is exported for callers that wish to distinguish "not configured" from other failures.

Functions

This section is empty.

Types

type Principal

type Principal struct {
	// Name is the human-readable identity used as the audit actor.
	Name string `json:"name"`
	// Token is the bearer token that authenticates this principal.
	Token string `json:"token"`
	// AllowedProfiles is a list of glob patterns (path.Match syntax) matched
	// against a profile name. An empty list for a non-admin principal means it
	// may launch nothing; a list containing "*" allows every profile.
	AllowedProfiles []string `json:"allowed_profiles"`
	// CanApprove permits the principal to approve or deny pending actions.
	CanApprove bool `json:"can_approve"`
	// Admin bypasses all profile restrictions and implies approval rights.
	Admin bool `json:"admin"`
}

Principal is a named identity that authenticates with a bearer token and carries its own authorization scope.

func (*Principal) CanLaunch

func (p *Principal) CanLaunch(profile string) bool

CanLaunch reports whether the principal may launch the named profile. Admins bypass all restrictions. For non-admins, the profile must match at least one of the AllowedProfiles glob patterns.

func (*Principal) MayApprove

func (p *Principal) MayApprove() bool

MayApprove reports whether the principal may approve or deny actions.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store holds principals indexed by token. It is safe for concurrent reads. A nil *Store means RBAC is not configured.

func FromEnv

func FromEnv() (*Store, error)

FromEnv builds a Store from the file named by RUNEWARD_AUTHZ_FILE. When the variable is unset (or empty) it returns (nil, nil), signaling that RBAC is not configured and the caller should fall back to legacy single-token auth.

func Load

func Load(filePath string) (*Store, error)

Load reads a JSON principals file of the form:

{"principals": [ {"name": "...", "token": "...", ...}, ... ]}

It rejects entries with empty names, empty tokens, or duplicate tokens.

func (*Store) Identify

func (s *Store) Identify(token string) (*Principal, bool)

Identify returns the principal that owns the given bearer token. It returns (nil, false) when the token is unknown, empty, or the store is nil. Token comparison is done with a constant-time compare to reduce timing leakage.

func (*Store) Len

func (s *Store) Len() int

Len reports the number of configured principals. A nil Store has length 0.

Jump to

Keyboard shortcuts

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