Skip to content

Add NetworkPolicy for operator and driver pods#544

Open
Rakshith-R wants to merge 2 commits into
ceph:mainfrom
Rakshith-R:network-policy
Open

Add NetworkPolicy for operator and driver pods#544
Rakshith-R wants to merge 2 commits into
ceph:mainfrom
Rakshith-R:network-policy

Conversation

@Rakshith-R

@Rakshith-R Rakshith-R commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a static NetworkPolicy for the operator pod that denies all ingress
    and allows open egress (API server access). Disabled by default; enabled
    with NETWORK_POLICY=true at build time.
  • Add code-generated NetworkPolicies for controller-plugin and csi-addons
    node agent pods as part of the driver reconciliation loop, gated by a
    startup check for the networking.k8s.io/v1 API group.
  • Controller-plugin NP allows ingress from csi-addons controller-manager
    on the csi-addons gRPC port (9070 RBD / 9080 CephFS) and (RBD only)
    port 50051 for CSI snapshot-metadata gRPC from backup applications.
  • Node agent NP allows ingress from csi-addons controller-manager on port
    9071, mirroring the csi-addons DaemonSet lifecycle.
  • Node-plugin DaemonSet is exempt (hostNetwork: true).

Why unrestricted egress (- {})

All policies use open egress instead of restricting to specific IPs because
the API server ClusterIP is not portable:

  1. Service CIDR varies per cluster10.96.0.1 (kubeadm),
    172.30.0.1 (OpenShift), custom ranges on managed clouds.
    Unknown at manifest authoring time.
  2. CNI ipBlock behavior is inconsistent — OVN-Kubernetes applies
    NetworkPolicy before or after DNAT depending on traffic direction,
    making ipBlock-based rules unreliable for service IPs
    (OVN-K8s docs).
    Cilium has similar quirks.
  3. HyperShift / non-standard ports — HyperShift clusters expose the
    API server on non-6443 ports. Hardcoding port 6443 breaks these setups.
  4. Precedent — OpenShift networking team guidance in
    operator-marketplace PR #723
    uses open egress for the same reasons.
  5. Ceph cluster access — Driver pods also need egress to the Ceph
    monitor/OSD network, which varies per deployment.

References

Test plan

  • make build passes
  • make test passes (existing tests)
  • NETWORK_POLICY=true make build-installer includes NP in output
  • Deploy operator with NP, verify pod remains Running
  • Create Driver CR, verify controller-plugin and node-agent NPs created
  • Toggle DeployCsiAddons: false, verify node-agent NP deleted
  • PVC provision (RBD + CephFS) works with NPs applied
  • CSIAddonsNode CRs register (gRPC connectivity through NP)

Manually tested all 6 NPs on live OCP 4.23 cluster — PVC provision,
CSIAddonsNode registration, operator reconcile all pass.

🤖 Generated with Claude Code

Replace the kubebuilder-scaffolded metrics NetworkPolicy with a policy
for the ceph-csi-operator pod. The policy denies all ingress (no
exposed ports needed -- metrics are disabled, health probes bypass NP)
and allows open egress (required for API server access where the
ClusterIP varies per cluster and CNI ipBlock behavior is inconsistent).

The policy is disabled by default. Set NETWORK_POLICY=true to include
it in the generated installer YAMLs:

  NETWORK_POLICY=true make build-installer

Assisted-by: Claude <noreply@anthropic.com>
Signed-off-by: Rakshith R <rar@redhat.com>
Create NetworkPolicies for controller-plugin and csi-addons node agent
pods as part of the driver reconciliation loop.

Controller-plugin NP: allows ingress from csi-addons controller-manager
on the csi-addons gRPC port (9070 RBD / 9080 CephFS). For RBD drivers,
also allows ingress on port 50051 for CSI snapshot-metadata gRPC from
backup applications (Velero, etc.). All egress is open for API server
and Ceph cluster access.

Node agent NP: allows ingress from csi-addons controller-manager on
port 9071 only. Mirrors the csi-addons daemonset lifecycle -- created
when DeployCsiAddons is true, deleted when false.

NP creation is gated by a startup check for the networking.k8s.io/v1
API group via the discovery client.

Node-plugin DaemonSet is not covered as it runs with hostNetwork: true
and is therefore exempt from NetworkPolicy.

Assisted-by: Claude <noreply@anthropic.com>
Signed-off-by: Rakshith R <rar@redhat.com>
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.

1 participant