From 32bb502d06e8ce2fcd9123ea7e6bf06c25dcf5bf Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 09:37:03 +0000 Subject: [PATCH 1/5] test(session): cover the controls-report purpose in the envelope tests ALL listed five of the six purposes, so the cross-purpose and signer-kind tests never checked ControlsReport. Add it, and a wildcard-free match that stops compiling when a new purpose is added without updating ALL. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SEiXYYveWxqv7a2tV4a3dG --- crates/limen-session/src/envelope.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/crates/limen-session/src/envelope.rs b/crates/limen-session/src/envelope.rs index ff817f3f..bbf2f4a6 100644 --- a/crates/limen-session/src/envelope.rs +++ b/crates/limen-session/src/envelope.rs @@ -238,14 +238,37 @@ mod tests { use limen_ca::{CaPurpose, CertificateAuthority, ComponentCertRequest, FileSigner}; - const ALL: [Purpose; 5] = [ + const ALL: [Purpose; 6] = [ Purpose::SessionGrant, Purpose::PolicySnapshot, Purpose::AuditManifest, Purpose::WebAppSession, Purpose::EvidencePack, + Purpose::ControlsReport, ]; + /// `ALL` must list every purpose, or the tests below silently skip the + /// one left out. This match has no wildcard, so a new variant stops it + /// compiling until it is added here and to `ALL`. + #[test] + fn all_lists_every_purpose_once() { + fn index(p: Purpose) -> usize { + match p { + Purpose::SessionGrant => 0, + Purpose::PolicySnapshot => 1, + Purpose::AuditManifest => 2, + Purpose::WebAppSession => 3, + Purpose::EvidencePack => 4, + Purpose::ControlsReport => 5, + } + } + let indices: Vec = ALL.into_iter().map(index).collect(); + assert_eq!(indices, (0..ALL.len()).collect::>()); + let labels: std::collections::BTreeSet<&[u8]> = + ALL.into_iter().map(Purpose::label).collect(); + assert_eq!(labels.len(), ALL.len(), "two purposes share a label"); + } + async fn internal_ca() -> CertificateAuthority { CertificateAuthority::create_self_signed( CaPurpose::Internal, @@ -283,7 +306,7 @@ mod tests { } } - /// The control plane signs four purposes with one key. Only the label in + /// The control plane signs five purposes with one key. Only the label in /// the signed message keeps, say, a policy snapshot from being replayed as /// a browser's web-app session, so the kind check can't be what stops it. #[tokio::test] From 759e70443ca12c6c4d34747c38d7d476155542dc Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 09:37:03 +0000 Subject: [PATCH 2/5] fix(examples): name the repository for gh in the policy-check workflow Both checkouts sit in subdirectories, so the workspace root is not a git repository and gh can't resolve {owner}/{repo}: the comment step failed. Set GH_REPO, and say that scripts/policy-pr-comment.sh must be copied too. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SEiXYYveWxqv7a2tV4a3dG --- docs/guides/policy-tooling.md | 2 +- examples/ci/policy-check.yml | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/guides/policy-tooling.md b/docs/guides/policy-tooling.md index b7fd20b6..f6ac3f57 100644 --- a/docs/guides/policy-tooling.md +++ b/docs/guides/policy-tooling.md @@ -122,4 +122,4 @@ Every call writes a `policy.suggest` audit event (window, policy version, counts ## In CI -`examples/ci/policy-check.yml` is a GitHub Actions workflow that runs the tests, posts the effective-access diff as a pull request comment (`scripts/policy-pr-comment.sh`), and fails when standing access widens without a label. Copy it into your policy repository. +`examples/ci/policy-check.yml` is a GitHub Actions workflow that runs the tests, posts the effective-access diff as a pull request comment (`scripts/policy-pr-comment.sh`), and fails when standing access widens without a label. Copy both files into your policy repository: the workflow into `.github/workflows/`, the script into `scripts/`. diff --git a/examples/ci/policy-check.yml b/examples/ci/policy-check.yml index e5984ea9..8494857e 100644 --- a/examples/ci/policy-check.yml +++ b/examples/ci/policy-check.yml @@ -1,7 +1,8 @@ # Check a policy change in a pull request (ADR-0028). # # Copy this into the repository that holds your Limen policy as -# .github/workflows/policy-check.yml and adjust `policy/` and the install step. +# .github/workflows/policy-check.yml, copy Limen's scripts/policy-pr-comment.sh +# into that repository's scripts/, and adjust `policy/` and the install step. # # What it does: # 1. runs the `policy_test` cases in the policy: a failing case fails the check; @@ -42,6 +43,9 @@ jobs: - name: Comment on the pull request env: GH_TOKEN: ${{ github.token }} + # The workspace root is not a git checkout (both are in + # subdirectories), so `gh` needs the repository named. + GH_REPO: ${{ github.repository }} PR: ${{ github.event.pull_request.number }} run: head/scripts/policy-pr-comment.sh diff.md - name: Standing access widens From e7ef54f751a9714ca5f3d622c8ec2caaab77b19d Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 09:37:03 +0000 Subject: [PATCH 3/5] fix(deploy): give the plain control-plane StatefulSet a pod security context The image runs as nonroot uid 65532 and the spool is a PVC, which starts root-owned on EBS. Without fsGroup the spool isn't writable. Match the Helm chart's podSecurityContext. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SEiXYYveWxqv7a2tV4a3dG --- deploy/kubernetes/limen/control-plane.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/deploy/kubernetes/limen/control-plane.yaml b/deploy/kubernetes/limen/control-plane.yaml index 3940ded3..344c11e2 100644 --- a/deploy/kubernetes/limen/control-plane.yaml +++ b/deploy/kubernetes/limen/control-plane.yaml @@ -41,6 +41,16 @@ spec: topologyKey: topology.kubernetes.io/zone labelSelector: matchLabels: { app.kubernetes.io/name: limen-control-plane } + # The image runs as distroless nonroot (uid 65532). A fresh volume + # (EBS, for one) is owned by root, so without fsGroup the spool can't + # be written and the control plane, whose audit fails closed, won't + # start. Matches the Helm chart's podSecurityContext. + securityContext: + runAsNonRoot: true + runAsUser: 65532 + runAsGroup: 65532 + fsGroup: 65532 + seccompProfile: { type: RuntimeDefault } containers: - name: control-plane image: REPLACE/limen-control-plane:REPLACE From 9809a1240f07b3d18d9239c1412a4ac8294043e8 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 09:42:38 +0000 Subject: [PATCH 4/5] fix(access): filter the approval queue in the query and honour its limit The approvable scope read the oldest 500 pending requests and then kept the ones the caller may approve. With more than 500 open requests, an approver whose roles only had newer ones saw an empty queue, and the requested limit was never applied. Select by approvable role and exclude the caller's own requests in SQL, apply the limit there, and keep the per-row check. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SEiXYYveWxqv7a2tV4a3dG --- crates/limen-control-plane/src/access/mod.rs | 13 ++++- .../limen-control-plane/src/access/store.rs | 19 +++++-- .../tests/access_requests.rs | 52 +++++++++++++++++++ 3 files changed, 80 insertions(+), 4 deletions(-) diff --git a/crates/limen-control-plane/src/access/mod.rs b/crates/limen-control-plane/src/access/mod.rs index e8f1a476..e9a36291 100644 --- a/crates/limen-control-plane/src/access/mod.rs +++ b/crates/limen-control-plane/src/access/mod.rs @@ -667,7 +667,18 @@ pub async fn list_requests( .map_err(|e| internal("reading groups", e))? .unwrap_or_default(); let policy = state.policy.current(); - let pending = store::pending(&state.db).await; + let roles: Vec = policy + .policy + .requestable_roles() + .map(|r| r.metadata.name.clone()) + .filter(|role| { + policy + .policy + .may_approve(role, who.username, groups.iter().map(String::as_str)) + }) + .collect(); + let pending = store::pending_for_roles(&state.db, &roles, who.username, limit).await; + // Checked again per row, so the SQL filter is never the only guard. pending.map(|rows| { rows.into_iter() .filter(|r| { diff --git a/crates/limen-control-plane/src/access/store.rs b/crates/limen-control-plane/src/access/store.rs index 7a8e2c08..724f4105 100644 --- a/crates/limen-control-plane/src/access/store.rs +++ b/crates/limen-control-plane/src/access/store.rs @@ -405,13 +405,26 @@ pub async fn list_requests( .collect() } -/// Pending requests that have not lapsed. -pub async fn pending(db: &Db) -> Result, sqlx::Error> { +/// Pending requests that have not lapsed, for `roles` only, oldest first, +/// leaving out `approver`'s own. Filtered here rather than after a capped +/// read, so a busy organisation's oldest requests can't hide the rest. +pub async fn pending_for_roles( + db: &Db, + roles: &[String], + approver: &str, + limit: i64, +) -> Result, sqlx::Error> { sqlx::query(concat!( "SELECT ", request_cols!(), - " FROM access_requests WHERE status = 'pending' AND expires_at > now() ORDER BY created_at LIMIT 500" + " FROM access_requests + WHERE status = 'pending' AND expires_at > now() + AND role = ANY($1) AND lower(requester) <> lower($2) + ORDER BY created_at LIMIT $3" )) + .bind(roles) + .bind(approver) + .bind(limit) .fetch_all(db) .await? .iter() diff --git a/crates/limen-control-plane/tests/access_requests.rs b/crates/limen-control-plane/tests/access_requests.rs index d537454d..457dd07b 100644 --- a/crates/limen-control-plane/tests/access_requests.rs +++ b/crates/limen-control-plane/tests/access_requests.rs @@ -434,6 +434,58 @@ async fn a_role_that_needs_two_approvers_gets_two_different_ones() { ); } +/// The approver's queue honours `limit`, oldest first, and leaves out the +/// approver's own requests (filtered in the query, not after a capped read). +#[tokio::test] +async fn the_approval_queue_honours_its_limit_and_skips_your_own() { + let Some(r) = Rig::start().await else { return }; + let (_, both) = + r.h.login(CONTRACTOR, &["developers", "sre-leads"]) + .await + .expect("a lead who also asks"); + let first = r + .request(&r.dev, "web-prod", "INC-1 disk") + .await + .expect("ssh"); + let second = r.request(&r.dev, "orders-prod", "").await.expect("db"); + let own = r + .request(&both, "web-prod", "INC-2 own") + .await + .expect("own"); + let queue = |who: CertificateDer<'static>, limit: u32| { + let access = r.access(); + async move { + let mut access = access; + access + .list_access_requests(forwarded( + ListAccessRequestsRequest { + scope: "approvable".into(), + status: String::new(), + limit, + }, + Some(&who), + )) + .await + .expect("queue") + .into_inner() + .requests + .into_iter() + .map(|q| q.id) + .collect::>() + } + }; + assert_eq!(queue(r.lead.clone(), 1).await, [first.id.clone()]); + assert_eq!( + queue(r.lead.clone(), 0).await, + [first.id.clone(), second.id.clone(), own.id.clone()] + ); + assert_eq!( + queue(both, 0).await, + [first.id, second.id], + "never your own" + ); +} + #[tokio::test] async fn a_denial_ends_it_and_a_requester_can_withdraw() { let Some(r) = Rig::start().await else { return }; From 35ee328a263948fddb280be364eabec7df48ca1c Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 09:51:04 +0000 Subject: [PATCH 5/5] test(access): satisfy clippy in the approval-queue test Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SEiXYYveWxqv7a2tV4a3dG --- crates/limen-control-plane/tests/access_requests.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/limen-control-plane/tests/access_requests.rs b/crates/limen-control-plane/tests/access_requests.rs index 457dd07b..e36a7226 100644 --- a/crates/limen-control-plane/tests/access_requests.rs +++ b/crates/limen-control-plane/tests/access_requests.rs @@ -474,7 +474,10 @@ async fn the_approval_queue_honours_its_limit_and_skips_your_own() { .collect::>() } }; - assert_eq!(queue(r.lead.clone(), 1).await, [first.id.clone()]); + assert_eq!( + queue(r.lead.clone(), 1).await, + std::slice::from_ref(&first.id) + ); assert_eq!( queue(r.lead.clone(), 0).await, [first.id.clone(), second.id.clone(), own.id.clone()]