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 ¶
- Variables
- func CanSeeRoster(d Decision) bool
- func Match(sel Selector, path string) bool
- func RenderPipeRoster(w io.Writer, pipe string, r Roster)
- func RenderPrincipalGrants(w io.Writer, principal string, rows []PrincipalRow)
- func RenderWhoami(w io.Writer, v WhoamiView)
- func ValidSelector(sel Selector) bool
- func ViaLabel(d Decision) string
- type Access
- type Decision
- type Grant
- type OrgRole
- type OrphanRef
- type Perm
- type Permissions
- type PipeLoss
- type PipeRef
- type Preview
- type PreviewInput
- type Principal
- type PrincipalRow
- type Reason
- type ReasonKind
- type Remediation
- type Roster
- type RosterRow
- type Selector
- type SourceRef
- type Subject
- type TerminalRef
- type WhoamiView
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
Types ¶
type Decision ¶
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.
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.
func (OrgRole) CanAdministerOrg ¶
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 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.
func (Perm) Effective ¶
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.
type Permissions ¶
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 PipeRef ¶
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
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 ¶
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.
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 PrincipalRow ¶
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.
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 ¶
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 ¶
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 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 ¶
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 ¶
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)