From a68fd6429f8c97627c6d69ca8ff750ad753347c3 Mon Sep 17 00:00:00 2001 From: Helmuth Gronewold Date: Fri, 22 Aug 2014 22:55:34 +0200 Subject: [PATCH 1/3] The secret key that encrypts the backups should not be world readable. --- setup/management.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup/management.sh b/setup/management.sh index b793b990..e8220609 100755 --- a/setup/management.sh +++ b/setup/management.sh @@ -10,6 +10,8 @@ mkdir -p $STORAGE_ROOT/backup if [ ! -f $STORAGE_ROOT/backup/secret_key.txt ]; then openssl rand -base64 2048 > $STORAGE_ROOT/backup/secret_key.txt fi +# The secret key to encrypt backups should not be world readable. +chmod 0600 $STORAGE_ROOT/backup/secret_key.txt # Link the management server daemon into a well known location. rm -f /usr/local/bin/mailinabox-daemon From ee9552734f950c2cf9895ea8734e1de7879568b0 Mon Sep 17 00:00:00 2001 From: Helmuth Gronewold Date: Fri, 22 Aug 2014 23:23:56 +0200 Subject: [PATCH 2/3] Fix permissions of backup secret according to Josh's comment at https://github.com/mail-in-a-box/mailinabox/pull/150#issuecomment-53120156 --- setup/management.sh | 4 +--- setup/migrate.py | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/setup/management.sh b/setup/management.sh index e8220609..fdde0c17 100755 --- a/setup/management.sh +++ b/setup/management.sh @@ -8,10 +8,8 @@ hide_output pip3 install rtyaml # Create a backup directory and a random key for encrypting backups. mkdir -p $STORAGE_ROOT/backup if [ ! -f $STORAGE_ROOT/backup/secret_key.txt ]; then - openssl rand -base64 2048 > $STORAGE_ROOT/backup/secret_key.txt + $(umask 077; openssl rand -base64 2048 > $STORAGE_ROOT/backup/secret_key.txt) fi -# The secret key to encrypt backups should not be world readable. -chmod 0600 $STORAGE_ROOT/backup/secret_key.txt # Link the management server daemon into a well known location. rm -f /usr/local/bin/mailinabox-daemon diff --git a/setup/migrate.py b/setup/migrate.py index 87c915ab..08460961 100755 --- a/setup/migrate.py +++ b/setup/migrate.py @@ -56,6 +56,10 @@ def migration_4(env): db = os.path.join(env["STORAGE_ROOT"], 'mail/users.sqlite') shell("check_call", ["sqlite3", db, "ALTER TABLE users ADD privileges TEXT NOT NULL DEFAULT ''"]) +def migration_5(env): + # The secret key for encrypting backups was world readable. Fix here. + os.chmod(os.path.join(env["STORAGE_ROOT"], 'backup/secret_key.txt'), 600) + def get_current_migration(): ver = 0 while True: From 90c7655d82e7492f3222ab153089d67830ad4547 Mon Sep 17 00:00:00 2001 From: Helmuth Gronewold Date: Sun, 24 Aug 2014 21:27:39 +0200 Subject: [PATCH 3/3] Fix wrong permissions of backup secret. Pyhton 3 needs octal permissions. --- setup/migrate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/migrate.py b/setup/migrate.py index 08460961..d2ecff24 100755 --- a/setup/migrate.py +++ b/setup/migrate.py @@ -58,7 +58,7 @@ def migration_4(env): def migration_5(env): # The secret key for encrypting backups was world readable. Fix here. - os.chmod(os.path.join(env["STORAGE_ROOT"], 'backup/secret_key.txt'), 600) + os.chmod(os.path.join(env["STORAGE_ROOT"], 'backup/secret_key.txt'), 0o600) def get_current_migration(): ver = 0