Skip to main content

Crate pb_mapper_auth

Crate pb_mapper_auth 

Source
Expand description

Authentication state for protocol-v2 connections and administrator operations.

§How a temporary credential works

Nothing secret is stored per key. A temporary credential is derived from the root key, the server instance id, and the key id, so the server can verify a credential it holds no copy of, and a key id is all the state a key needs:

issue:  root key + instance id + key id  --HKDF-->  credential handed to the client
verify: root key + instance id + key id  --HKDF-->  compare against what was presented

Because the material is derived, invalidating every key at once is a matter of changing an input: a root rotation replaces the root key, a state reset replaces the instance id. Neither has to touch individual keys.

§Where the state lives

                   key_id = generation:slot
                            |
  request ──> derive & compare ──> slots[slot]  ── lifecycle: Free/Active/
                                       │            Expired/Revoked, expires_at
                                       │
                                  Weak lease ──> Arc lease, owned by the actor's
                                       ^          timing wheel — the single place
                                       │          a lease's lifetime ends
  AuthContext (also Weak) ─────────────┘

The slot table is a preallocated array indexed straight off the key id, so verification costs an array index and churn does not grow memory. The SlotState docs (state.rs) cover the table’s layout, why generations exist, and why dead rows linger. Leases (leases.rs) owns the three structures a key’s lifetime spans; timing_wheel.rs schedules the expiries.

§Namespaces

A namespace decides which services a credential can see. By default a key owns one named by its own id, so revoking it takes the namespace with it. The administrator can instead allocate a namespace that no key owns and issue several keys into it, which lets one tenant hold a separately revocable key per device without moving the others:

allocate_namespace() --> 7
issue_in_namespace(7) --> key A ─┐  same services; revoking A leaves B working,
issue_in_namespace(7) --> key B ─┘  and namespace 7 is never handed out again

A key’s namespace is fixed at issue and read off its lease, so authentication does no extra work for it. ids.rs shows why the two kinds cannot collide, and persistence/namespaces.rs why the allocator lives outside the encrypted state.

§Where mutations happen

AuthRuntime (facade) ──channel──> one actor ──> encrypted snapshot + WAL

Every mutation is serialized through a single actor, so a request authorized before a root rotation cannot execute against the state that replaced it.

This root module holds the constants and the module map. The facade is in runtime.rs, the shared state in state.rs, the actor in actor/, the files in persistence/, and the expiry schedule in leases.rs.

Modules§

codes
The AuthFailure::code values this crate returns.

Structs§

AuthConfig
AuthConfigOverrides
Values that take the place of the environment variables AuthConfig::from_env_with reads: each Some replaces one, which is then not read at all, and each None leaves it in charge.
AuthContext
AuthFailure
AuthLease
AuthRuntime
A handle on a running authentication state. Clones share one handle, so cloning is cheap, and the actor stops once the last clone is dropped.
AuthStatus
Generation
Which tenant of a slot a credential belongs to. Bumped every time the row is reissued, and never reset, so a retired credential can never match the row that replaced it.
IssuedTemporaryKey
KeyId
The identity a client presents: a SlotIndex paired with the Generation of the row it was issued from.
KeyPage
LegacyConnectionGuard
SlotIndex
Which row of the slot table a credential lives in.
TemporaryKeyMetadata

Enums§

LegacyProtocolPolicy

Constants§

ADMIN_KEY_FILE
The live administrator key’s file name in a state directory.
ADMIN_KEY_ID
The administrator, which owns no slot and never expires.
ADMIN_NAMESPACE
The namespace administrator connections operate in. A key that was not issued into a namespace owns the one its id names, so this mirrors ADMIN_KEY_ID.
ADMIN_SCHEMA_VERSION
The schema_version every administrator answer carries: the KeyPage and AuthStatus this crate builds, and the relay’s service and connection pages.
CAPABILITY_KEY_NAMESPACES
Reported in AuthStatus::capabilities by a relay that can allocate namespaces, issue keys into them, and persist each key’s namespace.
DEFAULT_AUTH_STATE_DIR
DEFAULT_MAX_TEMP_KEY_TTL
DEFAULT_TEMP_KEY_CAPACITY
MAX_ALLOCATED_NAMESPACE
The last namespace the allocator can hand out: the top of generation 0, which no key id uses. See the module docs.
MAX_TEMP_KEY_CAPACITY
MAX_TEMP_KEY_TTL
MIN_TEMP_KEY_TTL

Functions§

acquire_state_dir_lock
admin_key_path
Where the live administrator key of state_dir is kept.
default_auth_state_dir
derive_temporary_key
discard_staged_admin_key
Drop a staged candidate once the rotation it belongs to is durably recorded at the live key file.
encrypted_auth_state_exists
generate_admin_key
initialize_admin_key
stage_admin_key_candidate
Write a root-rotation candidate to the staged sibling of path, returning the staged path.
staged_admin_key_path
The sibling path a root-rotation candidate is staged at, next to the live administrator key file path.
write_admin_key_file