expires_ns is evaluated against the application’s clock (L4 auth / ACL)¶
An ACE may carry an absolute deadline: expires_ns, nanoseconds on the application’s clock, with
0 meaning never. It is not a timer and nothing sweeps it — the policy compares it to the now
its caller passed in, on every single check. At the graph’s door that now is the application’s:
the subject-lookup hook writes it beside the subject token, and libtracer reads no clock
(RFC-0037)
(ADR-0050).
The example runs against the pure surface first, because effective_acl_t takes now as a
parameter — so it can step the clock without sleeping — and then confirms the identical rule at
the real graph_t door, where the hook hands in the application’s now.
What to notice¶
One merged list, four verdicts, zero invalidations. The example asks the same
effective_acl_tabout severalnows, including going back to an earlier one. That is why the graph caches the effective-ACE merge but never a verdict: a merge stays valid as the clock moves, so expiry needs no invalidation mechanism at all.Expiry is
expires_ns <= now, not<. At the deadline the grant is already gone. The example pins both sides of that single nanosecond.An expired ACE grants nothing — and still closes the vertex. Presence is what closes (open by default), and an expired entry is present. So a temporary grant that lapses does not restore the open state it replaced; it leaves the vertex shut to everyone. This is the trap: “the badge expired, so we are back to normal” is exactly wrong.
0means never expires, not expired at the epoch. The example checks that too, because the two readings of a zero field differ by the entire lifetime of the grant.The parser refuses an empty
expires_nsfor the same reason. An empty payload would load as0— the permissive reading — so an absent value must not be allowed to mean “never expires” (strict ACL parsing).No
now, no lease. An application with no clock leaves the hook’snowalone. A lease can then be proved neither live nor lapsed, so a leased grant gives nothing (and a leasedDENYstill refuses), while a standing grant reads as before. The example checks both.Nothing here is conditional, and nothing sleeps. No timers, no threads, no wall-clock rendezvous: the deadline is a number the example passes in, and the graph-level half steps a
nowthe example owns, so it is deterministic on any machine, on any 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 — `expires_ns` is evaluated against the CALLER's `now`, at check time.
9 *
10 * An ACE may carry an absolute deadline: `expires_ns`, nanoseconds on the application's clock,
11 * with `0` meaning "never". It is not a timer and nothing sweeps it — the policy compares it to
12 * the `now` its caller passed in, on every single check. At the `graph_t` door that `now` is
13 * the application's: the subject-lookup hook writes it beside the subject token, and the
14 * library reads no clock of its own (RFC-0037). That is why the graph caches the merged
15 * effective-ACE list but never a verdict: a merge stays valid as the clock moves, so expiry
16 * needs no invalidation mechanism at all (ADR-0050).
17 *
18 * The consequence to hold on to is the one that catches people out: an expired ACE grants
19 * nothing AND still closes the vertex. Presence is what closes (see acl_open_by_default), and
20 * an expired entry is present. A temporary grant that lapses therefore does not restore the
21 * open state it replaced — it leaves the vertex shut to everyone.
22 *
23 * This runs against the PURE surface — `effective_acl_t` takes `now` as a parameter, so the
24 * example can step the clock without sleeping — and then confirms the same rule at the real
25 * `graph_t` door, where the hook hands in the application's `now`. A hook that hands in none
26 * fails every lease closed.
27 *
28 * Runs under ctest as `example_acl_expiry`; returns non-zero on any failed check.
29 */
30
31#include <cstdint>
32#include <cstdio>
33#include <cstring>
34#include <span>
35#include <string_view>
36#include <vector>
37
38#include "libtracer/graph.hpp"
39#include "libtracer/mem_heap.hpp"
40#include "libtracer/security_acl.hpp"
41
42namespace {
43
44using tr::graph::ace_t;
45using tr::graph::acl_right_t;
46using tr::graph::effective_acl_t;
47using tr::graph::graph_t;
48using tr::graph::path_t;
49using tr::graph::role_t;
50using tr::graph::status_t;
51using tr::graph::vertex_handle_t;
52
53/** @brief Report expectation @p what and record a failure on @p ok. */
54void check(bool& ok, bool cond, const char* what) {
55 std::printf(" [%s] %s\n", cond ? "ok" : "FAIL", what);
56 ok = ok && cond;
57}
58
59/** @brief @p s as opaque subject-token bytes. */
60std::vector<std::byte> as_bytes(std::string_view s) {
61 std::vector<std::byte> out(s.size());
62 std::memcpy(out.data(), s.data(), s.size());
63 return out;
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/** @brief The application's clock: here a number the example sets, never a clock read. */
74struct app_clock_t {
75 bool running = true; /**< @brief False models an application with no clock. */
76 std::uint64_t now = 0; /**< @brief The application's `now`, in its own ns. */
77};
78
79/** @brief The caller context IS the subject token, and the app's `now` rides beside it. */
80std::expected<void, tr::wire::err_t> caller_is_subject(void* ctx, std::string_view caller,
81 tr::mem::bytes_t& out,
82 std::uint64_t& now_ns) {
83 const auto& clock = *static_cast<const app_clock_t*>(ctx);
84 if (clock.running) now_ns = clock.now; // left alone, `now_ns` says "no now supplied"
85 return put_subject(out, caller);
86}
87
88/** @brief @p right as the single `access_mask` bit it is. */
89constexpr std::uint32_t bit(acl_right_t right) { return static_cast<std::uint32_t>(right); }
90
91/** @brief A one-byte VALUE. */
92tr::view::view_t some_value() {
93 const std::byte one[1] = {std::byte{0x01}};
94 return *tr::view::over_bytes(one);
95}
96
97/** @brief True iff @p r was refused by an ACL gate. */
98template <class T>
99bool denied(const tr::graph::result_t<T>& r) {
100 return !r.has_value() && r.error() == status_t::PERMISSION_DENIED;
101}
102
103/** @brief A visitor's badge, valid until @ref kDeadline. */
104constexpr std::uint64_t kDeadline = 1'800'000'000'000'000'000ULL; // ~2027-01-15, in ns
105
106} // namespace
107
108int main() {
109 bool ok = true;
110
111 // The pure surface: build one effective-ACE list ONCE, then ask it about several `now`s.
112 // Nothing below rebuilds or invalidates it — that is the property being shown.
113 const ace_t issued[] = {{.subject = tr::graph::subject_of("visitor"),
114 .access_mask = bit(acl_right_t::READ),
115 .expires_ns = kDeadline}};
116 effective_acl_t merged;
117 check(ok, merged.append_own(issued), "the merge copies the list into its table");
118 const std::span<const std::byte> visitor_bytes = issued[0].subject;
119 const std::vector<std::byte> other = as_bytes("resident");
120
121 check(ok, merged.allows(visitor_bytes, bit(acl_right_t::READ), kDeadline - 1),
122 "one nanosecond before the deadline, the badge works");
123 check(ok, !merged.allows(visitor_bytes, bit(acl_right_t::READ), kDeadline),
124 "AT the deadline it does not — expiry is `expires_ns <= now`, not `<`");
125 check(ok, !merged.allows(visitor_bytes, bit(acl_right_t::READ), kDeadline + 1),
126 "and after it, of course, it does not");
127 check(ok, merged.allows(visitor_bytes, bit(acl_right_t::READ), kDeadline - 1),
128 "the SAME list answers yes again for an earlier `now`: no state changed, nothing "
129 "was invalidated, and nothing had to be");
130
131 // The expired entry is still an entry, so the vertex it guards stays shut.
132 check(ok, !merged.allows(other, bit(acl_right_t::READ), kDeadline - 1),
133 "the resident was never granted anything, and a present ACE closes the vertex");
134 check(ok, !merged.allows(other, bit(acl_right_t::READ), kDeadline + 1),
135 "…and the badge lapsing does not reopen it — this is the trap worth remembering");
136
137 // `0` is not a deadline in the distant past; it means the ACE never expires.
138 const ace_t permanent[] = {
139 {.subject = tr::graph::subject_of("resident"), .access_mask = bit(acl_right_t::READ)}};
140 effective_acl_t forever;
141 check(ok, forever.append_own(permanent), "the merge copies the list into its table");
142 check(ok, forever.allows(other, bit(acl_right_t::READ), kDeadline + 1),
143 "expires_ns == 0 means never expires, not expired at the epoch");
144
145 // The same predicate at the real door, where `now` is whatever the application's hook says.
146 app_clock_t clock{.now = kDeadline - 1};
147 graph_t g;
148 g.set_hook(&tr::graph::graph_hooks_t::subject_lookup, {caller_is_subject, &clock});
149 const vertex_handle_t v = g.register_vertex(path_t("/room"), role_t::STORED_VALUE);
150 (void)g.write(v, some_value());
151 const ace_t both[] = {
152 {.subject = tr::graph::subject_of("visitor"),
153 .access_mask = bit(acl_right_t::READ),
154 .expires_ns = kDeadline},
155 {.subject = tr::graph::subject_of("resident"), .access_mask = bit(acl_right_t::READ)},
156 };
157 (void)g.write(path_t("/room:acl"), *tr::view::over_bytes(tr::graph::encode_acl(both)));
158 check(ok, g.read(v, "visitor").has_value(), "the app's clock says before the deadline: reads");
159 clock.now = kDeadline;
160 check(ok, denied(g.read(v, "visitor")), "the app's clock reaches the deadline: refused");
161 // An application with no clock supplies no `now`. A lease then cannot be proved live, so it
162 // grants nothing; a standing grant is untouched, because it never asks.
163 clock = {.running = false};
164 check(ok, denied(g.read(v, "visitor")), "no now supplied: the lease fails closed");
165 check(ok, g.read(v, "resident").has_value(), "no now supplied: the standing grant still reads");
166
167 std::printf("one ACE list, four verdicts, zero invalidations — deadline %llu ns\n",
168 static_cast<unsigned long long>(kDeadline));
169 return ok ? 0 : 1;
170}
See also: security-acl module · protocol TLVs · open by default · inheritance · strict ACL parsing.