Skip to content

fix: repo audit: web deny prefix, broker/primary follow, kube recording evasion, revoked proxy, bot facts - #292

Merged
jfcmartins merged 6 commits into
mainfrom
claude/focused-thompson-ejh3u0
Nov 9, 2026
Merged

jfcmartins merged 6 commits into
mainfrom
claude/focused-thompson-ejh3u0

Conversation

@jfcmartins

Copy link
Copy Markdown
Collaborator

What and why

This PR fixes five issues found in a scheduled review of the repository. I checked the open PRs first (#290, #289, #288, #276); none of them already fixes any of these. Each fix is its own commit.

  1. A web deny rule with a trailing slash failed open (limen-policy/src/lib.rs, web_path_matches)
    • path_prefixes: ["/admin/"] matched only /admin/ itself. /admin/users and /admin/secret/x were allowed. valid_web_path accepts the trailing slash, so the rule looked correct.
    • Allow rules had the mirror problem: "/api/" refused /api/x.
    • Prefixes now match whole segments with the trailing slash ignored. This is noted in docs/policy.md.
    • Allow side: "/api/" now also admits /api itself. That is a small widening, but it is the same directory.
  2. The worker followed a server to any host under a top-level domain (limen-policy/src/delegation.rs, may_follow)
    • For a two-label bootstrap host (example.com, kafka.corp), "same domain" meant .com or .corp.
    • A Kafka metadata response or a MongoDB primary naming evil.com or attacker.corp was followed, and the credential went with it.
    • The parent must now still be a domain. Names under the bootstrap host itself (b-2.example.com) stay allowed. Anything else needs hosts; the guides now say so.
  3. Three ways to run a kube exec while its recording misses the output (limen-kube, limen-worker/src/kube/serve.rs)
    • Header cap: parse_headers silently stopped after 256 SPDY headers, so a streamtype: stdout placed after 256 junk headers was never seen. Such a block is now refused.
    • Stream cap: past 1024 streams, an exec ignored new ones, assuming the real streams come first. The client picks the order. An exec past the cap now ends; port-forward is unchanged.
    • base64 protocol: the WebSocket protocol filter dropped only base64.channel.k8s.io. v4.base64.channel.k8s.io still went through, and kubelet then answers in text frames the recorder doesn't read. Every base64 variant is now dropped.
    • A decoder error ends the stream before the bytes are forwarded (pump.rs), so all three now fail closed.
  4. A revoked proxy could still use the console and redeem web-app handoffs (console/mod.rs proxy_only, console/web_auth.rs redeem)
  5. Bot logins could be refused for having too many CI facts (services/bot_login.rs, ci_facts)
    • A GitHub job carries 13 provider claims. provider, iss and sub bring that to 16, which is exactly the CA's MAX_CI_FACTS.
    • So a rule pinning repository_id (as docs/guides/bots.md recommends), combined with an environment or with repository_owner_id, produced 17 facts. The CA refused, and every login of that bot failed.
    • The rule's claims now come first, and the provider's fill whatever room is left.
    • fix(deploy): example bot ids and rabbitmq fail-fast in setup.sh #289 pins repository_id in the example bots, which makes this more likely to show up.

Related: none (no phase work).

How it was verified

  • cargo fmt --all --check and cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean.
  • Unit tests, all passing:
    • cargo test -p limen-policy: 102
    • -p limen-kube: 27
    • -p limen-worker --lib: 357
    • -p limen-control-plane --lib: 138
    • -p limen-proxy: 36
  • Integration tests, all passing, against a throwaway local PostgreSQL 16 (LIMEN_TEST_DATABASE_URL):
    • control plane: handoff, bot_login, verify_gaps, control_plane, component_names
    • e2e: console, phase1, phase35, phase8, proxy_revocation
  • New tests:
    • web_path_prefixes_with_a_trailing_slash_cover_the_directory
    • new rows in a_worker_follows_only_hosts_near_the_one_it_was_given
    • refuses_more_headers_than_it_reads and spdy_exec_refuses_a_flood_of_streams. Both failed with the fix reverted.
    • base64_channel_protocols_are_not_forwarded, plus a row in only_binary_channel_protocols_are_readable
    • a_rule_naming_provider_ids_still_fits_a_certificate
    • e2e a_revoked_proxy_no_longer_serves_the_console. It failed with the console fix reverted.
  • protoc came from the system package (3.21), not mise's pinned 36.2, because mise isn't installed in this environment.

Not verified

  • Real Kubernetes: phase8 ran against the testkit's stand-in API, not a real cluster. That kubelet accepts v4.base64.channel.k8s.io and keeps waiting past junk SPDY streams comes from reading upstream, not from a run. unverified.
  • Live CI tokens: the bot facts fix is covered by unit tests only, not by a live GitHub or GitLab token.
  • RedeemWebHandoff after revocation: no test covers it. The console gate has one.
  • Not run: demos/demo-*.sh, the KMS/S3 integration suites, cargo deny / cargo audit (no dependency changes), and gitleaks (not installed here).

Review guide

Checklist

  • Tests added or updated; cargo fmt and cargo clippy ... -D warnings clean
  • Docs updated (docs/policy.md, docs/guides/mongodb.md, docs/guides/messaging.md)
  • Phase work: n/a
  • Secrets stay out of logs; mTLS and fail-closed audit intact (both revocation checks fail closed)
  • New dependency: n/a
  • New entry point or data store: n/a
  • Commits are conventional, small and focused

Compatibility and rollback

Policy meaning changes slightly in two places:

  • A path_prefixes entry ending in / now covers its directory.
  • Two-label bootstrap hosts need hosts to follow to sibling names.

Nothing changes in the wire format or schema. Revert the individual commit to roll one back.

Findings not fixed here (for the owner)

Confirmed by reading, not fixed:

  • Evidence packs stop verifying after about 12h (limen-verify/src/pack.rs:667). verify_pack checks the signer's component certificate against now, and that certificate lives 24h and renews at half-life. Fix: use verify_at(generated_at), as bucket.rs already does.
  • Two reviewers deciding a review's last two items at once can leave it open forever (reviews/mod.rs). Only the item row is locked, so each transaction still sees the other item as undecided. Lock the review row too.
  • An empty join-token label value produces a component certificate that never verifies (limen://label/env/ doesn't parse). Fix: validate in issue_component.
  • Peer proxy channels are cached forever (limen-proxy/src/peer.rs). They keep the first client certificate and ignore address changes, so peering breaks once that certificate expires.
  • DurationStr has no upper bound, and (now + ttl) in limen-proxy/src/sessions.rs panics past year 9999.
  • The static manifest deploy/kubernetes/limen/proxy.yaml lacks the chart's ADR-0045 startupProbe and maxUnavailable: 0.
  • The examples/ci/policy-check.yml example has three problems:
    • It calls scripts/policy-pr-comment.sh, which won't exist in a user's policy repository.
    • It isn't re-run when the approval label is added.
    • It uses unpinned actions/checkout@v4.
  • scripts/policy-pr-comment.sh edits the first comment carrying the marker, whoever wrote it.
  • infra.yml and workflows.yml don't run on mise.toml changes, even though mise.toml pins their tools.

Need verification:

  • The audit shipper batches by count only (500 records of up to 1 MiB each, against an 8 MiB ingest limit). An oversized batch may retry forever.
  • A crash between the key and certificate renames during component renewal can leave a mismatched pair.
  • Plain kube watch and log streams through the proxy don't end when the worker is revoked.
  • Some username comparisons are still case-sensitive, although migration 0026 says usernames compare case-insensitively.
  • Bare-name bootstraps may still follow to localhost.
  • Domains under a public suffix (example.co.uk) are still "nearby" each other.

Both #288 and #290 add an ADR numbered 0046. One of them needs renumbering.


Generated by Claude Code

…tory

A deny on path_prefixes ["/admin/"] matched only the path /admin/ itself:
stripping "/admin/" from /admin/users leaves "users", which doesn't start
with a slash, so the request was allowed. valid_web_path accepts the
trailing slash, so the rule looked correct and silently failed open. Allow
rules had the mirror problem ("/api/" refused /api/x).

Compare whole segments against the prefix with its trailing slash removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEiXYa75baYfYaGJtH6xci
may_follow treated the bootstrap's parent as its domain. For a two-label
bootstrap (example.com, kafka.corp) the parent is the top-level domain, so
a Kafka broker list or MongoDB primary naming evil.com or attacker.corp was
followed, with the credential. Require the parent to still be a domain;
names under the bootstrap host itself stay allowed. Resources that need
more list them in hosts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEiXYa75baYfYaGJtH6xci
…ecording

Two ways a client could keep an exec's stdout off the recording while the
API server still served it:

- parse_headers read at most 256 headers and dropped the rest, so a
  streamtype: stdout after 256 junk headers was never seen. Refuse a block
  with more headers than that instead.
- Past 1024 streams an exec ignored new ones, assuming the real ones came
  first; the client picks the order, so 1024 junk streams then stdout went
  unrecorded. An exec past the cap now ends (port-forward is unchanged).

A decoder error ends the stream before the bytes are forwarded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEiXYa75baYfYaGJtH6xci
The WebSocket protocol filter dropped only base64.channel.k8s.io, so
v4.base64.channel.k8s.io reached kubelet, which then sends output as text
frames the recorder doesn't read. Drop every base64 variant, and don't
count one as a readable channel protocol.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEiXYa75baYfYaGJtH6xci
…doffs

#263 made API calls check revocation (resolve_checked) but RedeemWebHandoff
and the console's proxy_only gate still checked only the certificate. A
revoked proxy could keep relaying the console and redeeming handoffs into
web-app sessions until its certificate expired. Check the revoked set in
both, failing closed when it can't be read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEiXYa75baYfYaGJtH6xci
ci_facts took every provider claim plus up to 12 rule claims, then added
provider, iss and sub. A GitHub job carries 13 provider claims, so a rule
that pins repository_id (as the bots guide recommends) with an environment,
or repository_id and repository_owner_id, produced 17 facts; the CA refuses
more than 16, and every login of that bot failed. Take the rule's claims
first, then the provider's while room is left.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEiXYa75baYfYaGJtH6xci
@jfcmartins
jfcmartins marked this pull request as ready for review November 9, 2026 10:07
@jfcmartins
jfcmartins merged commit 0192809 into main Nov 9, 2026
13 of 14 checks passed
@jfcmartins
jfcmartins deleted the claude/focused-thompson-ejh3u0 branch November 9, 2026 10:07
jfcmartins added a commit that referenced this pull request Nov 9, 2026
…sqlite3-sys) (#293)

Main's rust workflow has failed since #292: proxy_revocation.rs was not
rustfmt-clean, and a new advisory for libsqlite3-sys fails cargo audit.
The crate is in Cargo.lock only, as sqlx's optional SQLite driver, and is
never compiled. sqlx-sqlite 0.9.0 requires libsqlite3-sys below 0.38 and
the fix is 0.39, so there is nothing to bump. Recorded in deny.toml,
.cargo/audit.toml and ADR-0012.
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