Skip to content

Commit 7e067e0

Browse files
authored
Merge pull request #1460 from st3penta/stricter-quay-expiration-rule
Make quay_expiration.expires_label rule stricter
2 parents b4a65f3 + c29526c commit 7e067e0

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

antora/docs/modules/ROOT/pages/packages/release_quay_expiration.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ Check the image metadata for the presence of a "quay.expires-after" label. If it
1616
*Solution*: Make sure the image is built without setting the "quay.expires-after" label. This label is usually set if the container image was built by an "on-pr" pipeline during pre-merge CI.
1717

1818
* Rule type: [rule-type-indicator failure]#FAILURE#
19-
* FAILURE message: `The image has a 'quay.expires-after' label set to '%s'`
19+
* FAILURE message: `The label 'quay.expires-after' is not allowed in the released image`
2020
* Code: `quay_expiration.expires_label`
2121
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/release/quay_expiration/quay_expiration.rego#L16[Source, window="_blank"]

policy/release/quay_expiration/quay_expiration.rego

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import data.lib
2626
# - release
2727
# - production
2828
# - staging
29-
# failure_msg: The image has a 'quay.expires-after' label set to '%s'
29+
# failure_msg: The label 'quay.expires-after' is not allowed in the released image
3030
# solution: >-
3131
# Make sure the image is built without setting the "quay.expires-after" label. This
3232
# label is usually set if the container image was built by an "on-pr" pipeline
@@ -43,11 +43,6 @@ deny contains result if {
4343
# The quay.expires-after label is present
4444
label_name == "quay.expires-after"
4545

46-
# This is an edge case that may never happen, but let's assume that if
47-
# the value is an empty string then it is not an expiration and therefore
48-
# can be permitted
49-
count(label_value) > 0
50-
5146
# Send up the violation the details
52-
result := lib.result_helper(rego.metadata.chain(), [label_value])
47+
result := lib.result_helper(rego.metadata.chain(), [])
5348
}

policy/release/quay_expiration/quay_expiration_test.rego

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ test_release_pipeline if {
2020
lib.assert_empty(quay_expiration.deny) with input.image as _image_expires_none
2121
with data.rule_data as _rule_data_for_release
2222

23-
lib.assert_empty(quay_expiration.deny) with input.image as _image_expires_blank
24-
with data.rule_data as _rule_data_for_release
25-
2623
expected := {{
2724
"code": "quay_expiration.expires_label",
28-
"msg": "The image has a 'quay.expires-after' label set to '5d'",
25+
"msg": "The label 'quay.expires-after' is not allowed in the released image",
2926
}}
27+
28+
lib.assert_equal_results(expected, quay_expiration.deny) with input.image as _image_expires_blank
29+
with data.rule_data as _rule_data_for_release
30+
3031
lib.assert_equal_results(expected, quay_expiration.deny) with input.image as _image_expires_5d
3132
with data.rule_data as _rule_data_for_release
3233
}

0 commit comments

Comments
 (0)