Skip to content

Commit 886494b

Browse files
committed
Add support for trusted user CA keys and authorized principals in OpenSSH config
1 parent 2637dee commit 886494b

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

  • root/etc/s6-overlay/s6-rc.d/init-openssh-server-config

root/etc/s6-overlay/s6-rc.d/init-openssh-server-config/run

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,66 @@ if [[ -d "$PUBLIC_KEY_DIR" ]]; then
112112
done
113113
fi
114114

115+
# set trusted user CA keys
116+
if [[ -n "$TRUSTED_USER_CA_KEYS" ]]; then
117+
touch /config/.ssh/trusted_user_ca_keys
118+
if ! grep -q "${TRUSTED_USER_CA_KEYS}" /config/.ssh/trusted_user_ca_keys; then
119+
echo "$TRUSTED_USER_CA_KEYS" >> /config/.ssh/trusted_user_ca_keys
120+
echo "Trusted user CA keys added"
121+
fi
122+
fi
123+
124+
if [[ -n "$TRUSTED_USER_CA_KEYS_FILE" ]] && [[ -f "$TRUSTED_USER_CA_KEYS_FILE" ]]; then
125+
touch /config/.ssh/trusted_user_ca_keys
126+
TRUSTED_USER_CA_KEYS2=$(cat "$TRUSTED_USER_CA_KEYS_FILE")
127+
if ! grep -q "$TRUSTED_USER_CA_KEYS2" /config/.ssh/trusted_user_ca_keys; then
128+
echo "$TRUSTED_USER_CA_KEYS2" >> /config/.ssh/trusted_user_ca_keys
129+
echo "Trusted user CA keys from file added"
130+
fi
131+
fi
132+
133+
if [[ -f /config/.ssh/trusted_user_ca_keys ]]; then
134+
if ! grep -q "^TrustedUserCAKeys" /etc/ssh/sshd_config; then
135+
echo "TrustedUserCAKeys /config/.ssh/trusted_user_ca_keys" >> /etc/ssh/sshd_config
136+
else
137+
sed -i '/^#TrustedUserCAKeys/c\TrustedUserCAKeys /config/.ssh/trusted_user_ca_keys' /etc/ssh/sshd_config
138+
sed -i '/^TrustedUserCAKeys/c\TrustedUserCAKeys /config/.ssh/trusted_user_ca_keys' /etc/ssh/sshd_config
139+
fi
140+
fi
141+
142+
# set authorized principals
143+
if [[ -n "$AUTHORIZED_PRINCIPALS" ]]; then
144+
touch /config/.ssh/authorized_principals
145+
if ! grep -q "${AUTHORIZED_PRINCIPALS}" /config/.ssh/authorized_principals; then
146+
echo "$AUTHORIZED_PRINCIPALS" >> /config/.ssh/authorized_principals
147+
echo "Authorized principals added"
148+
fi
149+
fi
150+
151+
if [[ -n "$AUTHORIZED_PRINCIPALS_FILE" ]] && [[ -f "$AUTHORIZED_PRINCIPALS_FILE" ]]; then
152+
touch /config/.ssh/authorized_principals
153+
AUTHORIZED_PRINCIPALS2=$(cat "$AUTHORIZED_PRINCIPALS_FILE")
154+
if ! grep -q "$AUTHORIZED_PRINCIPALS2" /config/.ssh/authorized_principals; then
155+
echo "$AUTHORIZED_PRINCIPALS2" >> /config/.ssh/authorized_principals
156+
echo "Authorized principals from file added"
157+
fi
158+
fi
159+
160+
if [[ "$ADD_DEFAULT_USER_TO_AUTHORIZED_PRINCIPALS" == "true" ]]; then
161+
touch /config/.ssh/authorized_principals
162+
echo "$USER_NAME" > /config/.ssh/authorized_principals
163+
echo "$USER_NAME added to Authorized principals"
164+
fi
165+
166+
if [[ -f /config/.ssh/authorized_principals ]]; then
167+
if ! grep -q "^AuthorizedPrincipalsFile" /etc/ssh/sshd_config; then
168+
echo "AuthorizedPrincipalsFile /config/.ssh/authorized_principals" >> /etc/ssh/sshd_config
169+
else
170+
sed -i '/^#AuthorizedPrincipalsFile/c\AuthorizedPrincipalsFile /config/.ssh/authorized_principals' /etc/ssh/sshd_config
171+
sed -i '/^AuthorizedPrincipalsFile/c\AuthorizedPrincipalsFile /config/.ssh/authorized_principals' /etc/ssh/sshd_config
172+
fi
173+
fi
174+
115175
# back up old log files processed by logrotate
116176
if [[ -f /config/logs/openssh/openssh.log ]]; then
117177
mv /config/logs/openssh /config/logs/openssh.old.logs

0 commit comments

Comments
 (0)