interplane.Get Omega
Read in your language

omnet

aien-dev/omnet

Brought by drakestapleton

branch main Branches Tags History

omnet / cmd / tkad / README.md

225 lines · 13302 bytes Raw Blame History Rendered
1# tkad: bounded local Tailnet Lock service
2
3Production code is Omega, compiled by `tools/build-tkad.sh` with `tools/omc.sh`.
4Go and Python under `test/` are test-only. Protocol types are pinned to Tailscale
5v1.102.0 `tailcfg/tka.go` and `ipn/ipnlocal/tailnet-lock.go`.
6
7## Invocation and trust boundary
8
9Provision an empty directory owned by the effective UID, mode0700, under a trusted
10ancestor chain. Run `build/tkad /absolute/state/directory --init` exactly once.
11Subsequent starts use `build/tkad /absolute/state/directory`. Missing or corrupt
12snapshots refuse startup; initialization refuses an existing snapshot.
13
14The service creates `tkad.sock` inside its opened directory, mode0600. The
150700directory and0600socket enforce a same-UID/root **trusted local adapter**
16boundary. There is no SO_PEERCRED operation in the pinned native ABI and no claim
17of peer-credential inspection. Same-UID/root processes can act as the adapter,
18read secrets and change storage. This is not Noise authentication, HTTP serving,
19a deployed Headscale integration, or a distinct-UID privilege boundary. The
20adapter must authenticate remote clients and derive node IDs/admin assertions
21from its trusted identity model, never from remote JSON.
22
23A descriptor-held abstract AF_UNIX bind lock, derived from directory device and
24inode, admits one writer. All writers must use the same network namespace. Only
25a lock holder removes the reserved stale socket pathname. No PID-file or
26connect-failure lock inference is used. A process crash leaves a pathname that a
27new lock holder can remove safely.
28
29## IPC version1
30
31One request and one response per AF_UNIX stream connection. Integers are unsigned
32little endian. Header fields must be complete; there is no implicit terminator.
33
34Request header,20bytes:
35
36| Offset | Size | Meaning |
37|---|---|---|
38|0|4|Bytes `54 4b 41 01` (`TKA` and version1)|
39|4|1|Route ID below|
40|5|1|Trusted adapter admin assertion, exactly0 or1|
41|6|2|Reserved, zero|
42|8|8|Authenticated NodeID; RPCs require a registered positive signed64-bit ID|
43|16|4|Raw JSON byte length,0..65536|
44
45The body is the unmodified upstream JSON request. Response header,12bytes, has
46the same magic at0, HTTP-style status as u16at4, reserved zero u16at6, and JSON
47length u32at8. A200body follows the exact upstream response field shapes. Errors
48have a short fixed JSON body, never request details or secrets. Bad/truncated
49headers and oversized payload declarations close that connection without a reply.
50Each receive/send phase has an absolute3second deadline, nonblocking descriptors
51and kernel polling. A slow client can occupy one serial dispatch for that bounded
52period; this is not a high-throughput concurrent server.
53
54| ID | Route |
55|---|---|
56|1|`/machine/tka/init/begin`|
57|2|`/machine/tka/init/finish`|
58|3|`/machine/tka/bootstrap`|
59|4|`/machine/tka/sync/offer`|
60|5|`/machine/tka/sync/send`|
61|6|`/machine/tka/disable`|
62|7|`/machine/tka/sign`|
63|8|`/machine/tka/affected-sigs`|
64|9|Trusted registry upsert|
65|10|Trusted registry remove|
66|11|Trusted map/list read|
67
68RPCs1,2,6 require admin. All eight bind JSON `NodeKey` to the registered key of
69the header NodeID. `/sign` authenticates that caller but resolves the signed
70target from the signature's embedded node public key; it need not be the caller.
71Registry and map commands require admin and may use header NodeID0.
72
73Registry upsert takes `{NodeID,NodeKey,RotationPubkey,Signature?}`. `NodeKey` is
74`nodekey:`hex and `RotationPubkey` is a32byte base64 Ed25519 public key. IDs and
75node keys are unique. Optional `Signature` is a base64/byte-array upstream NKS;
76nonempty signatures require an active authority and valid authorization. A key
77change clears the old signature. Omitting Signature preserves it only when the
78key is unchanged. Unsigned nodes may be registered and signed later; this does
79not itself authorize them to peers. Remove takes `{NodeID}`. Map/list takes `{}`
80and returns `{TKAInfo,Revision,StoreID,Nodes:[{NodeID,NodePublic,RotationPubkey,KeySignature}]}`.
81`RotationPubkey` is the stored32byte base64 public key, exposed for adapter reconciliation.
82Inactive and pending authority produce `TKAInfo:null`; active produces `{Head}`; disabled
83produces `{Disabled:true}`. Unsigned nodes have `KeySignature:null`.
84Revision advances after each durable mutation. An exact registry upsert retry (same ID,
85node key, rotation key and omitted or identical signature) is nonmutating: it preserves the
86revision and pending initialization, including after restart. This also permits replay of an
87already accepted historical signature without reauthorizing it under a later authority.
88`StoreID` is the 128-bit identity of the store, 32 lowercase hex digits, drawn once from the
89kernel CSPRNG by initialization and never changed afterwards. It names the store and not the
90path: it survives restarts, an epoch boundary, and a rename of the store directory, and two
91independent stores never share one. A client that follows a path can therefore tell a
92replacement apart from the store it was talking to: the directory may be swapped under it and
93the identity is the only thing that reports it.
94Adapters must propagate these full values to initial/delta map responses and arrange notifications.
95No notification transport or Headscale integration is claimed here.
96
97## State transitions and durable publication
98
99Initialization binds a signed pending genesis to the initiating NodeID and the
100frozen registry. Any actual registry change invalidates pending initialization; an exact
101upsert retry does not. Finish requires exactly one valid direct signature for every frozen
102node, including its registered wrapping public key. A different initiator, partial roster, stale
103roster, invalid signature or invalid support-disablement secret rejects. Optional
104SupportDisablement is retained separately and never disables the authority.
105Pending genesis is not visible in map or bootstrap responses.
106
107Sync uses the authority unit's fork choice, offer sampling and intersection.
108Interactive sync requires the supplied Head to equal the server's **pre-update**
109head; mismatch rejects before staging. Stock `TailnetLockModify` sends its current
110head with newly generated AUMs, then checks that the reply names its last new AUM.
111Noninteractive sync validates the head encoding but permits a divergent remote
112head. Disable requires admin, the
113current head and a valid bounded secret. A disabled authority remains available
114for bootstrap's disablement secret and cannot be reinitialized in this profile.
115
116Each mutating request operates on an inactive candidate slot, including registry,
117signatures, pending state, support/disablement secrets and authority. The complete
118response is encoded and checked against capacity **before** persistence. A
119candidate whose registry snapshot would not fit the map response is rejected with
120413 and never committed, so a successful mutation cannot make the registry
121unreadable. Submitted node-key signatures are stored in canonical typed form:
122ignored CBOR fields are dropped before storage, so they cannot pad the snapshot.
123Only then is a complete snapshot streamed to storage, synced, atomically renamed and
124the directory synced. A successful commit is followed by an infallible live-slot
125switch. Pre-rename errors discard the candidate and return503. Post-rename fsync
126uncertainty exits74 immediately, without rollback or further serving. Exit74 also
127denotes failed storage cleanup, including during initialization; it means a
128storage fail-stop, not a definite successful commit. A transport
129failure after publication remains an inherently ambiguous client outcome; the
130adapter must reconcile through state reads.
131
132The semantic snapshot is version1: one128byte little-endian metadata frame,
133then each node's88byte record and optional signature frame, optional support and
134disablement secret frames, then each retained typed AUM frame in insertion order.
135Metadata holds status, node count, pending initiator, secret lengths, revision,
136authority count, a version marker, the header schema word and the store identity,
137listed in the word table below. Node records contain ID, signature length,
138authorization-state index, raw node key and raw rotation key. Storage adds its
139own framing, version, ordered BLAKE2s integrity chain and strict permission/type
140checks; see `om/store/README.md`.
141
142The 128-byte metadata frame is sixteen little-endian 64-bit words:
143
144|Word|Meaning|Rule|
145|---|---|---|
146|0|state status|0 pending init through 3 disabled|
147|1|registered node count|at most 64|
148|2|pending initiator NodeID|0 when none, otherwise a registered node|
149|3|support-disablement secret length|at most 1024|
150|4|disablement secret length|at most 1024, stored only when disabled|
151|5|reserved|must be 0|
152|6|Revision|saturates, never wraps|
153|7|retained authority count|at most 128|
154|8|header schema|must be exactly 1|
155|9,10|store identity, low then high word|128 random bits from init, never both 0|
156|11..14|reserved|must be 0|
157|15|marker|must be 1|
158
159A header whose schema word, identity or reserved words were altered is refused
160rather than served or repaired. There is no migration from a header without a
161schema word: no build that writes one has been released.
162
163AUMs retain typed reconstruction (`tkamodel keep=1`), not merely canonical wire
164serialization: an empty-but-present update metadata map must survive restart.
165Recovery reboots/replays and verifies every AUM, registry uniqueness, structural
166bounds, state status and every stored node signature against the historical
167state at which it was accepted. This permits retaining a now-revoked signature
168for affected-sigs/map propagation without treating it as currently authorized.
169Recovery rechecks support secrets against genesis and disablement secrets against
170the current authority. Corruption never
171falls back to a temporary snapshot or an empty installation.
172
173## Native loop lifecycle
174
175Every Omega loop has a finite safety bound. To avoid an eventual request-count
176trap, a quiescent epoch of100000dispatch iterations ends in a controlled exec of
177`/proc/self/exe --resume`. The running inode, not an installation pathname or
178argv0, is used. FD64holds the directory,65the writer lock and66the listener across
179exec; first-epoch handoff refuses occupied targets. Resume validates inherited
180descriptors, exact lock/listener addresses, directory/socket ownership and modes,
181then reloads the committed snapshot. It never binds, initializes or unlinks.
182Queued connections stay on the same listener and the PID is unchanged. Every
183accepted connection is closed before rollover. Exec failure exits76 and never
184retries or unlinks. The native exec operation supplies an empty environment;
185this service does not depend on environment configuration. Linux procfs and an
186unchanging effective UID are prerequisites.
187
188## Limits and tests
189
190Single tailnet;64registered nodes;128AUMs per authority;65536bytes per raw JSON
191request/response, with a4095token/depth32JSON parser and256members per object; individual crypto/model
192objects at most65536bytes, further constrained by JSON/base64 envelope capacity;
193secrets at most1024bytes. Response overflow is413before mutation. Resource limits
194are explicit rejections, not silent truncation or history eviction. Known-field
195matching follows Go's ASCII case folding plus the Kelvin-sign and long-s Unicode
196aliases; duplicate aliases are rejected. Exact decoded JSON key duplicates are
197rejected globally. Signature-map NodeID keys follow Go signed-decimal parsing,
198including leading plus/zeros, with duplicate decoded IDs rejected and registry
199IDs restricted to positive int64 values. Unknown fields are ignored. The
20032byte rotation-key registry requirement and disabled-state reinitialization
201restriction are explicit local profile limits, not general upstream limits.
202
203Run `GO=/path/to/go1.26.8 REGEN=1 sh cmd/tkad/test/run.sh` to regenerate fixtures
204through real pinned `tailscale.com/tka`, build the native binary, and exercise
205all eight RPCs plus registry/map, authorization errors, malformed frames,
206initialization races, restart, historical revocation and disk-write failure.
207Test-only syscall-boundary variants prove one-shot begin/commit failure recovery
208without process restart and fatal handling of post-rename directory-fsync failure.
209A two-dispatch epoch variant checks queued connections, stable PID/listener,
210retained writer exclusion and missing/swapped resume-descriptor refusal.
211A directory-replacement fixture proves the held descriptor, not the path, is the
212store: after init, replacing the directory at the same path does not redirect
213commits, and the replacement stays empty and refuses resume.
214A completed-response admin-bypass mutant must be detected; a trapping mutant
215must be rejected as an invalid test completion. Tests use isolated temporary
216state directories and no live services. These are host/socket regression tests,
217not stock-client end-to-end or constant-time qualification.
218
219### Third-party material
220
221The service composes Omega units adapted from Tailscale; their BSD-3-Clause
222notices remain in `om/tka/tailscale.LICENSE` and
223`om/tkasig/test/tailscale.LICENSE`. The Go fixture generator imports the pinned
224upstream module and contains no copied upstream source. Its deterministic
225private test keys are public fixtures, never deployment keys.