Skip to content

Commit

Permalink
chore: add network policies for Harbor
Browse files Browse the repository at this point in the history
  • Loading branch information
SdgJlbl committed May 17, 2024
1 parent afce8eb commit 0722718
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
14 changes: 14 additions & 0 deletions charts/substra-backend/templates/network-task-deny-all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Deny ALL networking in launched substra ml task
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ template "substra.fullname". }}-deny-ingress
labels:
{{ include "substra.labels" . | nindent 4 }}
spec:
podSelector:
matchLabels:
substra.ai/pod-type: compute-task
policyTypes:
- Ingress
- Egress
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{- if not .Values.containerRegistry.local }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ template "substra.name". }}-registry-remote-egress
spec:
egress:
- to:
- ipBlock:
cidr: 0.0.0.0/0
{{- if not .Values.server.allowLocalRequests }}
except:
- 10.0.0.0/8
- 192.168.0.0/16
- 172.16.0.0/20
{{- end }}
ports:
- protocol: TCP
port: {{ .Values.containerRegistry.port }}
podSelector:
matchLabels:
role-registry-client: 'true'
policyTypes:
- Egress
{{- end }}
77 changes: 77 additions & 0 deletions charts/substra-backend/templates/networkpolicy-registry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{{- if .Values.containerRegistry.local }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ template "substra.name". }}-registry-ingress
spec:
podSelector:
matchLabels:
app: docker-registry
policyTypes:
- Ingress
ingress:
- from:
- podSelector:
matchLabels:
app.kubernetes.io/part-of: {{ template "substra.name" . }}
role-registry-client: 'true'
# kaniko-function-xx send requests through the service, which changes the IP address calling the registry, preventing
# to connect as the connection doesn't come directly from the pod
- ipBlock:
cidr: 10.0.0.0/8
ports:
- protocol: TCP
port: {{ .Values.containerRegistry.port }}
# Nodeport range
- protocol: TCP
port: 30000
endPort: 32767
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ template "substra.name". }}-registry-egress
spec:
podSelector:
matchLabels:
app.kubernetes.io/part-of: {{ template "substra.name" . }}
role-registry-client: 'true'
policyTypes:
- Egress
egress:
- to:
- podSelector:
matchLabels:
app: docker-registry
ports:
- protocol: TCP
port: {{ .Values.containerRegistry.port }}
# Nodeport range
- protocol: TCP
port: 30000
endPort: 32767
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ template "substra.name". }}-registry-kaniko-egress
spec:
podSelector:
matchLabels:
app.kubernetes.io/component: substra-compute
role-registry-client: 'true'
policyTypes:
- Egress
egress:
- to:
- podSelector:
matchLabels:
app: docker-registry
ports:
- protocol: TCP
port: {{ .Values.containerRegistry.port }}
# Nodeport range
- protocol: TCP
port: 30000
endPort: 32767
{{- end }}

0 comments on commit 0722718

Please sign in to comment.