feat(api): the OpenAPI description covers compliance, evidence and manual findings (#1006) (#1021)
CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy Dashboard (push) Skipped
CI / Deploy Docs (push) Skipped
CI / Deploy MCP (push) Skipped
CI / Deploy Agent (push) Successful in 5m32s
CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy Dashboard (push) Skipped
CI / Deploy Docs (push) Skipped
CI / Deploy MCP (push) Skipped
CI / Deploy Agent (push) Successful in 5m32s
This commit was merged in pull request #1021.
This commit is contained in:
1 parent
8ae561a01a
commit
126345aa9d
7 files changed
+156
-60
No files matched your search
@@ -112,9 +112,19 @@ fn state_counts(controls: &[crate::evidence::compliance::ControlStatus]) -> serd
|
||||
/// Targets whose CRA status is computed at the same time for the summary.
|
||||
const SUMMARY_CONCURRENCY: usize = 4;
|
||||
|
||||
/// GET /api/v1/compliance/summary — every target's CRA state counts, for the
|
||||
/// overview. A target too large to evaluate in memory is listed with
|
||||
/// `counts: null` rather than failing the whole summary.
|
||||
/// Every target's CRA control counts per state, for the overview.
|
||||
///
|
||||
/// A target too large to evaluate in memory is listed with `counts: null`
|
||||
/// rather than failing the whole summary.
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/compliance/summary",
|
||||
tag = "Compliance",
|
||||
responses(
|
||||
(status = 200, description = "The counts per target"),
|
||||
(status = 401, description = "No valid bearer token"),
|
||||
)
|
||||
)]
|
||||
#[tracing::instrument(skip_all)]
|
||||
pub async fn compliance_summary(
|
||||
Extension(agent): AgentExt,
|
||||
@@ -158,8 +168,22 @@ pub async fn compliance_summary(
|
||||
Ok(Json(serde_json::json!({ "data": rows })))
|
||||
}
|
||||
|
||||
/// GET /api/v1/targets/{id}/compliance — the target's state against every CRA
|
||||
/// Annex I control, with the findings against each and the last scan.
|
||||
/// A target's state against every CRA Annex I control.
|
||||
///
|
||||
/// With the findings against each and the last scan.
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/targets/{id}/compliance",
|
||||
tag = "Compliance",
|
||||
params(("id" = String, Path, description = "The target's id")),
|
||||
responses(
|
||||
(status = 200, description = "The state per control"),
|
||||
(status = 400, description = "Not an id"),
|
||||
(status = 404, description = "No such target"),
|
||||
(status = 413, description = "Too large to evaluate in memory"),
|
||||
(status = 401, description = "No valid bearer token"),
|
||||
)
|
||||
)]
|
||||
#[tracing::instrument(skip_all, fields(target_id = %id))]
|
||||
pub async fn compliance_view(
|
||||
Extension(agent): AgentExt,
|
||||
@@ -185,8 +209,22 @@ pub async fn compliance_view(
|
||||
})))
|
||||
}
|
||||
|
||||
/// GET /api/v1/targets/{id}/evidence-pack — 404 for an unknown target, 413
|
||||
/// when it is too large to build in memory.
|
||||
/// A target's evidence pack to download.
|
||||
///
|
||||
/// 404 for an unknown target, 413 when it is too large to build in memory.
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/targets/{id}/evidence-pack",
|
||||
tag = "Compliance",
|
||||
params(("id" = String, Path, description = "The target's id")),
|
||||
responses(
|
||||
(status = 200, description = "The evidence pack"),
|
||||
(status = 400, description = "Not an id"),
|
||||
(status = 404, description = "No such target"),
|
||||
(status = 413, description = "Too large to build in memory"),
|
||||
(status = 401, description = "No valid bearer token"),
|
||||
)
|
||||
)]
|
||||
#[tracing::instrument(skip_all, fields(target_id = %id))]
|
||||
pub async fn evidence_pack(
|
||||
Extension(agent): AgentExt,
|
||||
@@ -231,14 +269,28 @@ pub async fn evidence_pack(
|
||||
const MAX_CONTROL_LOOKUP: usize = 50;
|
||||
|
||||
/// The query of [`describe_controls`]: comma-separated control ids.
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
#[derive(Debug, serde::Deserialize, utoipa::IntoParams)]
|
||||
#[into_params(parameter_in = Query)]
|
||||
pub struct ControlIdsQuery {
|
||||
/// The master control ids, comma-separated, at most 50.
|
||||
#[param(example = "mc-1,mc-2")]
|
||||
ids: String,
|
||||
}
|
||||
|
||||
/// GET /api/v1/controls?ids=mc-1,mc-2 — what the master controls stamped on
|
||||
/// a finding require, for the finding page. Unknown ids are left out; at
|
||||
/// most [`MAX_CONTROL_LOOKUP`] are described.
|
||||
/// What the master controls stamped on a finding require.
|
||||
///
|
||||
/// For the finding page. Unknown ids are left out; at most
|
||||
/// [`MAX_CONTROL_LOOKUP`] are described.
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/controls",
|
||||
tag = "Compliance",
|
||||
params(ControlIdsQuery),
|
||||
responses(
|
||||
(status = 200, description = "The controls"),
|
||||
(status = 401, description = "No valid bearer token"),
|
||||
)
|
||||
)]
|
||||
#[tracing::instrument(skip_all)]
|
||||
pub async fn describe_controls(
|
||||
Extension(agent): AgentExt,
|
||||
|
||||
@@ -18,11 +18,22 @@ fn open_findings_of(target_id: &str) -> mongodb::bson::Document {
|
||||
doc! { "repo_id": target_id, "status": { "$in": open } }
|
||||
}
|
||||
|
||||
/// The open findings of target `id`, counted by type and severity and by
|
||||
/// folder. Tenant-scoped like the findings list, and read-only, so every
|
||||
/// A target's open findings, counted by type and severity and by folder.
|
||||
///
|
||||
/// Tenant-scoped like the findings list, and read-only, so every
|
||||
/// role that may read findings may read it. A target without open findings
|
||||
/// (or of another tenant, whose findings are not in this tenant's database)
|
||||
/// gets an empty breakdown.
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/targets/{id}/finding-breakdown",
|
||||
tag = "Findings",
|
||||
params(("id" = String, Path, description = "The target's id")),
|
||||
responses(
|
||||
(status = 200, description = "The breakdown"),
|
||||
(status = 401, description = "No valid bearer token"),
|
||||
)
|
||||
)]
|
||||
#[tracing::instrument(skip_all, fields(target_id = %id))]
|
||||
pub async fn finding_breakdown(
|
||||
Extension(agent): AgentExt,
|
||||
|
||||
@@ -46,9 +46,11 @@ impl From<ManualKind> for ScanType {
|
||||
}
|
||||
}
|
||||
|
||||
/// `POST /api/v1/targets/{id}/findings`.
|
||||
#[derive(Debug, Deserialize)]
|
||||
/// The body of [`create_finding`]: a finding from a manual test.
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct CreateFindingRequest {
|
||||
/// `dast` or `pentest`: the manual test the finding comes from.
|
||||
#[schema(value_type = String, example = "pentest")]
|
||||
pub kind: ManualKind,
|
||||
/// The tool used, if any; `manual` otherwise.
|
||||
#[serde(default)]
|
||||
@@ -66,9 +68,14 @@ pub enum ImportFormat {
|
||||
}
|
||||
|
||||
/// `?format=&kind=` of an import.
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Deserialize, utoipa::IntoParams)]
|
||||
#[into_params(parameter_in = Query)]
|
||||
pub struct ImportParams {
|
||||
/// `sarif` or `zap`.
|
||||
#[param(value_type = String, example = "sarif")]
|
||||
pub format: ImportFormat,
|
||||
/// `dast` or `pentest`.
|
||||
#[param(value_type = String, example = "dast")]
|
||||
pub kind: ManualKind,
|
||||
}
|
||||
|
||||
@@ -124,8 +131,26 @@ async fn insert_new(db: &Database, finding: &mut Finding) -> Result<bool, Status
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// POST /api/v1/targets/{id}/findings — add one finding by hand. 409 when the
|
||||
/// same finding (tool, title, location) is already on the target.
|
||||
/// Add a finding from a manual DAST run or penetration test.
|
||||
///
|
||||
/// 409 when the same finding (tool, title, location) is already on the
|
||||
/// target. Only an organisation's administrator (IT_ADMIN, OWNER).
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/api/v1/targets/{id}/findings",
|
||||
tag = "Findings",
|
||||
params(("id" = String, Path, description = "The target's id")),
|
||||
request_body = CreateFindingRequest,
|
||||
responses(
|
||||
(status = 201, description = "The finding"),
|
||||
(status = 400, description = "Not an id"),
|
||||
(status = 403, description = "Only an administrator adds findings by hand"),
|
||||
(status = 404, description = "No such target"),
|
||||
(status = 409, description = "The same finding is already on the target"),
|
||||
(status = 422, description = "A malformed finding"),
|
||||
(status = 401, description = "No valid bearer token"),
|
||||
)
|
||||
)]
|
||||
#[tracing::instrument(skip_all, fields(target_id = %id))]
|
||||
pub async fn create_finding(
|
||||
Extension(agent): AgentExt,
|
||||
@@ -164,9 +189,26 @@ pub async fn create_finding(
|
||||
))
|
||||
}
|
||||
|
||||
/// POST /api/v1/targets/{id}/findings/import?format=sarif|zap&kind=dast|pentest
|
||||
/// — the body is the report itself. Findings already on the target are
|
||||
/// skipped, so importing a report again adds nothing.
|
||||
/// Import the findings of a SARIF or ZAP report; the body is the report.
|
||||
///
|
||||
/// Findings already on the target are skipped, so importing a report again
|
||||
/// adds nothing. Only an organisation's administrator (IT_ADMIN, OWNER).
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/api/v1/targets/{id}/findings/import",
|
||||
tag = "Findings",
|
||||
params(("id" = String, Path, description = "The target's id"), ImportParams),
|
||||
request_body(content = Object, description = "The SARIF or ZAP JSON report"),
|
||||
responses(
|
||||
(status = 200, description = "What the import did"),
|
||||
(status = 400, description = "Not an id"),
|
||||
(status = 403, description = "Only an administrator imports findings"),
|
||||
(status = 404, description = "No such target"),
|
||||
(status = 413, description = "The report is larger than 20 MiB"),
|
||||
(status = 422, description = "The report cannot be read"),
|
||||
(status = 401, description = "No valid bearer token"),
|
||||
)
|
||||
)]
|
||||
#[tracing::instrument(skip_all, fields(target_id = %id))]
|
||||
pub async fn import_findings(
|
||||
Extension(agent): AgentExt,
|
||||
|
||||
@@ -18,13 +18,24 @@ use compliance_core::tenant_ctx::TenantCtx;
|
||||
|
||||
use super::dto::{collect_cursor_async, tenant_db, AgentExt};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
/// The body of [`assess_target`].
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct AssessRequest {
|
||||
/// The target / repo id whose findings are assessed.
|
||||
pub target_id: String,
|
||||
}
|
||||
|
||||
/// `POST /api/v1/oscal/assess` — OSCAL assessment-results for a target's findings.
|
||||
/// A target's findings as OSCAL assessment results.
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/api/v1/oscal/assess",
|
||||
tag = "Compliance",
|
||||
request_body = AssessRequest,
|
||||
responses(
|
||||
(status = 200, description = "The OSCAL assessment results"),
|
||||
(status = 401, description = "No valid bearer token"),
|
||||
)
|
||||
)]
|
||||
pub async fn assess_target(
|
||||
Extension(agent): AgentExt,
|
||||
tenant: TenantCtx,
|
||||
|
||||
@@ -41,7 +41,7 @@ pub fn build_router() -> Router {
|
||||
fn described_routes() -> OpenApiRouter {
|
||||
OpenApiRouter::with_openapi(openapi::ApiDoc::openapi())
|
||||
.route("/api/v1/health", get(handlers::health))
|
||||
.route("/api/v1/oscal/assess", post(handlers::oscal::assess_target))
|
||||
.routes(routes!(handlers::oscal::assess_target))
|
||||
.route("/api/v1/stats/overview", get(handlers::stats_overview))
|
||||
// The tenant's projects (owned by the registry), for assigning targets.
|
||||
.route("/api/v1/projects", get(handlers::projects::list_projects))
|
||||
@@ -154,34 +154,15 @@ fn described_routes() -> OpenApiRouter {
|
||||
"/api/v1/targets/{id}/sbom-ecosystems",
|
||||
get(handlers::sbom_ecosystems::list_sbom_ecosystems),
|
||||
)
|
||||
.route(
|
||||
"/api/v1/targets/{id}/evidence-pack",
|
||||
get(handlers::evidence::evidence_pack),
|
||||
)
|
||||
.route(
|
||||
"/api/v1/targets/{id}/compliance",
|
||||
get(handlers::evidence::compliance_view),
|
||||
)
|
||||
.route(
|
||||
"/api/v1/targets/{id}/finding-breakdown",
|
||||
get(handlers::finding_breakdown::finding_breakdown),
|
||||
)
|
||||
.route(
|
||||
"/api/v1/compliance/summary",
|
||||
get(handlers::evidence::compliance_summary),
|
||||
)
|
||||
.route(
|
||||
"/api/v1/controls",
|
||||
get(handlers::evidence::describe_controls),
|
||||
)
|
||||
.routes(routes!(handlers::evidence::evidence_pack))
|
||||
.routes(routes!(handlers::evidence::compliance_view))
|
||||
.routes(routes!(handlers::finding_breakdown::finding_breakdown))
|
||||
.routes(routes!(handlers::evidence::compliance_summary))
|
||||
.routes(routes!(handlers::evidence::describe_controls))
|
||||
// Findings from a manual DAST run or penetration test.
|
||||
.route(
|
||||
"/api/v1/targets/{id}/findings",
|
||||
post(handlers::manual_findings::create_finding),
|
||||
)
|
||||
.route(
|
||||
"/api/v1/targets/{id}/findings/import",
|
||||
post(handlers::manual_findings::import_findings).layer(DefaultBodyLimit::max(
|
||||
.routes(routes!(handlers::manual_findings::create_finding))
|
||||
.routes(
|
||||
routes!(handlers::manual_findings::import_findings).layer(DefaultBodyLimit::max(
|
||||
handlers::manual_findings::MAX_IMPORT_BYTES,
|
||||
)),
|
||||
)
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
# such route, so the list only ever shrinks. Describe a route with
|
||||
# `#[utoipa::path]` and `.routes(routes!(...))`, then delete its line.
|
||||
/api/v1/health
|
||||
/api/v1/oscal/assess
|
||||
/api/v1/stats/overview
|
||||
/api/v1/projects
|
||||
/api/v1/metering/usage
|
||||
@@ -30,13 +29,6 @@
|
||||
/api/v1/targets/{id}/cve-groups
|
||||
/api/v1/targets/{id}/cve-groups/vex
|
||||
/api/v1/targets/{id}/sbom-ecosystems
|
||||
/api/v1/targets/{id}/evidence-pack
|
||||
/api/v1/targets/{id}/compliance
|
||||
/api/v1/targets/{id}/finding-breakdown
|
||||
/api/v1/compliance/summary
|
||||
/api/v1/controls
|
||||
/api/v1/targets/{id}/findings
|
||||
/api/v1/targets/{id}/findings/import
|
||||
/api/v1/pentest/lookup-repo
|
||||
/api/v1/pentest/sessions
|
||||
/api/v1/pentest/sessions/{id}
|
||||
|
||||
Reference in new issue
Block a user