acl

package
v0.58.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 9 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 acl evaluates pipe access: who may read, write or administer a pipe, and — just as importantly — why.

Pure by construction. No DB, no NATS, no HTTP. The storage layer hands it grants, the transport layer consumes its decisions, and the surfaces render its provenance. See docs/ACL.md.

Index

Constants

This section is empty.

Variables

View Source
var EveryoneID = uuid.MustParse("00000000-0000-0000-0000-000000000002")

EveryoneID is the pseudo-principal an ACL row names to grant the whole account. Seeded as a fixed UUID exactly the way the 'unauthenticated' placeholder already is, so the FK and the uniqueness constraint on acl_grants stay honest.

It lives here rather than in internal/db because this is the pure package the evaluator and the storage layer agree through — one definition, no drift. It must never equal uuid.Nil, which means "unauthenticated" everywhere else: an anonymous caller would then match every org-wide grant.

Functions

func CanSeeRoster

func CanSeeRoster(d Decision) bool

CanSeeRoster reports whether a principal may list who else can reach a pipe. Any access at all qualifies — including write-only, which is the case most easily got wrong: an inbox sender holds no read, and a naive "can you read it" gate would hide the roster from every sender in the org. Coordination needs it, and it leaks little, since handle and pipe names are already org-visible from `ppz ls`.

func Match

func Match(sel Selector, path string) bool

Match reports whether sel covers path.

Malformed selectors match nothing. That direction matters: a bad row in acl_grants must grant nothing, never the whole account.

func RenderPipeRoster

func RenderPipeRoster(w io.Writer, pipe string, r Roster)

RenderPipeRoster prints who can reach a pipe. Principals holding nothing are omitted — an org of 200 would otherwise render 198 empty rows.

func RenderPrincipalGrants

func RenderPrincipalGrants(w io.Writer, principal string, rows []PrincipalRow)

RenderPrincipalGrants prints what a principal can reach. Derived defaults appear alongside stored grants — showing only grants would read as "this agent can reach nothing", the exact misreading these surfaces exist to prevent.

func RenderWhoami

func RenderWhoami(w io.Writer, v WhoamiView)

RenderWhoami prints one caller's standing on one pipe, with the reason for every capability — held or not — and, when something is missing, how to get it.

func ValidSelector

func ValidSelector(sel Selector) bool

ValidSelector reports whether sel is well-formed. Storage rejects anything else: a malformed row would match nothing (Match fails closed), which is safe but silently useless — better to refuse it at the point someone types it.

func ViaLabel

func ViaLabel(d Decision) string

ViaLabel is the short provenance token used by --json and the GUI.

Types

type Access

type Access struct {
	Pipe PipeRef
	Perm Perm
}

Access is a principal's effective permission on one pipe.

type Decision

type Decision struct {
	Perm Perm
	Why  map[Perm]Reason
}

Decision is the result of evaluating one principal against one pipe.

Why carries provenance for every capability, granted or denied. It is not decoration: with defaults derived from (collar, pipe name) rather than stored, most access has NO row behind it, so a surface built on the grant table alone renders an almost-empty view and reports that nobody can reach alice.inbox when every member can write to it.

func Evaluate

func Evaluate(p Principal, s Subject, grants []Grant) Decision

Evaluate resolves a principal's access to a pipe.

func (Decision) Has

func (d Decision) Has(p Perm) bool

func (Decision) Reason

func (d Decision) Reason(p Perm) Reason

type Grant

type Grant struct {
	PrincipalID uuid.UUID
	Principal   string
	Selector    Selector
	Perm        Perm
	GrantedBy   string
	CreatedAt   time.Time
}

Grant is one stored ACL row.

type OrgRole

type OrgRole string

OrgRole is a principal's standing in the account.

const (
	OrgNone   OrgRole = ""
	OrgMember OrgRole = "member"
	OrgAdmin  OrgRole = "admin"
	OrgOwner  OrgRole = "owner"
)

func (OrgRole) AtLeast

func (r OrgRole) AtLeast(min OrgRole) bool

func (OrgRole) CanAdministerOrg

