1
0
Fork 0

feat: support configuring a shell for a user
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Pim van den Berg 2022-09-17 14:50:24 +02:00
parent aeee18b935
commit 699498fe2c
2 changed files with 15 additions and 8 deletions

View File

@ -16,7 +16,7 @@
| --- | --- | --- |
| `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` |
| `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};...` | Create user account(s) on startup |
| `USERADD` | `{username}:{uid}:{gid}:{shell};...` | Create user account(s) on startup |
| `GROUPADD` | `{groupname}:{gid};...` | Create group account(s) on startup |
| `BASE_DIR` | `/home` | Basedir used for user account creation (Default: `/home`) |
@ -28,7 +28,7 @@ $ docker run -it \
-v $(pwd)/jumpbox:/var/lib/jumpbox \
-e "ROOT_AUTHORIZED_KEYS=/var/lib/jumpbox/authorized_keys"
-e "HOSTKEYS=/var/lib/jumpbox/ssh_host_ed25519_key;/var/lib/jumpbox/ssh_host_rsa_key"
-e "USERADD=jumpbox:1000:1000"
-e "USERADD=jumpbox:1000:1000:/bin/bash"
-e "GROUPADD=jumpbox:1000"
-p 1022:22 \
pommib/jumpbox:latest
@ -50,6 +50,6 @@ services:
environment:
ROOT_AUTHORIZED_KEYS: /var/lib/jumpbox/authorized_keys
HOSTKEYS: /var/lib/jumpbox/ssh_host_ed25519_key;/var/lib/jumpbox/ssh_host_rsa_key
USERADD: jumpbox:1000:1000
USERADD: jumpbox:1000:1000:/bin/bash
GROUPADD: jumpbox:1000
```

View File

@ -22,6 +22,7 @@ if [ ! -d "$BASE_DIR" ]; then
fi
# GROUPADD="group1:1000;group2:1001;group3:1002"
i=""
while [ "$GROUPADD" != "$i" ] ;do
i=${GROUPADD%%;*}
GROUPADD="${GROUPADD#$i;}"
@ -32,20 +33,26 @@ while [ "$GROUPADD" != "$i" ] ;do
groupadd --gid "$GROUP_GID" "$GROUP_NAME"
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
i=${USERADD%%;*}
USERADD="${USERADD#$i;}"
USER_NAME=${i%%:*}
UID_GID="${i#$USER_NAME:}"
USER_UID="${UID_GID%%:*}"
USER_GID="${UID_GID#$USER_UID:}"
j="${i#$USER_NAME:}"
USER_UID="${j%%:*}"
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
# 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%%;*}