-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
5 changed files
with
129 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# | ||
# METADATA | ||
# title: Tekton Task Step image policies | ||
# description: >- | ||
# This package ensures that a Task definition contains valid values for the image references | ||
# used by the Task's steps. | ||
# | ||
package step_images | ||
|
||
import rego.v1 | ||
|
||
import data.lib | ||
|
||
# METADATA | ||
# title: Step images are valid | ||
# description: >- | ||
# Confirm that each step in the Task uses a container image that is accessible. | ||
# custom: | ||
# short_name: step_images_accessible | ||
# failure_msg: Step %d uses inaccessible image ref '%s' | ||
# solution: >- | ||
# Make sure the container image used in each step of the Task is pushed to the | ||
# registry and that it can be fetched. | ||
# | ||
deny contains result if { | ||
input.kind == "Task" | ||
|
||
some step_index, step in input.spec.steps | ||
image_ref := step.image | ||
is_null(ec.oci.image_manifest(image_ref)) | ||
|
||
result := lib.result_helper_with_term( | ||
rego.metadata.chain(), | ||
[step_index, image_ref], | ||
image_ref, | ||
) | ||
} |
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,68 @@ | ||
package step_images_test | ||
|
||
import rego.v1 | ||
|
||
import data.lib | ||
import data.step_images | ||
|
||
test_looks_at_tasks_only if { | ||
pipeline := { | ||
"kind": "Pipeline", | ||
"spec": {"steps": [{"image": "registry.io/repository/not_ok"}]}, | ||
} | ||
|
||
lib.assert_empty(step_images.deny) with input as pipeline | ||
} | ||
|
||
test_task_with_no_steps if { | ||
task := {"kind": "Task"} | ||
|
||
lib.assert_empty(step_images.deny) with input as task | ||
} | ||
|
||
test_task_with_valid_steps if { | ||
task := { | ||
"kind": "Task", | ||
"spec": {"steps": [ | ||
{"image": "registry.io/repository/ok:1"}, | ||
{"image": "registry.io/repository/ok:2"}, | ||
{"image": "registry.io/repository/ok:3"}, | ||
]}, | ||
} | ||
|
||
lib.assert_empty(step_images.deny) with input as task with ec.oci.image_manifest as mock_image_manifest | ||
} | ||
|
||
test_task_with_invalid_steps if { | ||
task := { | ||
"kind": "Task", | ||
"spec": {"steps": [ | ||
{"image": "registry.io/repository/ok:1"}, | ||
{"image": "registry.io/repository/not_ok:2"}, | ||
{"image": "registry.io/repository/ok:3"}, | ||
{"image": "registry.io/repository/not_ok:4"}, | ||
{"image": "registry.io/repository/ok:5"}, | ||
]}, | ||
} | ||
|
||
expected := { | ||
{ | ||
"code": "step_images.step_images_accessible", | ||
"msg": "Step 1 uses inaccessible image ref 'registry.io/repository/not_ok:2'", | ||
"term": "registry.io/repository/not_ok:2", | ||
}, | ||
{ | ||
"code": "step_images.step_images_accessible", | ||
"msg": "Step 3 uses inaccessible image ref 'registry.io/repository/not_ok:4'", | ||
"term": "registry.io/repository/not_ok:4", | ||
}, | ||
} | ||
|
||
lib.assert_equal_results(expected, step_images.deny) with input as task | ||
with ec.oci.image_manifest as mock_image_manifest | ||
} | ||
|
||
mock_image_manifest(ref) := m if { | ||
startswith(ref, "registry.io/repository/ok") | ||
m := {} | ||
} else := null |