THE WHITE DRAGON BOOK · CHAPTER 09

Chapter 9: Ephemeral Capabilities & Auto-Revoke Security

CH. 9 · EPHEMERAL AUTO-REVOKE SECURITY TTL TOKEN SCOPED EPOCH AUTO-REVOKED
Vector Architecture Diagram · asset-ch09

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:


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:


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().

← Back to White Dragon Book index