diff --git a/compliance-agent/src/api/handlers/dto.rs b/compliance-agent/src/api/handlers/dto.rs index 08e2258..baecd79 100644 --- a/compliance-agent/src/api/handlers/dto.rs +++ b/compliance-agent/src/api/handlers/dto.rs @@ -343,16 +343,24 @@ pub struct UpdateFeedbackRequest { pub feedback: String, } -#[derive(Deserialize)] +/// Which SBOM components a list or summary shows. +#[derive(Deserialize, utoipa::IntoParams)] +#[into_params(parameter_in = Query)] pub struct SbomFilter { + /// Only one target's components (its id). #[serde(default)] pub repo_id: Option, + /// Only one package manager's components, such as `npm` or `cargo`. #[serde(default)] pub package_manager: Option, + /// Only components whose name contains this text. #[serde(default)] pub q: Option, + /// Only components with known vulnerabilities (`true`), or only those + /// without (`false`). #[serde(default)] pub has_vulns: Option, + /// Only components with this licence. #[serde(default)] pub license: Option, /// Only components an image is known to contain (`true`), or only the @@ -363,9 +371,13 @@ pub struct SbomFilter { /// none and nobody has confirmed one. #[serde(default)] pub unresolved: Option, + /// The page, from 1 (default 1, at most 100 000). #[serde(default = "default_page", deserialize_with = "de_page")] + #[param(minimum = 1, maximum = 100_000)] pub page: u64, + /// Entries per page (default 50, at most 200). #[serde(default = "default_limit", deserialize_with = "de_limit")] + #[param(minimum = 1, maximum = 200)] pub limit: i64, } @@ -378,10 +390,15 @@ impl SbomFilter { } } -#[derive(Deserialize)] +/// The target and format of an SBOM export. +#[derive(Deserialize, utoipa::IntoParams)] +#[into_params(parameter_in = Query)] pub struct SbomExportParams { + /// The target (its id). pub repo_id: String, + /// `cyclonedx` (default) or `spdx`. #[serde(default = "default_export_format")] + #[param(example = "cyclonedx")] pub format: String, } @@ -389,9 +406,13 @@ fn default_export_format() -> String { "cyclonedx".to_string() } -#[derive(Deserialize)] +/// The two targets an SBOM diff compares. +#[derive(Deserialize, utoipa::IntoParams)] +#[into_params(parameter_in = Query)] pub struct SbomDiffParams { + /// The first target (its id). pub repo_a: String, + /// The second target (its id). pub repo_b: String, } diff --git a/compliance-agent/src/api/handlers/licenses.rs b/compliance-agent/src/api/handlers/licenses.rs index af808b4..21a7c7d 100644 --- a/compliance-agent/src/api/handlers/licenses.rs +++ b/compliance-agent/src/api/handlers/licenses.rs @@ -35,12 +35,16 @@ use crate::license_conclusions::MAX_CONCLUSIONS; pub const MAX_COMPONENTS: usize = 500; /// A component a licence is confirmed for, as the SBOM list shows it. -#[derive(Debug, Clone, Deserialize)] +#[derive(Debug, Clone, Deserialize, utoipa::ToSchema)] pub struct ComponentRef { + /// The package's name. pub name: String, + /// Its package manager, such as `npm` or `cargo`. pub package_manager: String, + /// Its version; empty with `all_versions`. #[serde(default)] pub version: String, + /// Its purl, when known. #[serde(default)] pub purl: Option, /// The licence the scan found, as the list shows it. Read only by a @@ -50,8 +54,9 @@ pub struct ComponentRef { } /// The body of [`conclude`]. -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, utoipa::ToSchema)] pub struct ConcludeRequest { + /// The components, at most 500. pub components: Vec, /// For every version of the packages, not just the listed ones. #[serde(default)] @@ -60,25 +65,38 @@ pub struct ConcludeRequest { /// licence of its own, named in `license_name`. #[serde(default)] pub license: Option, + /// The name of a licence of its own. #[serde(default)] pub license_name: Option, - /// Used for a licence of its own and where SPDX gives no category. + /// Used for a licence of its own and where SPDX gives no category, such + /// as `permissive`, `weak_copyleft` or `proprietary`. #[serde(default)] + #[schema(value_type = Option, example = "proprietary")] pub category: Option, + /// The copyright lines. #[serde(default)] pub copyright: Vec, + /// The licence's text. #[serde(default)] pub license_text: Option, + /// Where the licence is published. #[serde(default)] pub license_url: Option, + /// Where the licence was confirmed, such as a file or a contract. #[serde(default)] pub evidence: Option, + /// The contract a licence of its own comes from. #[serde(default)] pub contract_ref: Option, + /// When the licence ends. #[serde(default)] + #[schema(value_type = Option, format = Date)] pub valid_until: Option, + /// `shipped` or `build_only`. #[serde(default)] + #[schema(value_type = Option, example = "shipped")] pub usage: Option, + /// A note. #[serde(default)] pub note: Option, } @@ -196,8 +214,16 @@ fn conclusions_of( Ok(out) } -/// GET /api/v1/licenses/conclusions — every licence the workspace -/// confirmed, by package name. +/// Every licence the workspace confirmed, by package name. +#[utoipa::path( + get, + path = "/api/v1/licenses/conclusions", + tag = "Licences", + responses( + (status = 200, description = "The confirmed licences"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all)] pub async fn list_conclusions( Extension(agent): AgentExt, @@ -212,10 +238,22 @@ pub async fn list_conclusions( })) } -/// PUT /api/v1/licenses/conclusions — confirm a licence for one or more -/// components (one version, or every version of their packages). A second -/// confirmation of the same package and version replaces the first. 422 -/// with the reason when the licence or a field is not acceptable. +/// Confirm a licence for one or more components. +/// +/// One version, or every version of their packages. A second confirmation +/// of the same package and version replaces the first. 422 with the reason +/// when the licence or a field is not acceptable. +#[utoipa::path( + put, + path = "/api/v1/licenses/conclusions", + tag = "Licences", + request_body = ConcludeRequest, + responses( + (status = 200, description = "The licence was confirmed"), + (status = 422, description = "The licence or a field is not acceptable; `error` says why"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all)] pub async fn conclude( Extension(agent): AgentExt, @@ -261,15 +299,26 @@ pub async fn conclude( } /// The query of [`withdraw`]. -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, utoipa::IntoParams)] +#[into_params(parameter_in = Query)] pub struct WithdrawQuery { /// The conclusion's id (package and version, see /// [`license::conclusion_id`]); a query value, as it holds `/` and `@`. pub id: String, } -/// DELETE /api/v1/licenses/conclusions?id= — withdraw a confirmed licence; -/// the component shows the detected one again. 404 when there is none. +/// Withdraw a confirmed licence; the component shows the detected one again. +#[utoipa::path( + delete, + path = "/api/v1/licenses/conclusions", + tag = "Licences", + params(WithdrawQuery), + responses( + (status = 200, description = "The licence was withdrawn"), + (status = 404, description = "No such confirmed licence"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all)] pub async fn withdraw( Extension(agent): AgentExt, @@ -311,6 +360,16 @@ fn refuse_role() -> Refusal { ) } +/// The workspace's licence policy, and whether the requester may change it. +#[utoipa::path( + get, + path = "/api/v1/licenses/policy", + tag = "Licences", + responses( + (status = 200, description = "The policy"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all)] pub async fn get_policy( Extension(agent): AgentExt, @@ -324,6 +383,19 @@ pub async fn get_policy( }))) } +/// Replace the workspace's licence policy. +#[utoipa::path( + put, + path = "/api/v1/licenses/policy", + tag = "Licences", + request_body(content = Object, description = "The policy: which licences are allowed, need a review or are forbidden"), + responses( + (status = 200, description = "The policy was saved"), + (status = 403, description = "The role may not decide on licences (LEGAL, IT_ADMIN or OWNER)"), + (status = 422, description = "The policy is not acceptable; `error` says why"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all)] pub async fn put_policy( Extension(agent): AgentExt, @@ -437,9 +509,11 @@ fn decidable(entry: &SbomEntry) -> bool { .is_some_and(|l| spdx_license::is_spdx_expression(&spdx_license::normalise(l))) } -/// The query of [`check`] and [`notices`]. -#[derive(Debug, Deserialize)] +/// The query of [`check`]. +#[derive(Debug, Deserialize, utoipa::IntoParams)] +#[into_params(parameter_in = Query)] pub struct CheckQuery { + /// Only one target's components; every target's without. #[serde(default)] pub repo_id: Option, } @@ -447,6 +521,20 @@ pub struct CheckQuery { /// The most open components one check lists. pub const MAX_CHECK_ITEMS: usize = 2_000; +/// Judge the components against the licence policy. +/// +/// The counts per verdict, and the components that are forbidden, need a +/// review or expire soon, at most 2 000. +#[utoipa::path( + get, + path = "/api/v1/licenses/check", + tag = "Licences", + params(CheckQuery), + responses( + (status = 200, description = "The verdicts"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all)] pub async fn check( Extension(agent): AgentExt, @@ -522,13 +610,17 @@ pub async fn check( } /// The body of [`review`]. -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, utoipa::ToSchema)] pub struct ReviewRequest { + /// The components. pub components: Vec, /// For every version of the packages, not just the listed ones. #[serde(default)] pub all_versions: bool, + /// `approved` or `rejected`. + #[schema(value_type = String, example = "approved")] pub decision: ReviewDecision, + /// Why. #[serde(default)] pub note: Option, } @@ -639,6 +731,19 @@ fn reviewed( Ok(out) } +/// Decide in a legal review whether the components' licences may be used. +#[utoipa::path( + post, + path = "/api/v1/licenses/review", + tag = "Licences", + request_body = ReviewRequest, + responses( + (status = 200, description = "The review was saved"), + (status = 403, description = "The role may not decide on licences (LEGAL, IT_ADMIN or OWNER)"), + (status = 422, description = "A component without a licence to review; `error` says why"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all)] pub async fn review( Extension(agent): AgentExt, @@ -687,6 +792,19 @@ pub async fn review( }))) } +/// Withdraw a legal review. +#[utoipa::path( + delete, + path = "/api/v1/licenses/review", + tag = "Licences", + params(WithdrawQuery), + responses( + (status = 200, description = "The review was withdrawn"), + (status = 403, description = "The role may not decide on licences (LEGAL, IT_ADMIN or OWNER)"), + (status = 404, description = "No such review"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all)] pub async fn withdraw_review( Extension(agent): AgentExt, @@ -715,16 +833,31 @@ pub async fn withdraw_review( } /// The query of [`notices`]. -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, utoipa::IntoParams)] +#[into_params(parameter_in = Query)] pub struct NoticesQuery { + /// The target (its id). pub repo_id: String, + /// `text` (default) or `markdown`. #[serde(default)] + #[param(value_type = Option, example = "markdown")] pub format: NoticeFormat, /// Also list components only used to build. #[serde(default)] pub build_only: bool, } +/// A target's third-party notices to ship with the product. +#[utoipa::path( + get, + path = "/api/v1/sbom/notices", + tag = "Licences", + params(NoticesQuery), + responses( + (status = 200, description = "The notices file"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all)] pub async fn notices( Extension(agent): AgentExt, diff --git a/compliance-agent/src/api/handlers/sbom.rs b/compliance-agent/src/api/handlers/sbom.rs index 569c35d..7a84507 100644 --- a/compliance-agent/src/api/handlers/sbom.rs +++ b/compliance-agent/src/api/handlers/sbom.rs @@ -16,6 +16,16 @@ pub(crate) const MAX_EXPORT_COMPONENTS: u64 = 100_000; /// Package names listed per license in the summary; `count` stays exact. const MAX_LICENSE_PACKAGES: i64 = 100; +/// The package managers and licences the SBOM list can be filtered by. +#[utoipa::path( + get, + path = "/api/v1/sbom/filters", + tag = "SBOM", + responses( + (status = 200, description = "The package managers and licences"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all)] pub async fn sbom_filters( Extension(agent): AgentExt, @@ -50,6 +60,17 @@ pub async fn sbom_filters( }))) } +/// List the tenant's SBOM components, filtered and a page at a time. +#[utoipa::path( + get, + path = "/api/v1/sbom", + tag = "SBOM", + params(SbomFilter), + responses( + (status = 200, description = "A page of components"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all, fields(repo_id = ?filter.repo_id, package_manager = ?filter.package_manager))] pub async fn list_sbom( Extension(agent): AgentExt, @@ -198,6 +219,20 @@ async fn unresolved_ids( .collect() } +/// A target's SBOM as a CycloneDX or SPDX document to download. +/// +/// Never truncated: a target with more than 100 000 components is refused. +#[utoipa::path( + get, + path = "/api/v1/sbom/export", + tag = "SBOM", + params(SbomExportParams), + responses( + (status = 200, description = "The SBOM document"), + (status = 413, description = "Too many components to export"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all)] pub async fn export_sbom( Extension(agent): AgentExt, @@ -274,14 +309,27 @@ pub async fn export_sbom( } /// The target whose SBOM quality is asked for. -#[derive(serde::Deserialize)] +#[derive(serde::Deserialize, utoipa::IntoParams)] +#[into_params(parameter_in = Query)] pub struct SbomQualityParams { + /// The target (its id). pub repo_id: String, } -/// GET /api/v1/sbom/quality?repo_id= — the target's SBOM quality score -/// (sbomqs against BSI TR-03183-2 and NTIA, #496) from its newest scan that -/// scored one, with that scan's id and end; `data: null` when none did. +/// A target's SBOM quality score from its newest scan that scored one. +/// +/// sbomqs against BSI TR-03183-2 and NTIA (#496), with that scan's id and +/// end; `data: null` when none did. +#[utoipa::path( + get, + path = "/api/v1/sbom/quality", + tag = "SBOM", + params(SbomQualityParams), + responses( + (status = 200, description = "The score, or null"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all, fields(repo_id = %params.repo_id))] pub async fn sbom_quality( Extension(agent): AgentExt, @@ -308,6 +356,19 @@ pub async fn sbom_quality( })) } +/// The licences of the SBOM components, most components first. +/// +/// The confirmed licence where there is one, else the detected one. +#[utoipa::path( + get, + path = "/api/v1/sbom/licenses", + tag = "SBOM", + params(SbomFilter), + responses( + (status = 200, description = "One row per licence"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all)] pub async fn license_summary( Extension(agent): AgentExt, @@ -411,6 +472,19 @@ fn summarize_licenses( summaries } +/// Compare the SBOMs of two targets. +/// +/// The components only in one of them and those whose version differs. +#[utoipa::path( + get, + path = "/api/v1/sbom/diff", + tag = "SBOM", + params(SbomDiffParams), + responses( + (status = 200, description = "The differences"), + (status = 401, description = "No valid bearer token"), + ) +)] #[tracing::instrument(skip_all)] pub async fn sbom_diff( Extension(agent): AgentExt, diff --git a/compliance-agent/src/api/routes.rs b/compliance-agent/src/api/routes.rs index 60e6c11..e5a9c2f 100644 --- a/compliance-agent/src/api/routes.rs +++ b/compliance-agent/src/api/routes.rs @@ -185,31 +185,30 @@ fn described_routes() -> OpenApiRouter { handlers::manual_findings::MAX_IMPORT_BYTES, )), ) - .route("/api/v1/sbom", get(handlers::list_sbom)) - .route("/api/v1/sbom/filters", get(handlers::sbom_filters)) - .route("/api/v1/sbom/export", get(handlers::export_sbom)) - .route("/api/v1/sbom/licenses", get(handlers::license_summary)) - .route("/api/v1/sbom/quality", get(handlers::sbom_quality)) - .route("/api/v1/sbom/diff", get(handlers::sbom_diff)) + .routes(routes!(handlers::list_sbom)) + .routes(routes!(handlers::sbom_filters)) + .routes(routes!(handlers::export_sbom)) + .routes(routes!(handlers::license_summary)) + .routes(routes!(handlers::sbom_quality)) + .routes(routes!(handlers::sbom_diff)) // Licences the workspace confirms for its components. - .route( - "/api/v1/licenses/conclusions", - get(handlers::licenses::list_conclusions) - .put(handlers::licenses::conclude) - .delete(handlers::licenses::withdraw), - ) + .routes(routes!( + handlers::licenses::list_conclusions, + handlers::licenses::conclude, + handlers::licenses::withdraw + )) // The licence policy, what it says about each component, and the // legal review that resolves what it asks a review for. - .route( - "/api/v1/licenses/policy", - get(handlers::licenses::get_policy).put(handlers::licenses::put_policy), - ) - .route("/api/v1/licenses/check", get(handlers::licenses::check)) - .route( - "/api/v1/licenses/review", - post(handlers::licenses::review).delete(handlers::licenses::withdraw_review), - ) - .route("/api/v1/sbom/notices", get(handlers::licenses::notices)) + .routes(routes!( + handlers::licenses::get_policy, + handlers::licenses::put_policy + )) + .routes(routes!(handlers::licenses::check)) + .routes(routes!( + handlers::licenses::review, + handlers::licenses::withdraw_review + )) + .routes(routes!(handlers::licenses::notices)) .route("/api/v1/issues", get(handlers::list_issues)) .route("/api/v1/scan-runs", get(handlers::list_scan_runs)) // MCP token management (per-tenant API tokens for the MCP server) diff --git a/compliance-agent/src/api/undescribed_routes.txt b/compliance-agent/src/api/undescribed_routes.txt index c86d591..0f7e7b2 100644 --- a/compliance-agent/src/api/undescribed_routes.txt +++ b/compliance-agent/src/api/undescribed_routes.txt @@ -37,17 +37,6 @@ /api/v1/controls /api/v1/targets/{id}/findings /api/v1/targets/{id}/findings/import -/api/v1/sbom -/api/v1/sbom/filters -/api/v1/sbom/export -/api/v1/sbom/licenses -/api/v1/sbom/quality -/api/v1/sbom/diff -/api/v1/licenses/conclusions -/api/v1/licenses/policy -/api/v1/licenses/check -/api/v1/licenses/review -/api/v1/sbom/notices /api/v1/issues /api/v1/scan-runs /api/v1/mcp-servers