-
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
- Loading branch information
1 parent
29a38b6
commit 80de33a
Showing
20 changed files
with
7,413 additions
and
2 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
15 changes: 15 additions & 0 deletions
15
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,15 @@ | ||
apiVersion: config.ratify.deislabs.io/v1beta1 | ||
kind: Verifier | ||
metadata: | ||
name: verifier-vulnerabilityreport | ||
spec: | ||
name: vulnerabilityreport | ||
artifactTypes: application/sarif+json | ||
parameters: | ||
nestedReferences: application/vnd.cncf.notary.signature | ||
maximumAge: 24h | ||
disallowedSeverity: | ||
- high | ||
- critical | ||
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,80 @@ | ||
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 | ||
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_signature_pass_verify(value) | ||
} | ||
notary_signature_pass_verify(nestedReports) if { | ||
count_with_success := notary_signature_signature_count(nestedReports) | ||
count_with_success > 0 | ||
} | ||
notary_signature_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) | ||
} | ||
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"] |
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,82 @@ | ||
apiVersion: templates.gatekeeper.sh/v1beta1 | ||
kind: ConstraintTemplate | ||
metadata: | ||
name: vulnerabilityreportvalidation | ||
spec: | ||
crd: | ||
spec: | ||
names: | ||
kind: VulnerabilityReportValidation | ||
validation: | ||
openAPIV3Schema: | ||
type: object | ||
properties: | ||
issuer: | ||
type: string | ||
targets: | ||
- target: admission.k8s.gatekeeper.sh | ||
rego: | | ||
package vulnerabilityreportvalidation | ||
# TODO: add support for custom reason message propagating to user | ||
import future.keywords.if | ||
import future.keywords.in | ||
import future.keywords.every | ||
default require_signature := false # change to true to require notation signature on vulnerability report | ||
# Get data from Ratify | ||
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] | ||
vuln_results := [res | subject_result.verifierReports[i].name == "vulnerabilityreport"; res := subject_result.verifierReports[i]] | ||
count(vuln_results) > 0 | ||
not process_vuln_reports(vuln_results) | ||
result := sprintf("Subject failed verification: %s", [subject_validation[0]]) | ||
} | ||
process_vuln_reports(reports) if { | ||
# At least one report must be valid | ||
some vuln_report in reports | ||
vuln_report.isSuccess == true | ||
valid_signatures(vuln_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 | ||
} |
Oops, something went wrong.