@@ -98,6 +98,20 @@ manifest := {
9898 " metadata-with-empty-annotations" : {" metadata" : {" annotations" : {}}},
9999}
100100
101+ network_policy_manifest := {
102+ " apiVersion" : " networking.k8s.io/v1" ,
103+ " kind" : " NetworkPolicy" ,
104+ " metadata" : {" name" : " default-deny" },
105+ " spec" : {" podSelector" : {}, " policyTypes" : [" Ingress" , " Egress" ]},
106+ }
107+
108+ service_manifest := {
109+ " apiVersion" : " v1" ,
110+ " kind" : " Service" ,
111+ " metadata" : {" name" : " simple-demo-operator-controller-manager-metrics-service" },
112+ " spec" : {" ports" : [{" port" : 8443 , " targetPort" : 8443 }]},
113+ }
114+
101115# regal ignore:rule-length
102116test_all_image_ref if {
103117 lib.assert_equal (
@@ -137,12 +151,14 @@ test_all_good if {
137151 lib.assert_empty (olm.deny) with input.image.files as {" manifests/csv.yaml" : manifest}
138152 with input.image.config.Labels as {olm.manifestv1: " manifests/" }
139153 with data.rule_data.allowed_olm_image_registry_prefixes as [" registry.io" ]
154+ with data.rule_data.allowed_olm_resource_kinds as [" ClusterServiceVersion" ]
140155}
141156
142157test_all_good_custom_dir if {
143158 lib.assert_empty (olm.deny) with input.image.files as {" other/csv.yaml" : manifest}
144159 with input.image.config.Labels as {olm.manifestv1: " other/" }
145160 with data.rule_data.allowed_olm_image_registry_prefixes as [" registry.io" ]
161+ with data.rule_data.allowed_olm_resource_kinds as [" ClusterServiceVersion" ]
146162}
147163
148164test_related_img_unpinned if {
@@ -162,6 +178,7 @@ test_related_img_unpinned if {
162178 lib.assert_equal_results (olm.deny, expected) with input.image.files as {" manifests/csv.yaml" : unpinned_manifest}
163179 with input.image.config.Labels as {olm.manifestv1: " manifests/" }
164180 with data.rule_data.allowed_olm_image_registry_prefixes as [" registry.io" ]
181+ with data.rule_data.allowed_olm_resource_kinds as [" ClusterServiceVersion" ]
165182}
166183
167184test_feature_annotations_format if {
@@ -201,6 +218,7 @@ test_feature_annotations_format if {
201218 lib.assert_equal_results (olm.deny, expected) with input.image.files as {" manifests/csv.yaml" : bad_manifest}
202219 with input.image.config.Labels as {olm.manifestv1: " manifests/" }
203220 with data.rule_data.allowed_olm_image_registry_prefixes as [" registry.io" ]
221+ with data.rule_data.allowed_olm_resource_kinds as [" ClusterServiceVersion" ]
204222}
205223
206224test_feature_annotations_format_custom_rule_data if {
@@ -218,6 +236,7 @@ test_feature_annotations_format_custom_rule_data if {
218236 with input.image.config.Labels as {olm.manifestv1: " manifests/" }
219237 with data.rule_data.required_olm_features_annotations as [" foo" , " spam" ]
220238 with data.rule_data.allowed_olm_image_registry_prefixes as [" registry.io" ]
239+ with data.rule_data.allowed_olm_resource_kinds as [" ClusterServiceVersion" ]
221240}
222241
223242test_required_olm_features_annotations_provided if {
@@ -231,6 +250,7 @@ test_required_olm_features_annotations_provided if {
231250 with input.image.config.Labels as {olm.manifestv1: " manifests/" }
232251 with data.rule_data.allowed_olm_image_registry_prefixes as [" registry.io" ]
233252 with data.rule_data.required_olm_features_annotations as []
253+ with data.rule_data.allowed_olm_resource_kinds as [" ClusterServiceVersion" ]
234254
235255 d := [
236256 # Wrong type
@@ -268,6 +288,7 @@ test_required_olm_features_annotations_provided if {
268288 with input.image.config.Labels as {olm.manifestv1: " manifests/" }
269289 with data.rule_data.allowed_olm_image_registry_prefixes as [" registry.io" ]
270290 with data.rule_data.required_olm_features_annotations as d
291+ with data.rule_data.allowed_olm_resource_kinds as [" ClusterServiceVersion" ]
271292}
272293
273294test_csv_semver_format_bad_semver if {
@@ -281,6 +302,7 @@ test_csv_semver_format_bad_semver if {
281302 lib.assert_equal_results (olm.deny, expected) with input.image.files as {" manifests/csv.yaml" : csv}
282303 with input.image.config.Labels as {olm.manifestv1: " manifests/" }
283304 with data.rule_data.allowed_olm_image_registry_prefixes as [" registry.io" ]
305+ with data.rule_data.allowed_olm_resource_kinds as [" ClusterServiceVersion" ]
284306}
285307
286308test_csv_semver_format_missing if {
@@ -294,6 +316,7 @@ test_csv_semver_format_missing if {
294316 lib.assert_equal_results (olm.deny, expected) with input.image.files as {" manifests/csv.yaml" : csv}
295317 with input.image.config.Labels as {olm.manifestv1: " manifests/" }
296318 with data.rule_data.allowed_olm_image_registry_prefixes as [" registry.io" ]
319+ with data.rule_data.allowed_olm_resource_kinds as [" ClusterServiceVersion" ]
297320}
298321
299322test_subscriptions_annotation_format if {
@@ -340,6 +363,7 @@ test_subscriptions_annotation_format if {
340363 lib.assert_equal_results (olm.deny, expected) with input.image.files as files
341364 with input.image.config.Labels as {olm.manifestv1: " m/" }
342365 with data.rule_data.allowed_olm_image_registry_prefixes as [" registry.io" ]
366+ with data.rule_data.allowed_olm_resource_kinds as [" ClusterServiceVersion" ]
343367}
344368
345369test_unpinned_snapshot_references_operator if {
@@ -353,6 +377,7 @@ test_unpinned_snapshot_references_operator if {
353377 with data.rule_data.allowed_olm_image_registry_prefixes as [" registry.io" ]
354378 with ec.oci.image_manifest as ` {"config": {"digest": "sha256:goat"}}`
355379 with input.image.ref as unpinned_component.containerImage
380+ with data.rule_data.allowed_olm_resource_kinds as [" ClusterServiceVersion" ]
356381}
357382
358383test_unpinned_snapshot_references_different_input if {
@@ -373,6 +398,7 @@ test_unmapped_references_in_operator if {
373398 lib.assert_equal_results (olm.deny, expected) with input.snapshot.components as [component1]
374399 with input.image.files as {" manifests/csv.yaml" : manifest}
375400 with data.rule_data as {" pipeline_intention" : " release" , " allowed_olm_image_registry_prefixes" : [" registry.io" ]}
401+ with data.rule_data.allowed_olm_resource_kinds as [" ClusterServiceVersion" ]
376402 with ec.oci.image_manifest as _mock_image_partial
377403 with ec.oci.descriptor as mock_ec_oci_image_descriptor
378404 with input.image.config.Labels as {olm.manifestv1: " manifests/" }
@@ -436,6 +462,7 @@ test_unmapped_references_none_found if {
436462 with input.image.files as {" manifests/csv.yaml" : manifest}
437463 with input.image.config.Labels as {olm.manifestv1: " manifests/" }
438464 with data.rule_data.allowed_olm_image_registry_prefixes as [" registry.io" ]
465+ with data.rule_data.allowed_olm_resource_kinds as [" ClusterServiceVersion" ]
439466}
440467
441468test_allowed_registries if {
@@ -444,6 +471,7 @@ test_allowed_registries if {
444471 with data.rule_data.allowed_olm_image_registry_prefixes as [" registry.io" , " registry.redhat.io" ]
445472 with input.image.config.Labels as {olm.manifestv1: " manifests/" }
446473 with input.image.files as {" manifests/csv.yaml" : manifest}
474+ with data.rule_data.allowed_olm_resource_kinds as [" ClusterServiceVersion" ]
447475}
448476
449477test_bundle_image_index if {
@@ -457,6 +485,7 @@ test_bundle_image_index if {
457485
458486 lib.assert_equal_results (olm.deny, expected_deny) with data.rule_data.pipeline_intention as " release"
459487 with data.rule_data.allowed_olm_image_registry_prefixes as [" registry.io" , " registry.redhat.io" ]
488+ with data.rule_data.allowed_olm_resource_kinds as [" ClusterServiceVersion" ]
460489 with input.image.config.Labels as {olm.manifestv1: " manifests/" }
461490 with input.image.files as {" manifests/csv.yaml" : manifest}
462491 with input.image.ref as pinned1
@@ -482,6 +511,7 @@ test_unallowed_registries if {
482511 # This expects failure as registry.io is not a member of allowed_olm_image_registry_prefixes
483512 lib.assert_equal_results (olm.deny, expected) with data.rule_data.pipeline_intention as " release"
484513 with data.rule_data.allowed_olm_image_registry_prefixes as [" registry.access.redhat.com" , " registry.redhat.io" ]
514+ with data.rule_data.allowed_olm_resource_kinds as [" ClusterServiceVersion" ]
485515 with input.image.config.Labels as {olm.manifestv1: " manifests/" }
486516 with input.image.files as {" manifests/csv.yaml" : manifest}
487517}
@@ -604,3 +634,23 @@ test_image_ref_with_repo_only if {
604634 expected := " registry.io/repo"
605635 lib.assert_equal (olm._image_ref (img), expected)
606636}
637+
638+ test_disallowed_olm_resource_kind if {
639+ expected := {{
640+ " code" : " olm.allowed_resource_kinds" ,
641+ " msg" : " The \" NetworkPolicy\" manifest kind is not in the list of OLM allowed resource kinds." ,
642+ " term" : " NetworkPolicy" ,
643+ }}
644+
645+ lib.assert_equal_results (olm.deny, expected) with input.image.config.Labels as {olm.manifestv1: " manifests/" }
646+ with input.image.files as {" manifests/networkpolicy.yaml" : network_policy_manifest}
647+ with data.rule_data.allowed_olm_resource_kinds as [" foo" , " bar" ]
648+ }
649+
650+ test_allowed_olm_resource_kind if {
651+ expected_empty := {}
652+
653+ lib.assert_equal_results (olm.deny, expected_empty) with input.image.config.Labels as {olm.manifestv1: " manifests/" }
654+ with input.image.files as {" manifests/service.yaml" : service_manifest}
655+ with data.rule_data.allowed_olm_resource_kinds as [" Service" ]
656+ }
0 commit comments