1
0

Compare commits

...

4 Commits

Author SHA1 Message Date
699498fe2c feat: support configuring a shell for a user
Some checks failed
continuous-integration/drone/push Build is failing
2022-09-17 15:01:11 +02:00
aeee18b935 feat: install vim 2022-09-17 15:00:56 +02:00
825e872a8d fix(Dockerfile): fail build when apt-get fails 2022-09-17 15:00:56 +02:00
058adb0514 feat: add support for configuring SSH2 HostKeys 2022-09-17 15:00:53 +02:00
4 changed files with 51 additions and 14 deletions

View File

@ -1,16 +1,17 @@
FROM debian:bookworm-slim FROM debian:bookworm-slim
RUN set -eux; \ RUN set -eux && \
apt-get update; \ apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get upgrade -y; \ DEBIAN_FRONTEND=noninteractive apt-get upgrade -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
openssh-server \ openssh-server \
curl \ curl \
telnet \ telnet \
net-tools \ net-tools \
screen \ screen \
; \ vim \
rm -rf /var/lib/apt/lists/*; \ && \
rm -rf /var/lib/apt/lists/* && \
rm /etc/ssh/ssh_host_*key* rm /etc/ssh/ssh_host_*key*
ADD start.sh / ADD start.sh /

View File

@ -15,7 +15,8 @@
| Key | Format | Description | | Key | Format | Description |
| --- | --- | --- | | --- | --- | --- |
| `ROOT_AUTHORIZED_KEYS` | `/path/to/file` | Path to file that contains the public SSH keys that can be used for root user authentication. This file will be copied to `/root/.ssh/authorized_keys` | | `ROOT_AUTHORIZED_KEYS` | `/path/to/file` | Path to file that contains the public SSH keys that can be used for root user authentication. This file will be copied to `/root/.ssh/authorized_keys` |
| `USERADD` | `{username}:{uid}:{gid};...` | Create user account(s) on startup | | `HOSTKEYS` | `/path/to/hostkey;...` | Specifies a (semi-colon separated list of) file(s) containing a private host key used by SSH. |
| `USERADD` | `{username}:{uid}:{gid}:{shell};...` | Create user account(s) on startup |
| `GROUPADD` | `{groupname}:{gid};...` | Create group account(s) on startup | | `GROUPADD` | `{groupname}:{gid};...` | Create group account(s) on startup |
| `BASE_DIR` | `/home` | Basedir used for user account creation (Default: `/home`) | | `BASE_DIR` | `/home` | Basedir used for user account creation (Default: `/home`) |
@ -26,7 +27,8 @@ $ docker run -it \
--name jumpbox \ --name jumpbox \
-v $(pwd)/jumpbox:/var/lib/jumpbox \ -v $(pwd)/jumpbox:/var/lib/jumpbox \
-e "ROOT_AUTHORIZED_KEYS=/var/lib/jumpbox/authorized_keys" -e "ROOT_AUTHORIZED_KEYS=/var/lib/jumpbox/authorized_keys"
-e "USERADD=jumpbox:1000:1000" -e "HOSTKEYS=/var/lib/jumpbox/ssh_host_ed25519_key;/var/lib/jumpbox/ssh_host_rsa_key"
-e "USERADD=jumpbox:1000:1000:/bin/bash"
-e "GROUPADD=jumpbox:1000" -e "GROUPADD=jumpbox:1000"
-p 1022:22 \ -p 1022:22 \
pommib/jumpbox:latest pommib/jumpbox:latest
@ -47,6 +49,7 @@ services:
- '${PWD}/jumpbox:/var/lib/jumpbox' - '${PWD}/jumpbox:/var/lib/jumpbox'
environment: environment:
ROOT_AUTHORIZED_KEYS: /var/lib/jumpbox/authorized_keys ROOT_AUTHORIZED_KEYS: /var/lib/jumpbox/authorized_keys
USERADD: jumpbox:1000:1000 HOSTKEYS: /var/lib/jumpbox/ssh_host_ed25519_key;/var/lib/jumpbox/ssh_host_rsa_key
USERADD: jumpbox:1000:1000:/bin/bash
GROUPADD: jumpbox:1000 GROUPADD: jumpbox:1000
``` ```

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
set -x set -ex
IMAGE=pommib/jumpbox:latest IMAGE=pommib/jumpbox:latest
docker pull $IMAGE docker pull $IMAGE

View File

@ -22,6 +22,7 @@ if [ ! -d "$BASE_DIR" ]; then
fi fi
# GROUPADD="group1:1000;group2:1001;group3:1002" # GROUPADD="group1:1000;group2:1001;group3:1002"
i=""
while [ "$GROUPADD" != "$i" ] ;do while [ "$GROUPADD" != "$i" ] ;do
i=${GROUPADD%%;*} i=${GROUPADD%%;*}
GROUPADD="${GROUPADD#$i;}" GROUPADD="${GROUPADD#$i;}"
@ -32,19 +33,51 @@ while [ "$GROUPADD" != "$i" ] ;do
groupadd --gid "$GROUP_GID" "$GROUP_NAME" groupadd --gid "$GROUP_GID" "$GROUP_NAME"
done done
# USERADD="user1:1000:1000;user2:1001:1000;user3:1002:1002" # USERADD="user1:1000:1000:/bin/bash;user2:1001:1000:/bin/sh;user3:1002:1002:/bin/sh"
i=""
j=""
while [ "$USERADD" != "$i" ] ;do while [ "$USERADD" != "$i" ] ;do
i=${USERADD%%;*} i=${USERADD%%;*}
USERADD="${USERADD#$i;}" USERADD="${USERADD#$i;}"
USER_NAME=${i%%:*} USER_NAME=${i%%:*}
UID_GID="${i#$USER_NAME:}" j="${i#$USER_NAME:}"
USER_UID="${UID_GID%%:*}" USER_UID="${j%%:*}"
USER_GID="${UID_GID#$USER_UID:}" j="${j#$USER_UID:}"
USER_GID="${j%%:*}"
j="${j#$USER_GID:}"
USER_SHELL=$j
useradd --home-dir "$BASE_DIR/$USER_NAME" --uid "$USER_UID" --gid "$USER_GID" "$USER_NAME" useradd --home-dir "$BASE_DIR/$USER_NAME" --shell "$USER_SHELL" --uid "$USER_UID" --gid "$USER_GID" "$USER_NAME"
done done
# HOSTKEYS="/var/lib/jumpbox/ssh_host_ed25519_key;/var/lib/jumpbox/ssh_host_rsa_key"
i=""
if [ -n "$HOSTKEYS" ]; then
while [ "$HOSTKEYS" != "$i" ]; do
i=${HOSTKEYS%%;*}
HOSTKEYS="${HOSTKEYS#$i;}"
if [ ! -e "$i" ]; then
echo "Could not read $i, file is missing"
continue
else
echo "Configuring HostKey $i"
fi
FILENAME=$(basename "$i")
if [ ! -e "/etc/ssh/$FILENAME" ]; then
install -m 0600 "$i" "/etc/ssh/$FILENAME"
ssh-keygen -y -f "$i" > "/etc/ssh/$FILENAME.pub"
ssh-keygen -l -f "/etc/ssh/$FILENAME.pub"
fi
if ! grep "^HostKey /etc/ssh/$FILENAME" /etc/ssh/sshd_config; then
echo "HostKey /etc/ssh/$FILENAME" >> /etc/ssh/sshd_config
fi
done
fi
if [ -z "$(find /etc/ssh/ -maxdepth 1 -name 'ssh_host_*_key' -print -quit)" ]; then if [ -z "$(find /etc/ssh/ -maxdepth 1 -name 'ssh_host_*_key' -print -quit)" ]; then
echo "Creating SSH2 ED25519 key; this may take some time ..." echo "Creating SSH2 ED25519 key; this may take some time ..."
ssh-keygen -q -f /etc/ssh/ssh_host_ed25519_key -N '' -t ed25519 ssh-keygen -q -f /etc/ssh/ssh_host_ed25519_key -N '' -t ed25519