Skip to content

Commit 5dc73d6

Browse files
authored
feat(docs): Some SBOM policies (#1125)
Signed-off-by: Jose I. Paris <[email protected]>
1 parent 8f489ed commit 5dc73d6

File tree

7 files changed

+192
-9
lines changed

7 files changed

+192
-9
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2024 The Chainloop Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: workflowcontract.chainloop.dev/v1
16+
kind: Policy
17+
metadata:
18+
name: cyclonedx-banned-licenses
19+
description: Checks that components don't have banned licenses
20+
annotations:
21+
category: sbom
22+
spec:
23+
type: SBOM_CYCLONEDX_JSON
24+
embedded: |
25+
package main
26+
27+
import rego.v1
28+
29+
banned_licenses := ["GPL-2.0", "GPL-3.0"]
30+
31+
deny contains ref if {
32+
some i
33+
comp := input.components[i]
34+
some j
35+
license := comp.licenses[j].license
36+
license.name == banned_licenses[_]
37+
ref := sprintf("Forbidden license %v for %v (%v)", [license.name, comp.name, comp["bom-ref"]])
38+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2024 The Chainloop Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: workflowcontract.chainloop.dev/v1
16+
kind: Policy
17+
metadata:
18+
name: cyclonedx-banned-packages
19+
description: Checks that there are no banned packages in the SBOM.
20+
annotations:
21+
category: sbom
22+
spec:
23+
type: SBOM_CYCLONEDX_JSON
24+
embedded: |
25+
package main
26+
27+
import rego.v1
28+
29+
# It supports packages with version. When specified, requires it to be semver, and would also fail when version is lower
30+
banned_packages := ["[email protected]"]
31+
32+
# deny all versions
33+
deny contains ref if {
34+
some i
35+
comp := input.components[i]
36+
some j
37+
banned := banned_packages[j]
38+
nv := split(banned, "@")
39+
not nv[1]
40+
comp.name == nv[0]
41+
ref := sprintf("Banned package: %v", [comp.name])
42+
}
43+
44+
# deny specific versions
45+
deny contains ref if {
46+
some i
47+
comp := input.components[i]
48+
some j
49+
banned := banned_packages[j]
50+
nv := split(banned, "@")
51+
comp.name == nv[0]
52+
result := semver.compare(comp.version, nv[1])
53+
result <= 0
54+
ref := sprintf("Banned package: %v %v", [comp.name, comp.version])
55+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2024 The Chainloop Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: workflowcontract.chainloop.dev/v1
16+
kind: Policy
17+
metadata:
18+
name: cyclonedx-required-packages
19+
description: Checks that SBOM has a maximum of 30 days old
20+
annotations:
21+
category: sbom
22+
spec:
23+
type: SBOM_CYCLONEDX_JSON
24+
embedded: |
25+
package main
26+
27+
import rego.v1
28+
29+
limit := 30
30+
31+
nanosecs_per_second = (1000 * 1000) * 1000
32+
33+
nanosecs_per_day = ((24 * 60) * 60) * nanosecs_per_second
34+
35+
maximum_age = limit * nanosecs_per_day
36+
37+
deny contains msg if {
38+
sbom_ns = time.parse_rfc3339_ns(input.metadata.timestamp)
39+
exceeding = time.now_ns() - (sbom_ns + maximum_age)
40+
exceeding > 0
41+
msg := sprintf("SBOM created at: %s which is too old (freshness limit set to %d days)", [input.metadata.timestamp, limit])
42+
}

docs/examples/policies/cyclonedx-licenses.yaml renamed to docs/examples/policies/sbom/cyclonedx-licenses.yaml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,24 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# Checks that all components have a license
1615
apiVersion: workflowcontract.chainloop.dev/v1
1716
kind: Policy
1817
metadata:
1918
name: cyclonedx-licenses
19+
description: Checks for components without licenses
20+
annotations:
21+
category: sbom
2022
spec:
2123
type: SBOM_CYCLONEDX_JSON
2224
embedded: |
2325
package main
2426
25-
deny[msg] {
26-
count(without_license) > 0
27-
msg := "SBOM has components without licenses"
28-
}
29-
30-
without_license = {comp.purl |
27+
import rego.v1
28+
29+
deny contains ref if {
3130
some i
3231
comp := input.components[i]
3332
not comp.licenses
33+
# log name and bom-ref fields
34+
ref := sprintf("Missing licenses for %v (%v)", [comp.name, comp["bom-ref"]])
3435
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2024 The Chainloop Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: workflowcontract.chainloop.dev/v1
16+
kind: Policy
17+
metadata:
18+
name: cyclonedx-required-packages
19+
description: Checks that SBOM contains required packages
20+
annotations:
21+
category: sbom
22+
spec:
23+
type: SBOM_CYCLONEDX_JSON
24+
embedded: |
25+
package main
26+
27+
import rego.v1
28+
29+
required_packages := {"glibc", "libcrypto3"}
30+
31+
deny contains msg if {
32+
count(all_matches) != count(required_packages)
33+
missing := required_packages - all_matches
34+
some i
35+
msg := sprintf("missing package: %v", [missing[i]])
36+
}
37+
38+
all_matches contains name if {
39+
some i
40+
comp := input.components[i]
41+
comp.name == required_packages[_]
42+
name := comp.name
43+
}

docs/examples/policies/sbom-present.yaml renamed to docs/examples/policies/sbom/sbom-present.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ apiVersion: workflowcontract.chainloop.dev/v1
1616
kind: Policy
1717
metadata:
1818
name: sbom-present
19+
description: Checks a SBOM is present in the attestation materials
20+
annotations:
21+
category: sbom
1922
spec:
2023
type: ATTESTATION
2124
embedded: |

docs/examples/policies/sbom-syft.yaml renamed to docs/examples/policies/sbom/spdx-sbom-syft.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ apiVersion: workflowcontract.chainloop.dev/v1
1616
kind: Policy
1717
metadata:
1818
name: made-with-syft
19+
description: Verifies that the SPDX was created with Syft
20+
annotations:
21+
category: sbom
1922
spec:
2023
type: SBOM_SPDX_JSON
2124
embedded: |
2225
package main
2326
2427
import future.keywords.in
25-
26-
# Verifies that the SPDX was created with Syft
2728
2829
deny[msg] {
2930
not made_with_syft

0 commit comments

Comments
 (0)