Skip to content

Commit a056c2a

Browse files
committed
Add NetworkPolicy reconcilers for driver operand pods
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>
1 parent 44fd95e commit a056c2a

10 files changed

Lines changed: 319 additions & 1 deletion

File tree

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,13 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified
292292

293293
.PHONY: deploy
294294
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
295+
$(call enable-network-policy)
295296
mkdir -p build
296297
cd build && echo "$$BUILD_INSTALLER_OVERLAY" > kustomization.yaml
297298
cd build && $(KUSTOMIZE) edit add resource ../config/default/
298299
$(KUSTOMIZE) build build | $(KUBECTL) apply -f -
299300
rm -rf build
301+
$(call disable-network-policy)
300302

301303
.PHONY: undeploy
302304
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.

PendingReleaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
- Fencing can now be enabled in the ceph-csi-drivers Helm chart either globally for all drivers or on a per-driver basis.
99
- Added `enabled` field to log rotation configuration in the ceph-csi-drivers Helm chart. Users can now disable log rotation by setting `log.rotation.enabled: false` either globally in `operatorConfig.driverSpecDefaults` or per-driver in `drivers.<driver-type>`. This resolves Helm warnings when disabling file logging from parent charts.
1010
- Added support to set the priorityClass in the operator helm chart.
11+
- Added NetworkPolicies for the operator pod and CSI driver pods (controller-plugin, csi-addons node agent). Disabled by default; enabled with `NETWORK_POLICY=true` at build time. Driver NPs are created by the operator when `networking.k8s.io/v1` is available on the cluster. Node-plugin pods are exempt (`hostNetwork: true`).
1112
## NOTE

config/rbac/role.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ rules:
8787
- get
8888
- list
8989
- watch
90+
- apiGroups:
91+
- networking.k8s.io
92+
resources:
93+
- networkpolicies
94+
verbs:
95+
- create
96+
- delete
97+
- get
98+
- list
99+
- patch
100+
- update
101+
- watch
90102
- apiGroups:
91103
- storage.k8s.io
92104
resources:

deploy/all-in-one/install-openshift.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15802,6 +15802,18 @@ rules:
1580215802
- get
1580315803
- list
1580415804
- watch
15805+
- apiGroups:
15806+
- networking.k8s.io
15807+
resources:
15808+
- networkpolicies
15809+
verbs:
15810+
- create
15811+
- delete
15812+
- get
15813+
- list
15814+
- patch
15815+
- update
15816+
- watch
1580515817
- apiGroups:
1580615818
- storage.k8s.io
1580715819
resources:

deploy/all-in-one/install.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15788,6 +15788,18 @@ rules:
1578815788
- get
1578915789
- list
1579015790
- watch
15791+
- apiGroups:
15792+
- networking.k8s.io
15793+
resources:
15794+
- networkpolicies
15795+
verbs:
15796+
- create
15797+
- delete
15798+
- get
15799+
- list
15800+
- patch
15801+
- update
15802+
- watch
1579115803
- apiGroups:
1579215804
- storage.k8s.io
1579315805
resources:

deploy/charts/ceph-csi-operator/templates/manager-rbac.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ rules:
8888
- get
8989
- list
9090
- watch
91+
- apiGroups:
92+
- networking.k8s.io
93+
resources:
94+
- networkpolicies
95+
verbs:
96+
- create
97+
- delete
98+
- get
99+
- list
100+
- patch
101+
- update
102+
- watch
91103
- apiGroups:
92104
- storage.k8s.io
93105
resources:

deploy/multifile/operator.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,18 @@ rules:
345345
- get
346346
- list
347347
- watch
348+
- apiGroups:
349+
- networking.k8s.io
350+
resources:
351+
- networkpolicies
352+
verbs:
353+
- create
354+
- delete
355+
- get
356+
- list
357+
- patch
358+
- update
359+
- watch
348360
- apiGroups:
349361
- storage.k8s.io
350362
resources:

