Skip to content

Commit 241a42c

Browse files
author
Gabe Pacuilla
authored
DEV: Ensure secure file permissions by default (#627)
`discourse-setup` will now ensure container definitions are installed with `0600` permissions mode only. `launcher` will now throw a warning when an existing container definition is world-readable. Also clean up leftover `launcher setup` logic which no longer exists. Merge pre-existing logic into `check_prereqs` function.
1 parent 165ede9 commit 241a42c

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

discourse-setup

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ then
884884
DATE=`date +"%Y-%m-%d-%H%M%S"`
885885
BACKUP=$app_name.yml.$DATE.bak
886886
echo Saving old file as $BACKUP
887-
cp $web_file containers/$BACKUP
887+
install -m0600 $web_file containers/$BACKUP
888888
if [ "$DEBUG" != "1" ]
889889
then
890890
echo "Stopping existing container in 5 seconds or Control-C to cancel."
@@ -902,7 +902,7 @@ else
902902
then
903903
check_ports
904904
fi
905-
cp -v $web_template $web_file
905+
install -v -m0600 $web_template $web_file
906906
if [ "$data_name" == "data" ]
907907
then
908908
echo "--------------------------------------------------"
@@ -918,7 +918,7 @@ else
918918
echo "Problem changing DISCOURSE_DB_PASSWORD" in $web_file
919919
fi
920920

921-
cp -v $data_template $data_file
921+
install -v -m0600 $data_template $data_file
922922
quote=\'
923923
sed -i -e "s/password ${quote}SOME_SECRET${quote}/password '$DISCOURSE_DB_PASSWORD'/w $changelog" $data_file
924924
if [ -s $changelog ]

launcher

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,16 @@ check_prereqs() {
278278
fi
279279
exit 1
280280
fi
281+
282+
# 8. container definition file is accessible and is not insecure (world-readable)
283+
if [[ ! -e "$config_file" || ! -r "$config_file" ]]; then
284+
echo "ERROR: $config_file does not exist or is not readable."
285+
echo
286+
echo "Available configs ( `cd containers && ls -dm *.yml | tr -s '\n' ' ' | awk '{ gsub(/\.yml/, ""); print }'`)"
287+
exit 1
288+
elif [[ "$(find $config_file -perm -004)" ]]; then
289+
echo "WARNING: $config_file file is world-readable. You can secure this file by running: chmod o-rwx $config_file"
290+
fi
281291
}
282292

283293

@@ -486,15 +496,6 @@ fi
486496
exit 0
487497
}
488498

489-
if [ ! "$command" == "setup" ]; then
490-
if [[ ! -e $config_file ]]; then
491-
echo "Config file was not found, ensure $config_file exists"
492-
echo
493-
echo "Available configs ( `cd containers && ls -dm *.yml | tr -s '\n' ' ' | awk '{ gsub(/\.yml/, ""); print }'`)"
494-
exit 1
495-
fi
496-
fi
497-
498499
docker_version=($($docker_path --version))
499500
docker_version=${test[2]//,/}
500501
restart_policy=${restart_policy:---restart=always}

0 commit comments

Comments
 (0)