Skip to content

CMP-4496: Add NetworkPolicy RBAC for operands to operator Role and CSV - #1313

Merged
yuumasato merged 2 commits into
ComplianceAsCode:masterfrom
taimurhafeez:CMP-4496-Add-NetworkPolicy-RBAC-for-operands-to-CSV-and-operator-role
Aug 21, 2026
Merged

CMP-4496: Add NetworkPolicy RBAC for operands to operator Role and CSV#1313
yuumasato merged 2 commits into
ComplianceAsCode:masterfrom
taimurhafeez:CMP-4496-Add-NetworkPolicy-RBAC-for-operands-to-CSV-and-operator-role

Conversation

@taimurhafeez

@taimurhafeez taimurhafeez commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

What

  • Adds networking.k8s.io/networkpolicies RBAC rule (verbs: create, delete, get, update) to the operator Role (config/rbac/operator_role.yaml)
  • Adds matching entry in the CSV namespace-scoped permissions (config/manifests/bases/compliance-operator.clusterserviceversion.yaml) under the compliance-operator service account
  • Adds kubebuilder RBAC marker in compliancescan_controller.go to keep the three RBAC sources of truth in sync
  • Regenerates the bundle CSV via make bundle

Why

The Conforma policy olm.required_network_policy_rbac_for_operands requires the CSV to declare RBAC permissions for networking.k8s.io/networkpolicies with verbs create, delete, and update (or patch).

Test plan

Prerequisites

  • Access to an OpenShift cluster (Tested on OCP 4.22)
  • podman installed and logged into registry (e.g.,quay.io)
  • A quay.io org with repos for compliance-operator, compliance-operator-bundle, and compliance-operator-catalog

1. Build and push images

# Set your quay org
export IMAGE_REPO=quay.io/<your-quay-org>

# Generate bundle (regenerates bundle/manifests/compliance-operator.clusterserviceversion.yaml)
make bundle VERSION=1.8.0-dev

# Build operator image
make image

# Push operator image
podman tag ghcr.io/complianceascode/compliance-operator:latest ${IMAGE_REPO}/compliance-operator:latest
podman push ${IMAGE_REPO}/compliance-operator:latest

# Build and push bundle image
make bundle-image VERSION=1.8.0-dev
make bundle-push

# Build and push catalog image
make catalog

2. Deploy via OLM

# Deploy CatalogSource, OperatorGroup, and Subscription
make catalog-deploy
oc get csv -n openshift-compliance
NAME                             DISPLAY               VERSION     REPLACES   PHASE
compliance-operator.v1.8.0-dev   Compliance Operator   1.8.0-dev              Succeeded

3.Verify OLM installation is complete

# CSV is Succeeded
oc get csv -n openshift-compliance
# NAME                             DISPLAY               VERSION     PHASE
# compliance-operator.v1.8.0-dev   Compliance Operator   1.8.0-dev   Succeeded

# Subscription exists
oc get subscription -n openshift-compliance
# NAME                      PACKAGE               SOURCE                CHANNEL
# compliance-operator-sub   compliance-operator   compliance-operator   alpha

# InstallPlan completed
oc get installplan -n openshift-compliance
# NAME            CSV                              APPROVAL    APPROVED
# install-cdt2v   compliance-operator.v1.8.0-dev   Automatic   true

# Operator pod is running
oc get pods -n openshift-compliance
# NAME                                   READY   STATUS    RESTARTS   AGE
# compliance-operator-7d8b6779b6-mn7gs   1/1     Running   0          4m

4. Verify NetworkPolicy RBAC in the OLM-created Role

Check the OLM-created Role contains the networkpolicies rule
oc get roles -n openshift-compliance -o yaml | grep -B 2 -A 6 networkpolicies
Expected output:

  - networking.k8s.io
  resources:
  - networkpolicies
  verbs:
  - create
  - delete
  - get
  - update

5. Verify the CSV permissions section

Expected output should show networkpolicies with verbs create, delete, get, update under the permissions (namespace-scoped) section.

6. Verify SA has the permissions

oc auth can-i create networkpolicies --as=system:serviceaccount:openshift-compliance:compliance-operator -n openshift-compliance
yes

