Chapter 9: Ephemeral Capabilities & Auto-Revoke Security
Chapter 9: Ephemeral Capabilities & Auto-Revoke Security
"A secret that outlives the function call that needed it is not a credential — it is a loaded weapon left in RAM."
1. Historical Contrast: Ambient Authority vs. Ephemeral Capabilities
Classic Unix security (and the POSIX model documented throughout Linux Kernel Development) relies on ambient authority: a process inherits a uid, gid, and a flat environ[] block filled with long-lived static secrets (API_KEY, AWS_SECRET_ACCESS_KEY, GITHUB_TOKEN, .env files on disk). Every third-party dependency, logging library, and child subprocess inside that address space automatically inherits those credentials for the entire lifetime of the host or container.
When a static key leaks — via a crash dump, a verbose exception trace, a supply-chain package, or an abandoned CI runner — the blast radius spans months until a human manually rotates it.
The White Dragon Book replaces ambient static secrets with Ephemeral Capability Intersections governed by two mathematical laws:
- Monotonic Narrowing Trust Cone: A parent scope may only mint child leases with a strictly narrower permission set (
scope_child ⊆ scope_parent) and a strictly shorter or equal TTL (ttl_child ≤ ttl_parent). Privilege escalation is syntactically unrepresentable. - RAM-Only Lease + Zero-Wipe on
dispose(): Secrets never touch disk, never live inprocess.env, are never returned as cacheable strings outside a scoped callback, and are cryptographically zeroed in RAM (Buffer.fill(0)) while callingprovider.revoke(lease)the instantdispose()runs.
2. Live Implementation: sections/ephemeral-token/index.mts
The reference implementation in sections/ephemeral-token/index.mts binds a provider's mint / refresh / revoke lifecycle directly to an EphemeralCapabilityIntersection:
// sections/ephemeral-token/index.mts
export interface TokenLease {
readonly tokenId: string;
readonly scope: string;
readonly issuedAtMs: number;
readonly expiresAtMs: number;
}
export class EphemeralCapabilityIntersection {
private secretBuf: Buffer | null = null;
private lease: TokenLease | null = null;
private refreshTimer: ReturnType<typeof setInterval> | null = null;
private revoked = false;
async acquire(): Promise<TokenLease> {
if (this.revoked) throw new CapabilityRevokedError(this.scope);
const { secret, lease } = await this.provider.mint(this.scope, this.ttlMs);
this.storeSecret(secret);
this.lease = lease;
// Auto-refresh at 60% of TTL while intersection lease remains active
const intervalMs = Math.max(25, Math.floor(this.ttlMs * 0.6));
this.refreshTimer = setInterval(() => { void this.tryRefresh(); }, intervalMs);
this.refreshTimer.unref?.();
return lease;
}
async withSecret<T>(fn: (secret: string, lease: TokenLease) => Promise<T> | T): Promise<T> {
if (this.revoked || !this.secretBuf || !this.lease || Date.now() > this.lease.expiresAtMs) {
throw new CapabilityRevokedError(this.scope); // Fail closed
}
return await fn(this.secretBuf.toString("utf8"), this.lease);
}
async dispose(): Promise<void> {
if (this.revoked) return;
this.revoked = true;
if (this.refreshTimer) { clearInterval(this.refreshTimer); this.refreshTimer = null; }
if (this.secretBuf) { this.secretBuf.fill(0); this.secretBuf = null; }
const oldLease = this.lease;
this.lease = null;
if (oldLease) await this.provider.revoke(oldLease);
}
}
Four design invariants make this pattern airtight:
- Callback-Scoped Exposure (
withSecret): Callers borrow the secret only for the duration of one async operation; any use afterdispose()or TTL expiry throwsERR_CAPABILITY_REVOKED(fail-closed). - Heartbeat Rotation at 60% TTL: Long-running tasks keep short-lived leases (seconds/minutes) alive via background rotation without ever holding a 90-day static token. Each rotation zeroes the previous
Bufferbefore overwriting. - Built-in Telemetry Redaction (
redact()): Every log or trace line passing through the intersection automatically scrubs the active secret into***EPHEMERAL_REDACTED***. - Origin Arena Synergy: When paired with
B8G_ARENA_V1(Chapter 6), disposing an origin both revokes the remote lease and unmaps the local memory page in233 µs.
3. Comparison: Static Credentials vs. White Dragon Ephemeral Capabilities
| Security Property | .env / process.env Secrets |
Vault Static-Mount Sidecar | White Dragon EphemeralCapabilityIntersection |
|---|---|---|---|
| Storage Medium | Disk + inherited environ[] |
Tmpfs file on disk | RAM-only Buffer (zero disk writes) |
| Default Lifetime | Months / infinite | Hours / pod lifetime | Short TTL + 60% heartbeat rotation |
| Delegation Model | Ambient (all children inherit) | Broad role / pod identity | Monotonic narrowing trust cone |
| Teardown Behavior | Remains valid until manual rotate | Waits for lease TTL expiry | Immediate fill(0) + provider.revoke() |
| Post-Use Access | Succeeds silently | Succeeds until TTL | Throws ERR_CAPABILITY_REVOKED (fail-closed) |
| Log / Trace Leakage | Raw plaintext in stack traces | Requires external scrubbers | Built-in redact() -> ***EPHEMERAL_REDACTED*** |
4. Key Takeaway
Treat every credential as a short-lived memory allocation bound to an intersection. Narrow it monotonically on delegation, rotate it on a heartbeat, scrub it from telemetry, and zero-wipe + revoke it automatically on dispose().