func (r OrgRole) CanAdministerOrg() bool

CanAdministerOrg reports whether the role carries implicit admin on every pipe in the account. Computed, never stored, so no revoke can lock an owner out of their own org.

type OrphanRef

type OrphanRef struct {
	Handle string
	Owner  string // "" when the owner is no longer resolvable
}

OrphanRef is a handle whose owner has left the org.

type Perm

type Perm uint8

Perm is a capability bitset.

read and write are INDEPENDENT — neither implies the other. admin implies both, plus the right to manage the pipe's ACL, retention and existence.

The independence is load-bearing: `<handle>.inbox` needs write without read (anyone may send to alice, only alice reads what arrived), and it is enforceable rather than merely declarable because NATS keeps the two apart — writes are a bare subject publish, reads go entirely through the JetStream API.

const (
	Read Perm = 1 << iota
	Write
	Admin
)

func (Perm) Effective

func (p Perm) Effective() Perm

Effective applies the one implication in the lattice — admin carries read and write — returning a bitset with those bits actually set.

Evaluate applies this while resolving; Compile needs it too, because it is handed raw Perms and an admin-only bitset has neither the read nor the write bit set.

func (Perm) String

func (p Perm) String() string

type Permissions

type Permissions struct {
	PubAllow []string
	PubDeny  []string
	SubAllow []string
	SubDeny  []string
}

Permissions is a NATS user's permission set, ready to be signed into a user JWT.

func Compile

func Compile(accountID string, access []Access) Permissions

Compile turns a principal's effective access across the account into a NATS permission set.

`access` is expected to enumerate every pipe in the account, including those the principal cannot touch: the excluded set is what makes the deny-list representation possible.

func Unrestricted

func Unrestricted() Permissions

Unrestricted is the credential an org gets while enforcement is off — today's behaviour, unchanged. Kept here beside Compile so the two shapes are read together.

type PipeLoss

type PipeLoss struct {
	Pipe  string
	Owner string
}

PipeLoss is one pipe losing access for everyone but its owner.

type PipeRef

type PipeRef struct {
	Path    string
	Subject string
	Stream  string
}

PipeRef is one pipe: how it is NAMED, where it actually rides, and the JetStream stream behind it. The three are not interchangeable.

Path is the logical path an ACL selector matches — `alice.heartbeat`. Subject is the NATS subject the pipe is really published to and subscribed on, which for presence is `<account>._presence.<handle>` rather than the logical path (Phase 0b). Stream is the JetStream stream name, which flattens dots to underscores.

Keeping the wire subject here rather than deriving it from Path is what stops the compiler emitting permissions for a subject nothing uses: an earlier version built pub/sub entries from Path, which silently denied every heartbeat publish in an org the moment enforcement was switched on.

type Preview

type Preview struct {
	// Reported first and loudest: Evaluate returns nothing for a
	// non-member BEFORE it checks handle ownership, so these pipes
	// become reachable only by org owner/admin and the nominal owner
	// loses their own handles. It is the case that locks people out
	// with no obvious cause.
	OrphanedHandles []OrphanRef

	// InsertAccount falls back to the 'unauthenticated' placeholder
	// when an org is created without an owner. Such an org has no real
	// principal holding implicit admin, so nobody could fix it after.
	PlaceholderOwnedOrg bool

	SharedTerminals   []TerminalRef
	InboxReadLoss     []PipeLoss
	CollaredUserPipes []PipeLoss
	// contains filtered or unexported fields
}

Preview is the report shown before enabling.

func BuildPreview

func BuildPreview(in PreviewInput) Preview

BuildPreview reports what enabling enforcement would take away.

func (Preview) AllAffectedPipes

func (p Preview) AllAffectedPipes() []string

AllAffectedPipes is every pipe path that loses access for someone. Uncollared pipes are shared org space and are never listed — including them would bury the signal under rows that change nothing.

func (Preview) IsEmpty

func (p Preview) IsEmpty() bool

IsEmpty reports whether enabling would change nothing.

type PreviewInput

