mirror of
https://github.com/rommapp/romm.git
synced 2026-11-28 17:48:31 +01:00
chore(security): verify dev toolchain downloads (#5218)
* chore(security): verify dev toolchain downloads and pin dev image digests dev-setup.sh piped astral.sh's uv installer into sh and fetched Node and the Trunk launcher without any checksum. uv now comes from its GitHub release tarball checked against the published .sha256, Node against the release's SHASUMS256.txt, and the Trunk launcher from its versioned URL against a pinned sha256 (the launcher then verifies the CLI against the pins in .trunk/trunk.yaml). The dev Dockerfile pinned ubuntu:22.04 and the uv image by tag only; both are now pinned by digest like docker/Dockerfile. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(dev-setup): pick musl uv builds and stage downloads outside ~/.local/bin code-review pass: a partial Trunk download no longer leaves a non-executable trunk that later runs skip, and download temp dirs are removed on any exit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(dev-setup): simplify pass on the verified downloads Drop the uv-only musl branch (Node and apt already rule out musl hosts), fail fast when no published checksum matches, create ~/.local/bin once, and remove a dead cleanup the EXIT trap already covers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
committed by
GitHub
parent
47dccbc95d
commit
2216f122c1
@@ -5,6 +5,7 @@ set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
LOCAL_BIN="${HOME}/.local/bin"
|
||||
mkdir -p "${LOCAL_BIN}"
|
||||
export PATH="${LOCAL_BIN}:${PATH}:/usr/sbin:/sbin"
|
||||
|
||||
with_db=false
|
||||
@@ -20,6 +21,32 @@ done
|
||||
|
||||
log() { printf '==> %s\n' "$*"; }
|
||||
|
||||
# The Trunk launcher verifies the CLI against the sha256 pins in .trunk/trunk.yaml.
|
||||
TRUNK_LAUNCHER_VERSION=1.3.5
|
||||
TRUNK_LAUNCHER_SHA256=700f8bbedfd226595999ea2202b9a7af75ba8398dd711f5f159f5bbba6cbf322
|
||||
|
||||
DOWNLOAD_DIR="$(mktemp -d)"
|
||||
trap 'rm -rf "${DOWNLOAD_DIR}"' EXIT
|
||||
|
||||
sha256_of() {
|
||||
if command -v sha256sum >/dev/null; then sha256sum "$1"; else shasum -a 256 "$1"; fi |
|
||||
cut -d' ' -f1
|
||||
}
|
||||
|
||||
fetch_verified() {
|
||||
local url="$1" want="$2" dest="$3" have
|
||||
if [[ -z ${want} ]]; then
|
||||
echo "No published checksum for ${url}" >&2
|
||||
exit 1
|
||||
fi
|
||||
curl -fsSL "${url}" -o "${dest}"
|
||||
have="$(sha256_of "${dest}")"
|
||||
if [[ ${have} != "${want}" ]]; then
|
||||
echo "Checksum mismatch for ${url}: expected '${want}', got '${have}'" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
as_root() {
|
||||
if [[ ${EUID} -eq 0 ]]; then "$@"; else sudo "$@"; fi
|
||||
}
|
||||
@@ -41,15 +68,29 @@ apt_install() {
|
||||
}
|
||||
|
||||
setup_uv() {
|
||||
local want have
|
||||
local want have platform target url sum
|
||||
want="$(sed -n 's/^ARG UV_VERSION=//p' "${ROOT}/docker/Dockerfile")"
|
||||
have="$(uv --version 2>/dev/null || true)"
|
||||
have="${have#uv }"
|
||||
have="${have%% *}"
|
||||
if [[ ${have} == "${want}" ]]; then return 0; fi
|
||||
platform="$(uname -sm)"
|
||||
case "${platform}" in
|
||||
"Linux x86_64") target=x86_64-unknown-linux-gnu ;;
|
||||
"Linux aarch64") target=aarch64-unknown-linux-gnu ;;
|
||||
"Darwin x86_64") target=x86_64-apple-darwin ;;
|
||||
"Darwin arm64") target=aarch64-apple-darwin ;;
|
||||
*)
|
||||
echo "No uv build for ${platform}; install uv ${want} by hand" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
url="https://github.com/astral-sh/uv/releases/download/${want}/uv-${target}.tar.gz"
|
||||
log "Installing uv ${want} (found ${have:-none})"
|
||||
curl -LsSf "https://astral.sh/uv/${want}/install.sh" |
|
||||
env UV_UNMANAGED_INSTALL="${LOCAL_BIN}" sh >/dev/null
|
||||
sum="$(curl -fsSL "${url}.sha256")"
|
||||
fetch_verified "${url}" "${sum%% *}" "${DOWNLOAD_DIR}/uv.tar.gz"
|
||||
tar -xzf "${DOWNLOAD_DIR}/uv.tar.gz" -C "${DOWNLOAD_DIR}" --strip-components=1
|
||||
install -m 755 "${DOWNLOAD_DIR}/uv" "${DOWNLOAD_DIR}/uvx" "${LOCAL_BIN}/"
|
||||
hash -r
|
||||
}
|
||||
|
||||
@@ -61,7 +102,7 @@ setup_backend() {
|
||||
}
|
||||
|
||||
setup_node() {
|
||||
local want have full os arch dest
|
||||
local want have full os arch dest file sum
|
||||
want="$(tr -d '[:space:]' <"${ROOT}/frontend/.nvmrc")"
|
||||
have="$(node --version 2>/dev/null || true)"
|
||||
if [[ ${have} == "v${want}."* ]]; then return 0; fi
|
||||
@@ -75,9 +116,11 @@ setup_node() {
|
||||
esac
|
||||
dest="${HOME}/.local/share/node/${full}"
|
||||
log "Installing Node ${full} (found ${have:-none})"
|
||||
mkdir -p "${dest}" "${LOCAL_BIN}"
|
||||
curl -fsSL "https://nodejs.org/dist/${full}/node-${full}-${os}-${arch}.tar.xz" |
|
||||
tar -xJ -C "${dest}" --strip-components=1
|
||||
mkdir -p "${dest}"
|
||||
file="node-${full}-${os}-${arch}.tar.xz"
|
||||
sum="$(curl -fsSL "https://nodejs.org/dist/${full}/SHASUMS256.txt" | awk -v f="${file}" '$2 == f { print $1 }')"
|
||||
fetch_verified "https://nodejs.org/dist/${full}/${file}" "${sum}" "${DOWNLOAD_DIR}/${file}"
|
||||
tar -xJf "${DOWNLOAD_DIR}/${file}" -C "${dest}" --strip-components=1
|
||||
ln -sf "${dest}/bin/node" "${dest}/bin/npm" "${dest}/bin/npx" "${LOCAL_BIN}/"
|
||||
hash -r
|
||||
}
|
||||
@@ -95,9 +138,9 @@ setup_frontend() {
|
||||
setup_trunk() {
|
||||
command -v trunk >/dev/null && return 0
|
||||
log "Installing Trunk and its linters"
|
||||
mkdir -p "${LOCAL_BIN}"
|
||||
curl -fsSL https://trunk.io/releases/trunk -o "${LOCAL_BIN}/trunk"
|
||||
chmod +x "${LOCAL_BIN}/trunk"
|
||||
fetch_verified "https://trunk.io/releases/launcher/${TRUNK_LAUNCHER_VERSION}/trunk" \
|
||||
"${TRUNK_LAUNCHER_SHA256}" "${DOWNLOAD_DIR}/trunk"
|
||||
install -m 755 "${DOWNLOAD_DIR}/trunk" "${LOCAL_BIN}/trunk"
|
||||
hash -r
|
||||
(cd "${ROOT}" && trunk install --ci >/dev/null 2>&1) ||
|
||||
log "Trunk could not download its linters (network policy?); trunk check will retry on first use"
|
||||
|
||||
Reference in New Issue
Block a user