Skip to content

Commit 8afd439

Browse files
authored
Merge pull request #55 from cron-eu/import-pub-keys
Add IMPORT_PUB_KEYS setting to add misc ssh pub keys
2 parents 215fd48 + c36b312 commit 8afd439

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ Application root is `/app`. Application runs as user `application` (uid=1000).
149149
| `IMPORT_GITLAB_SERVER` | ssh | git.cron.eu | Gitlab instance to import SSH key from |
150150
| `IMPORT_GITLAB_PUB_KEYS` | ssh | | Gitlab user to import SSH keys from |
151151
| `IMPORT_GITHUB_PUB_KEYS` | ssh | | GitHub user to import SSH keys from |
152+
| `IMPORT_PUB_KEYS` | ssh | | Additional SSH public keys to load, comma separated |
152153
| `SSH_CONFIG` | ssh | | The whole content of the `.ssh/config` file |
153154
| `SSH_KNOWN_HOSTS` | ssh | | The whole content of the `.ssh/known_hosts` file |
154155
| `SSH_PRIVATE_KEY` | ssh | | A SSH private key to load in an `ssh-agent`, useful if you run a SSH container with commands | |

example-app/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#IMPORT_GITLAB_SERVER=
99
#IMPORT_GITLAB_PUB_KEYS=
1010
#IMPORT_GITHUB_PUB_KEYS=
11+
# Comma separated list of SSH public keys
12+
#IMPORT_PUB_KEYS=ssh-ed25519 ...
1113

1214
# -----------------------------------------
1315
# For your application itself

files/ssh/entrypoint.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ fi
2424
# Make sure 'application' home directory exists...
2525
mkdir -p $APP_USER_HOME && chown $APP_USER $APP_USER_HOME
2626

27-
if [[ "$IS_RUN" == "false" ]] && [[ -z "${IMPORT_GITLAB_PUB_KEYS}" ]] && [[ -z "${IMPORT_GITHUB_PUB_KEYS}" ]]; then
28-
echo "WARNING: env variable \$IMPORT_GITHUB_PUB_KEYS or IMPORT_GITLAB_PUB_KEYS is not set. Please set it to have access to this container via SSH."
27+
if [[ "$IS_RUN" == "false" ]] && [[ -z "${IMPORT_GITLAB_PUB_KEYS}" ]] && [[ -z "${IMPORT_GITHUB_PUB_KEYS}" ]] && [[ -z "${IMPORT_PUB_KEYS}" ]] ; then
28+
echo "WARNING: env variable \$IMPORT_GITHUB_PUB_KEYS, \$IMPORT_GITLAB_PUB_KEYS and \$IMPORT_PUB_KEYS are not set. Please set it one of it have access to this container via SSH."
2929
fi
3030

3131
# -------------------------------------------------------------------------
@@ -62,6 +62,23 @@ if [[ ! -z "${IMPORT_GITHUB_PUB_KEYS}" && "$IS_RUN" == "false" ]]; then
6262
done
6363
fi
6464

65+
# -------------------------------------------------------------------------
66+
# Import SSH keys from IMPORT_PUB_KEYS
67+
68+
if [[ ! -z "${IMPORT_PUB_KEYS}" && "$IS_RUN" == "false" ]]; then
69+
echo "* importing SSH keys from \$IMPORT_PUB_KEYS:"
70+
mkdir -p $APP_USER_HOME/.ssh
71+
echo "# Keys from \$IMPORT_PUB_KEYS:" >> $APP_USER_HOME/.ssh/authorized_keys
72+
IFS=',' read -ra keys <<< "$IMPORT_PUB_KEYS"
73+
for key in "${keys[@]}"; do
74+
trimmed=$(echo "$key" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
75+
echo " - $trimmed"
76+
echo "$trimmed" >> $APP_USER_HOME/.ssh/authorized_keys
77+
done
78+
chmod 600 $APP_USER_HOME/.ssh/authorized_keys
79+
chown ${APP_USER}: $APP_USER_HOME/.ssh/authorized_keys
80+
fi
81+
6582
# -------------------------------------------------------------------------
6683
# Import SSH user settings from env
6784

0 commit comments

Comments
 (0)