Interfaces
Summary: the traits where the parts of secrets meet: the server’s ports, the hooks into auth-chad, the client’s transport, and the CLI’s adapters.
Key terms: port, Ports, Store, ProjectStore, Random, AuditBuffer, Rules, Hooks, Http, KeyDirectory, Gh, Opener.
Related: Map · Data · AGENTS.md
Every side effect in secrets is a trait that the caller injects, used through generic parameters. On the server, the
use cases in App<P: Ports> name four ports: a store, a clock, a random source and an audit buffer. The stores and the
test fakes implement them. auth-chad’s account API calls back into this application through its Hooks trait, which
Rules implements. Clients reach the server through auth-chad’s Http trait, so the same client code runs in the CLI
and in the browser.
The picture as text
flowchart LR
subgraph http [secrets-server-http]
R[routes]
H[Rules: auth-chad Hooks]
end
subgraph app [secrets-server-app]
A["App, generic over Ports"]
end
S[(Store: SQLite, PostgreSQL, MemStore)]
C[Clock + Random]
B[AuditBuffer]
R --> A
H --> A
A --> S
A --> C
A --> B
Server ports
| Trait | Methods | Implemented by |
|---|---|---|
Ports | Names the four types: Store, Clock, Random, Audit | secrets-server’s wiring; MemPorts in tests |
Store | Health + KeyStore + ProjectStore + ProfileStore + AuditStore + auth-chad’s Reader | Blanket: any type with all six |
Health | ping | Both stores, MemStore |
KeyStore | keys by fingerprint, put_keys | Both stores, MemStore |
ProjectStore | Log entries, wraps, records, commit(Batch), projects_for, rotation_required | Both stores, MemStore |
ProfileStore | profile, device_envelope, prune_expired | Both stores, MemStore |
AuditStore | append_audit, audit (one page), prune_audit | Both stores, MemStore |
Random | fill(buf) | The OS random source; SeqRandom in tests |
AuditBuffer | push, take, restore: read events wait in memory and are stored once per second | MemoryAuditBuffer |
A new storage backend implements these traits and runs secrets_store_tests::conformance! in its tests.
use secrets_core::id::{Id, Project};
use secrets_server_app::{ProjectStore, StoreError};
async fn log_length<S: ProjectStore>(store: &S, project: &Id<Project>) -> Result<usize, StoreError> {
Ok(store.log_entries(project).await?.len())
}
A test assembles the ports from fakes:
use std::sync::atomic::{AtomicU8, Ordering};
use secrets_core::ports::FixedClock;
use secrets_server_app::{MemoryAuditBuffer, Ports, Random};
use secrets_store_tests::MemStore;
struct Counting(AtomicU8);
impl Random for Counting {
fn fill(&self, buf: &mut [u8]) {
buf.fill(self.0.fetch_add(1, Ordering::Relaxed)); // tests only
}
}
struct TestPorts;
impl Ports for TestPorts {
type Store = MemStore;
type Clock = FixedClock;
type Random = Counting;
type Audit = MemoryAuditBuffer;
}
secrets_store_tests::fixtures::mem_app() builds a whole App this way.
Hooks into auth-chad
Rules<P> in crates/server-http/src/auth.rs implements auth-chad’s Hooks. auth-chad decides the account step;
Rules adds this application’s checks and rows to the same transaction.
| Hook | What secrets does there |
|---|---|
commit_signup | Reads the identity public keys from the signup’s app field and stores the profile with auth-chad’s writes |
valid_names | Handle ^[a-z0-9_-]{3,32}$ and a display name |
invite_data, may_invite | Only users with the admin flag invite; an invite from the API never makes an admin |
may_request_device, device_kind | Checks the scope grammar and the device keys; the scope decides user or machine |
may_approve | A machine request for a project is visible only to its owners |
commit_approve | A user device: the sealed identity key. A machine: the signed device_grant entries and wraps. One transaction |
commit_revoke, commit_undo | Deletes envelopes and marks the user’s environments rotation_required |
The full contract of each hook is on auth-chad’s interfaces page.
Other server traits
| Trait | Purpose |
|---|---|
Fail | Turns an application failure into the {"error": code} answer of a route |
LogSink | Receives the optional request log, one line per request; NoLog discards it |
Shared traits in secrets-core
| Trait | Purpose |
|---|---|
Clock | The current time, injected so tests are exact; FixedClock for tests |
KeyDirectory | Public keys by fingerprint, so log validation can verify entries of past members; implemented for [PublicKeys] |
IdKind | The type prefix of an ID (usr_, prj_, env_, dev_, sec_, inv_) |
Client traits
secrets-client re-exports auth-chad’s client traits, so one transport serves the account API and this application’s
routes.
| Trait | You give | In the browser |
|---|---|---|
Http | send(request) -> response | auth-chad’s browser::Fetch |
Clock, Draws | Time and random bytes | The system |
The CLI’s adapters.rs implements them with ureq and the OS. Tests run the real router in memory through the same
traits.
CLI adapters
| Trait | Purpose | Real implementation |
|---|---|---|
Gh | Runs the GitHub CLI with input on stdin, for machine create --github | SystemGh |
Opener | Opens an address in the person’s browser | SystemBrowser |
Where the details are
- The ports and the
Batchtype:crates/server-app/src/ports.rs. - The hooks:
crates/server-http/src/auth.rs. - The client API:
crates/client/src/lib.rs, and auth-chad’s client recipe.