Skip to content

CMP-3765: Add customRule enforce-trusted-tls-registries#845

Merged
rhmdnd merged 1 commit intoComplianceAsCode:masterfrom
Anna-Koudelkova:CMP-3765-add-rule-enforce-trusted-TLS
Mar 2, 2026
Merged

CMP-3765: Add customRule enforce-trusted-tls-registries#845
rhmdnd merged 1 commit intoComplianceAsCode:masterfrom
Anna-Koudelkova:CMP-3765-add-rule-enforce-trusted-TLS

Conversation

@Anna-Koudelkova
Copy link
Copy Markdown
Collaborator

Sketch of a rule for enforcing using only registries using TLS.

This is more of a fun and play than actual help, feel free to close this immediately - thanks a lot for including me in the meeting!

@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Oct 29, 2025

Hi @Anna-Koudelkova. Thanks for your PR.

I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@Anna-Koudelkova Anna-Koudelkova changed the title Add customRule enforce-trusted-tls-registries CMP-3765: Add customRule enforce-trusted-tls-registries Oct 29, 2025
@openshift-ci-robot
Copy link
Copy Markdown
Collaborator

@Anna-Koudelkova: This pull request references CMP-3765 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.21.0" version, but no target version was set.

Details

In response to this:

Sketch of a rule for enforcing using only registries using TLS.

This is more of a fun and play than actual help, feel free to close this immediately - thanks a lot for including me in the meeting!

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

checkType: Platform
scannerType: CEL
inputs:
- name: hcoList
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're dealing with a singular resource we can use hco.

h.metadata.name == 'kubevirt-hyperconverged' &&
h.metadata.namespace == 'openshift-cnv'
).all(h,
h.spec.storageImport.insecureRegistries == null
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we should be able to simplify this to:

expression: |-
    !has(hco.spec.storageImport) ||
    hco.spec.storageImport.insecureRegistries.size() == 0

Copy link
Copy Markdown
Collaborator

@rhmdnd rhmdnd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work 🎉

I was able to get this working on a live cluster with just a few changes:

diff --git a/config/samples/custom-rules/openshift-virtualization/kubevirt-enforce-trusted-tls-registries.yaml b/config/samples/custom-rules/openshift-virtualization/kubevirt-enforce-trusted-tls-registries.yaml
index 550bbbcc4..6c9eed345 100644
--- a/config/samples/custom-rules/openshift-virtualization/kubevirt-enforce-trusted-tls-registries.yaml
+++ b/config/samples/custom-rules/openshift-virtualization/kubevirt-enforce-trusted-tls-registries.yaml
@@ -1,11 +1,11 @@
 apiVersion: compliance.openshift.io/v1alpha1
 kind: CustomRule
 metadata:
-  name: kubevirt-enforce-trusted-tls
+  name: kubevirt-enforce-trusted-tls-registries
   namespace: openshift-compliance
 spec:
   title: "Only trusted registries using TLS can be used"
-  id: kubevirt_enforce_trusted_tls
+  id: kubevirt_enforce_trusted_tls_registries
   description: |-
     By only pulling container images from trusted registries, organizations 
     can reduce the risk of introducing unknown vulnerabilities or malicious 
@@ -18,18 +18,12 @@ spec:
   checkType: Platform
   scannerType: CEL
   inputs:
-    - name: hcoList
+    - name: hco
       kubernetesInputSpec:
         apiVersion: hco.kubevirt.io/v1beta1
         resource: hyperconvergeds
+        resourceName: kubevirt-hyperconverged
+        resourceNamespace: openshift-cnv
   expression: |
-    hcoList.items.filter(h,
-        h.metadata.name == 'kubevirt-hyperconverged' &&
-        h.metadata.namespace == 'openshift-cnv'
-    ).size() == 1 &&
-    hcoList.items.filter(h,
-        h.metadata.name == 'kubevirt-hyperconverged' &&
-        h.metadata.namespace == 'openshift-cnv'
-    ).all(h,
-        h.spec.storageImport.insecureRegistries == null
-    )
+    !has(hco.spec.storageImport) ||
+    hco.spec.storageImport.insecureRegistries.size() == 0

@github-actions
Copy link
Copy Markdown

🤖 To deploy this PR, run the following command:

make catalog-deploy CATALOG_IMG=ghcr.io/complianceascode/compliance-operator-catalog:845-28c78c95786de1435629cc932b58c4be62a74043

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 7, 2026

🤖 To deploy this PR, run the following command:

make catalog-deploy CATALOG_IMG=ghcr.io/complianceascode/compliance-operator-catalog:845-53d515b86d0f507e6239a4147ec54a323932aee8

@Anna-Koudelkova
Copy link
Copy Markdown
Collaborator Author

Thanks for the reviews and explanations! I have forgotten this exists for a while - but now it should be rebased and modified based on your suggestions.

@Anna-Koudelkova Anna-Koudelkova force-pushed the CMP-3765-add-rule-enforce-trusted-TLS branch from 53d515b to aa3b73e Compare March 2, 2026 12:25
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 2, 2026

🤖 To deploy this PR, run the following command:

make catalog-deploy CATALOG_IMG=ghcr.io/complianceascode/compliance-operator-catalog:845-aa3b73ec5fd789d649c1f2f069fe1e253ac7161b

@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Mar 2, 2026

@Anna-Koudelkova: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-rosa aa3b73e link true /test e2e-rosa
ci/prow/e2e-aws-serial-arm aa3b73e link true /test e2e-aws-serial-arm
ci/prow/e2e-aws-serial aa3b73e link true /test e2e-aws-serial

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Copy link
Copy Markdown
Collaborator

@rhmdnd rhmdnd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

Only one minor recommendation if we absolutely have to respin the patch.

resourceNamespace: openshift-cnv
expression: |-
!has(hco.spec.storageImport) ||
hco.spec.storageImport.insecureRegistries.size() == 0
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another potential protection we could take would be to guard against insecureRegistries not being present.

expression: |-
    !has(hco.spec.storageImport) ||
    !has(hco.spec.storageImport.insecureRegistries) ||
    hco.spec.storageImport.insecureRegistries.size() == 0

That would mean if someone has storageImports specified, but not insecureRegistries, then the check behaves the same as if they didn't have storageImports configured at all.

We can catch that in a follow up unless there is a reason to respin the patch.

@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Mar 2, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Anna-Koudelkova, rhmdnd

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [Anna-Koudelkova,rhmdnd]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@rhmdnd
Copy link
Copy Markdown
Collaborator

rhmdnd commented Mar 2, 2026

Merging since this isn't baked into a profile yet, doesn't have any outstanding issues, and is completely unrelated to CI failures.

@rhmdnd rhmdnd merged commit 6e338a6 into ComplianceAsCode:master Mar 2, 2026
17 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants