Skip to content

Commit 76a6df6

Browse files
committed
create function to harden sshd config ; execute it before repairing old backports
1 parent 7662215 commit 76a6df6

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

templates/common/util_functions

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,24 @@ function prepare_conda_env() {
490490
fi
491491
}
492492

493+
function harden_sshd_config() {
494+
# disable sha1 algorithms for kex and kex-gss features
495+
declare -rA feature_map=(["kex"]="kexalgorithms" ["kex-gss"]="gssapikexalgorithms")
496+
for ftr in "${!feature_map[@]}" ; do
497+
export feature=${feature_map[$ftr]}
498+
sshd_config_line=$(
499+
(sshd -T | awk "/^${feature} / {print $2}" | sed -e 's/,/\n/g';
500+
ssh -Q "${ftr}" ) \
501+
| sort | uniq | grep sha1 | perl -e \
502+
'print("$ENV{feature} -",join(q",",map{ chomp; $_ }<STDIN>), $/)')
503+
grep -v "^${feature} -" /etc/ssh/sshd_config > /tmp/sshd_config_new
504+
echo "$sshd_config_line >> /tmp/sshd_config_new"
505+
# TODO: test whether sshd will reload with this change before mv
506+
mv /tmp/sshd_config_new /etc/ssh/sshd_config
507+
done
508+
systemctl reload ssh
509+
}
510+
493511
function prepare_common_env() {
494512
SPARK_NLP_VERSION="3.2.1" # Must include subminor version here
495513
SPARK_JARS_DIR=/usr/lib/spark/jars
@@ -550,9 +568,10 @@ function prepare_common_env() {
550568

551569
is_complete prepare.common && return
552570

553-
repair_old_backports
571+
harden_sshd_config
554572

555573
if is_debuntu ; then
574+
repair_old_backports
556575
clean_up_sources_lists
557576
apt-get update -qq --allow-releaseinfo-change
558577
apt-get -y clean

0 commit comments

Comments
 (0)