Skip to content

Commit

Permalink
Merge pull request #546 from manics/network-policy
Browse files Browse the repository at this point in the history
Initial network Policies for hub proxy singleuser
  • Loading branch information
minrk authored Mar 19, 2018
2 parents e8cd4ac + 85e8fff commit cf8d9a8
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 3 deletions.
5 changes: 2 additions & 3 deletions jupyterhub/templates/hub/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,10 @@ data:
{{ if .Values.singleuser.cpu.guarantee -}}
singleuser.cpu.guarantee: {{ .Values.singleuser.cpu.guarantee | quote}}
{{- end }}
{{ if .Values.singleuser.extraLabels -}}
singleuser.extra-labels: |
{{ range $key, $value := .Values.singleuser.extraLabels -}}
hub.jupyter.org/network-access-hub: "true"
{{ range $key, $value := .Values.singleuser.extraLabels -}}
{{ $key | quote }}: {{ $value | quote }}
{{- end }}
{{- end }}
{{ if .Values.singleuser.extraEnv -}}
singleuser.extra-env: |
Expand Down
3 changes: 3 additions & 0 deletions jupyterhub/templates/hub/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ spec:
component: hub
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
hub.jupyter.org/network-access-proxy-api: "true"
hub.jupyter.org/network-access-proxy-http: "true"
hub.jupyter.org/network-access-singleuser: "true"
{{ if .Values.hub.labels -}}
# Because toYaml + indent is super flaky
{{ range $key, $value := .Values.proxy.labels -}}
Expand Down
32 changes: 32 additions & 0 deletions jupyterhub/templates/hub/netpol-hub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{- if and .Values.hub.networkPolicy.enabled }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: hub-network-policy
spec:
podSelector:
matchLabels:
name: hub
app: jupyterhub
component: hub
policyTypes:
- Ingress
- Egress
ingress:
- from:
- podSelector:
matchLabels:
hub.jupyter.org/network-access-hub: "true"
ports:
- protocol: TCP
port: 8081
egress:
# The default is to allow all egress for hub
# If you want to restrict it the following egress is required
# proxy:8001
# singleuser:8888
# Kubernetes api-server
{{ if .Values.hub.networkPolicy.egress }}
{{ toYaml .Values.hub.networkPolicy.egress | indent 2 }}
{{- end }}
{{- end }}
35 changes: 35 additions & 0 deletions jupyterhub/templates/hub/netpol-singleuser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{- if and .Values.singleuser.networkPolicy.enabled }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: singleuser-network-policy
spec:
podSelector:
matchLabels:
app: jupyterhub
component: singleuser-server
policyTypes:
- Ingress
- Egress
ingress:
- from:
- podSelector:
matchLabels:
hub.jupyter.org/network-access-singleuser: "true"
ports:
- protocol: TCP
port: 8888
egress:
- to:
- podSelector:
matchLabels:
name: hub
app: jupyterhub
component: hub
ports:
- protocol: TCP
port: 8081
{{ if .Values.singleuser.networkPolicy.egress }}
{{ toYaml .Values.singleuser.networkPolicy.egress | indent 2 }}
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions jupyterhub/templates/proxy/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ spec:
# required for kube-lego to work
app: kube-lego
{{- end }}
hub.jupyter.org/network-access-hub: "true"
hub.jupyter.org/network-access-singleuser: "true"
spec:
{{- if .Values.rbac.enabled }}
serviceAccountName: proxy
Expand Down
49 changes: 49 additions & 0 deletions jupyterhub/templates/proxy/netpol-proxy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{{- if and .Values.proxy.networkPolicy.enabled }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: proxy-network-policy
spec:
podSelector:
matchLabels:
name: proxy
component: proxy
policyTypes:
- Ingress
- Egress
ingress:
- ports:
- protocol: TCP
port: 80
- protocol: TCP
port: 443
# kube-lego /healthz
- protocol: TCP
port: 8080
# nginx /healthz
- protocol: TCP
port: 10254
- from:
- podSelector:
matchLabels:
hub.jupyter.org/network-access-proxy-http: "true"
ports:
- protocol: TCP
port: 8000
- from:
- podSelector:
matchLabels:
hub.jupyter.org/network-access-proxy-api: "true"
ports:
- protocol: TCP
port: 8001
egress:
# The default is to allow all egress for proxy
# If you want to restrict it the following egress is required
# hub:8081
# singleuser:8888
# Kubernetes api-server
{{- if .Values.proxy.networkPolicy.egress }}
{{ toYaml .Values.proxy.networkPolicy.egress | indent 2 }}
{{- end }}
{{- end }}
21 changes: 21 additions & 0 deletions jupyterhub/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ hub:
imagePullPolicy: IfNotPresent
pdb:
enabled: true
networkPolicy:
enabled: false
egress:
- to:
- ipBlock:
cidr: 0.0.0.0/0

rbac:
enabled: true
Expand Down Expand Up @@ -97,6 +103,12 @@ proxy:
key:
cert:
hosts: []
networkPolicy:
enabled: false
egress:
- to:
- ipBlock:
cidr: 0.0.0.0/0


# Google OAuth secrets
Expand All @@ -122,6 +134,15 @@ singleuser:
cloudMetadata:
enabled: false
ip: 169.254.169.254
networkPolicy:
enabled: false
egress:
# Required egress is handled by other rules so it's safe to modify this
- to:
- ipBlock:
cidr: 0.0.0.0/0
except:
- 169.254.169.254/32
extraLabels: {}
extraEnv: {}
lifecycleHooks:
Expand Down

0 comments on commit cf8d9a8

Please sign in to comment.