Skip to content

feat(random): bounded secure entropy capability for application tokens #180

Closed

Description

@zackees

Context

Coordinated with FastLED/cli#229 and #155. Two source investigations confirmed FastLED has one production getrandom call in crates/fastled-cli/src/commands.rs: fill 32 bytes, encode lowercase hex, and fail startup if entropy generation fails. The token authorizes the local test-server endpoints. Token length, encoding and HTTP authorization policy belong to FastLED.

kernal-api already pins optional getrandom =0.4.3 behind crash, but exposes no secure-randomness capability. Its private crash/spool.rs random_suffix falls back to timestamp XOR process ID; that collision-avoidance helper is not suitable for authorization tokens and must not be reused for this API. The backend fill contract reports partial-read failures, so failure behavior must not expose partially generated output as success.

Proposal

Add a facade-owned secure entropy operation with an explicit per-call byte limit and owned error contract. Reuse the existing private OS-random backend without exposing its types or enabling crash/profiling facilities. Keep token serialization and security policy in the application. Document actual OS blocking/readiness behavior; do not claim cancellation or deadlines merely because a blocking call is wrapped in a future.

Acceptance criteria

  • Focused RED test before implementation, then GREEN and broad checks in both repositories.
  • Facade-owned types, bounded output/allocation, empty and oversized requests defined; no backend error types leak.
  • Entropy failure returns an error, never timestamp/PID/pseudorandom fallback or partially initialized successful output. Errors and logs contain no generated bytes.
  • Deterministic injected backend tests cover success, partial-write failure, limit rejection before backend invocation and error mapping; native supported-platform smoke tests verify the OS path without claiming statistical tests prove cryptographic quality.
  • Resolve and document blocking, readiness, cancellation and timeout semantics honestly before adopting the contract.
  • Feature isolation keeps crash, profiler and unrelated heavy dependencies disabled; no second random provider or runtime is introduced.
  • FastLED preserves its 32-byte lowercase-hex token and startup-failure policy, removes direct getrandom imports/manifest dependency, and retains authorization policy regressions.
  • Review, supported-platform validation, usable release and exact published adoption before closing.

Decisions

  • Scope is secure entropy, not token generation: product wire format stays in FastLED.
  • Reuse the already selected backend rather than the insecure-for-tokens crash suffix fallback.
  • Prefer an opt-in capability so ordinary consumers do not enable unrelated crash facilities.
  • No build-time improvement claim without comparable measurements.

Related issues

#155 tracks complete FastLED dependency migration. Existing WASM guest randomness proposals are a separate ABI boundary, not duplicates of this native application capability.

Activity

  1. zackees commented on Sep 16, 2026

    @zackees
    CollaboratorAuthor

    Complete on both sides; closing with the evidence, same as #190 and #182.

    kernal-api — landed in 4e59628 (feat(random): add bounded secure operating-system entropy), in src/random.rs with docs/secure-random.md and tests/secure_random.rs. Against this issue's criteria:

    • MAX_RANDOM_BYTES = 64 * 1024, and SecureRandom::new(max_operations, timeout) bounds outstanding work to 1–64 operations with a positive caller timeout of at most one day.
    • The documented contract is that "Oversized requests fail before admission or allocation; saturation fails immediately without a waiter queue. Empty requests need no runtime or OS call." — the limit rejection before backend invocation this issue asked for.
    • No fallback: the commit that landed it states "no partial output or fallback", and success_and_partial_failure_never_confuse_output is the injected-backend test covering exactly the partial-write case, alongside timed_out_native_work_keeps_capacity_until_completion and dropped_request_keeps_capacity_until_completion.
    • Feature isolation holds: the module documentation states it uses the existing private OS entropy backend "independently of crash, profiling, GUI and WASM facilities", and it does not reuse crash/spool.rs's timestamp-XOR-PID helper, which this issue explicitly ruled out for authorization tokens.

    FastLED — adoption landed with FastLED/cli#242 (merged). crates/fastled-cli/src/commands.rs reads:

    let entropy = kernal_api::random::SecureRandom::new(1, std::time::Duration::from_secs(5))?;

    and the migration went further than this issue required — direct getrandom is not merely removed but banned, enforced by tests/unit/test_kernal_boundary.py:

    assert "getrandom" not in dependencies
    assert "getrandom::" not in source.read_text(), source

    The remaining getrandom in Cargo.lock is the transitive one behind kernal-api's own private backend, which is the intended shape. The 32-byte lowercase-hex token and startup-failure policy stayed in FastLED, as this issue required.

    🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions