Compare commits
4 Commits
9e250080cd
...
699498fe2c
Author | SHA1 | Date | |
---|---|---|---|
699498fe2c | |||
aeee18b935 | |||
825e872a8d | |||
058adb0514 |
11
Dockerfile
11
Dockerfile
@ -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 /
|
||||||
|
@ -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
|
||||||
```
|
```
|
||||||
|
2
build.sh
2
build.sh
@ -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
|
||||||
|
43
start.sh
43
start.sh
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user