Repository navigation
test: caller resolution, role gates, and TLS identity Debug redaction - #340
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
This PR adds tests only. It changes no production code (
git diffshows 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.rsand testkitidp.rs, and #276 only bumps versions.Gaps found, ranked by impact:
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 aCaller::Useror a relayed worker. The integration tests only cover the happy path throughcommon::forwarded, and only when Postgres is available. None of the denial branches were tested:A regression in any of these lets one component impersonate a user or an admin. Tested here.
The role gates and
refusal()in the same file.direct_proxyrefuses relayed callers,adminandreaderdistinguish auditors, andrefusal()lets a lock win over an ended login. Before this PR, only the self-test exercisedrefusal(), and nothing exercised the gates in isolation. Tested here.limen-tunnel/src/tls.rsIdentityderivesDebugwhile holding aPrivateKeyDer. Redaction today depends on rustls-pki-types' ownDebugimpl. Nothing pinned it, so changing the derive or the dependency could print key bytes. Tested here.Not addressed:
server_config_with_resolverhas no test thatClientAuth::Requiredrefuses an anonymous client. The equivalentserver_configpath is covered intests/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 newtls::tests::debug_of_an_identity_never_shows_the_private_key.cargo test -p limen-control-plane --locked, run withCARGO_INCREMENTAL=0 CARGO_PROFILE_{DEV,TEST}_DEBUG=0to fit the sandbox's disk: 0 failures. The lib unit tests (212 passed) include the 6 newcaller::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:>=)direct_proxyignoresvia_proxy. This one first survived becauseresolvecan never yield a relayed proxy, so I added a hand-builtCallerto pin it.readeraccepts any useradminaccepts an auditortls.rs: I replaced the derive with aDebugthat printskey.secret_der(), and the test failed. The test also asserts that its own leak scanner finds a printed scalar.Not verified
postgres kms s3) and noLIMEN_TEST_*variables here. The 207 control-plane integration tests that "passed" return early withoutLIMEN_TEST_DATABASE_URL, so they did not actually run. The new tests are unit tests and don't need these services.mise, so the build used Ubuntu'sprotobuf-compiler3.21.12, whilemise.tomlpins protoc 36.2. CI will build with the pinned version.gitleaksnot run. It isn't installed here. The diff contains only test code, and keys are generated at runtime.Review guide
caller.rstests: therequest()helper builds aPeerInfoplus 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
cargo fmtandcargo clippy ... -D warningscleanlimen_core::secret::Secret); mTLS and fail-closed audit intact (tests only, no invariant touched)Compatibility and rollback
None (tests only).
Generated by Claude Code