Skip to content

Add support for trusted user CA keys and authorized principals in OpenSSH config #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions readme-vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ opt_param_env_vars:
- {env_var: "USER_PASSWORD_FILE", env_value: "/path/to/file", desc: "Optionally specify a file that contains the password. This setting supersedes the `USER_PASSWORD` option (works with docker secrets)."}
- {env_var: "USER_NAME", env_value: "linuxserver.io", desc: "Optionally specify a user name (Default:`linuxserver.io`)"}
- {env_var: "LOG_STDOUT", env_value: "", desc: "Set to `true` to log to stdout instead of file."}
- {env_var: "TRUSTED_USER_CA_KEYS", env_value: "", desc: "Optionally trusted user CA keys, which will automatically be added to trusted user CA keys."}
- {env_var: "TRUSTED_USER_CA_KEYS_FILE", env_value: "/path/to/file", desc: "Optionally specify a file containing the trusted user CA keys (works with docker secrets)."}
- {env_var: "AUTHORIZED_PRINCIPALS", env_value: "", desc: "Optionally specify a list of authorized principals. space separated list."}
- {env_var: "AUTHORIZED_PRINCIPALS_FILE", env_value: "/path/to/file", desc: "Optionally specify a file containing a list of authorized principals."}
- {env_var: "ADD_DEFAULT_USER_TO_AUTHORIZED_PRINCIPALS", env_value: "false", desc: "Set to `true` to add the default user to the list of authorized principals."}
readonly_supported: false
nonroot_supported: false
# application setup block
Expand Down Expand Up @@ -115,6 +120,7 @@ init_diagram: |
"openssh-server:latest" <- Base Images
# changelog
changelogs:
- {date: "12.02.25:", desc: "Add support for trusted user CA keys"}
- {date: "10.02.25:", desc: "Add support for sshd_config.d"}
- {date: "12.01.25:", desc: "Rebase to Alpine 3.21."}
- {date: "24.11.24:", desc: "Move sshd_config to /config/sshd/sshd_config."}
Expand Down
58 changes: 58 additions & 0 deletions root/etc/s6-overlay/s6-rc.d/init-openssh-server-config/run
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,64 @@ if [[ -d "$PUBLIC_KEY_DIR" ]]; then
done
fi

# set trusted user CA keys
if [[ -n "$TRUSTED_USER_CA_KEYS" ]]; then
touch /config/.ssh/trusted_user_ca_keys
if ! grep -q "${TRUSTED_USER_CA_KEYS}" /config/.ssh/trusted_user_ca_keys; then
echo "$TRUSTED_USER_CA_KEYS" >> /config/.ssh/trusted_user_ca_keys
echo "Trusted user CA keys added"
fi
fi

if [[ -n "$TRUSTED_USER_CA_KEYS_FILE" ]] && [[ -f "$TRUSTED_USER_CA_KEYS_FILE" ]]; then
touch /config/.ssh/trusted_user_ca_keys
TRUSTED_USER_CA_KEYS2=$(cat "$TRUSTED_USER_CA_KEYS_FILE")
if ! grep -q "$TRUSTED_USER_CA_KEYS2" /config/.ssh/trusted_user_ca_keys; then
echo "$TRUSTED_USER_CA_KEYS2" >> /config/.ssh/trusted_user_ca_keys
echo "Trusted user CA keys from file added"
fi
fi

if [[ -f /config/.ssh/trusted_user_ca_keys ]]; then
if ! grep -q "^TrustedUserCAKeys" /etc/ssh/sshd_config; then
echo "TrustedUserCAKeys /config/.ssh/trusted_user_ca_keys" >> /etc/ssh/sshd_config
else
sed -i '/^#TrustedUserCAKeys/c\TrustedUserCAKeys /config/.ssh/trusted_user_ca_keys' /etc/ssh/sshd_config
sed -i '/^TrustedUserCAKeys/c\TrustedUserCAKeys /config/.ssh/trusted_user_ca_keys' /etc/ssh/sshd_config
fi
fi

# set authorized principals
if [[ -n "$AUTHORIZED_PRINCIPALS" ]]; then
touch /config/.ssh/authorized_principals

for principal in $AUTHORIZED_PRINCIPALS; do
echo "$principal" >> /config/.ssh/authorized_principals
echo "add $principal Authorized principals added"
done
fi

if [[ -n "$AUTHORIZED_PRINCIPALS_FILE" ]] && [[ -f "$AUTHORIZED_PRINCIPALS_FILE" ]]; then
touch /config/.ssh/authorized_principals
cat $AUTHORIZED_PRINCIPALS_FILE >> /config/.ssh/authorized_principals
echo "Authorized principals from file added"
fi

if [[ "$ADD_DEFAULT_USER_TO_AUTHORIZED_PRINCIPALS" == "true" ]]; then
touch /config/.ssh/authorized_principals
echo "$USER_NAME" > /config/.ssh/authorized_principals
echo "$USER_NAME added to Authorized principals"
fi

if [[ -f /config/.ssh/authorized_principals ]]; then
if ! grep -q "^AuthorizedPrincipalsFile" /etc/ssh/sshd_config; then
echo "AuthorizedPrincipalsFile /config/.ssh/authorized_principals" >> /etc/ssh/sshd_config
else
sed -i '/^#AuthorizedPrincipalsFile/c\AuthorizedPrincipalsFile /config/.ssh/authorized_principals' /etc/ssh/sshd_config
sed -i '/^AuthorizedPrincipalsFile/c\AuthorizedPrincipalsFile /config/.ssh/authorized_principals' /etc/ssh/sshd_config
fi
fi

# back up old log files processed by logrotate
if [[ -f /config/logs/openssh/openssh.log ]]; then
mv /config/logs/openssh /config/logs/openssh.old.logs
Expand Down