-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add vulnerability report verifier (#1173)
- Loading branch information
1 parent
00f16de
commit 60bc25f
Showing
28 changed files
with
7,884 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
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
14 changes: 14 additions & 0 deletions
14
config/samples/config_v1beta1_verifier_vulnerabilityreport.yaml
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,14 @@ | ||
apiVersion: config.ratify.deislabs.io/v1beta1 | ||
kind: Verifier | ||
metadata: | ||
name: verifier-vulnerabilityreport | ||
spec: | ||
name: vulnerabilityreport | ||
artifactTypes: application/sarif+json | ||
parameters: | ||
maximumAge: 24h | ||
disallowedSeverities: | ||
- high | ||
- critical | ||
denylistCVEs: | ||
- CVE-2021-44228 # Log4Shell |
11 changes: 11 additions & 0 deletions
11
config/samples/config_v1beta1_verifier_vulnerabilityreport2.yaml
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,11 @@ | ||
apiVersion: config.ratify.deislabs.io/v1beta1 | ||
kind: Verifier | ||
metadata: | ||
name: verifier-vulnerabilityreport | ||
spec: | ||
name: vulnerabilityreport | ||
artifactTypes: application/sarif+json | ||
parameters: | ||
maximumAge: 24h | ||
denylistCVEs: | ||
- CVE-2021-44228 # Log4Shell |
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
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
11 changes: 11 additions & 0 deletions
11
library/notation-nested-validation/samples/constraint.yaml
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,11 @@ | ||
apiVersion: constraints.gatekeeper.sh/v1beta1 | ||
kind: NotationNestedValidation | ||
metadata: | ||
name: notation-nested-constraint | ||
spec: | ||
enforcementAction: deny | ||
match: | ||
kinds: | ||
- apiGroups: [""] | ||
kinds: ["Pod"] | ||
namespaces: ["default"] |
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,88 @@ | ||
apiVersion: templates.gatekeeper.sh/v1beta1 | ||
kind: ConstraintTemplate | ||
metadata: | ||
name: notationnestedvalidation | ||
spec: | ||
crd: | ||
spec: | ||
names: | ||
kind: NotationNestedValidation | ||
validation: | ||
openAPIV3Schema: | ||
type: object | ||
properties: | ||
issuer: | ||
type: string | ||
targets: | ||
- target: admission.k8s.gatekeeper.sh | ||
rego: | | ||
package notationnestedvalidation | ||
# This template defines policy for notation nested validation. | ||
# It checks the following: | ||
# - If there are any system errors | ||
# - If there are errors for any of the images | ||
# - Each image has a valid notary project signature | ||
# - Each nested artifact has a valid notary project signature | ||
import future.keywords.if | ||
remote_data := response { | ||
images := [img | img = input.review.object.spec.containers[_].image] | ||
images_init := [img | img = input.review.object.spec.initContainers[_].image] | ||
images_ephemeral := [img | img = input.review.object.spec.ephemeralContainers[_].image] | ||
other_images := array.concat(images_init, images_ephemeral) | ||
all_images := array.concat(other_images, images) | ||
response := external_data({"provider": "ratify-provider", "keys": all_images}) | ||
} | ||
violation[{"msg": msg}] { | ||
general_violation[{"result": msg}] | ||
} | ||
# Check if there are any system errors | ||
general_violation[{"result": result}] { | ||
err := remote_data.system_error | ||
err != "" | ||
result := sprintf("System error calling external data provider: %s", [err]) | ||
} | ||
# Check if there are errors for any of the images | ||
general_violation[{"result": result}] { | ||
count(remote_data.errors) > 0 | ||
result := sprintf("Error validating one or more images: %s", remote_data.errors) | ||
} | ||
# Check if the success criteria is true | ||
general_violation[{"result": result}] { | ||
subject_validation := remote_data.responses[_] | ||
subject_result := subject_validation[1] | ||
failed_verify(subject_result) | ||
result := sprintf("Subject failed verification: %s", [subject_validation[0]]) | ||
} | ||
failed_verify(reports) if { | ||
newReports := {"nestedResults": reports.verifierReports} | ||
has_subject_failed_verify(newReports) | ||
} | ||
has_subject_failed_verify(nestedReports) if { | ||
[path, value] := walk(nestedReports) | ||
path[count(path) - 1] == "nestedResults" | ||
not notary_project_signature_pass_verify(value) | ||
} | ||
notary_project_signature_pass_verify(nestedReports) if { | ||
count_with_success := notary_project_signature_count(nestedReports) | ||
count_with_success > 0 | ||
} | ||
notary_project_signature_count(nestedReports) := number if { | ||
sigs := [x | | ||
some i | ||
nestedReports[i].isSuccess == true | ||
nestedReports[i].artifactType == "application/vnd.cncf.notary.signature" | ||
x := nestedReports[i].subject | ||
] | ||
number := count(sigs) | ||
} | ||
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,3 @@ | ||
# Ratify Rego Policies | ||
|
||
This folder contains `.rego` files that contain rego policies to be used ONLY with Ratify's [Rego Policy Provider](https://ratify.dev/docs/1.0/reference/crds/policies#regopolicy) |
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,70 @@ | ||
# Copyright The Ratify Authors. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
|
||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
package ratify.policy | ||
|
||
import future.keywords.if | ||
import future.keywords.in | ||
import future.keywords.every | ||
|
||
# This template defines policy for vulnerability report validation. | ||
# It checks the following: | ||
# - If there are any system errors | ||
# - If there are errors for any of the images | ||
# - There is at least one vulnerability report that was verified | ||
# - Only considers the latest vulnerability report | ||
# - The latest vulnerability report is valid (isSuccess = true) | ||
# - The latest vulnerability report has a valid notary project signature (if require_signature = true) | ||
|
||
default require_signature := false # change to true to require notary project signature on vulnerability report | ||
default valid := false | ||
|
||
# all artifacts MUST be valid | ||
valid { | ||
not failed_verify(input) | ||
} | ||
|
||
failed_verify(reports) { | ||
not process_vuln_reports(reports) | ||
} | ||
|
||
process_vuln_reports(subject_result) if { | ||
# collect verifier reports from vulnerabilityreport verifier | ||
vuln_results := [res | subject_result.verifierReports[i].verifierReports[j].name == "vulnerabilityreport"; res := subject_result.verifierReports[i].verifierReports[j]] | ||
count(vuln_results) > 0 | ||
# calculate the timestamp between current time and creation time | ||
timestamp_diff_results_map := {diff_in_ns: i | diff_in_ns := time.now_ns() - time.parse_rfc3339_ns(vuln_results[i].extensions["createdAt"])} | ||
count(timestamp_diff_results_map) > 0 | ||
# extract time difference durations into separate array to find global minimum | ||
timestamp_diff_results_arr := [key | timestamp_diff_results_map[key]] | ||
smallest_timestamp_diff := min(timestamp_diff_results_arr) | ||
# validate latest report | ||
process_vuln_report(vuln_results[timestamp_diff_results_map[smallest_timestamp_diff]]) | ||
} | ||
|
||
process_vuln_report(report) if { | ||
report.isSuccess == true | ||
valid_signatures(report) | ||
} | ||
|
||
valid_signatures(_) := true { | ||
require_signature == false | ||
} | ||
|
||
valid_signatures(report) := true { | ||
require_signature | ||
count(report.nestedResults) > 0 | ||
some nestedResult in report.nestedResults | ||
nestedResult.artifactType == "application/vnd.cncf.notary.signature" | ||
nestedResult.isSuccess | ||
} |
11 changes: 11 additions & 0 deletions
11
library/vulnerability-report-validation/samples/constraint.yaml
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,11 @@ | ||
apiVersion: constraints.gatekeeper.sh/v1beta1 | ||
kind: VulnerabilityReportValidation | ||
metadata: | ||
name: vulnerability-report-validation-constraint | ||
spec: | ||
enforcementAction: deny | ||
match: | ||
kinds: | ||
- apiGroups: [""] | ||
kinds: ["Pod"] | ||
namespaces: ["default"] |
Oops, something went wrong.