[feature] SSH Public Key Login for DevContainer
All checks were successful
DevStar DevContainer Operator CI Pipeline - main branch / build-and-push-devstar-devcontainer-operator (push) Successful in 1m14s

This commit is contained in:
Mingchen Dai
2024-10-13 11:24:13 +00:00
parent 239edcc756
commit 50e6da3137
6 changed files with 42 additions and 3 deletions

View File

@@ -19,6 +19,23 @@ spec:
app: {{.ObjectMeta.Name}}
devstar-resource-type: devstar-devcontainer
spec:
# 安全策略,禁止挂载 ServiceAccount Token
automountServiceAccountToken: false
volumes:
- name: root-ssh-dir
emptyDir: {}
initContainers:
- name: init-root-ssh-dir
image: {{.Spec.StatefulSet.Image}}
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- {{range .Spec.StatefulSet.SSHPublicKeyList}} echo "{{.}}" >> /root/.ssh/authorized_keys && {{end}} chmod -R 700 /root/.ssh/ && echo 'SSH Public Key(s) imported.'
# 注意,必须递归设置 ~/.ssh/ 目录下权限 700否则即使配置了 ~/.ssh/authorized_keys 也不会生效
volumeMounts:
- name: root-ssh-dir
mountPath: /root/.ssh
containers:
- name: {{.ObjectMeta.Name}}
image: {{.Spec.StatefulSet.Image}}
@@ -27,6 +44,7 @@ spec:
- {{.}}
{{end}}
imagePullPolicy: IfNotPresent
# securityContext: TODO: 设置 DevContainer 安全策略
ports:
- name: ssh-port
protocol: TCP
@@ -34,6 +52,8 @@ spec:
volumeMounts:
- name: pvc-devcontainer
mountPath: /data
- name: root-ssh-dir
mountPath: /root/.ssh
livenessProbe:
exec:
command: