mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-25 18:40:06 -04:00
Validating git commit against my gpg signing key during upgrade. Upgrade will not take place unless the git commit is correctly signed.
This commit is contained in:
parent
795d5340c7
commit
d4ef9cf12f
1 changed files with 31 additions and 2 deletions
33
upgrade.sh
33
upgrade.sh
|
|
@ -75,6 +75,10 @@ fi
|
|||
trap '
|
||||
EXIT_STATUS=$?
|
||||
rm -f /tmp/wrolpi-upgrade.env
|
||||
# Clean up temporary GPG keyring if it exists.
|
||||
if [ -n "$GNUPGHOME" ] && [ -d "$GNUPGHOME" ]; then
|
||||
rm -rf "$GNUPGHOME"
|
||||
fi
|
||||
if [ $EXIT_STATUS -eq 0 ]; then
|
||||
echo "WROLPi upgrade has completed"
|
||||
else
|
||||
|
|
@ -91,8 +95,33 @@ set -o pipefail
|
|||
systemctl stop wrolpi-api
|
||||
systemctl stop wrolpi-app
|
||||
|
||||
# Pull the latest commit of the requested branch.
|
||||
(cd /opt/wrolpi && git fetch && git checkout "${BRANCH}" && git reset --hard origin/"${BRANCH}") || exit 4
|
||||
# Fetch the latest commits without modifying the working tree.
|
||||
git -C /opt/wrolpi fetch || exit 4
|
||||
|
||||
# Import the trusted GPG key from the current (pre-upgrade) working tree into a temporary keyring.
|
||||
GNUPGHOME=$(mktemp -d)
|
||||
export GNUPGHOME
|
||||
gpg --batch --quiet --import /opt/wrolpi/wrolpi/roland@learningselfreliance.com.gpg
|
||||
|
||||
# Verify the fetched commit is signed by the trusted key before checking it out.
|
||||
if ! git -C /opt/wrolpi verify-commit origin/"${BRANCH}" 2>&1; then
|
||||
echo "ERROR: origin/${BRANCH} is not signed by the trusted WROLPi GPG key. Aborting upgrade."
|
||||
rm -rf "$GNUPGHOME"
|
||||
exit 5
|
||||
fi
|
||||
|
||||
# Signature verified, safe to apply.
|
||||
(cd /opt/wrolpi && git checkout "${BRANCH}" && git reset --hard origin/"${BRANCH}") || exit 4
|
||||
|
||||
# Verify HEAD again after checkout in case the branch was swapped between fetch and checkout.
|
||||
if ! git -C /opt/wrolpi verify-commit HEAD 2>&1; then
|
||||
echo "ERROR: HEAD commit signature verification failed after checkout. Aborting upgrade."
|
||||
rm -rf "$GNUPGHOME"
|
||||
exit 6
|
||||
fi
|
||||
|
||||
rm -rf "$GNUPGHOME"
|
||||
unset GNUPGHOME
|
||||
|
||||
/opt/wrolpi/scripts/upgrade.sh 2>&1 | tee /opt/wrolpi/upgrade.log
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue