Skip to content

Commit 71a564b

Browse files
committed
allow the StaticResourceController to manage the networkpolicies after CVO application
1 parent 5134a63 commit 71a564b

7 files changed

Lines changed: 107 additions & 274 deletions
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Allow all egress for guard, installer, and pruner pods in the openshift-kube-apiserver namespace.
2+
#
3+
# These pods run on the pod network (unlike kube-apiserver which uses hostNetwork and
4+
# bypasses NetworkPolicy entirely). They need egress for:
5+
# - installer/pruner: API server access to manage static pod manifests
6+
# - guard: kube-apiserver health checks on port 6443
7+
# - all: DNS resolution via openshift-dns
8+
#
9+
# All egress is permitted because the API server address can vary by cluster configuration.
10+
apiVersion: networking.k8s.io/v1
11+
kind: NetworkPolicy
12+
metadata:
13+
name: allow-all-egress
14+
namespace: openshift-kube-apiserver
15+
spec:
16+
podSelector:
17+
matchExpressions:
18+
- key: app
19+
operator: In
20+
values:
21+
- guard
22+
- installer
23+
- pruner
24+
egress:
25+
- {}
26+
policyTypes:
27+
- Egress
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Default-deny policy for the openshift-kube-apiserver namespace.
2+
# This policy selects all pods in the namespace and enables default-deny for both
3+
# ingress and egress by specifying policyTypes without any allow rules.
4+
#
5+
# NetworkPolicies are additive (use OR logic):
6+
# - This policy enables default-deny for all pods
7+
# - Subsequent policies add specific allow rules
8+
# - If any policy allows traffic, that traffic is permitted
9+
# - Policies cannot override or block traffic allowed by other policies
10+
#
11+
# Note: kube-apiserver static pods use hostNetwork: true and bypass all NetworkPolicy rules.
12+
# This policy only affects pods running on the pod network (guard, installer, pruner).
13+
apiVersion: networking.k8s.io/v1
14+
kind: NetworkPolicy
15+
metadata:
16+
name: default-deny
17+
namespace: openshift-kube-apiserver
18+
spec:
19+
podSelector: {}
20+
policyTypes:
21+
- Ingress
22+
- Egress

manifests/0000_12_kube-apiserver-operand_networkpolicies.yaml

Lines changed: 0 additions & 129 deletions
This file was deleted.

manifests/0000_20_kube-apiserver-operator_11_networkpolicies.yaml

Lines changed: 0 additions & 145 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Allow all egress and metrics ingress for the kube-apiserver-operator pod.
2+
#
3+
# Egress is needed for:
4+
# - DNS resolution via openshift-dns
5+
# - Kubernetes API server communication (address varies by cluster configuration)
6+
# - kube-apiserver health checks on port 6443 (hostNetwork, accessed via node IPs)
7+
#
8+
# Ingress is needed for:
9+
# - Prometheus metrics scraping on port 8443
10+
apiVersion: networking.k8s.io/v1
11+
kind: NetworkPolicy
12+
metadata:
13+
name: allow-all-egress-and-metrics-ingress
14+
namespace: openshift-kube-apiserver-operator
15+
annotations:
16+
include.release.openshift.io/self-managed-high-availability: "true"
17+
include.release.openshift.io/single-node-developer: "true"
18+
spec:
19+
podSelector:
20+
matchLabels:
21+
app: kube-apiserver-operator
22+
egress:
23+
- {}
24+
ingress:
25+
- ports:
26+
- protocol: TCP
27+
port: 8443
28+
policyTypes:
29+
- Ingress
30+
- Egress
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Default-deny policy for the openshift-kube-apiserver-operator namespace.
2+
# This policy selects all pods in the namespace and enables default-deny for both
3+
# ingress and egress by specifying policyTypes without any allow rules.
4+
#
5+
# NetworkPolicies are additive (use OR logic):
6+
# - This policy enables default-deny for all pods
7+
# - Subsequent policies add specific allow rules
8+
# - If any policy allows traffic, that traffic is permitted
9+
# - Policies cannot override or block traffic allowed by other policies
10+
#
11+
# Without this policy, all pods would have unrestricted network access (allow-all).
12+
apiVersion: networking.k8s.io/v1
13+
kind: NetworkPolicy
14+
metadata:
15+
name: default-deny
16+
namespace: openshift-kube-apiserver-operator
17+
annotations:
18+
include.release.openshift.io/self-managed-high-availability: "true"
19+
include.release.openshift.io/single-node-developer: "true"
20+
spec:
21+
podSelector: {}
22+
policyTypes:
23+
- Ingress
24+
- Egress

pkg/operator/starter.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ func RunOperator(ctx context.Context, controllerContext *controllercmd.Controlle
240240
"assets/alerts/kube-apiserver-requests.yaml",
241241
"assets/alerts/kube-apiserver-slos-basic.yaml",
242242
"assets/alerts/podsecurity-violations.yaml",
243+
// Network policies
244+
"assets/kube-apiserver/networkpolicy-operand-allow.yaml",
245+
// Default-deny policies must be applied last
246+
"assets/kube-apiserver/networkpolicy-operand-default-deny.yaml",
243247
},
244248
(&resourceapply.ClientHolder{}).
245249
WithKubernetes(kubeClient).

0 commit comments

Comments
 (0)