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
+27
-2
@@ -122,7 +122,22 @@ fi
|
||||
# fast instead of hanging the install on a silent username/password
|
||||
# prompt.
|
||||
if [ -d "$APP_DIR/.git" ]; then
|
||||
GIT_TERMINAL_PROMPT=0 git -C "$APP_DIR" fetch --tags --force || true
|
||||
# Deliberately NOT --force (S7, matches scripts/upgrade.sh): a plain
|
||||
# `git fetch --tags` refuses to move a tag ref this checkout already
|
||||
# has onto a different commit, so a rewritten/tampered release tag
|
||||
# gets reported here instead of silently followed. A fresh checkout
|
||||
# with no tags at all, or an unreachable remote, both legitimately
|
||||
# fail this fetch too — this is a first install, not an upgrade, so
|
||||
# either case still falls through to "stay on whatever's checked out"
|
||||
# below rather than blocking the install.
|
||||
FETCH_OUTPUT="$(GIT_TERMINAL_PROMPT=0 git -C "$APP_DIR" fetch --tags 2>&1)" || {
|
||||
echo "$FETCH_OUTPUT" >&2
|
||||
if echo "$FETCH_OUTPUT" | grep -q "would clobber existing tag"; then
|
||||
echo "==> A release tag points at a different commit than expected —" \
|
||||
"leaving it alone rather than force-following it. Investigate" \
|
||||
"with 'git fetch --tags --dry-run -v' before deploying." >&2
|
||||
fi
|
||||
}
|
||||
LATEST_TAG="$(git -C "$APP_DIR" tag --sort=-creatordate | head -n1)"
|
||||
if [ -n "$LATEST_TAG" ]; then
|
||||
echo "==> Checking out latest release: $LATEST_TAG"
|
||||
@@ -153,7 +168,17 @@ if [ ! -d "$VENV_DIR" ]; then
|
||||
fi
|
||||
echo "==> Installing Evection and its dependencies"
|
||||
sudo -u "$EVECTION_USER" -H "$VENV_DIR/bin/pip" install --upgrade pip
|
||||
sudo -u "$EVECTION_USER" -H "$VENV_DIR/bin/pip" install "$APP_DIR"
|
||||
# requirements.txt (generated by `pip-compile --generate-hashes`, committed
|
||||
# alongside pyproject.toml) pins every dependency to an exact, hash-
|
||||
# verified version (S7) — two installs of the same release get identical
|
||||
# dependency code, and a tampered or substituted package on the index
|
||||
# fails the hash check instead of installing silently. --require-hashes
|
||||
# also means every entry in the file must carry a hash, so an
|
||||
# unreviewed/unpinned addition fails closed rather than installing
|
||||
# unverified. The app itself is installed separately with --no-deps: its
|
||||
# own version is pinned by which git tag is checked out, not by this file.
|
||||
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 "$APP_DIR"
|
||||
|
||||
# --- 4. .env --------------------------------------------------------------
|
||||
|
||||
|
||||
+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