oc auth can-i delete networkpolicies --as=system:serviceaccount:openshift-compliance:compliance-operator -n openshift-compliance
yes

oc auth can-i get networkpolicies --as=system:serviceaccount:openshift-compliance:compliance-operator -n openshift-compliance
yes

oc auth can-i update networkpolicies --as=system:serviceaccount:openshift-compliance:compliance-operator -n openshift-compliance
yes

@openshift-ci-robot

Copy link
Copy Markdown
Collaborator

@taimurhafeez: This pull request references CMP-4496 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 "5.0.0" version, but no target version was set.

Details

In response to this:

What

  • Adds networking.k8s.io/networkpolicies RBAC rule (verbs: create, delete, get, update) to the operator Role (config/rbac/operator_role.yaml)
  • Adds matching entry in the CSV namespace-scoped permissions (config/manifests/bases/compliance-operator.clusterserviceversion.yaml) under the compliance-operator service account
  • Regenerates the bundle CSV via make bundle

Why

The Conforma policy olm.required_network_policy_rbac_for_operands requires the CSV to declare RBAC permissions for networking.k8s.io/networkpolicies with verbs create, delete, and update (or patch).

Test plan

Prerequisites

  • Access to an OpenShift cluster
  • podman installed and logged into registry (e.g.,quay.io)
  • A quay.io org with repos for compliance-operator, compliance-operator-bundle, and compliance-operator-catalog

1. Build and push images

# Set your quay org
export IMAGE_REPO=quay.io/<your-quay-org>

# Generate bundle (regenerates bundle/manifests/compliance-operator.clusterserviceversion.yaml)
make bundle VERSION=1.8.0-dev

# Build operator image
make image

# Push operator image
podman tag ghcr.io/complianceascode/compliance-operator:latest ${IMAGE_REPO}/compliance-operator:latest
podman push ${IMAGE_REPO}/compliance-operator:latest

# Build and push bundle image
make bundle-image VERSION=1.8.0-dev
make bundle-push

# Build and push catalog image
make catalog

2. Deploy via OLM

# Deploy CatalogSource, OperatorGroup, and Subscription
make catalog-deploy
oc get csv -n openshift-compliance
NAME                             DISPLAY               VERSION     REPLACES   PHASE
compliance-operator.v1.8.0-dev   Compliance Operator   1.8.0-dev              Succeeded

3.Verify OLM installation is complete

# CSV is Succeeded
oc get csv -n openshift-compliance
# NAME                             DISPLAY               VERSION     PHASE
# compliance-operator.v1.8.0-dev   Compliance Operator   1.8.0-dev   Succeeded

# Subscription exists
oc get subscription -n openshift-compliance
# NAME                      PACKAGE               SOURCE                CHANNEL
# compliance-operator-sub   compliance-operator   compliance-operator   alpha

# InstallPlan completed
oc get installplan -n openshift-compliance
# NAME            CSV                              APPROVAL    APPROVED
# install-cdt2v   compliance-operator.v1.8.0-dev   Automatic   true

# Operator pod is running
oc get pods -n openshift-compliance
# NAME                                   READY   STATUS    RESTARTS   AGE
# compliance-operator-7d8b6779b6-mn7gs   1/1     Running   0          4m

4. Verify NetworkPolicy RBAC in the OLM-created Role

Check the OLM-created Role contains the networkpolicies rule

oc get roles -n openshift-compliance -o yaml | grep -B 2 -A 6 networkpolicies
Expected output:

 - networking.k8s.io
 resources:
 - networkpolicies
 verbs:
 - create
 - delete
 - get
 - update

###5. Verify the CSV permissions section
Expected output should show networkpolicies with verbs create, delete, get, update under the permissions (namespace-scoped) section.

6. Verify SA has the permissions

oc auth can-i create networkpolicies --as=system:serviceaccount:openshift-compliance:compliance-operator -n openshift-compliance
yes

oc auth can-i delete networkpolicies --as=system:serviceaccount:openshift-compliance:compliance-operator -n openshift-compliance
yes

