Private
Public Access
Pin dependencies by hash and refuse to follow a rewritten release tag (S7)
pyproject.toml used broad version ranges with no lock file, so two deployments of the same release could end up with different dependency versions, and there was no check that a package actually matches what was reviewed/tested — a compromised or substituted package on the index could install silently. requirements.txt and requirements-dev.txt (generated via `pip-compile --generate-hashes`, see the new README section on regenerating them) pin every dependency to an exact version with its hash. install.sh and upgrade.sh now install from requirements.txt with --require-hashes, then the app itself with --no-deps — a tampered or substituted package fails the hash check instead of installing. Both scripts also no longer `git fetch --tags --force`: a plain fetch refuses to move a tag ref they already have onto a different commit, so a rewritten/tampered release tag is reported and stops the deploy/install instead of being silently followed into production. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
03dd37e69d
commit
cb5617edb8
6 files changed
+1257
-4
No files matched your search
+32
-2
@@ -54,7 +54,30 @@ cd "$APP_DIR"
|
||||
# the service user has no reason to have its own git credentials set up,
|
||||
# and GIT_TERMINAL_PROMPT=0 means a credential problem fails fast instead
|
||||
# of hanging the upgrade on a silent username/password prompt.
|
||||
GIT_TERMINAL_PROMPT=0 git fetch --tags --force
|
||||
#
|
||||
# Deliberately NOT --force (S7): a plain `git fetch --tags` refuses to
|
||||
# move a tag ref this checkout already has onto a different commit — the
|
||||
# exact situation if a release tag were rewritten (rolled back, re-cut
|
||||
# against a different commit, or tampered with) rather than a new tag
|
||||
# being added. --force would silently follow that rewritten tag into
|
||||
# production; refusing and stopping here means a human has to look at
|
||||
# what actually changed before this script will deploy it.
|
||||
set +e
|
||||
FETCH_OUTPUT="$(GIT_TERMINAL_PROMPT=0 git fetch --tags 2>&1)"
|
||||
FETCH_STATUS=$?
|
||||
set -e
|
||||
if [ "$FETCH_STATUS" -ne 0 ]; then
|
||||
echo "$FETCH_OUTPUT" >&2
|
||||
if echo "$FETCH_OUTPUT" | grep -q "would clobber existing tag"; then
|
||||
echo
|
||||
echo "A release tag points at a different commit than this checkout" \
|
||||
"already has for it, rather than only new tags having been added." \
|
||||
"Refusing to force-follow a rewritten tag (S7) — review what" \
|
||||
"actually changed before deciding to update it yourself, e.g.:" \
|
||||
" git fetch --tags --dry-run -v" >&2
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
LATEST_TAG="$(git tag --sort=-creatordate | head -n1)"
|
||||
if [ -z "$LATEST_TAG" ]; then
|
||||
echo "No tags found in this repo — nothing to deploy." \
|
||||
@@ -85,7 +108,14 @@ else
|
||||
fi
|
||||
|
||||
echo "==> Installing updated dependencies"
|
||||
sudo -u "$EVECTION_USER" -H "$VENV_DIR/bin/pip" install --upgrade "$APP_DIR"
|
||||
# requirements.txt (generated by `pip-compile --generate-hashes`, committed
|
||||
# alongside pyproject.toml, and checked out as part of $LATEST_TAG above)
|
||||
# pins every dependency to an exact, hash-verified version (S7) — this
|
||||
# deploy gets exactly the dependency code that release was tested
|
||||
# against, and a tampered or substituted package on the index fails the
|
||||
# hash check instead of installing silently.
|
||||
sudo -u "$EVECTION_USER" -H "$VENV_DIR/bin/pip" install --require-hashes -r "$APP_DIR/requirements.txt"
|
||||
sudo -u "$EVECTION_USER" -H "$VENV_DIR/bin/pip" install --no-deps --upgrade "$APP_DIR"
|
||||
|
||||
echo "==> Running migrations"
|
||||
sudo -u "$EVECTION_USER" -H env DJANGO_SETTINGS_MODULE=config.settings.prod \
|
||||
|
||||
Reference in new issue
Block a user