policy

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package policy is the authorization matrix for sqi's four built-in roles. It maps (role, permission) to allow/deny and is consulted by the REST auth middleware and the WebSocket subscribe path. It has no dependencies beyond the Principal it evaluates, so it stays pure and exhaustively testable.

The matrix here is the server-side source of truth; web/src/auth/policy.ts mirrors it and docs/auth.md documents it — keep all three in lockstep.

Index

Constants

This section is empty.

Variables

All is every declared permission. It is the source for PermissionsFor's superuser answer and for the exhaustiveness test that keeps this list in step with the constants above.

Functions

func Can

func Can(p auth.Principal, perm Permission) bool

Can reports whether p may perform perm. A Superuser principal (the anonymous identity injected when auth is disabled, and reserved bootstrap) bypasses the matrix. Otherwise the permission is granted if any of p.Roles grants it.

func IsRole

func IsRole(name string) bool

IsRole reports whether name is a role the policy matrix defines. It is the authority for role validity — API-level validation calls it rather than keeping its own list, so a role can never be assignable-but-ungranted (a user with zero permissions and no error) or granted-but-unassignable.

func PermissionsFor

func PermissionsFor(p auth.Principal) []string

PermissionsFor returns p's effective permissions as sorted strings, for transmission to clients over GET /auth/me. Clients gate on these strings directly rather than re-deriving them from roles, so the policy matrix lives in exactly one place. A Superuser principal (auth disabled) reports the full set, which is what keeps auth-off clients showing every control enabled.

Always returns a non-nil slice so it marshals as [] rather than null.

func Roles

func Roles() map[string]map[Permission]bool

Roles returns a read-only snapshot of the role → permission grants matrix, keyed by role name. It lets tests in the external policy_test package assert against the real matrix rather than a hand-copied mirror, which cannot notice when the two drift apart. Each call returns a fresh deep copy, so callers cannot mutate package state through it.

Types

type Permission

type Permission string

Permission is a per-resource-verb capability gating one or more routes.

const (
	// JobsRead grants read access to jobs.
	JobsRead Permission = "jobs.read"
	// JobsWrite grants create/update/delete access to jobs.
	JobsWrite Permission = "jobs.write"
	// JobsReadAll grants visibility of jobs owned by anyone. Without it a
	// principal is owner-scoped: it sees, and may mutate, only jobs it owns.
	// This single predicate governs both reads and writes — a principal that
	// may not see another user's job must not be able to mutate it either.
	JobsReadAll Permission = "jobs.read.all"
	// JobsSubmitAs grants setting Job.Owner to a user other than yourself.
	// Modeled as a permission rather than an operator/admin role check so a
	// narrow role for a proxy service (a pipeline gateway submitting for
	// artists) could hold it without also holding workers.manage.
	JobsSubmitAs Permission = "jobs.submit_as"
	// WorkersRead grants read access to workers.
	WorkersRead Permission = "workers.read"
	// WorkersManage grants management access to workers (drain, restart, etc).
	WorkersManage Permission = "workers.manage"
	// InfraRead grants read access to infrastructure.
	InfraRead Permission = "infra.read"
	// InfraManage grants management access to infrastructure.
	InfraManage Permission = "infra.manage"
	// ProductsRead grants read access to products.
	ProductsRead Permission = "products.read"
	// ProductsManage grants management access to products.
	ProductsManage Permission = "products.manage"
	// DiagnosticsRead grants read access to server diagnostics.
	DiagnosticsRead Permission = "diagnostics.read"
	// UsersRead grants read access to users.
	UsersRead Permission = "users.read"
	// UsersManage grants management access to users.
	UsersManage Permission = "users.manage"
	// APIKeysSelf grants access to manage own API keys.
	APIKeysSelf Permission = "apikeys.self"
	// APIKeysAdmin grants access to manage all API keys.
	APIKeysAdmin Permission = "apikeys.admin"
	// IsolationManage grants setting a queue's run-as-user, i.e. choosing the OS
	// identity that arbitrary job code executes under. It is separate from
	// InfraManage, which operator holds, because it is an escalation surface,
	// not ordinary queue configuration.
	IsolationManage Permission = "isolation.manage"
	// WorkersEnroll grants issuing worker join tokens — that is, attaching
	// arbitrary compute that receives and executes job code. It is kept
	// separate from WorkersManage (enable/disable/delete an existing worker)
	// for the same reason IsolationManage is: the privilege is different in
	// kind, not merely in degree.
	WorkersEnroll Permission = "workers.enroll"
)

Jump to

Keyboard shortcuts

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