Skip to content

Commit

Permalink
docs: setup enforce digest rule
Browse files Browse the repository at this point in the history
  • Loading branch information
mxab committed May 8, 2024
1 parent 1cd553b commit 74c39e4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
14 changes: 14 additions & 0 deletions misc/hashitalk_secure2024/demos/digest/digest.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package digest

import rego.v1


errors contains err_msg if {
some g, t
input.TaskGroups[g].Tasks[t].Driver == "docker"
image := input.TaskGroups[g].Tasks[t].Config.image

not regex.match( "@sha256:[a-f0-9]{64}$", image)

err_msg := sprintf("Invalid image reference: %v", [image])
}
22 changes: 22 additions & 0 deletions misc/hashitalk_secure2024/demos/digest/digest_test.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package digest_test

import rego.v1

import data.digest

test_has_error_when_image_is_tagged if {
result := digest.errors with input as {"TaskGroups": [{"Tasks": [{
"Driver": "docker",
"Config": {"image": "alpine:3.19.1"},
}]}]}
result == { "Invalid image reference: alpine:3.19.1" }
}

test_has_no_errors_if_image_uses_digest if {
result := digest.errors with input as {"TaskGroups": [{"Tasks": [{
"Driver": "docker",
"Config": {"image": "alpine@sha256:c5b1261d6d3e43071626931fc004f70149baeba2c8ec672bd4f27761f8e1ad6b"},
}]}]}

result == set()
}

0 comments on commit 74c39e4

Please sign in to comment.