Skip to content

Check that the operator works without the NetworkPolicy RBAC permission - #13099

Open
KasparMetsa wants to merge 1 commit into
strimzi:mainfrom
KasparMetsa:remove-network-policy-rbac-in-np-generation-test
Open

Check that the operator works without the NetworkPolicy RBAC permission#13099
KasparMetsa wants to merge 1 commit into
strimzi:mainfrom
KasparMetsa:remove-network-policy-rbac-in-np-generation-test

Conversation

@KasparMetsa

Copy link
Copy Markdown
Contributor

Remove the NetworkPolicy RBAC permission in testNPGenerationEnvironmentVariable and check that the Cluster Operator still works.

Fixes #12971

Type of change

  • Refactoring

Description

testNPGenerationEnvironmentVariable sets STRIMZI_NETWORK_POLICY_GENERATION=false and checks that no Strimzi NetworkPolicy exists. During the test the operator still had the RBAC permission for NetworkPolicies, so the test proved that no network policy was created, not that the operator never asked for one.

The test now removes the networkpolicies resource from the operator (Cluster)Role after the installation, reads the role back, and checks that networkpolicies is gone.

The change is in the test only. It works for both RBAC scopes:

  • a Role for namespace-scoped installations
  • a ClusterRole for cluster-wide ones

The test also deploys Kafka Exporter now, because it was the only component that creates a network policy that this test did not deploy.

The reason there was no Kafka Exporter before seems to be because the test is from 2021, and Kafka Exporter got its NetworkPolicy in 2023 (#8236), so the test predates it.

Testing

The test passes on a local kind cluster with cluster-wide RBAC and with STRIMZI_RBAC_SCOPE=NAMESPACE.

I also ran it without the removal step. It failed with "Cluster Operator still has the RBAC permission for NetworkPolicies". The test also logs the resource names it inspected, so a failing run shows what the role really held.

AI assistance (Claude Code) was used for this change, to explore the tests, write it and run it locally against a real Kubernetes cluster. I reviewed everything before submitting and can explain and defend all of it.

Checklist

  • Update documentation
  • Update CHANGELOG.md (if present)
  • Reference relevant issue(s) and close them after merging
  • Write tests
  • Make sure all tests pass
  • Try your changes inside a Kubernetes cluster, not just from unit tests
  • AI assistance was used to create this PR (see the Strimzi AI policy)

Signed-off-by: Kaspar Metsa <kaspar.metsa@axual.com>
@snyk-io

snyk-io Bot commented Aug 26, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@scholzj scholzj added this to the 1.3.0 milestone Aug 26, 2026
@scholzj
scholzj requested review from im-konge and see-quick August 26, 2026 16:17
@codecov

codecov Bot commented Aug 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.68%. Comparing base (edcc8ef) to head (8bb5b22).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main   #13099      +/-   ##
============================================
- Coverage     80.68%   80.68%   -0.01%     
  Complexity     6630     6630              
============================================
  Files           344      344              
  Lines         22765    22765              
  Branches       3116     3116              
============================================
- Hits          18368    18367       -1     
  Misses         3179     3179              
- Partials       1218     1219       +1     

see 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@im-konge

im-konge commented Sep 1, 2026

Copy link
Copy Markdown
Member

/gha run pipeline=regression

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

⏳ System test verification started: link

The following 6 job(s) will be executed:

  • regression-brokers-and-security-amd64 (cncf-ubuntu-8-32-x86)
  • regression-operators-amd64 (cncf-ubuntu-8-32-x86)
  • regression-operands-amd64 (cncf-ubuntu-8-32-x86)
  • regression-brokers-and-security-arm64 (cncf-ubuntu-8-32-arm)
  • regression-operators-arm64 (cncf-ubuntu-8-32-arm)
  • regression-operands-arm64 (cncf-ubuntu-8-32-arm)

Tests will start after successful build completion.

@see-quick see-quick 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.

Thanks for the PR, looks good just one nit.

steps = {
@Step(value = "Deploy Cluster Operator with STRIMZI_NETWORK_POLICY_GENERATION set to false.", expected = "Cluster Operator is deployed with network policy generation disabled."),
@Step(value = "Deploy Kafka cluster with Cruise Control.", expected = "Kafka cluster is deployed."),
@Step(value = "Remove the networkpolicies resource from the Cluster Operator (Cluster)Role and read the role back.", expected = "The role no longer lists networkpolicies."),

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.

Can we improve this comment saying why we removing RBAC permissions (i.e., proves that operator never attempts any NetworkPolicy API call ... because if it did I think it would get 4xx error and fail).

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

🎉 System test verification passed: link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Strengthen testNPGenerationEnvironmentVariable by removing NetworkPolicy RBAC

4 participants