oc auth can-i get networkpolicies --as=system:serviceaccount:openshift-compliance:compliance-operator -n openshift-compliance
yes

oc auth can-i update networkpolicies --as=system:serviceaccount:openshift-compliance:compliance-operator -n openshift-compliance
yes

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.

@taimurhafeez
taimurhafeez requested review from Vincent056, abushkin-redhat, vickeybrown and yuumasato and removed request for xiaojiey July 29, 2026 12:12
@taimurhafeez
taimurhafeez marked this pull request as draft July 29, 2026 12:18
@taimurhafeez
taimurhafeez marked this pull request as ready for review July 30, 2026 09:49
@openshift-ci
openshift-ci Bot requested a review from mrogers950 July 30, 2026 09:49
@taimurhafeez

Copy link
Copy Markdown
Collaborator Author

/retest-required

@yuumasato yuumasato mentioned this pull request Aug 3, 2026
3 tasks
@taimurhafeez

Copy link
Copy Markdown
Collaborator Author

/retest-required

@taimurhafeez
taimurhafeez force-pushed the CMP-4496-Add-NetworkPolicy-RBAC-for-operands-to-CSV-and-operator-role branch from a852f8f to 529958f Compare August 6, 2026 09:11
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

🤖 To deploy this PR, run the following command:

make catalog-deploy CATALOG_IMG=ghcr.io/complianceascode/compliance-operator-catalog:1313-529958f799d867a1b9b88e1b6e1ac78c74f9498d

@yuumasato

Copy link
Copy Markdown
Member

/retest

1 similar comment
@yuumasato

Copy link
Copy Markdown
Member

/retest

@yuumasato yuumasato added this to the 1.10.0 milestone Aug 11, 2026
@taimurhafeez

Copy link
Copy Markdown
Collaborator Author

/retest

1 similar comment
@taimurhafeez

Copy link
Copy Markdown
Collaborator Author

/retest

@abushkin-redhat

Copy link
Copy Markdown
Collaborator

/lgtm

@openshift-ci openshift-ci Bot added the lgtm label Aug 18, 2026
@taimurhafeez
taimurhafeez force-pushed the CMP-4496-Add-NetworkPolicy-RBAC-for-operands-to-CSV-and-operator-role branch from 529958f to 82f7364 Compare August 20, 2026 12:04
@openshift-ci openshift-ci Bot removed the lgtm label Aug 20, 2026
abushkin-redhat added a commit to abushkin-redhat/compliance-operator that referenced this pull request Aug 20, 2026
The operator now creates and reconciles label-scoped NetworkPolicies for its
operand pods (result server, scanners, aggregator, profileparser, rerunner) so
operand traffic is governed at runtime rather than left unrestricted.

- Add the compliance.openshift.io/netpol-managed marker to every operand pod
  template (pod template only for the result-server and profileparser
  Deployments, to avoid mutating their immutable selectors).
- Create three named policies in the operator namespace via get-or-create/update
  (no list/watch, matching the RBAC granted for CMP-4496): default-deny
  (ingress+egress), allow-all-egress, and result-server ingress on 8443 from
  pod-network scanners and host-networked node scanners.
- Reconcile the policies at the start of the scan launching phase, before any
  operand pods are created.
- Read NetworkPolicy directly from the API server (manager client cache
  DisableFor) so a by-name Get does not start an informer list+watch, which the
  operand RBAC does not grant.

Depends on ComplianceAsCode#1313 (CMP-4496) for the NetworkPolicy RBAC.
@abushkin-redhat

Copy link
Copy Markdown
Collaborator

/retest-required

@taimurhafeez
taimurhafeez force-pushed the CMP-4496-Add-NetworkPolicy-RBAC-for-operands-to-CSV-and-operator-role branch from 82f7364 to 5924a5c Compare August 21, 2026 10:09
@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:1313-5924a5c35b467c3d2fd36ac8fcc59fcd95151f15

@yuumasato yuumasato left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci

openshift-ci Bot commented Aug 21, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: taimurhafeez, yuumasato

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 [taimurhafeez,yuumasato]

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

@yuumasato
yuumasato merged commit 651f576 into ComplianceAsCode:master Aug 21, 2026
16 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