Skip to content

fix: five small correctness fixes from a repository review - #331

Merged
jfcmartins merged 5 commits into
mainfrom
claude/focused-thompson-aprto1
Nov 15, 2026
Merged

jfcmartins merged 5 commits into
mainfrom
claude/focused-thompson-aprto1

Conversation

@jfcmartins

Copy link
Copy Markdown
Collaborator

What and why

Five independent fixes found in a scheduled review of the repository. Each is its own commit. None of them overlap with the open PRs (#329 console UX, #327 motion, #300 OIDC groups claim, #276 release).

  1. demos: leak checks could miss a leak (demo-phase4.sh, demo-phase6.sh, demo-public-cert.sh)
    • Under set -o pipefail, logs | grep -q X returns 141 when grep matches early and the writer gets SIGPIPE. The if then reads that as "not found".
    • So the phase 4 "no token in the logs" and phase 6 "no password in the worker log" checks could pass with the secret present.
    • The public-cert demo had the opposite problem: it could fail with "no warning" when the warning was there.
    • The fix greps a captured copy of the logs. Proof: set -o pipefail; if seq 1 2000000 | grep -qF 5; … takes the not-found branch.
  2. ca: refuse component labels that would make a certificate that can't verify (limen-ca/src/authority.rs)
    • Labels allows an empty value, but IdentityUri::parse rejects an empty segment.
    • A join token labelled {"zone": ""} therefore enrolled a component whose certificate failed every verification with "malformed identity URI".
    • issue_component now validates labels the way issue_user already validates CI facts. It refuses before the join token is used up.
  3. audit: back off when the spool commit fails after a send (limen-audit/src/ship.rs)
    • After a successful send whose commit then failed (full disk, offsets directory not writable), the shipper reset its backoff and looped straight back. The offset hadn't moved, so it re-sent the same batch with no pause, forever.
    • The new test counts sends: without the fix it saw about 40,000 in 300 ms. With a single-threaded runtime the loop never yields and the test hangs.
    • It now waits with the shipper's jittered backoff, and resets the backoff only once a commit lands.
  4. idp-check: only spread the batch claim upward (limen-control-plane/src/idp_check.rs)
    • The claim on a batch of logins is sized to outlast 50 sequential IdP calls, so another replica can't re-claim it and redeem the same rotating refresh token mid-batch. A second redemption reads as a refusal and locks the person.
    • The claim went through the ±10% check jitter, which could shorten it to 90% of that bound. It is now spread by 0 to +10%.
  5. verify: don't overflow on seq = u64::MAX (limen-verify/src/bucket.rs)
    • seq comes from event lines in the bucket. seq + 1 panics in debug builds and wraps in release. It now saturates, and the line still shows up as a gap.

Related: no phase change; bug fixes only.

How it was verified

  • cargo fmt --all --check: clean.
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean.
  • Run with protoc 3.21 from apt, not the 36.2 that mise.toml pins, because mise isn't available here:
    • cargo test -p limen-ca: 30 passed, including the new component_labels_must_round_trip_through_the_certificate.
    • cargo test -p limen-audit: 43 lib tests passed. The new a_failed_commit_backs_off_instead_of_resending_at_once was also run with the fix reverted, and it failed (sent 39827 times).
    • cargo test -p limen-control-plane --lib idp_check: 5 passed, including the new a_claim_always_outlasts_a_whole_batch_of_slow_calls.
    • cargo test -p limen-verify: all passed, including the new the_largest_seq_is_a_gap_not_an_overflow.
  • Demos: bash -n on all three scripts, plus a shell test showing that the old pattern misses an early match and the new one catches it.

Not verified

  • The changed demos were not run end to end; they need the compose stack.
  • shellcheck and gitleaks were not run (neither is installed here).
  • The full control-plane suite was not run, nor the integration tests that need postgres kms s3.
  • The IdP-check race was found by reading the code. It was not reproduced against a slow IdP.

Checklist

  • Tests added or updated; cargo fmt and cargo clippy ... -D warnings clean
  • Docs updated: n/a
  • Phase work: n/a (the demo fixes only make existing checks reliable)
  • Secrets stay out of logs; mTLS and fail-closed audit intact (the shipper still never skips records)
  • New dependency: n/a
  • New entry point or data store: n/a
  • Commits are conventional, small and focused

Compatibility and rollback

  • A join token with an empty label value now refuses enrollment with an invalid-request error. Before, it gave a certificate that could never verify, so nothing that worked before stops working.
  • No migrations or config changes.
  • Each commit reverts on its own.

Remaining concerns

These came out of the same review and are not fixed here.

  • Duplicate events: access::expire emits audit events inside a 100-row transaction. An audit failure partway through rolls back the rows whose events were already written, and the next tick writes them again.
  • SCIM deactivation: if the lock is written but the audit write fails, SCIM reports that the change was not made. Okta's retry then sees the lock as already in place, so the lock stays with no UserLock event.
  • Envelope test: the cross-purpose test in limen-session/src/envelope.rs lists 5 of the 6 Purpose variants; ControlsReport is missing.
  • Stale fuzz build: fuzz/Cargo.lock is stale, and the fuzz targets are only built weekly.
  • No shellcheck in CI: nothing runs shellcheck on the repository's *.sh, although mise.toml pins it.
  • Unvalidated alerts and manifests: deploy/prometheus/alerts.yml and deploy/kubernetes/** are not validated in CI.
  • Missing securityContext: the plain Kubernetes manifests have none (the Helm chart sets fsGroup: 65532), so the spool volume may not be writable on EBS.
  • Example CI script: examples/ci/policy-check.yml calls head/scripts/policy-pr-comment.sh, which won't exist in a user's policy repository.

Generated by Claude Code

Under `set -o pipefail`, `logs | grep -q X` returns 141 when grep matches
early and the writer gets SIGPIPE, so the `if` reads a found secret as
"not found". The phase 4 token check and phase 6 password check could
therefore pass with a secret in the logs; the public-cert demo had the
mirror problem (a spurious "no warning" failure). Grep a captured copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEiXYZ8UQNGWJJHgaqCU64
`Labels` allows an empty value, but `IdentityUri::parse` rejects an empty
segment, so a join token labelled `{"zone": ""}` enrolled a component
whose certificate then failed every verification as "malformed identity
URI". Validate label keys and values in `issue_component` as
`issue_user` already does for CI facts; the refusal happens before the
join token is consumed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEiXYZ8UQNGWJJHgaqCU64
A send that succeeded but could not be committed reset the backoff and
looped straight back: the offset hadn't moved, so the same batch was
re-sent immediately, forever, while the commit kept failing (a full
disk, an unwritable offsets directory). The new test saw ~40k sends in
300 ms. Retry with the shipper's jittered backoff instead, and reset it
only once a commit lands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEiXYZ8UQNGWJJHgaqCU64
The claim on a batch of logins is sized to outlast 50 sequential IdP
calls, so another replica can't re-claim and redeem the same rotating
refresh token mid-batch (the second redemption reads as a refusal and
locks the person). It was passed through the ±10% check jitter, which
could shorten it to 90% of that bound. Spread it by 0..+10% instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEiXYZ8UQNGWJJHgaqCU64
`seq` is read from event lines in S3, which a tamperer can write. Gap
detection did `seq + 1`, which panics in debug builds and wraps in
release. Saturate instead; the line still shows up as a gap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEiXYZ8UQNGWJJHgaqCU64
@jfcmartins
jfcmartins marked this pull request as ready for review November 15, 2026 22:32
@jfcmartins
jfcmartins merged commit 43d0f41 into main Nov 15, 2026
22 checks passed
@jfcmartins
jfcmartins deleted the claude/focused-thompson-aprto1 branch November 15, 2026 22:59
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