type PreviewInput struct {
	OrgOwnerID            uuid.UUID
	OrgOwnerIsPlaceholder bool
	Members               []Principal
	Sources               []SourceRef
	Pipes                 []PipeRef
}

PreviewInput is everything the preview needs, already read out of the database. Kept as plain data so the reporting logic stays pure.

type Principal

type Principal struct {
	ID      uuid.UUID
	Name    string
	OrgRole OrgRole
}

Principal is the subject of a grant: a human, a service account, or @everyone.

type PrincipalRow

type PrincipalRow struct {
	Pipe     string
	Decision Decision
}

PrincipalRow is one pipe a principal can reach.

func (PrincipalRow) MarshalJSON

func (r PrincipalRow) MarshalJSON() ([]byte, error)

type Reason

type Reason struct {
	Kind   ReasonKind
	Grant  *Grant // set when Kind == ReasonGrant
	Detail string // the string every surface prints
}

Reason explains one capability — granted or denied.

func (Reason) Label

func (r Reason) Label() string

Label is the short provenance token used by --json and the VIA column.

type ReasonKind

type ReasonKind string

ReasonKind is where a capability came from.

const (
	ReasonNone        ReasonKind = ""
	ReasonDefault     ReasonKind = "default"
	ReasonGrant       ReasonKind = "grant"
	ReasonHandleOwner ReasonKind = "handle-owner"
	ReasonOrgRole     ReasonKind = "org-role"
	ReasonKeyScope    ReasonKind = "key-scope"
)

type Remediation

type Remediation struct {
	Command    string
	RunnableBy []string
}

Remediation tells a denied caller how to get unstuck, and who can do it. Printing the exact command AND the principals able to run it is what makes a denial actionable by an agent: it can ask over that principal's inbox instead of failing opaquely.

type Roster

type Roster struct {
	Rows     []RosterRow
	Enforced bool
}

Roster is a pipe's access list plus whether it is enforced. The two travel together so a call site cannot render the rows and forget the caveat.

type RosterRow

type RosterRow struct {
	Principal string
	Decision  Decision
}

RosterRow is one principal's standing on a pipe.

func (RosterRow) MarshalJSON

func (r RosterRow) MarshalJSON() ([]byte, error)

type Selector

type Selector string

Selector names the pipes a grant applies to. It matches a pipe's SUBJECT PATH — what natsubj.BuildSubject produces, minus the account prefix.

alice.inbox   exactly that pipe
alice.*       one token — every pipe directly under alice
alice.**      one or more trailing tokens — everything under alice
*.inbox       every handle's inbox
**            every pipe in the account

`*` and `**` map 1:1 onto NATS `*` and `>`, which is what keeps the Phase 3 credential compiler close to mechanical.

The manifold/collar ambiguity is inherited deliberately: natsubj already documents that `acct.X.pipe` is indistinguishable at the wire level between a manifold and a source segment. Matching the path inherits exactly that and introduces nothing new.

type SourceRef

type SourceRef struct {
	Handle        string
	Kind          string // "pty" | "message"
	OwnerID       uuid.UUID
	OwnerIsMember bool
}

SourceRef is one handle in the account and who owns it.

type Subject

type Subject struct {
	Path   string
	Collar string
	Name   string
	Owner  uuid.UUID
}

Subject is the pipe being evaluated.

Path is the subject path — what natsubj.BuildSubject produces, minus the account prefix. Collar is the owning handle ("" for uncollared pipes) and Owner is that handle's principal.

type TerminalRef

type TerminalRef struct {
	Handle string
	Owner  string
}

TerminalRef is a shared terminal that becomes private.

type WhoamiView

type WhoamiView struct {
	// Enforced is whether this org actually enforces ACLs. A view
	// saying "you cannot read this" while the read demonstrably
	// succeeds is worse than no view — it is a control that lies, and
	// it lies most convincingly to whoever is checking they are safe.
	Enforced    bool
	Pipe        string
	Principal   string
	Decision    Decision
	Remediation *Remediation
}

WhoamiView is the self-service explanation for one pipe.

func (WhoamiView) MarshalJSON

func (v WhoamiView) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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