Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helm network policies back #11940

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{- if .Values.networkPolicies.enabled }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ $.Release.Name }}-db
spec:
podSelector:
matchLabels:
app: {{ $.Release.Name }}-db
policyTypes:
- Ingress
ingress:
- from:
# Allow all node pods to access the database pods.
- podSelector:
matchLabels:
app: {{ $.Release.Name }}
# Allow all runner pods to access the database pods.
- podSelector:
matchLabels:
app: runner
ports:
- protocol: TCP
port: 5432
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{- if .Values.networkPolicies.enabled }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ $.Release.Name }}-node
spec:
podSelector:
matchLabels:
app: {{ $.Release.Name }}
policyTypes:
- Ingress
ingress:
# Allow all ingress traffic between the node pods and from runner pod.
- from:
- podSelector:
matchLabels:
app: {{ $.Release.Name }}
- podSelector:
matchLabels:
app: runner
{{- end }}
27 changes: 27 additions & 0 deletions charts/chainlink-cluster/templates/geth-networkpolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{{- if .Values.networkPolicies.enabled }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ $.Release.Name }}-geth
spec:
podSelector:
matchLabels:
app: geth
policyTypes:
- Ingress
ingress:
- from:
# Allow http and websocket connections from the node pods.
- podSelector:
matchLabels:
app: {{ $.Release.Name }}
# Allow http and websocket connections from the runner pods.
- podSelector:
matchLabels:
app: runner
ports:
- protocol: TCP
port: 8544
- protocol: TCP
port: 8546
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{- if .Values.networkPolicies.enabled }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ $.Release.Name }}-mockserver
spec:
podSelector:
matchLabels:
app: mockserver
policyTypes:
- Ingress
ingress:
- from:
# Allow http traffic from the node pods.
- podSelector:
matchLabels:
app: {{ $.Release.Name }}
# Allow http traffic from the runner pods.
- podSelector:
matchLabels:
app: runner
ports:
- protocol: TCP
port: 1080
{{- end }}
43 changes: 43 additions & 0 deletions charts/chainlink-cluster/templates/networkpolicy-default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{- if .Values.networkPolicies.enabled }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default
spec:
podSelector:
matchLabels: {}
policyTypes:
- Ingress
- Egress
ingress:
{{- if and .Values.networkPolicyDefault.ingress.allowCustomCidrs (not (empty .Values.networkPolicyDefault.ingress.customCidrs)) }}
# Using a comma separated list to make it easy to pass in with:
# `helm template ... --set networkPolicyDefault.ingress.customCidrs=...`
{{- $cidrs := splitList "," .Values.networkPolicyDefault.ingress.customCidrs }}
- from:
{{- range $cidr := $cidrs }}
- ipBlock:
cidr: {{ $cidr | quote }}
{{- end }}
{{- else }}
# Deny all ingress if no rules are specified. Rules can still be specified in other templates.
- {}
{{- end }}
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: "{{ $.Release.Namespace }}"
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
podSelector:
matchLabels:
k8s-app: kube-dns
ports:
- protocol: TCP
port: 53
- protocol: UDP
port: 53
{{- end }}
21 changes: 21 additions & 0 deletions charts/chainlink-cluster/templates/runner-networkpolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{- if .Values.networkPolicies.enabled }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ $.Release.Name }}-runner
spec:
podSelector:
matchLabels:
app: runner
policyTypes:
- Ingress
ingress:
# Allow all ingress traffic between the node pods and from runner pod.
- from:
- podSelector:
matchLabels:
app: {{ $.Release.Name }}
- podSelector:
matchLabels:
app: runner
{{- end }}
3 changes: 3 additions & 0 deletions charts/chainlink-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ nodeSelector:
tolerations:
affinity:

networkPolicies:
enabled: true

# Configure the default network policy.
networkPolicyDefault:
ingress:
Expand Down
Loading