Skip to content

test: caller resolution, role gates, and TLS identity Debug redaction - #340

Merged
jfcmartins merged 2 commits into
mainfrom
claude/lucid-volta-rbevmn
Nov 16, 2026
Merged

jfcmartins merged 2 commits into
mainfrom
claude/lucid-volta-rbevmn

Conversation

@jfcmartins

Copy link
Copy Markdown
Collaborator

What and why

This PR adds tests only. It changes no production code (git diff shows 0 removed lines, and both hunks are new #[cfg(test)] modules).

It comes from a scheduled test-gap sweep of the crates that make access decisions. I skipped modules touched by open PRs: #300 touches oidc.rs, config.rs, lib.rs, console/integrations.rs and testkit idp.rs, and #276 only bumps versions.

Gaps found, ranked by impact:

  1. limen-control-plane/src/caller.rs (resolve, resolve_caller) had no unit tests. This function decides who a request is from. It is where a forwarded certificate (x-limen-client-cert) becomes a Caller::User or a relayed worker. The integration tests only cover the happy path through common::forwarded, and only when Postgres is available. None of the denial branches were tested:

    • forwarding with no certificate
    • forwarding by a worker or the control plane
    • a proxy forwarding a proxy or control-plane certificate
    • the 8 KiB limit
    • malformed base64
    • a forwarded certificate from a foreign CA

    A regression in any of these lets one component impersonate a user or an admin. Tested here.

  2. The role gates and refusal() in the same file. direct_proxy refuses relayed callers, admin and reader distinguish auditors, and refusal() lets a lock win over an ended login. Before this PR, only the self-test exercised refusal(), and nothing exercised the gates in isolation. Tested here.

  3. limen-tunnel/src/tls.rs Identity derives Debug while holding a PrivateKeyDer. Redaction today depends on rustls-pki-types' own Debug impl. Nothing pinned it, so changing the derive or the dependency could print key bytes. Tested here.

  4. Not addressed: server_config_with_resolver has no test that ClientAuth::Required refuses an anonymous client. The equivalent server_config path is covered in tests/reverse_tunnel.rs.

Related: test coverage, no phase work.

How it was verified

  • cargo fmt --all: clean.
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean.
  • cargo test -p limen-tunnel --locked: all pass, including the new tls::tests::debug_of_an_identity_never_shows_the_private_key.
  • cargo test -p limen-control-plane --locked, run with CARGO_INCREMENTAL=0 CARGO_PROFILE_{DEV,TEST}_DEBUG=0 to fit the sandbox's disk: 0 failures. The lib unit tests (212 passed) include the 6 new caller::tests.

Each test can fail. I broke the code under test one change at a time and restored it after each run:

  • caller.rs, 10 mutations, all caught:
    • any component may forward
    • an anonymous caller with the forwarded marker is allowed
    • any forwarded component kind is accepted
    • the size limit is off by one (>=)
    • direct_proxy ignores via_proxy. This one first survived because resolve can never yield a relayed proxy, so I added a hand-built Caller to pin it.
    • reader accepts any user
    • admin accepts an auditor
    • logout wins over a lock
    • the proxy's address is reported instead of the client's
    • a foreign-CA forwarded certificate resolves as anonymous
  • tls.rs: I replaced the derive with a Debug that prints key.secret_der(), and the test failed. The test also asserts that its own leak scanner finds a printed scalar.

Not verified

  • Integration tests did not run. There is no compose stack (postgres kms s3) and no LIMEN_TEST_* variables here. The 207 control-plane integration tests that "passed" return early without LIMEN_TEST_DATABASE_URL, so they did not actually run. The new tests are unit tests and don't need these services.
  • Different protoc version. The sandbox had no mise, so the build used Ubuntu's protobuf-compiler 3.21.12, while mise.toml pins protoc 36.2. CI will build with the pinned version.
  • gitleaks not run. It isn't installed here. The diff contains only test code, and keys are generated at runtime.
  • Demos: n/a (no behavior change).

Review guide

  • caller.rs tests: the request() helper builds a PeerInfo plus relay metadata. refused() checks both the status code and the message.
  • tls.rs: the scan is limited to the 32-byte private scalar, because the key's OIDs and public point also appear in the public certificate.

Checklist

  • Tests added or updated; cargo fmt and cargo clippy ... -D warnings clean
  • Docs updated: n/a
  • Phase work: n/a
  • Secrets stay out of logs (limen_core::secret::Secret); mTLS and fail-closed audit intact (tests only, no invariant touched)
  • New dependency: n/a
  • New entry point or data store: n/a
  • Commits are conventional, small and focused

Compatibility and rollback

None (tests only).


Generated by Claude Code

Unit tests for caller.rs, which had none: who may forward a request
(only a direct proxy), which forwarded certificates count (users and
workers, never proxies or the control plane), the 8 KiB limit, malformed
and foreign-CA forwarded certificates, the client address, the
direct_proxy/admin/reader/user/component gates, and lock-over-logout in
refusal(). No database needed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEiXYYo94ggHjRu7KywN9C
Identity derives Debug and holds a private key. Pin that its Debug
output carries no part of the key's private scalar, so a change to the
derive or to rustls-pki-types can't put key bytes in a log line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEiXYYo94ggHjRu7KywN9C
@jfcmartins
jfcmartins marked this pull request as ready for review November 16, 2026 10:09
@jfcmartins
jfcmartins merged commit 1c22b0a into main Nov 16, 2026
23 checks passed
@jfcmartins
jfcmartins deleted the claude/lucid-volta-rbevmn branch November 16, 2026 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants