The caller context is not the subject (L4 auth / ACL)

An ACE names a subject token — opaque bytes. An operation arrives carrying a caller context — this node’s own NAME for the inbound link the frame came in on. Those are different things, and the pluggable subject_lookup_fn_t is the seam between them (ADR-0018): it is where an integrator turns “the frame came in on link ws:7” into “and that link belongs to alice”.

That split is what lets the ACL model stay fixed while identity gets stronger. v1’s transport-authenticated peer id and a later raw-key ed25519 identity are both just tokens (ADR-0045); libtracer does authorization, and the transport does authentication.

What to notice

  • The ACE names the principal, not the link. The example’s ACL says alice; nothing anywhere says ws:7. Only the resolver — integrator code — knows the two are connected, which is why a principal survives being dialled in on a different link tomorrow.

  • The ERROR arm is a deny, not a fallback. “I cannot name this caller” — a stale link, a revoked peer, a lookup that failed — refuses at every gate. The predecessor of this signature returned std::optional, whose nullopt meant fully trusted, so an unresolvable caller used to be granted everything (#905). The example’s last check is that specific disaster: the unnameable caller cannot rewrite the :acl to grant itself access.

  • The empty caller context never reaches the resolver. The example counts invocations through its ctx: two local writes, zero calls. The trusted local channel is settled before the resolver, so a resolver author never has to have an opinion about it — and a remote op, which always carries a non-empty link NAME, cannot reach that arm.

  • It is a {fn, ctx} pair, not a std::function. Assigning a std::function destroys the old target, so a setter racing a gate freed the resolver’s captured state while a reader was inside the call. A bare function pointer is publishable in one word, so the pair lives in a sink_slot_t and the gate reads a coherent snapshot (#1049). Whatever state the resolver needs travels in ctx, which the caller owns and must keep alive across every gated operation.

  • The token goes into the gate’s buffer. The seam appends the subject to the out buffer the gate hands it, a stack frame that spills to the graph’s own source only past 64 bytes, so a gated operation allocates nothing for its subject. A refused append is a deny too.

  • It also carries the application’s now. The seam’s last argument is the now an ACE’s expires_ns is compared against. This resolver issues no leases, so it leaves it alone, and a lease would then fail closed (RFC-0037, expiry).

  • Install it at wiring time, from one thread, before frames flow. graph_hooks_t::subject_lookup is configuration, which the verb says on purpose.

  • Nothing here is conditional — the target builds and runs under every CI leg.

Source

  1/*
  2 * SPDX-License-Identifier: Apache-2.0
  3 * SPDX-FileCopyrightText: Copyright 2026 avatarsd LLC
  4 */
  5
  6/**
  7 * @file
  8 * @brief ONE CONCEPT — the caller context is not the subject; a RESOLVER maps one to the other.
  9 *
 10 * An ACE names a SUBJECT TOKEN — opaque bytes. An operation arrives carrying a CALLER CONTEXT —
 11 * this node's own NAME for the inbound link the frame came in on. Those are different things,
 12 * and the pluggable `subject_lookup_fn_t` is the seam between them (ADR-0018): it is where an
 13 * integrator turns "the frame came in on link `ws:7`" into "and that link belongs to `alice`".
 14 * Authorization is what libtracer does; deciding whose identity a link carries is the
 15 * resolver's, which is why v1's transport-authenticated peer id and a later ed25519 key both
 16 * fit the same ACL model without changing it.
 17 *
 18 * Three properties of the seam that a resolver author has to get right, all shown below:
 19 *
 20 *  - The ERROR arm is a **deny**, not a fallback (#905). "I cannot name this caller" refuses at
 21 *    every gate. Its predecessor returned `std::optional`, whose `nullopt` meant FULLY TRUSTED —
 22 *    so an unresolvable caller used to be granted everything.
 23 *  - The EMPTY caller context never reaches the resolver at all. The graph settles it as the
 24 *    trusted local channel first, so the resolver is never asked to have an opinion about it.
 25 *  - It is a `{fn, ctx}` pair, not a `std::function` (#1049): whatever state the resolver needs
 26 *    travels in a caller-owned `ctx` that must outlive every gated operation.
 27 *  - It returns the token through the gate's `out` buffer, never as an owning container, so a
 28 *    gated operation allocates nothing for its subject (#1781).
 29 *
 30 * Runs under ctest as `example_acl_subject_resolver`; returns non-zero on any failed check.
 31 */
 32
 33#include <cstdio>
 34#include <cstring>
 35#include <expected>
 36#include <span>
 37#include <string_view>
 38#include <vector>
 39
 40#include "libtracer/graph.hpp"
 41#include "libtracer/mem_heap.hpp"
 42#include "libtracer/security_acl.hpp"
 43
 44namespace {
 45
 46using tr::graph::ace_t;
 47using tr::graph::acl_right_t;
 48using tr::graph::graph_t;
 49using tr::graph::path_t;
 50using tr::graph::role_t;
 51using tr::graph::status_t;
 52using tr::graph::vertex_handle_t;
 53
 54/** @brief Report expectation @p what and record a failure on @p ok. */
 55void check(bool& ok, bool cond, const char* what) {
 56    std::printf("  [%s] %s\n", cond ? "ok" : "FAIL", what);
 57    ok = ok && cond;
 58}
 59
 60/** @brief The resolver's own state — caller-owned, and the reason `ctx` exists. */
 61struct link_directory_t {
 62    /** @brief How many times the gate invoked the resolver — the empty caller never does. */
 63    int invocations = 0;
 64};
 65
 66/** @brief Append @p subject to the gate's buffer @p out; a refused append fails closed. */
 67std::expected<void, tr::wire::err_t> put_subject(tr::mem::bytes_t& out, std::string_view subject) {
 68    if (!out.append(reinterpret_cast<const std::byte*>(subject.data()), subject.size()))
 69        return std::unexpected(tr::wire::err_t::ACCESS_DENIED);
 70    return {};
 71}
 72
 73/**
 74 * @brief A resolver with a real mapping in it: link name in, principal out.
 75 *
 76 * `ws:7` is a link this node accepted; `alice` is who is behind it. An ACE names `alice`,
 77 * because a principal outlives the link it happens to be dialled in on today.
 78 */
 79std::expected<void, tr::wire::err_t> resolve_link_owner(void* ctx, std::string_view caller,
 80                                                        tr::mem::bytes_t& out, std::uint64_t&) {
 81    static_cast<link_directory_t*>(ctx)->invocations += 1;
 82    if (caller == "ws:7") return put_subject(out, "alice");
 83    if (caller == "ws:8") return put_subject(out, "bob");
 84    // Every other link is one this node cannot put a name to: a stale link, a revoked peer,
 85    // a lookup that failed. That is a DENY, and saying so is the whole point of the arm.
 86    return std::unexpected(tr::wire::err_t::ACCESS_DENIED);
 87}
 88
 89/** @brief One ALLOW ACE granting @p subject exactly @p right, as a writable `:acl` value. */
 90tr::view::view_t one_grant(std::string_view subject, acl_right_t right) {
 91    const ace_t ace{.subject = tr::graph::subject_of(subject),
 92                    .access_mask = static_cast<std::uint32_t>(right)};
 93    const std::vector<std::byte> acl = tr::graph::encode_acl(std::span<const ace_t>(&ace, 1));
 94    return *tr::view::over_bytes(acl);
 95}
 96
 97/** @brief A one-byte VALUE — the payload every write below carries. */
 98tr::view::view_t some_value() {
 99    const std::byte one[1] = {std::byte{0x01}};
100    return *tr::view::over_bytes(one);
101}
102
103/** @brief True iff @p r was refused by an ACL gate. */
104template <class T>
105bool denied(const tr::graph::result_t<T>& r) {
106    return !r.has_value() && r.error() == status_t::PERMISSION_DENIED;
107}
108
109}  // namespace
110
111int main() {
112    bool ok = true;
113    link_directory_t directory;
114
115    graph_t g;
116    g.set_hook(&tr::graph::graph_hooks_t::subject_lookup, {resolve_link_owner, &directory});
117    const vertex_handle_t v = g.register_vertex(path_t("/dev/temp"), role_t::STORED_VALUE);
118    (void)g.write(v, some_value());  // the trusted local caller seeds a value…
119    (void)g.write(path_t("/dev/temp:acl"), one_grant("alice", acl_right_t::READ));  // …and the ACL
120
121    check(ok, directory.invocations == 0,
122          "two local writes, zero resolver calls — the empty context is settled first (#905)");
123
124    // The ACE says `alice`. Nothing anywhere says `ws:7`; the resolver is the only thing that
125    // knows the two are connected, and it is an integrator's code, not the library's.
126    check(ok, g.read(v, "ws:7").has_value(), "link ws:7 resolves to alice, who is granted READ");
127    check(ok, denied(g.read(v, "ws:8")), "link ws:8 resolves to bob, who is not");
128    check(ok, denied(g.read(v, "ws:9")),
129          "link ws:9 resolves to NOBODY — the error arm denies, it does not wave through");
130    check(ok, directory.invocations == 3, "three remote reads, three resolver calls");
131
132    // The deny arm is a deny at EVERY gate, control plane included — which is exactly what the
133    // std::optional predecessor got wrong: an unnameable caller could rewrite the ACL.
134    check(ok, denied(g.write(v, some_value(), "ws:9")), "…and the unnameable caller cannot WRITE");
135    check(ok,
136          denied(g.write(v, path_t::parse("/dev/temp:acl")->field(),
137                         one_grant("ws:9", acl_right_t::READ), "ws:9")),
138          "…and above all cannot rewrite the :acl to grant itself the access");
139
140    std::printf("resolver invoked %d times; ws:7=alice, ws:8=bob, everything else denied\n",
141                directory.invocations);
142    return ok ? 0 : 1;
143}

See also: security-acl module · graph module · network formation · open by default · the reserved wildcard subject.