docs/design/network-policy.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# NetworkPolicy for Ceph-CSI Operator and Driver Pods
2+
3+
This document describes the NetworkPolicy implementation for the
4+
ceph-csi-operator and the CSI driver pods it manages.
5+
6+
## Component Inventory
7+
8+
| Component | Pod Labels | hostNetwork | NP Coverage |
9+
|---|---|---|---|
10+
| Operator pod | `control-plane: ceph-csi-op-controller-manager` | No | Static manifest |
11+
| Controller-plugin (per driver) | `app: {driver}-ctrlplugin` | Configurable | Code-generated |
12+
| csi-addons node agent (per driver) | `app: {driver}-nodeplugin-csi-addons` | No | Code-generated |
13+
| Node-plugin DaemonSet | `app: {driver}-nodeplugin` | Yes (hardcoded) | Exempt |
14+
15+
## Policies
16+
17+
### Operator Pod
18+
19+
- **Ingress:** Deny all. No exposed ports (metrics disabled by default,
20+
kubelet health probes bypass NetworkPolicy).
21+
- **Egress:** Open (`- {}`). Required for API server access. The API server
22+
ClusterIP varies per cluster (10.96.0.1 on kubeadm, 172.30.0.1 on OpenShift)
23+
and CNI ipBlock behavior is inconsistent across implementations, so
24+
restricting egress to a specific IP is not portable.
25+
26+
### Controller-Plugin
27+
28+
- **Ingress:** Two rules:
29+
1. csi-addons controller-manager → csi-addons gRPC port (9070 for RBD,
30+
9080 for CephFS). Source restricted to pods with labels
31+
`app.kubernetes.io/name: csi-addons` + `control-plane: controller-manager`
32+
in any namespace.
33+
2. (RBD only) Any pod → snapshot-metadata gRPC port 50051. Open source
34+
because backup applications (Velero, etc.) can run in any namespace
35+
with any labels. See [CSI snapshot-metadata](https://kubernetes-csi.github.io/docs/external-snapshot-metadata.html).
36+
- **Egress:** Open. Required for API server and Ceph cluster access.
37+
38+
### csi-addons Node Agent
39+
40+
- **Ingress:** csi-addons controller-manager → port 9071 only.
41+
- **Egress:** Open.
42+
- **Lifecycle:** Mirrors the csi-addons DaemonSet — created when
43+
`DeployCsiAddons` is true, deleted when false. Not created for NFS drivers.
44+
45+
### Node-Plugin DaemonSet
46+
47+
No NetworkPolicy. Runs with `hostNetwork: true`, which makes it exempt
48+
from NetworkPolicy enforcement.
49+
50+
## Gating
51+
52+
### Static Manifest (Operator Pod)
53+
54+
The operator pod NP is in `config/network-policy/` and referenced from
55+
`config/default/kustomization.yaml` as a commented resource. It is
56+
**disabled by default**. Set `NETWORK_POLICY=true` when building to include it:
57+
58+
```console
59+
NETWORK_POLICY=true make build-installer
60+
```
61+
62+
### Code-Generated NPs (Driver Pods)
63+
64+
Driver pod NPs are created by the operator at runtime. The operator checks
65+
for the `networking.k8s.io/v1` API group at startup via the discovery client.
66+
If the API is not available, no NPs are created and a log message is emitted.
67+
68+
## API Server Egress Rationale
69+
70+
Open egress (`- {}`) is used instead of restricting to a specific API server
71+
IP because:
72+
73+
1. The API server ClusterIP varies per cluster and is unknown at manifest
74+
authoring time.
75+
2. CNI implementations handle `ipBlock` inconsistently with DNAT (OVN-K8s
76+
timing, Cilium quirks).
77+
3. HyperShift clusters may use non-standard API server ports.
78+
79+
This follows the precedent set by
80+
[operator-marketplace PR #723](https://github.com/operator-framework/operator-marketplace/pull/723).
81+
82+
## References
83+
84+
- [CSI snapshot-metadata sidecar](https://kubernetes-csi.github.io/docs/external-snapshot-metadata.html)
85+
- [kubernetes-csi/external-snapshot-metadata](https://github.com/kubernetes-csi/external-snapshot-metadata)
86+
- [operator-marketplace NP precedent](https://github.com/operator-framework/operator-marketplace/pull/723)

docs/kubernetes-installation.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,3 +495,33 @@ Expected output:
495495
```text
496496
No resources found in ceph-csi-operator-system namespace.
497497
```
498+
499+
## 6. Optional: Enable NetworkPolicies
500+
501+
NetworkPolicies for the operator pod and CSI driver pods are included but
502+
**disabled by default**. To include them in the generated manifests, pass
503+
`NETWORK_POLICY=true` to the build target:
504+
505+
```bash
506+
NETWORK_POLICY=true make build-installer
507+
# or for OpenShift:
508+
NETWORK_POLICY=true make build-openshift-installer
509+
```
510+
511+
When enabled:
512+
513+
- The **operator pod** gets a policy that denies all ingress and allows open
514+
egress (required for API server access).
515+
- Each **controller-plugin** pod gets a policy allowing ingress only from the
516+
csi-addons controller-manager on the csi-addons gRPC port, and (for RBD)
517+
from any pod on port 50051 for snapshot-metadata gRPC.
518+
- Each **csi-addons node agent** pod (when `deployCsiAddons: true`) gets a
519+
policy allowing ingress only from the csi-addons controller-manager on
520+
port 9071.
521+
- The **node-plugin** DaemonSet runs with `hostNetwork: true` and is exempt
522+
from NetworkPolicies.
523+
524+
Driver pod NetworkPolicies are created by the operator when the cluster
525+
supports the `networking.k8s.io/v1` API group (checked at startup).
526+
527+
For design details, see [docs/design/network-policy.md](design/network-policy.md).

0 commit comments

Comments
 (0)