-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
279 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
{{- if .Values.ssh.enabled }} | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: {{ template "notebooks.fullname" . }}-ssh | ||
labels: | ||
app: {{ template "notebooks.name" . }}-ssh | ||
chart: {{ template "notebooks.chart" . }} | ||
release: {{ .Release.Name }} | ||
heritage: {{ .Release.Service }} | ||
spec: | ||
{{- if not .Values.ssh.autoscaling.enabled }} | ||
replicas: {{ .Values.ssh.replicaCount }} | ||
{{- end }} | ||
selector: | ||
matchLabels: | ||
app: {{ template "notebooks.name" . }}-ssh | ||
release: {{ .Release.Name }} | ||
template: | ||
metadata: | ||
labels: | ||
app: {{ template "notebooks.name" . }}-ssh | ||
chart: {{ template "notebooks.chart" . }} | ||
release: {{ .Release.Name }} | ||
heritage: {{ .Release.Service }} | ||
spec: | ||
{{- with .Values.imagePullSecrets }} | ||
imagePullSecrets: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
serviceAccountName: {{ if .Values.rbac.create }}"{{ template "notebooks.fullname" . }}"{{ else }}"{{ .Values.rbac.serviceAccountName }}"{{ end }} | ||
securityContext: | ||
fsGroup: 1000 | ||
containers: | ||
- name: ssh | ||
securityContext: | ||
allowPrivilegeEscalation: false | ||
runAsNonRoot: true | ||
runAsUser: 1000 | ||
image: "{{ .Values.ssh.image.repository }}:{{ .Values.ssh.image.tag }}" | ||
imagePullPolicy: {{ .Values.ssh.image.pullPolicy }} | ||
ports: | ||
- name: ssh | ||
containerPort: 2022 | ||
protocol: TCP | ||
resources: | ||
{{- toYaml .Values.ssh.resources | nindent 12 }} | ||
{{- if not (kindIs "invalid" .Values.ssh.hostKeySecret) }} | ||
volumeMounts: | ||
- name: ssh-host-key | ||
mountPath: /opt/ssh/ssh_host_keys | ||
readOnly: true | ||
{{- end }} | ||
{{- with .Values.nodeSelector }} | ||
nodeSelector: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
{{- with .Values.affinity }} | ||
affinity: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
{{- with .Values.tolerations }} | ||
tolerations: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
{{- if not (kindIs "invalid" .Values.ssh.hostKeySecret) }} | ||
volumes: | ||
- name: ssh-host-key | ||
secret: | ||
secretName: {{ .Values.ssh.hostKeySecret | quote }} | ||
{{- end }} | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: {{ template "notebooks.fullname" . }}-ssh | ||
labels: | ||
app: {{ template "notebooks.name" . }}-ssh | ||
chart: {{ template "notebooks.chart" . }} | ||
release: {{ .Release.Name }} | ||
heritage: {{ .Release.Service }} | ||
spec: | ||
type: {{ .Values.service.type }} | ||
ports: | ||
- name: ssh | ||
{{- if eq .Values.ssh.service.type "NodePort" }} | ||
nodePort: {{ .Values.ssh.service.port }} | ||
{{- end }} | ||
port: {{ .Values.ssh.service.port }} | ||
protocol: TCP | ||
targetPort: ssh | ||
selector: | ||
app: {{ template "notebooks.name" . }}-ssh | ||
release: {{ .Release.Name }} | ||
--- | ||
apiVersion: autoscaling/v1 | ||
kind: HorizontalPodAutoscaler | ||
metadata: | ||
name: {{ template "notebooks.fullname" . }}-ssh | ||
spec: | ||
scaleTargetRef: | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
name: {{ template "notebooks.fullname" . }}-ssh | ||
minReplicas: {{ .Values.ssh.autoscaling.minReplicas }} | ||
maxReplicas: {{ .Values.ssh.autoscaling.maxReplicas }} | ||
targetCPUUtilizationPercentage: {{ .Values.ssh.autoscaling.targetCPUUtilizationPercentage }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from typing import Any, Dict, List | ||
from ...config import config | ||
|
||
|
||
def main() -> List[Dict[str, Any]]: | ||
if not config.sessions.ssh.enabled: | ||
return [] | ||
patches = [ | ||
{ | ||
"type": "application/json-patch+json", | ||
"patch": [ | ||
{ | ||
"op": "add", | ||
"path": "/service/spec/ports/-", | ||
"value": { | ||
"name": "ssh", | ||
"port": config.sessions.ssh.service_port, | ||
"protocol": "TCP", | ||
"targetPort": "ssh", | ||
}, | ||
}, | ||
{ | ||
"op": "add", | ||
"path": "/statefulset/spec/template/spec/containers/0/ports", | ||
"value": [ | ||
{ | ||
"name": "ssh", | ||
"containerPort": config.sessions.ssh.container_port, | ||
"protocol": "TCP", | ||
}, | ||
], | ||
}, | ||
], | ||
} | ||
] | ||
if config.sessions.ssh.host_key_secret: | ||
patches.append( | ||
{ | ||
"type": "application/json-patch+json", | ||
"patch": [ | ||
{ | ||
"op": "add", | ||
"path": "/statefulset/spec/template/spec/containers/0/volumeMounts/-", | ||
"value": { | ||
"name": "ssh-host-keys", | ||
"mountPath": config.sessions.ssh.host_key_location, | ||
}, | ||
}, | ||
{ | ||
"op": "add", | ||
"path": "/statefulset/spec/template/spec/volumes/-", | ||
"value": { | ||
"name": "ssh-host-keys", | ||
"secret": {"secretName": config.sessions.ssh.host_key_secret}, | ||
}, | ||
}, | ||
], | ||
} | ||
) | ||
return patches |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
FROM alpine:3.17.1 | ||
|
||
RUN apk add --update --no-cache openssh-server tini && \ | ||
mkdir -p /opt/ssh && \ | ||
adduser -D jovyan && \ | ||
passwd -d jovyan && \ | ||
chown -R jovyan:users /opt/ssh && \ | ||
addgroup jovyan shadow | ||
|
||
USER jovyan | ||
RUN mkdir -p /opt/ssh/sshd_config.d && \ | ||
mkdir -p /opt/ssh/ssh_host_keys && \ | ||
ssh-keygen -q -N "" -t dsa -f /opt/ssh/ssh_host_keys/ssh_host_dsa_key && \ | ||
ssh-keygen -q -N "" -t rsa -b 4096 -f /opt/ssh/ssh_host_keys/ssh_host_rsa_key && \ | ||
ssh-keygen -q -N "" -t ecdsa -f /opt/ssh/ssh_host_keys/ssh_host_ecdsa_key && \ | ||
ssh-keygen -q -N "" -t ed25519 -f /opt/ssh/ssh_host_keys/ssh_host_ed25519_key | ||
COPY sshd_config /opt/ssh/sshd_config | ||
ENTRYPOINT ["tini", "-g", "--"] | ||
CMD [ "/usr/sbin/sshd", "-D", "-f", "/opt/ssh/sshd_config", "-e" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Include /opt/ssh/sshd_config.d/*.conf | ||
Port 2022 | ||
|
||
HostKey /opt/ssh/ssh_host_keys/ssh_host_dsa_key | ||
HostKey /opt/ssh/ssh_host_keys/ssh_host_rsa_key | ||
HostKey /opt/ssh/ssh_host_keys/ssh_host_ecdsa_key | ||
HostKey /opt/ssh/ssh_host_keys/ssh_host_ed25519_key | ||
|
||
ChallengeResponseAuthentication no | ||
|
||
X11Forwarding no | ||
PrintMotd no | ||
PidFile /opt/ssh/sshd.pid | ||
|
||
AcceptEnv LANG LC_* | ||
|
||
Match User jovyan | ||
PermitTTY no | ||
X11Forwarding no | ||
PermitTunnel no | ||
GatewayPorts no | ||
ForceCommand /sbin/nologin | ||
PermitEmptyPasswords yes |