generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a new check to validate npm provenance and extract facts fo…
…r policy engine Signed-off-by: behnazh-w <[email protected]>
- Loading branch information
Showing
8 changed files
with
491 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* Copyright (c) 2023 - 2024, Oracle and/or its affiliates. All rights reserved. */ | ||
/* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/. */ | ||
|
||
/* Souffle datalog rules to assist in authoring in-toto policies.*/ | ||
|
||
/** | ||
* This relation provides the external parameters of a SLSA v1 provenance generated by npm. | ||
The external parameters include details of the triggering hosted build service workflow. | ||
|
||
Here is the related section of an example predicate we process in this relation: | ||
"externalParameters": { | ||
"workflow": { | ||
"ref": "refs/heads/main", | ||
"repository": "https://github.com/npm/node-semver", | ||
"path": ".github/workflows/release.yml" | ||
} | ||
}, | ||
|
||
Parameters: | ||
component_id: number | ||
The target software component id. | ||
purl: symbol | ||
The Package URL identifier for the provenance subject. | ||
ref: symbol | ||
The Git reference. | ||
repository: symbol | ||
The repository URL. | ||
path: symbol | ||
The GitHub Actions workflow path. | ||
|
||
*/ | ||
.decl slsa_v1_npm_external_parameters(component_id: number, purl: symbol, ref: symbol, repository: symbol, path: symbol) | ||
|
||
slsa_v1_npm_external_parameters(component_id, purl, ref, repository, path):- | ||
provenance(prov_id, component_id, _, _, _, _), | ||
statement(stmt_id, prov_id, "https://in-toto.io/Statement/v1", "https://slsa.dev/provenance/v1"), | ||
subject(sub_id, stmt_id, purl), | ||
predicate(pred_id, stmt_id), | ||
build_definition(build_id, pred_id, _), | ||
external_parameters(external_params_id, build_id), | ||
workflow(_, external_params_id, ref, repository, path). | ||
|
||
/** | ||
* This relation provides the external parameters of a SLSA v1 provenance generated by npm. | ||
The external parameters include details of the triggering hosted build service workflow. | ||
|
||
Here is the related section of an example predicate we process in this relation: | ||
"internalParameters": { | ||
"github": { | ||
"event_name": "push", | ||
"repository_id": "1357199", | ||
"repository_owner_id": "6078720" | ||
} | ||
}, | ||
|
||
|
||
Parameters: | ||
component_id: number | ||
The target software component id. | ||
purl: symbol | ||
The Package URL identifier for the provenance subject. | ||
github_event_name: symbol | ||
TODO | ||
github_repository_id: symbol | ||
TODO | ||
github_repository_owner_id: symbol | ||
TODO | ||
|
||
*/ | ||
.decl slsa_v1_npm_internal_parameters( | ||
component_id: number, | ||
purl: symbol, | ||
github_event_name: symbol, | ||
github_repository_id: symbol, | ||
github_repository_owner_id: symbol | ||
) | ||
|
||
slsa_v1_npm_internal_parameters( | ||
component_id, | ||
purl, | ||
github_event_name, | ||
github_repository_id, | ||
github_repository_owner_id | ||
):- | ||
provenance(prov_id, component_id, _, _, _, _), | ||
statement(stmt_id, prov_id, "https://in-toto.io/Statement/v1", "https://slsa.dev/provenance/v1"), | ||
subject(sub_id, stmt_id, purl), | ||
predicate(pred_id, stmt_id), | ||
build_definition(build_id, pred_id, _), | ||
internal_parameters(_, build_id, github_event_name, github_repository_id, github_repository_owner_id). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* Copyright (c) 2024 - 2024, Oracle and/or its affiliates. All rights reserved. */ | ||
/* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/. */ | ||
|
||
#include "prelude.dl" | ||
|
||
Policy("test_policy", component_id, "") :- | ||
// Checks if the npm attestation has been successfully processed. | ||
check_passed(component_id, "mcn_npm_attestation_validation_1"), | ||
// This relation provides the external parameters of a SLSA v1 provenance generated by npm. | ||
slsa_v1_npm_external_parameters(component_id, purl, ref, repository, path), | ||
// This relation provides the internal parameters of a SLSA v1 provenance generated by npm. | ||
slsa_v1_npm_internal_parameters(component_id, purl, event_name, repository_id, repository_owner_id), | ||
// This match constraint makes sure the subjects we are interested in exist in the provenance. | ||
match("pkg:npm/semver@.*", purl), | ||
// Here we can add constraints that we are interested in. | ||
approved_refs(ref), | ||
approved_repository_owner_ids(repository_owner_id), | ||
repository = "https://github.com/npm/node-semver", | ||
path = ".github/workflows/release.yml". | ||
|
||
Policy("test_policy", component_id, "") :- | ||
// Checks if the npm attestation has been successfully processed. | ||
check_passed(component_id, "mcn_npm_attestation_validation_1"), | ||
// Checks if the repository URL in the provenance matches the repository metadata on deps.dev. | ||
check_passed(component_id, "mcn_provenance_derived_repo_1"), | ||
// Checks if the commit hash in the provenance matches the release tag. | ||
check_passed(component_id, "mcn_provenance_derived_commit_1"), | ||
// This relation provides the external parameters of a SLSA v1 provenance generated by npm. | ||
slsa_v1_npm_external_parameters(component_id, purl, ref, repository, path), | ||
// This relation provides the internal parameters of a SLSA v1 provenance generated by npm. | ||
slsa_v1_npm_internal_parameters(component_id, purl, event_name, repository_id, repository_owner_id), | ||
// This match constraint makes sure the subjects we are interested in exist in the provenance. | ||
match("pkg:npm/semver@.*", purl), | ||
// Here we can add constraints that we are interested in. | ||
approved_refs(ref), | ||
approved_repository_owner_ids(repository_owner_id), | ||
path = ".github/workflows/release.yml". | ||
|
||
// Create a relation containing the approved Git branches for publishing the artifact. | ||
.decl approved_refs(name: symbol) | ||
approved_refs("refs/heads/main"). | ||
approved_refs("refs/heads/master"). | ||
approved_refs("refs/heads/release"). | ||
|
||
// Create a relation containing the approved repository owner IDs for publishing the artifact. | ||
.decl approved_repository_owner_ids(name: symbol) | ||
approved_repository_owner_ids("6078720"). | ||
approved_repository_owner_ids("71096353"). | ||
|
||
// Apply the policy to the desired software components. | ||
apply_policy_to("test_policy", component_id) :- | ||
is_component(component_id, purl), | ||
match("pkg:npm/semver@.*", purl). |
Oops, something went wrong.