|
| 1 | +apiVersion: v1 |
| 2 | +kind: ConfigMap |
| 3 | +metadata: |
| 4 | + name: dev-environment-entrypoint |
| 5 | +data: |
| 6 | + entrypoint.sh: | |
| 7 | + #!/bin/bash |
| 8 | +
|
| 9 | + echo "Ensuring SSH keys directory exists at /home/dev/ssh_keys." |
| 10 | + mkdir -p /home/dev/ssh_keys |
| 11 | +
|
| 12 | + # Generate keys if they do not exist |
| 13 | + if [ ! -f /home/dev/ssh_keys/ssh_host_rsa_key ]; then |
| 14 | + echo "Generating new SSH host RSA key." |
| 15 | + ssh-keygen -t rsa -f /home/dev/ssh_keys/ssh_host_rsa_key -N '' |
| 16 | + fi |
| 17 | + if [ ! -f /home/dev/ssh_keys/ssh_host_ecdsa_key ]; then |
| 18 | + echo "Generating new SSH host ECDSA key." |
| 19 | + ssh-keygen -t ecdsa -f /home/dev/ssh_keys/ssh_host_ecdsa_key -N '' |
| 20 | + fi |
| 21 | + if [ ! -f /home/dev/ssh_keys/ssh_host_ed25519_key ]; then |
| 22 | + echo "Generating new SSH host ED25519 key." |
| 23 | + ssh-keygen -t ed25519 -f /home/dev/ssh_keys/ssh_host_ed25519_key -N '' |
| 24 | + fi |
| 25 | +
|
| 26 | + # Correct permissions for SSH keys |
| 27 | + chmod 600 /home/dev/ssh_keys/ssh_host_* |
| 28 | +
|
| 29 | + # Ensure the run directory for the PID file exists and has the right permissions |
| 30 | + echo "Ensuring run directory exists at /home/dev/run." |
| 31 | + mkdir -p /home/dev/run |
| 32 | + chown dev:dev /home/dev/run |
| 33 | +
|
| 34 | +
|
| 35 | + echo "Starting SSH service with host keys from /home/dev/ssh_keys on port 2222." |
| 36 | + /usr/sbin/sshd -D -e -f /etc/ssh/sshd_config \ |
| 37 | + -o Port={{ .Values.service.targetPort }} \ |
| 38 | + -o HostKey=/home/dev/ssh_keys/ssh_host_rsa_key \ |
| 39 | + -o HostKey=/home/dev/ssh_keys/ssh_host_ecdsa_key \ |
| 40 | + -o HostKey=/home/dev/ssh_keys/ssh_host_ed25519_key \ |
| 41 | + -o PidFile=/home/dev/run/sshd.pid |
| 42 | +
|
| 43 | + if [ $? -ne 0 ]; then |
| 44 | + echo "Failed to start SSH service." |
| 45 | + else |
| 46 | + echo "SSH service started successfully." |
| 47 | + fi |
| 48 | +
|
| 49 | + # Keep the container running if no command is provided |
| 50 | + echo "No additional command provided, container will keep running." |
| 51 | + tail -f /dev/null |
0 commit comments