security & ACL — access control on the graph¶
In one paragraph
Access control is a pure policy over typed entries. A vertex stores a list of
tr::graph::ace_t — subject, granted-rights mask, flags, expiry. The graph does
the walking: it merges a vertex’s own entries with the INHERIT-flagged entries
of its ancestors into an effective_acl_t, then hands that list plus the
application’s check-time now to the policy the build selected. Neither the
graph nor the policy reads a clock: the subject-lookup hook supplies now
(RFC-0037). The
policy touches no graph state and takes no locks, which is what makes ACE
edge cases — expiry, inheritance, ordering — unit-testable with no live graph.
What it does¶
An ACE (access-control entry) grants a subject a set of rights on a vertex.
The subject is an opaque token, not a name the protocol interprets: how a
deployment maps a peer to a token is the deployment’s business, and the special
token EVERYONE@ matches any resolved subject. The rights are bits in
acl_right_t. An entry may carry an absolute expiry, after which it grants
nothing, and the kAceInherit flag, which is what makes it visible to
descendants.
EVERYONE@ is reserved, and the core enforces the reservation rather than
describing it (#908). The
wire has one spelling for a subject token — the acl/acl-aces vector sends
peer-a and EVERYONE@ as the same opaque VALUE — so a deployment whose
resolver passes a caller-supplied identity through (a username, a certificate
CN, a peer name) could otherwise mint a principal that is the wildcard, and an
entry meant for that one principal would grant everyone. A subject token equal
to kEveryoneSubject therefore matches nothing in either policy, and
graph_t::acl_allows refuses such a caller outright — at every gate, on a
guarded vertex and on a bare one, the same fail-closed arm the resolver’s own
error return takes. is_reserved_subject is public so a resolver can refuse it
at its own door too. EVERYONE@ is the only special subject: ADR-0020 originally
named OWNER@ alongside it, but no evaluator here ever special-cased that string,
so an OWNER@ ACE matched nobody — and since any present ACE closes an otherwise-open
vertex, such an ACE locked the vertex it was written to delegate. ADR-0020’s
erratum (#1033) withdraws the
name rather than reserving it; OWNER@ is an ordinary opaque token, and real owner
semantics would need a per-vertex owner identity the graph does not hold.
Evaluation is split in two on purpose:
The graph owns the walk. It collects the vertex’s own entries in stored order, then appends each ancestor’s
INHERIT-flagged entries, producing one merged list in evaluation order.effective_acl_tis that list plus the verdict call over it.The policy owns the decision. Given a merged list, a subject, one right bit and the current time, it answers
ALLOW,DENY, orNO_MATCH.NO_MATCHmeans no applicable entry decided the bit — the caller applies the open-by-default rule itself rather than the policy guessing.
Two policies ship, and the build picks one (see config):
Policy |
Profile |
Semantics |
|---|---|---|
|
the default, MCU-class |
ALLOW entries only, with a single |
|
host |
ordered first-match-per-bit, DENY included |
Because the choice is per-target configuration and the check runs on the data plane, it is made at compile time — a runtime branch on every access would be a cost paid by the target that does not need the feature.
The owner is the node’s local host, the empty caller context. It bootstraps the device’s ACL and is the only party that writes :acl (RFC-0036 §3.3); it grants orchestrators WRITE where they create and bind and READ where they subscribe, which is what makes third-party binding possible. A remote peer that must manage ACLs asks an owner-app vertex (reference/13).
The wire side¶
An ACL lives on the wire as the :acl ACL TLV described in
reference §protocol TLVs §0x0A, and the
typed parse/build pair lives with the policy rather than in the codec:
parse_acl turns a decoded ACL TLV into ace_t values, encode_acl turns them
back into bytes. Keeping them here is why an ACE test needs no hand-rolled byte
builder.
An ace_t views its subject rather than owning it, so an ACE is a plain value
that copies for free. What owns the bytes depends on where the ACE came from:
parse_acl writes its ACEs into a core array the caller supplies, and their
subjects point into the parsed value; an application’s own ACEs point at its own
bytes (subject_of("alice") views a string’s characters); and a vertex keeps
its :acl, and the merge it caches, in an ace_table_t: one block from the
graph’s source holding the ACEs and copies of their subjects. A subject view
cannot be built from a temporary container, so the classic dangling spelling
({.subject = make_bytes("alice")}) is a compile error.
Parse-time validation is policy-gated: under the ALLOW-only profile a DENY
entry or an unrecognized flag is rejected with TYPE_MISMATCH at write time, so
stored entries never carry a semantic the running policy cannot evaluate.
Parsing an ACL is strict, and that is a security property, not fussiness
(#906). A lenient read of
an access-control document does not lose a field — it changes what the document
grants. A type sent as a big-endian u16 0x0001 (DENY) has 0x00 in its low
byte, so a width-tolerant load turned a refusal into a grant; a dropped
expires_ns turned a time-limited grant permanent; an ignored unknown key
dropped whatever restriction a newer writer meant to add. So parse_acl rejects
a numeric field whose payload is empty or wider than the field, a known key
whose value TLV is the wrong type, an unknown key, a repeated key, and a body
whose (NAME key, value) pairing does not hold. A payload narrower than the
field is fine: little-endian zero-extension names the same integer, which is why
a two-byte access_mask — the acl/acl-aces vector’s spelling before RFC-0026
canonicalized the field at u32 — keeps parsing.
The walk is pair-consuming, the same mechanics wire::config_reader_t uses — and
the exact opposite ruling on unknown keys, deliberately. Config is where a newer
peer legitimately sends more than the receiver understands; an ACL is not.
Pitfalls¶
NO_MATCHis notDENY. A policy that collapses the two takes the open-by-default decision away from the caller and changes behaviour on every vertex with no applicable entry.Expiry is absolute, in nanoseconds on the application’s clock. The subject-lookup hook writes the application’s
nowbeside the subject token, and the epoch is whatever the application writesexpires_nsagainst (RFC-0037). A hook that supplies nonowfails every lease closed: a leasedALLOWgrants nothing and a leasedDENYstill refuses. Standing grants never consult it. A policy that read a clock itself could not be tested deterministically, and libtracer reads no clock at all.Inheritance is a flag, not a mode. Only
kAceInherit-flagged entries of an ancestor reach a descendant; an entry without it is local no matter where it sits in the tree.The subject token is opaque. Comparing it is a byte comparison; the protocol never parses it, so an implementation that reads structure into it has invented a private extension.
A resolver may not return
EVERYONE@. It is the one string carved out of the otherwise opaque token space, and a resolver that hands it back names no principal — the core refuses that caller instead of letting an identity impersonate the wildcard.
API reference¶
-
struct ace_t¶
One ACE of a vertex’s
:acl(ADR-0020 / #81) — a record that VIEWS its subject.Evaluation is the pure per-target policy of ADR-0050 (
security_acl.hpp): the default ALLOW-only MCU profile rejects a DENY ACE (or any flag bit beyondkAceInherit) at write time with TYPE_MISMATCH, so stored ACEs never carry semantics the selected evaluator would silently weaken; the fullsecurity_aclhost policy (acl_policy_t = full_acl_policy_t) stores DENY and evaluates ordered first-match-per-bit.The subject is a view (#2287): an ACE parsed from an
:aclvalue points into that value, an ACE an application writes points at its own bytes, and an ACE a vertex stores points into the ace_table_t that holds it. So the record is trivially copyable and owns nothing — whoever holds the bytes decides how long the view stays good.Public Members
-
ace_type_t type = ace_type_t::ALLOW¶
ALLOW or DENY (policy-gated at parse).
-
std::uint8_t flags = 0¶
ACE flags; only
kAceInheritis accepted.
-
subject_view_t subject¶
Opaque subject token (ADR-0018), viewed; the special subject
"EVERYONE@"matches any resolved subject.
-
std::uint32_t access_mask = 0¶
Granted rights (an OR of
acl_right_tbits).
-
std::uint64_t expires_ns = 0¶
Absolute expiry in ns on the APPLICATION’s clock (the
nowits subject-lookup hook supplies, RFC-0037); 0 = never expires. An expired ACE grants nothing.
-
ace_type_t type = ace_type_t::ALLOW¶
-
enum class tr::graph::ace_type_t : std::uint8_t¶
An ACE’s type (ADR-0020): ALLOW grants; DENY refuses (full policy only).
Values:
-
enumerator ALLOW¶
The ACE grants its mask’s rights.
-
enumerator DENY¶
The ACE refuses them — evaluated only by
full_acl_policy_t(ADR-0050); the ALLOW-only profile rejects DENY at parse time.
-
enumerator ALLOW¶
-
enum class tr::graph::acl_right_t : std::uint32_t¶
One right bit of an ACE
access_mask(docs/reference/05 §0x0A, RFC-0036 §3.1).Two rights, and nothing else: a
:field is a path under its vertex and is gated by the vertex’s own READ and WRITE (RFC-0036 §3.2). Single-bit values so a gate tests exactly one right. A mask bit outside kAceRights is refused when the ACL is installed. Writing:aclis not a right: only the owner, the empty local caller, may do it (RFC-0036 §3.3).Values:
-
enumerator READ¶
Read the vertex value and its
:fields, and subscribe to it.
-
enumerator WRITE¶
Write the vertex value and its
:fields, and create under it.
-
enumerator READ¶
-
constexpr std::uint32_t tr::graph::kAceRights = 0x03¶
Every right bit an ACE may carry (RFC-0036 §3.1); any other bit is refused at install.
-
constexpr std::uint8_t tr::graph::kAceInherit = 0x1¶
The one ACE flag the core subset honors: propagate to the subtree (ADR-0020).
-
constexpr std::string_view tr::graph::kEveryoneSubject = "EVERYONE@"¶
The wildcard subject spelling (ADR-0020): an ACE carrying exactly these bytes as its subject applies to every resolved subject.
It is RESERVED, not merely magic (#908). The wire has one spelling for a subject token — the
acl/acl-acesconformance vector sendspeer-aand this string as the same opaque VALUE — so a principal that could BE these bytes would be indistinguishable from the wildcard, and the deployments at risk are exactly the ones whose resolver passes a caller-supplied identity through (usernames, cert CNs, peer names). The core therefore refuses to let a resolved subject spell it (see is_reserved_subject), rather than leaving every integrator to know to blacklist it.Note
This is the ONLY special subject. ADR-0020 originally named
OWNER@alongside it, but no evaluator here ever special-cased that string, so anOWNER@ACE matched nobody — and since any present ACE closes an otherwise-open vertex, such an ACE LOCKED the vertex it was written to delegate. ADR-0020’s erratum (#1033) withdraws the name rather than reserving it: with no document telling an operator to write that ACE, there is nothing for an impersonatedOWNER@principal to match either. It is an ordinary opaque token. Real owner semantics need a per-vertex owner identity the graph does not hold and would change how a STORED ACE evaluates — an amendment, not this.
-
constexpr std::uint64_t tr::graph::kAceNowUnknown = ~std::uint64_t{0}¶
The
nowan ACL gate evaluates with when the application supplied none (RFC-0037).The subject-lookup hook starts with its
now_nsout-parameter at this value and the application overwrites it with its own clock. Left here, no lease can be proved either live or lapsed, so a leased ALLOW grants nothing and a leased DENY still refuses: the gate fails closed both ways. A standing ACE (expires_ns == 0) never consultsnow.
-
inline bool tr::graph::is_reserved_subject(std::span<const std::byte> subject) noexcept¶
True iff
subjectspells a RESERVED subject token — today exactly kEveryoneSubject — and so may never be a resolved principal (#908).Checked in the two places a subject reaches an ACE comparison in
core/: once per policy evaluation (allow_only_policy_t::allows/full_acl_policy_t::allows— between them the only callers ofdetail_acl::ace_applies, and whateffective_acl_t::allowsdrives), where a reserved subject matches nothing; and once per resolver return ingraph_t::acl_allows— the only site that invokes a resolver — which is decisive: that caller is refused at every gate, like the resolver’s own error arm (#905). Public so an integrator’s resolver can reject the token at its own door too.
-
enum class tr::graph::acl_verdict_t : std::uint8_t¶
A pure policy’s answer for one ACE list (ADR-0050).
NO_MATCHmeans no applicable ACE decided the bit — the caller keeps walking (ancestor lists) and finally applies the open-by-default rule itself.Values:
-
enumerator ALLOW¶
A matching ACE grants the right.
-
enumerator DENY¶
A matching DENY ACE refuses it (full policy only).
-
enumerator NO_MATCH¶
No applicable ACE decided — keep walking / default.
-
enumerator ALLOW¶
-
class subject_view_t : public std::span<const std::byte>¶
An ACE’s subject token, VIEWED (#2287): a
std::span<const std::byte>that refuses to be built from a temporary container.std::span<const std::byte>binds to an rvaluestd::vector<std::byte>and dangles at the end of the statement, which for an ACE written as{.subject = bytes_of("alice")}is before the ACE is ever read. This view deletes that one conversion, so the mistake is a compile error; a span, an lvalue container and a borrowed range all convert as before.Public Functions
-
constexpr subject_view_t() noexcept = default¶
The empty subject.
-
inline constexpr subject_view_t(std::span<const std::byte> s) noexcept¶
View
s.
-
constexpr subject_view_t() noexcept = default¶
-
inline subject_view_t tr::graph::subject_of(std::string_view s) noexcept¶
View the characters of
sas a subject token —{.subject = subject_of("alice")}. The view is good for as long as the characters are (a literal’s, forever).
-
class ace_table_t¶
An OWNING ACE list (#2287): the ACEs and every subject token they view, in ONE block drawn from one source — what a vertex stores as its
:acland its cached merge.The block holds the ACEs first and their subject bytes after them, and each stored ACE’s ace_t::subject views its own bytes in that tail, so the table is self-contained: a caller’s ACEs, or another table’s, can be appended and then dropped. An append builds the whole next block and swaps it in, so a refused one leaves the table as it was; appends happen at
:aclwrites and cache rebuilds, never per operation. Reads are astd::span<const ace_t>(the table converts to one), which is what every evaluator takes.Public Functions
-
inline explicit ace_table_t(mem::block_source_t &src) noexcept¶
An empty table that draws its block from
src.
-
ace_table_t(const ace_table_t&) = delete¶
Non-copyable — a copy is a failable allocation; use append.
-
ace_table_t &operator=(const ace_table_t&) = delete¶
Non-assignable by copy.
-
inline ace_table_t(ace_table_t &&o) noexcept¶
Move: the block changes hands, and
ois left empty.
-
inline ace_table_t &operator=(ace_table_t &&o) noexcept¶
Move-assign: this table’s block goes back to its source first.
-
~ace_table_t() = default¶
Hand the block back to its source.
-
inline bool append(std::span<const ace_t> from, std::uint8_t required_flags = 0) noexcept¶
Append, in order, every ACE of
fromthat carries all ofrequired_flags, copying its subject into this table —0appends them all,kAceInheritthe inheritable ones (what a descendant’s merge takes from an ancestor, ADR-0020).- Parameters:
from – Must not view this table.
- Return values:
false – The source refused the block; the table is unchanged.
-
inline void clear() noexcept¶
Drop every ACE; the block is kept.
-
inline std::size_t size() const noexcept¶
How many ACEs the table holds.
-
inline bool empty() const noexcept¶
True when the table holds no ACE.
-
inline mem::block_source_t &source() const noexcept¶
The source the block is drawn from.
-
inline explicit ace_table_t(mem::block_source_t &src) noexcept¶
-
class effective_acl_t¶
One vertex’s EFFECTIVE ACL (ADR-0020/0050): its own ACEs plus the INHERIT-flagged ancestor ACEs, pre-merged in evaluation order.
The pure owner of the effective-ACL semantics that previously lived inline in
graph_t::acl_allows: build the merged list with append_own (the target’s ACEs, stored order) followed by one append_ancestor per ancestor, NEAREST-FIRST (which filters tokAceInherit— a non-INHERIT ancestor ACE applies to that vertex only), then evaluate with allows. Pure like the policies it drives: no graph access, no locks, no clock reads of its own — unit-testable with synthetic ACE lists.The merged list is what the graph caches per vertex (the ADR-0050 cached effective-ACE merge): only the MERGE is cached, never a verdict —
expires_nsis evaluated against the caller’snowat check time, so expiry needs no invalidation. It is an ace_table_t (#2287): it copies the subjects it merges, so it stays good after the lists it was built from are gone, and an append the source refuses leaves it as it was.Public Functions
-
inline explicit effective_acl_t(mem::block_source_t &src = mem::default_root()) noexcept¶
An empty merge whose table draws from
src.
-
inline bool append_own(std::span<const ace_t> aces) noexcept¶
Append the target vertex’s own ACEs (all of them, stored order).
Note
Call BEFORE any append_ancestor — own ACEs evaluate first (the effective-ACL ordering of ADR-0020).
- Return values:
false – The source refused the table; the merge is unchanged.
-
inline bool append_ancestor(std::span<const ace_t> aces) noexcept¶
Append one ancestor’s ACEs, keeping only the
kAceInherit-flagged ones (a non-INHERIT ACE applies to that vertex only, ADR-0020).Call once per strict ancestor, NEAREST-FIRST, so the full policy’s first-match-per-bit ordering follows the effective-ACL definition.
- Return values:
false – The source refused the table; the merge is unchanged.
-
inline std::span<const ace_t> merged() const noexcept¶
The merged effective-ACE list, in evaluation order.
-
inline ace_table_t release() noexcept¶
Move the merged table out (what the graph stores in its per-vertex cache).
-
template<class Policy = acl_policy_t>
inline bool allows(std::span<const std::byte> subject, std::uint32_t bit, std::uint64_t now) const noexcept¶ The final ACL verdict over THIS instance’s merged list (the static allows over merged).
Public Static Functions
-
template<class Policy = acl_policy_t>
static inline bool allows(std::span<const ace_t> merged, std::span<const std::byte> subject, std::uint32_t bit, std::uint64_t now, std::uint8_t required_flags = 0) noexcept¶ The final ACL verdict over a pre-merged effective-ACE list.
Hands
mergedto the purePolicyONCE (the merge already applied the per-listrequired_flagsfiltering and the own-before-ancestors order, so one pass is verdict-identical to the per-list walk) and applies the open-by-default rule: no effective ACE at all ⇒ allowed (enforcement is opt-in via ACL presence); ANY present ACE — even an expired one — closes the vertex, soNO_MATCHover a non-empty list denies.- Parameters:
merged – A list built by append_own / append_ancestor (or this instance’s merged, via the member overload).
subject – The resolved subject token bytes (ADR-0018).
bit – The requested right (one
acl_right_tbit).now – The application’s check-time
now(RFC-0037), or kAceNowUnknown when it supplied none.required_flags – ACEs lacking these bits are skipped, exactly as
Policy::allowsskips them:0evaluates the whole list (the bearer’s own check),kAceInheritevaluates the inheritable subsequence — what a BARE descendant sees. Filtering in place rather than against a pre-projected copy is what lets the merge be stored once; it is order-identical by construction, since skipping elements cannot reorder the ones that remain, which matters because the full policy is first-match-per-bit in stored order.
- Returns:
true iff
subjectmay exercisebit.
-
inline explicit effective_acl_t(mem::block_source_t &src = mem::default_root()) noexcept¶
-
template<class Policy = acl_policy_t>
result_t<void> tr::graph::parse_acl(const wire::tlv_node_t &acl, mem::block_array_t<ace_t> &out) noexcept¶ Parse a decoded
:aclACL TLV into typed ACEs (docs/reference/05 §0x0A).STRICT by construction, because an ACL is a security document: a shape the builder never emits is rejected with
TYPE_MISMATCHat write time rather than read leniently, since leniency here does not lose a field — it INVERTS or WIDENS a grant (#906). Rejected, per ACE:a DENY ACE under a policy that cannot evaluate one (
Policy::kAcceptsDeny), and any flag bit beyondkAceInherit— the inheritance-only subset both adapters honor today; richer NFSv4 flags gate on the graph’s merge honoring them first;a missing
type/subject/access_mask, or an emptysubjecttoken;a numeric field whose payload is empty or wider than the field (
detail_acl::ace_field_ok—type/flagsu8,access_masku32,expires_nsu64), which is where a big-endian u16typeof0x0001used to truncate from DENY to ALLOW;a KNOWN key carrying the wrong value TLV type — rejected, never skipped: a dropped
expires_nsturns a time-limited grant permanent;an UNKNOWN key, a repeated key, a non-
NAMEchild in a key slot, and an odd child count (a key with no value, or a value with no key).
The walk is pair-consuming, the mechanics of
wire::config_reader_t(#927): it steps one whole(NAME key, value)pair at a time, so a value can never be re-read as the next key — which asubjectsent as aNAME(a spelling this function accepts, forEVERYONE@) previously could be. The unknown-key ruling is the OPPOSITE of that reader’s, deliberately: config is where a newer peer legitimately sends more than the receiver understands, so it skips the pair; an ACL is not, so a silently dropped attribute would widen access.Every key runs through the same checks, driven by one
{key, width}table (detail_acl::kAceKeys) and a seen-bitmask, so the required-field rule is a single compare againstdetail_acl::kAceRequired(#1799).The ACEs are views (#2287): each ace_t::subject points into
acl'sbytes, so they are good for as long as those bytes are. Copy them into an ace_table_t to keep them longer, which is whatvertex_t::set_acldoes.- Template Parameters:
Policy – The accepting policy (defaults to the target’s selection).
- Parameters:
acl – A validated ACL node (
ACL{ ACL{NAME/VALUE…}* }), walked in place (#1829).out – Replaced by the typed ACEs, in wire order; the array is drawn from its source.
- Return values:
status_t::TYPE_MISMATCH – The ACL is not a shape this function accepts.
status_t::BACKPRESSURE –
out'ssource refused the array. On any refusaloutholds no ACE of this ACL.
-
inline std::vector<std::byte> tr::graph::encode_acl(std::span<const ace_t> aces)¶
The vector spelling of encode_acl, kept until the #1781 contract step: the core-array form plus one copy.
- Returns:
The ACL bytes; EMPTY when the heap refused them (an encoded ACL is never empty).
-
inline bool tr::graph::encode_acl(std::span<const ace_t> aces, mem::bytes_t &out) noexcept¶
Encode typed ACEs as the wire
ACL{ ACL{…}* }TLV bytes, appended to a core byte array (#1781) — the typed builder, the inverse of parse_acl.Emits NAME-tagged
type(u8) /flags(u8) /subject(opaque VALUE) /access_mask(u32) children, plusexpires_ns(u64) when non-zero, per docs/reference/05 §0x0A. Encoding is unvalidated by design (tests build deliberately-rejectable ACLs with it); parse_acl is the gate. The bytes are sized first and written in one reservation, so a refusal appends nothing.- Return values:
false – The source refused the bytes;
outis unchanged.
The two selectable policies are documented with the rest of the build configuration, on config.
See: graph (which owns the effective-ACE walk), config (which selects the policy), reference §protocol TLVs (the wire layout), reference §host embedding.