Skip to content

Commit

Permalink
nixos/acme: Set up webroot as non-root user
Browse files Browse the repository at this point in the history
(cherry picked from commit 5b4f9c4)
  • Loading branch information
m1cr0man committed Feb 6, 2021
1 parent 96508ce commit 93ac91d
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions nixos/modules/security/acme.nix
Original file line number Diff line number Diff line change
Expand Up @@ -267,21 +267,19 @@ let
${data.postRun}
fi
'');

} // (optionalAttrs (data.webroot != null) {
# Lego always tries to create .well-known/acme-challenge, but if webroot is owned
# by the wrong user then it will crash and break cert renewal.
ExecStartPre = "+" + pkgs.writeShellScript "acme-${cert}-make-webroot" ''
mkdir -p '${data.webroot}/.well-known/acme-challenge'
cd '${data.webroot}'
chown 'acme:${data.group}' . .well-known .well-known/acme-challenge
'';
});
};

# Working directory will be /tmp
script = ''
set -euo pipefail
${optionalString (data.webroot != null) ''
# Ensure the webroot exists
mkdir -p '${data.webroot}/.well-known/acme-challenge'
chown 'acme:${data.group}' ${data.webroot}/{.well-known,.well-known/acme-challenge} \
|| echo "Please fix the permissions under ${data.webroot}/.well-known/acme-challenge" && exit 1
''}
echo '${domainHash}' > domainhash.txt
# Check if we can renew
Expand Down

0 comments on commit 93ac91d

Please sign in to comment.