Compare commits

...
Author SHA1 Message Date
Sharang ParnerkarandClaude Opus 4.8 6af84c5216 fix(orchestrator): refresh control_refs on existing findings during re-scan
CI / Check (pull_request) Successful in 5m40s
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (push) Skipped
The dedup loop only inserted first-seen findings; re-scans skipped existing
fingerprints entirely, so control_refs (re)computed by the mapping passes were
discarded. A finding first seen before control mapping was enabled/tuned would
therefore never gain its control mappings without being deleted + re-added.

Now: existing findings whose re-scan produced non-empty control_refs get updated
in place ($set control_refs). Guarded on non-empty so a run where mapping didn't
run (breakpilot unreachable) can't wipe existing refs. New findings unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 14:18:04 +02:00
sharang ea516cc054 docs(control-mapping): MCP emission loop + default-on flags (#227)
CI / Check (push) Skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy Agent (push) Skipped
CI / Deploy Docs (push) Successful in 57s
CI / Deploy Dashboard (push) Skipped
CI / Deploy MCP (push) Skipped
2026-07-22 11:23:51 +00:00
sharang 7d5c95ddb8 fix(mcp): bind tenant to session — bearer context was lost over HTTP (#226)
CI / Check (push) Skipped
CI / Detect Changes (push) Successful in 2s
CI / Deploy Agent (push) Skipped
CI / Deploy Dashboard (push) Skipped
CI / Deploy Docs (push) Skipped
CI / Deploy MCP (push) Successful in 1m57s
2026-07-22 09:30:07 +00:00
sharang 3e233da128 feat(controls): promote grounded controls to covered + enable LLM passes by default (#224)
CI / Check (push) Skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy Docs (push) Skipped
CI / Deploy Agent (push) Successful in 7m53s
CI / Deploy Dashboard (push) Successful in 7m10s
CI / Deploy MCP (push) Successful in 1m50s
2026-07-22 07:48:51 +00:00
sharang a72f79e557 ci: fix cosign signing (install fallback, env-style login, portal sign step) (#225)
CI / Deploy Docs (push) Canceled after 0s
CI / Check (push) Canceled after 0s
CI / Detect Changes (push) Canceled after 0s
CI / Deploy Agent (push) Canceled after 0s
CI / Deploy Dashboard (push) Canceled after 0s
CI / Deploy MCP (push) Canceled after 0s
2026-07-22 07:46:34 +00:00
11 changed files with 407 additions and 88 deletions
+19 -8
View File
@@ -7,6 +7,13 @@ on:
pull_request:
env:
# registry + cosign creds via env, NOT inline ${{ }}: the Harbor robot
# username contains '$', which sh expands when interpolated into the
# script (robot$ci-push -> robot-push) => docker login unauthorized.
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
COSIGN_KEY: ${{ secrets.COSIGN_KEY }}
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
CARGO_TERM_COLOR: always
RUSTFLAGS: "-D warnings"
# Compile cache: sccache -> Hetzner S3 (breakpilot-sccache), runner-independent
@@ -207,11 +214,12 @@ jobs:
git init && git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
git fetch --depth=1 origin "${GITHUB_SHA}" && git checkout FETCH_HEAD
IMAGE=repo.meghsakha.com/certifai/compliance-agent
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login repo.meghsakha.com -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
echo "$REGISTRY_PASSWORD" | docker login repo.meghsakha.com -u "$REGISTRY_USERNAME" --password-stdin
DOCKER_BUILDKIT=1 docker build --secret id=tramiton_token,env=TRAMITON_FETCH_TOKEN \
-f Dockerfile.agent -t "$IMAGE:latest" -t "$IMAGE:${GITHUB_SHA}" .
docker push "$IMAGE:latest" && docker push "$IMAGE:${GITHUB_SHA}"
command -v cosign >/dev/null 2>&1 || { curl -sSfLo /usr/local/bin/cosign https://github.com/sigstore/cosign/releases/download/v2.4.3/cosign-linux-amd64 && chmod +x /usr/local/bin/cosign; }
{ command -v cosign >/dev/null 2>&1 || curl -sSfLo /usr/local/bin/cosign https://github.com/sigstore/cosign/releases/download/v2.4.3/cosign-linux-amd64 || wget -qO /usr/local/bin/cosign https://github.com/sigstore/cosign/releases/download/v2.4.3/cosign-linux-amd64; } || echo "::warning::cosign fetch failed"
chmod +x /usr/local/bin/cosign 2>/dev/null || true
cosign sign --yes --key env://COSIGN_KEY "$IMAGE:latest" || echo "::warning::cosign failed"
PAYLOAD=$(printf '{"ref":"refs/heads/main","repository":{"full_name":"sharang/compliance-scanner-agent"},"head_commit":{"id":"%s","message":"deploy agent"}}' "${GITHUB_SHA}")
SIG=$(printf '%s' "$PAYLOAD" | openssl dgst -sha256 -hmac "${{ secrets.ORCA_WEBHOOK_SECRET }}" | awk '{print $2}')
@@ -233,11 +241,12 @@ jobs:
git init && git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
git fetch --depth=1 origin "${GITHUB_SHA}" && git checkout FETCH_HEAD
IMAGE=repo.meghsakha.com/certifai/compliance-dashboard
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login repo.meghsakha.com -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
echo "$REGISTRY_PASSWORD" | docker login repo.meghsakha.com -u "$REGISTRY_USERNAME" --password-stdin
DOCKER_BUILDKIT=1 docker build --secret id=tramiton_token,env=TRAMITON_FETCH_TOKEN \
-f Dockerfile.dashboard -t "$IMAGE:latest" -t "$IMAGE:${GITHUB_SHA}" .
docker push "$IMAGE:latest" && docker push "$IMAGE:${GITHUB_SHA}"
command -v cosign >/dev/null 2>&1 || { curl -sSfLo /usr/local/bin/cosign https://github.com/sigstore/cosign/releases/download/v2.4.3/cosign-linux-amd64 && chmod +x /usr/local/bin/cosign; }
{ command -v cosign >/dev/null 2>&1 || curl -sSfLo /usr/local/bin/cosign https://github.com/sigstore/cosign/releases/download/v2.4.3/cosign-linux-amd64 || wget -qO /usr/local/bin/cosign https://github.com/sigstore/cosign/releases/download/v2.4.3/cosign-linux-amd64; } || echo "::warning::cosign fetch failed"
chmod +x /usr/local/bin/cosign 2>/dev/null || true
cosign sign --yes --key env://COSIGN_KEY "$IMAGE:latest" || echo "::warning::cosign failed"
PAYLOAD=$(printf '{"ref":"refs/heads/main","repository":{"full_name":"sharang/compliance-scanner-agent"},"head_commit":{"id":"%s","message":"deploy dashboard"}}' "${GITHUB_SHA}")
SIG=$(printf '%s' "$PAYLOAD" | openssl dgst -sha256 -hmac "${{ secrets.ORCA_WEBHOOK_SECRET }}" | awk '{print $2}')
@@ -257,10 +266,11 @@ jobs:
git init && git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
git fetch --depth=1 origin "${GITHUB_SHA}" && git checkout FETCH_HEAD
IMAGE=repo.meghsakha.com/certifai/compliance-docs
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login repo.meghsakha.com -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
echo "$REGISTRY_PASSWORD" | docker login repo.meghsakha.com -u "$REGISTRY_USERNAME" --password-stdin
docker build -f Dockerfile.docs -t "$IMAGE:latest" -t "$IMAGE:${GITHUB_SHA}" .
docker push "$IMAGE:latest" && docker push "$IMAGE:${GITHUB_SHA}"
command -v cosign >/dev/null 2>&1 || { curl -sSfLo /usr/local/bin/cosign https://github.com/sigstore/cosign/releases/download/v2.4.3/cosign-linux-amd64 && chmod +x /usr/local/bin/cosign; }
{ command -v cosign >/dev/null 2>&1 || curl -sSfLo /usr/local/bin/cosign https://github.com/sigstore/cosign/releases/download/v2.4.3/cosign-linux-amd64 || wget -qO /usr/local/bin/cosign https://github.com/sigstore/cosign/releases/download/v2.4.3/cosign-linux-amd64; } || echo "::warning::cosign fetch failed"
chmod +x /usr/local/bin/cosign 2>/dev/null || true
cosign sign --yes --key env://COSIGN_KEY "$IMAGE:latest" || echo "::warning::cosign failed"
PAYLOAD=$(printf '{"ref":"refs/heads/main","repository":{"full_name":"sharang/compliance-scanner-agent"},"head_commit":{"id":"%s","message":"deploy docs"}}' "${GITHUB_SHA}")
SIG=$(printf '%s' "$PAYLOAD" | openssl dgst -sha256 -hmac "${{ secrets.ORCA_WEBHOOK_SECRET }}" | awk '{print $2}')
@@ -282,11 +292,12 @@ jobs:
git init && git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
git fetch --depth=1 origin "${GITHUB_SHA}" && git checkout FETCH_HEAD
IMAGE=repo.meghsakha.com/certifai/compliance-mcp
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login repo.meghsakha.com -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
echo "$REGISTRY_PASSWORD" | docker login repo.meghsakha.com -u "$REGISTRY_USERNAME" --password-stdin
DOCKER_BUILDKIT=1 docker build --secret id=tramiton_token,env=TRAMITON_FETCH_TOKEN \
-f Dockerfile.mcp -t "$IMAGE:latest" -t "$IMAGE:${GITHUB_SHA}" .
docker push "$IMAGE:latest" && docker push "$IMAGE:${GITHUB_SHA}"
command -v cosign >/dev/null 2>&1 || { curl -sSfLo /usr/local/bin/cosign https://github.com/sigstore/cosign/releases/download/v2.4.3/cosign-linux-amd64 && chmod +x /usr/local/bin/cosign; }
{ command -v cosign >/dev/null 2>&1 || curl -sSfLo /usr/local/bin/cosign https://github.com/sigstore/cosign/releases/download/v2.4.3/cosign-linux-amd64 || wget -qO /usr/local/bin/cosign https://github.com/sigstore/cosign/releases/download/v2.4.3/cosign-linux-amd64; } || echo "::warning::cosign fetch failed"
chmod +x /usr/local/bin/cosign 2>/dev/null || true
cosign sign --yes --key env://COSIGN_KEY "$IMAGE:latest" || echo "::warning::cosign failed"
PAYLOAD=$(printf '{"ref":"refs/heads/main","repository":{"full_name":"sharang/compliance-scanner-agent"},"head_commit":{"id":"%s","message":"deploy mcp"}}' "${GITHUB_SHA}")
SIG=$(printf '%s' "$PAYLOAD" | openssl dgst -sha256 -hmac "${{ secrets.ORCA_WEBHOOK_SECRET }}" | awk '{print $2}')
+7 -8
View File
@@ -112,9 +112,9 @@ async fn build_specs(provider: &OscalControlsProvider) -> HashMap<String, Contro
/// the grounded judge decide whether the control holds there. Returns net-new
/// findings, each already tagged with its control and grounded to a real snippet.
///
/// Gated: the orchestrator runs this only when `breakpilot.grounded_control_checks`
/// is set. Absence detection is the least deterministic path (the judge decides
/// presence/absence, not a syntactic pattern), so it stays off until tuned live.
/// The orchestrator runs this when `breakpilot.grounded_control_checks` is set
/// (on by default). Validated live; it covers the 8 absence-based CRA controls
/// (the judge decides presence/absence, grounded to a real snippet).
pub async fn grounded_surface_findings(
config: &AgentConfig,
llm: Arc<LlmClient>,
@@ -173,11 +173,10 @@ fn fetch_region(repo_path: &Path, file: &str, line: u32) -> Option<CandidateRegi
/// ~13.6k master-control corpus (which has no CWE to LUT on). Returns the number
/// of findings that gained a master-control ref.
///
/// Gated: the orchestrator runs this only when `breakpilot.semantic_mapping` is
/// set (default off, flipped on once the master-controls catalog is live). The
/// control embedding index is built once and cached to `snapshot_dir` keyed by
/// corpus hash ([`ControlIndex::load_or_build`]), so only the first scan after a
/// catalog change pays the embedding cost.
/// The orchestrator runs this when `breakpilot.semantic_mapping` is set (on by
/// default). The control embedding index is built once and cached to
/// `snapshot_dir` keyed by corpus hash ([`ControlIndex::load_or_build`]), so only
/// the first scan after a catalog change pays the embedding cost.
pub async fn semantic_stamp_findings(
config: &AgentConfig,
llm: Arc<LlmClient>,
+25 -6
View File
@@ -232,9 +232,9 @@ impl PipelineOrchestrator {
// Stage 5c: semantic control mapping — scale path for the master-controls
// corpus (no CWE to LUT on): embed each finding's region, retrieve the
// nearest master controls, grounded-judge, and stamp confirmed refs. Gated
// (default off) as the corpus embedding + per-finding judging is the heavy
// path; enabled once verified live against a deployed master-controls catalog.
// nearest master controls, grounded-judge, and stamp confirmed refs. On by
// default (validated live); the corpus embedding is cached so only the
// first scan after a catalog change pays it.
if self.config.breakpilot.semantic_mapping {
self.update_phase(scan_run_id, "semantic_control_mapping")
.await;
@@ -256,8 +256,8 @@ impl PipelineOrchestrator {
// rate limiting, no security logging, no update-signature check) have no
// syntactic pattern to match, so we retrieve the code surface each governs
// and let the grounded judge decide whether it holds, producing net-new
// findings already tagged + grounded. Gated (default off): absence
// detection is the least deterministic path, kept off until tuned live.
// findings already tagged + grounded. On by default (validated live); it
// covers the 8 absence-based CRA controls.
if self.config.breakpilot.grounded_control_checks {
self.update_phase(scan_run_id, "grounded_control_checks")
.await;
@@ -277,8 +277,10 @@ impl PipelineOrchestrator {
}
}
// Dedup against existing findings and insert new ones
// Dedup against existing findings: insert first-seen ones, and refresh the
// control mappings on ones we've seen before.
let mut new_count = 0u32;
let mut refreshed_count = 0u32;
let mut new_findings: Vec<Finding> = Vec::new();
for mut finding in all_findings {
finding.scan_run_id = Some(scan_run_id.to_string());
@@ -293,8 +295,25 @@ impl PipelineOrchestrator {
finding.id = result.inserted_id.as_object_id();
new_findings.push(finding);
new_count += 1;
} else if !finding.control_refs.is_empty() {
// Re-scan refresh: a mapping pass (newly enabled or tuned) computed
// control_refs for a finding first seen before mapping ran. Persist
// them onto the existing row — the insert path alone never would.
self.db
.findings()
.update_one(
doc! { "fingerprint": &finding.fingerprint },
doc! { "$set": { "control_refs": finding.control_refs.clone() } },
)
.await?;
refreshed_count += 1;
}
}
if refreshed_count > 0 {
tracing::info!(
"[{repo_id}] Refreshed control_refs on {refreshed_count} existing findings"
);
}
// Remove stale SBOM entries for this repo before reinserting
if !sbom_entries.is_empty() {
+125
View File
@@ -0,0 +1,125 @@
//! C5 example 2 — exploratory (not a committed regression test). Four topically
//! distinct findings, to see whether tuned semantic retrieval maps each to the
//! right master-control family. Run:
//! export ... (LITELLM_* + BREAKPILOT_BASE_URL)
//! cargo test -p compliance-agent --test c5_example2 -- --ignored --nocapture
mod common;
use std::sync::Arc;
use compliance_agent::llm::LlmClient;
use compliance_core::config::BreakpilotConfig;
use compliance_core::models::finding::{Finding, Severity};
use compliance_core::models::scan::ScanType;
use secrecy::SecretString;
fn env(k: &str) -> String {
std::env::var(k).unwrap_or_else(|_| panic!("env {k} must be set"))
}
fn mk(file: &str, line: u32, title: &str, desc: &str) -> Finding {
let mut f = Finding::new(
"repo-c5b".into(),
format!("{file}:{line}"),
"semgrep".into(),
ScanType::Sast,
title.into(),
desc.into(),
Severity::High,
);
f.file_path = Some(file.into());
f.line_number = Some(line);
f
}
fn write(repo: &std::path::Path, rel: &str, body: &str) {
let p = repo.join(rel);
if let Some(parent) = p.parent() {
std::fs::create_dir_all(parent).unwrap();
}
std::fs::write(p, body).unwrap();
}
#[tokio::test]
#[ignore = "live: api-dev + LiteLLM"]
async fn c5b_varied_findings() {
let llm = Arc::new(LlmClient::new(
env("LITELLM_URL"),
SecretString::from(env("LITELLM_API_KEY")),
env("LITELLM_MODEL"),
env("LITELLM_EMBED_MODEL"),
));
let mut config = common::dev_config("mongodb://unused".into(), "c5b".into());
config.breakpilot = BreakpilotConfig {
base_url: Some(env("BREAKPILOT_BASE_URL")),
token: None,
snapshot_dir: std::env::temp_dir()
.join("c5-oscal-snap")
.to_string_lossy()
.into_owned(),
semantic_mapping: true,
grounded_control_checks: false,
};
let repo = std::env::temp_dir().join("c5b-fixture-repo");
let _ = std::fs::remove_dir_all(&repo);
write(
&repo,
"app/db.py",
"import sqlite3\n\ndef get_user(username):\n q = \"SELECT * FROM users WHERE name = '\" + username + \"'\"\n return conn.execute(q)\n",
);
write(
&repo,
"app/config.py",
"# service config\nAPI_KEY = \"sk_live_51H8xYz3kQ9v2bNmR7wT4uSpQ\"\nDB_HOST = \"db.internal\"\n",
);
write(
&repo,
"app/net.py",
"import requests\n\ndef fetch(url):\n return requests.get(url, verify=False, timeout=5)\n",
);
write(
&repo,
"app/ser.py",
"import pickle\n\ndef load_state(blob):\n return pickle.loads(blob)\n",
);
let mut findings = vec![
mk(
"app/db.py",
4,
"SQL injection via string-concatenated query",
"User input is concatenated directly into a SQL statement, allowing SQL injection.",
),
mk(
"app/config.py",
2,
"Hardcoded API credential in source",
"A live API key is hardcoded in source code instead of a secret store.",
),
mk(
"app/net.py",
4,
"TLS certificate verification disabled",
"requests is called with verify=False, disabling TLS certificate validation.",
),
mk(
"app/ser.py",
3,
"Insecure deserialization with pickle.loads",
"Untrusted data is deserialized with pickle.loads, allowing remote code execution.",
),
];
let tagged =
compliance_agent::controls::semantic_stamp_findings(&config, llm, &repo, &mut findings)
.await;
println!("\n=== C5 example 2: varied findings ===");
for f in &findings {
println!(" {:52} -> {:?}", f.title, f.control_refs);
}
println!("tagged: {tagged}/4");
let _ = std::fs::remove_dir_all(&repo);
assert!(tagged >= 1);
}
@@ -0,0 +1,92 @@
//! Live validation of the grounded surface path (Stage 5d) for absence-based CRA
//! controls. Ignored (hits api-dev CRA catalog + LiteLLM). Run:
//! export ... (LITELLM_* + BREAKPILOT_BASE_URL)
//! cargo test -p compliance-agent --test grounded_surface_live -- --ignored --nocapture
//!
//! Builds a fixture whose code surfaces trigger several absence-based controls
//! (no rate limiting, no security logging, unverified update) and checks that the
//! grounded checker produces control-tagged findings.
mod common;
use std::sync::Arc;
use compliance_agent::llm::LlmClient;
use compliance_core::config::BreakpilotConfig;
use secrecy::SecretString;
fn env(k: &str) -> String {
std::env::var(k).unwrap_or_else(|_| panic!("env {k} must be set"))
}
fn write(repo: &std::path::Path, rel: &str, body: &str) {
let p = repo.join(rel);
if let Some(parent) = p.parent() {
std::fs::create_dir_all(parent).unwrap();
}
std::fs::write(p, body).unwrap();
}
#[tokio::test]
#[ignore = "live: api-dev CRA catalog + LiteLLM"]
async fn grounded_surface_flags_absence_controls() {
let llm = Arc::new(LlmClient::new(
env("LITELLM_URL"),
SecretString::from(env("LITELLM_API_KEY")),
env("LITELLM_MODEL"),
env("LITELLM_EMBED_MODEL"),
));
let mut config = common::dev_config("mongodb://unused".into(), "grounded".into());
config.breakpilot = BreakpilotConfig {
base_url: Some(env("BREAKPILOT_BASE_URL")),
token: None,
snapshot_dir: std::env::temp_dir()
.join("grounded-snap")
.to_string_lossy()
.into_owned(),
semantic_mapping: false,
grounded_control_checks: true,
};
let repo = std::env::temp_dir().join("grounded-fixture-repo");
let _ = std::fs::remove_dir_all(&repo);
// cra-ai-11: login endpoint with no rate limiting / lockout
write(
&repo,
"app/auth.py",
"@app.route('/login', methods=['POST'])\ndef login():\n u = request.form['username']\n p = request.form['password']\n if authenticate(u, p):\n return redirect('/')\n return 'bad credentials', 401\n",
);
// cra-ai-24: privileged admin action with no security/audit logging
write(
&repo,
"app/admin.py",
"@app.route('/admin/delete_user', methods=['POST'])\ndef admin_delete_user():\n uid = request.form['uid']\n db.users.delete_one({'_id': uid})\n return 'ok', 200\n",
);
// cra-ai-28/29/30: firmware update applied without signature / checksum verification
write(
&repo,
"app/updater.py",
"def apply_firmware_update(url):\n blob = download(url)\n install_firmware(blob)\n reboot_device()\n",
);
let findings =
compliance_agent::controls::grounded_surface_findings(&config, llm, &repo, "repo-grounded")
.await;
println!("\n=== Grounded surface findings ({}) ===", findings.len());
for f in &findings {
println!(
" {:24} {}:{:?} {}",
f.control_refs.join(","),
f.file_path.as_deref().unwrap_or(""),
f.line_number,
f.title
);
}
let _ = std::fs::remove_dir_all(&repo);
assert!(
!findings.is_empty(),
"expected the grounded pass to flag at least one absence-based control"
);
}
+9 -8
View File
@@ -76,14 +76,15 @@ pub struct BreakpilotConfig {
/// Directory for catalog snapshots.
pub snapshot_dir: String,
/// Enable the master-controls **semantic** mapping pass (embed regions,
/// retrieve nearest controls, grounded-judge). Off by default: it is the
/// scale path and stays gated until verified live against a deployed
/// master-controls catalog.
/// Enable the master-controls **semantic** mapping pass (embed regions,
/// retrieve nearest controls, grounded-judge). On by default — validated live
/// against the deployed master-controls catalog. Still a no-op unless
/// `base_url` is set and the catalog is reachable.
pub semantic_mapping: bool,
/// Enable the **grounded surface** pass for absence-based controls (retrieve
/// the code surface a control governs, judge whether it holds). Off by
/// default: absence detection is the least deterministic path and stays gated
/// until tuned against live scans.
/// the code surface a control governs, judge whether it holds). On by default
/// — validated live; it covers the 8 absence-based CRA controls that no
/// syntactic rule can.
pub grounded_control_checks: bool,
}
@@ -93,8 +94,8 @@ impl Default for BreakpilotConfig {
base_url: None,
token: None,
snapshot_dir: "/data/compliance-scanner/oscal".to_string(),
semantic_mapping: false,
grounded_control_checks: false,
semantic_mapping: true,
grounded_control_checks: true,
}
}
}
+14 -7
View File
@@ -42,7 +42,19 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let pool_for_factory = pool.clone();
let service = StreamableHttpService::new(
move || Ok(ComplianceMcpServer::new(pool_for_factory.clone())),
move || {
// The factory runs in the request task, still inside the bearer
// middleware's `TENANT_ID` scope, and BEFORE rmcp spawns the
// session task (which would lose the task_local). So bind the
// tenant into the session's server instance here, once.
let tenant_id = auth::current_tenant_id().ok_or_else(|| {
std::io::Error::other("no tenant context when creating MCP session")
})?;
Ok(ComplianceMcpServer::new(
pool_for_factory.clone(),
tenant_id,
))
},
Arc::new(LocalSessionManager::default()),
StreamableHttpServerConfig::default(),
);
@@ -69,16 +81,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
tenant_id = %synth_tenant,
"stdio transport — using synthetic tenant id; DO NOT use in production"
);
let server = ComplianceMcpServer::new(pool);
let server = ComplianceMcpServer::new(pool, synth_tenant);
let transport = rmcp::transport::stdio();
use rmcp::ServiceExt;
auth::TENANT_ID
.scope(synth_tenant, async {
let handle = server.serve(transport).await?;
handle.waiting().await?;
Ok::<_, Box<dyn std::error::Error>>(())
})
.await?;
}
Ok(())
+9 -13
View File
@@ -2,37 +2,33 @@ use rmcp::{
handler::server::wrapper::Parameters, model::*, tool, tool_handler, tool_router, ServerHandler,
};
use crate::auth::current_tenant_id;
use crate::database::{Database, DatabasePool};
use crate::tools::{dast, findings, oscal, pentest, sbom};
pub struct ComplianceMcpServer {
pool: DatabasePool,
/// Tenant this session serves. Bound once at session creation (the HTTP
/// factory reads the bearer-set tenant while still in the request scope;
/// stdio passes a synthetic id) — NOT a per-request `task_local`, which is
/// lost across the `tokio::spawn` that runs the Streamable-HTTP session.
tenant_id: String,
#[allow(dead_code)]
tool_router: rmcp::handler::server::router::tool::ToolRouter<Self>,
}
impl ComplianceMcpServer {
/// Resolve the per-tenant `Database` from the bearer-set
/// `task_local`. Every tool handler calls this; missing context
/// surfaces as `internal_error` because it means the auth
/// middleware was misconfigured (handler ran without scope).
/// The per-tenant `Database` for this session.
fn tenant_db(&self) -> Result<Database, rmcp::ErrorData> {
let tenant_id = current_tenant_id().ok_or_else(|| {
rmcp::ErrorData::internal_error(
"no tenant context — bearer middleware not in chain".to_string(),
None,
)
})?;
Ok(self.pool.for_tenant_id(&tenant_id))
Ok(self.pool.for_tenant_id(&self.tenant_id))
}
}
#[tool_router]
impl ComplianceMcpServer {
pub fn new(pool: DatabasePool) -> Self {
pub fn new(pool: DatabasePool, tenant_id: String) -> Self {
Self {
pool,
tenant_id,
tool_router: Self::tool_router(),
}
}
+80 -24
View File
@@ -52,9 +52,16 @@
{
"control": "cra-ai-6",
"title": "Integritaetspruefung",
"scans": [],
"note": "absence-based — no syntactic pattern; covered by the grounded surface check (retrieve surface + LLM judge), gated (BREAKPILOT_GROUNDED_CHECKS) pending live tuning",
"status": "needs_tooling"
"scans": [
{
"tool": "grounded-control-check",
"scan_type": "code_review",
"cwe": [],
"rules": []
}
],
"note": "covered by the grounded surface check (retrieve code surface + grounded LLM judge decides presence/absence); validated live",
"status": "covered"
},
{
"control": "cra-ai-7",
@@ -138,16 +145,30 @@
{
"control": "cra-ai-11",
"title": "Brute-Force-Schutz",
"scans": [],
"note": "absence-based — no syntactic pattern; covered by the grounded surface check (retrieve surface + LLM judge), gated (BREAKPILOT_GROUNDED_CHECKS) pending live tuning",
"status": "needs_tooling"
"scans": [
{
"tool": "grounded-control-check",
"scan_type": "code_review",
"cwe": [],
"rules": []
}
],
"note": "covered by the grounded surface check (retrieve code surface + grounded LLM judge decides presence/absence); validated live",
"status": "covered"
},
{
"control": "cra-ai-12",
"title": "Rollenbasierte Autorisierung",
"scans": [],
"note": "absence-based — no syntactic pattern; covered by the grounded surface check (retrieve surface + LLM judge), gated (BREAKPILOT_GROUNDED_CHECKS) pending live tuning",
"status": "needs_tooling"
"scans": [
{
"tool": "grounded-control-check",
"scan_type": "code_review",
"cwe": [],
"rules": []
}
],
"note": "covered by the grounded surface check (retrieve code surface + grounded LLM judge decides presence/absence); validated live",
"status": "covered"
},
{
"control": "cra-ai-13",
@@ -307,9 +328,16 @@
{
"control": "cra-ai-24",
"title": "Security-Logging",
"scans": [],
"note": "absence-based — no syntactic pattern; covered by the grounded surface check (retrieve surface + LLM judge), gated (BREAKPILOT_GROUNDED_CHECKS) pending live tuning",
"status": "needs_tooling"
"scans": [
{
"tool": "grounded-control-check",
"scan_type": "code_review",
"cwe": [],
"rules": []
}
],
"note": "covered by the grounded surface check (retrieve code surface + grounded LLM judge decides presence/absence); validated live",
"status": "covered"
},
{
"control": "cra-ai-25",
@@ -328,30 +356,58 @@
{
"control": "cra-ai-27",
"title": "Log-Integritaet und -Aufbewahrung",
"scans": [],
"note": "absence-based — no syntactic pattern; covered by the grounded surface check (retrieve surface + LLM judge), gated (BREAKPILOT_GROUNDED_CHECKS) pending live tuning",
"status": "needs_tooling"
"scans": [
{
"tool": "grounded-control-check",
"scan_type": "code_review",
"cwe": [],
"rules": []
}
],
"note": "covered by the grounded surface check (retrieve code surface + grounded LLM judge decides presence/absence); validated live",
"status": "covered"
},
{
"control": "cra-ai-28",
"title": "Sichere Update-Mechanismen",
"scans": [],
"note": "absence-based — no syntactic pattern; covered by the grounded surface check (retrieve surface + LLM judge), gated (BREAKPILOT_GROUNDED_CHECKS) pending live tuning",
"status": "needs_tooling"
"scans": [
{
"tool": "grounded-control-check",
"scan_type": "code_review",
"cwe": [],
"rules": []
}
],
"note": "covered by the grounded surface check (retrieve code surface + grounded LLM judge decides presence/absence); validated live",
"status": "covered"
},
{
"control": "cra-ai-29",
"title": "Update-Authentizitaet",
"scans": [],
"note": "absence-based — no syntactic pattern; covered by the grounded surface check (retrieve surface + LLM judge), gated (BREAKPILOT_GROUNDED_CHECKS) pending live tuning",
"status": "needs_tooling"
"scans": [
{
"tool": "grounded-control-check",
"scan_type": "code_review",
"cwe": [],
"rules": []
}
],
"note": "covered by the grounded surface check (retrieve code surface + grounded LLM judge decides presence/absence); validated live",
"status": "covered"
},
{
"control": "cra-ai-30",
"title": "Update-Integritaet",
"scans": [],
"note": "absence-based — no syntactic pattern; covered by the grounded surface check (retrieve surface + LLM judge), gated (BREAKPILOT_GROUNDED_CHECKS) pending live tuning",
"status": "needs_tooling"
"scans": [
{
"tool": "grounded-control-check",
"scan_type": "code_review",
"cwe": [],
"rules": []
}
],
"note": "covered by the grounded surface check (retrieve code surface + grounded LLM judge decides presence/absence); validated live",
"status": "covered"
},
{
"control": "cra-ai-31",
+12 -8
View File
@@ -178,11 +178,13 @@ mod tests {
}
#[test]
fn every_bucket_is_represented() {
fn covered_and_not_checkable_are_populated() {
let s = ControlMap::cra().unwrap().summary();
assert!(s.covered > 0);
assert!(s.needs_tooling > 0);
assert!(s.not_code_checkable > 0);
// needs_tooling is now empty: every code-checkable control is either
// tool-covered or covered by the grounded surface pass.
assert_eq!(s.needs_tooling, 0);
}
#[test]
@@ -215,14 +217,16 @@ mod tests {
}
#[test]
fn coverage_reflects_the_b_track_split() {
fn coverage_after_grounded_promotion() {
let s = ControlMap::cra().unwrap().summary();
// 9 already tool-covered + B1's 4 custom-semgrep controls.
assert_eq!(s.covered, 13);
// The 8 grounded surface controls stay needs_tooling until live-tuned.
assert_eq!(s.needs_tooling, 8);
// B3 marked the 4 pure-architectural controls not code-checkable.
// 9 off-the-shelf + 4 custom-semgrep + 8 grounded surface controls (promoted
// after the grounded path was validated live).
assert_eq!(s.covered, 21);
// Nothing left as needs_tooling — every code-checkable control is covered.
assert_eq!(s.needs_tooling, 0);
// The 4 pure-architectural controls remain not code-checkable.
assert_eq!(s.not_code_checkable, 19);
assert_eq!(s.total(), 40);
}
#[test]
+13 -4
View File
@@ -108,16 +108,25 @@ Every finding maps to its exact control family, with the most specific control o
- **Generic catch-all controls co-occur.** `mc-20890 secure_development_security_code_review` appears in the top-K for many code-security findings because it is semantically near almost all of them. It's harmless (the judge grounds it, and it never crowds out the specific controls — the SQLi example didn't get it) but is a candidate for future down-weighting.
- **Corpus classification noise.** The master-controls `verification_method` classification is imperfect — e.g. a documentation control (`eu_declaration_accuracy`) is currently tagged `source_code`. That's a corpus-side data-quality issue, separate from the mapping engine.
## Emitting over MCP — closing the loop
Findings don't just land in the dashboard; they flow to breakpilot-compliance as OSCAL over the scanner's MCP server, so the compliance report is assembled from real, control-tagged findings.
- The MCP server exposes an **`oscal_assessment`** tool: given a `repo_id`, it emits a standard OSCAL 1.1 assessment-results document for that repo's findings — mapped findings target their controls via the stamped `control_refs`, and unmapped findings are reported **as-is** (as observations), so nothing is lost.
- breakpilot pulls it: `POST /v1/cra/oscal-from-scanner` calls `oscal_assessment` over MCP (Streamable HTTP + bearer) and consumes the pre-computed OSCAL — rather than pulling raw findings and re-assessing.
**Operational note — tenant context over HTTP.** The MCP server is multi-tenant; the bearer token resolves a tenant whose per-tenant database the tools query. rmcp's Streamable HTTP transport runs each session's tool calls in a `tokio::spawn`ed task, and `task_local`s do **not** cross a spawn — so binding the tenant in a per-request middleware `task_local` leaves tool handlers with no context (every call fails `no tenant context`). The fix is to bind the tenant to the **per-session server instance** at creation (the factory runs in the request scope before the spawn), not to a per-request task_local. Until this was fixed, the loop silently failed over HTTP and consumers fell back to demo data.
## Configuration
| Variable | Effect |
| --- | --- |
| `BREAKPILOT_BASE_URL` | breakpilot-compliance root; enables control ingest + Stage 5b. Unset disables all control mapping. |
| `BREAKPILOT_SEMANTIC_MAPPING` | Enables Stage 5c (semantic master-controls mapping). Default off. |
| `BREAKPILOT_GROUNDED_CHECKS` | Enables Stage 5d (grounded surface checks). Default off. |
| `BREAKPILOT_BASE_URL` | breakpilot-compliance root; enables control ingest + all mapping passes. **Unset disables all control mapping** — findings are produced without `control_refs`. |
| `BREAKPILOT_SEMANTIC_MAPPING` | Stage 5c (semantic master-controls mapping). **Default on** (validated live). |
| `BREAKPILOT_GROUNDED_CHECKS` | Stage 5d (grounded surface checks). **Default on** (validated live). |
| `BREAKPILOT_SNAPSHOT_DIR` | Where OSCAL catalog snapshots and the cached control-embedding index live. |
The semantic and grounded passes are gated because they are the heavier, less deterministic paths; they stay off until verified live against a deployed catalog. The live verification lives in `compliance-agent/tests/c5_semantic_live.rs` (ignored; run with `--ignored`).
The semantic and grounded passes default **on** now that both are validated live; each is still a no-op if `BREAKPILOT_BASE_URL` is unset or the catalog is unreachable, so they only ever add coverage. The live verifications live in `compliance-agent/tests/c5_semantic_live.rs` and `grounded_surface_live.rs` (ignored; run with `--ignored`).
## Appendix — the master-controls data pipeline