Skip to content

Commit fcacd0f

Browse files
committed
ssh fixes
1 parent 22936dc commit fcacd0f

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

docker/Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ RUN apt-get update && \
77

88
COPY entrypoint.sh /entrypoint.sh
99
COPY sshd_config /etc/ssh/sshd_config
10-
RUN chmod +x /entrypoint.sh
10+
RUN groupadd -r -g 2137 ve && useradd -m -r -s /bin/bash -u 2137 -g ve ve
11+
RUN chmod +x /entrypoint.sh && \
12+
chown -R ve:ve /var/run/sshd /run /volume /entrypoint.sh /etc/ssh
1113

1214
EXPOSE 2137
1315

docker/entrypoint.sh

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
#!/bin/bash
22

3+
# Create .ssh directory for the ve user if it doesn't exist
4+
mkdir -p /home/ve/.ssh
5+
chmod 700 /home/ve/.ssh
6+
37
# Check if SSH_KEY environment variable is set
48
if [ -n "$SSH_KEY" ]; then
5-
echo "$SSH_KEY" >> /root/.ssh/authorized_keys
6-
echo "Public key added to /root/.ssh/authorized_keys"
9+
echo "$SSH_KEY" >> /home/ve/.ssh/authorized_keys
10+
chmod 600 /home/ve/.ssh/authorized_keys
11+
echo "Public key added to /home/ve/.ssh/authorized_keys"
712
fi
813

14+
# Adjust ownership of .ssh directory and authorized_keys file
15+
chown -R ve:ve /home/ve/.ssh
16+
917
# Check the ROLE environment variable
1018
case "$ROLE" in
1119
standalone)
1220
echo "Running as standalone"
1321
/usr/sbin/sshd -D -e
22+
tail -f /dev/null
1423
;;
1524
proxy)
1625
echo "Running as proxy"

docker/sshd_config

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Port 2137
33
PermitRootLogin prohibit-password
44
PasswordAuthentication no
55
ChallengeResponseAuthentication no
6-
UsePAM yes
6+
UsePAM no
77
PrintMotd no
88
Subsystem sftp /usr/lib/openssh/sftp-server
99

pkg/plugin/mount.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func setupPortForwarding(namespace, podName string, port int) error {
162162
}
163163

164164
func mountPVCOverSSH(namespace, podName string, port int, localMountPoint, pvcName string) error {
165-
sshfsCmd := exec.Command("sshfs", "-o", "StrictHostKeyChecking=no,UserKnownHostsFile=/dev/null", fmt.Sprintf("root@localhost:/volume"), localMountPoint, "-p", fmt.Sprintf("%d", port))
165+
sshfsCmd := exec.Command("sshfs", "-o", "StrictHostKeyChecking=no,UserKnownHostsFile=/dev/null", fmt.Sprintf("ve@localhost:/volume"), localMountPoint, "-p", fmt.Sprintf("%d", port))
166166
sshfsCmd.Stdout = os.Stdout
167167
sshfsCmd.Stderr = os.Stderr
168168
if err := sshfsCmd.Run(); err != nil {
@@ -200,6 +200,12 @@ func createPodSpec(podName string, port int, pvcName, sshKey, role string) *core
200200
})
201201
}
202202

203+
runAsNonRoot := true
204+
runAsUser := int64(2137)
205+
runAsGroup := int64(2137)
206+
allowPrivilegeEscalation := false
207+
readOnlyRootFilesystem := false
208+
203209
container := corev1.Container{
204210
Name: "volume-exposer",
205211
Image: "bfenski/volume-exposer:latest",
@@ -209,6 +215,13 @@ func createPodSpec(podName string, port int, pvcName, sshKey, role string) *core
209215
},
210216
},
211217
Env: envVars,
218+
SecurityContext: &corev1.SecurityContext{
219+
AllowPrivilegeEscalation: &allowPrivilegeEscalation,
220+
ReadOnlyRootFilesystem: &readOnlyRootFilesystem,
221+
Capabilities: &corev1.Capabilities{
222+
Drop: []corev1.Capability{"ALL"},
223+
},
224+
},
212225
}
213226

214227
podSpec := &corev1.Pod{
@@ -222,6 +235,11 @@ func createPodSpec(podName string, port int, pvcName, sshKey, role string) *core
222235
},
223236
Spec: corev1.PodSpec{
224237
Containers: []corev1.Container{container},
238+
SecurityContext: &corev1.PodSecurityContext{
239+
RunAsNonRoot: &runAsNonRoot,
240+
RunAsUser: &runAsUser,
241+
RunAsGroup: &runAsGroup,
242+
},
225243
},
226244
}
227245

0 commit comments

Comments
 (0)