Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions components/cloud-environment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,27 @@ The interface between this component and consuming repositories:
- The component is repo-agnostic and must never contain secrets or
repo-specific logic.

## The `gh` pin

`gh` is installed from its checksummed upstream release asset
(`github.com/cli/cli/releases`, `linux_amd64`), not from `apt`: Ubuntu's own
archive ships a years-stale `gh` (2.45.0 observed live in a cloud session),
and `cli.github.com` — the upstream apt repo — is not on the default
allowlist. The pinned version is **2.98.0**; it and the SHA-256 beside it are
the same pair
[`melodic-software/ci-runner`](https://github.com/melodic-software/ci-runner/blob/main/Dockerfile)
bakes into the CI runner image and `melodic-software/dotfiles` pins through
mise on local machines, so all three lanes run one `gh`. Bump the three
together, and authenticate a new asset against the checksums `cli/cli`
publishes for that release before recording its hash here.

The install is amd64-only, mirroring the runner image: the pinned hash covers
that one asset, and a non-x86_64 VM is a logged `WARN` skip rather than an
unverified download. Like every other step it is best-effort — `github.com` is
on the default allowlist, but the GitHub proxy's repository scope can `403`
release assets from repositories not attached to a session, and a silent miss
surfaces in the verification checklist rather than failing the build.

## Network prerequisite

The environment must use **Custom** network access with **"Also include
Expand Down Expand Up @@ -161,6 +182,12 @@ the snapshot.
a manual obligation. Either way the env copy is only a warm cache: each
repo's bootstrap installs its exact pins repo-locally, so a stale warm
cache costs build time, not correctness.
- The `gh` pin has no in-repo manifest either, and unlike the toolchains above
it is not a warm cache: no repo bootstrap reinstalls `gh`, so this script is
the only thing holding cloud sessions at the fleet version. Bump
`GH_VERSION` and `GH_SHA256` in the same change as the CI runner image and
the dotfiles mise pin. The version is lockstep-tested against this README in
`setup.test.sh`.
- A merged change does **not** reach existing environments on its own: the
snapshot rebuilds only on an edit to the environment's script/network
fields or on ~7-day cache expiry. To pick up a new version immediately,
Expand Down
71 changes: 53 additions & 18 deletions components/cloud-environment/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@
# builds.dotnet.microsoft.com / download.visualstudio.microsoft.com) is
# 403-blocked under Trusted network access. The environment must use Custom
# network access with "Also include default list of common package managers"
# checked plus those four hosts added.
# checked plus those four hosts added. github.com is already on the default
# allowlist, so the pinned gh release asset needs no host of its own; the
# residual risk it carries is the GitHub proxy's repository scope, which can
# 403 release assets from repositories not attached to the session. That is
# why the gh step is best-effort and logs a WARN like every other step.
# shellcheck disable=SC2030,SC2031 # each parallel track deliberately
# reassigns LOG subshell-locally to its own temp log so track output never
# interleaves; the main shell's LOG is untouched by design.
set -u

SCRIPT_VERSION='2026-09-06.2'
SCRIPT_VERSION='2026-09-07.1'
STAMP='/opt/melodic-env-setup.done'
STAMP_FALLBACK='/tmp/melodic-env-setup.done'
# Fleet plugin list: the one standards-hosted, settings-shaped file every
Expand Down Expand Up @@ -191,6 +195,18 @@ if [[ -n "$REPO_ROOT" && -f "$REPO_ROOT/.node-version" ]]; then
fi
fi

# gh pin: a fleet pin with no in-repo manifest to read, so it is declared here
# and held in lockstep with the other two lanes by hand — the CI runner image
# (melodic-software/ci-runner, Dockerfile ARG GH_VERSION/GH_SHA256) and local
# dev machines (melodic-software/dotfiles, mise). All three must carry the same
# gh, or a script that passes on one lane fails on another. The hash is the
# sha256 of the exact release asset the install below names; bump version and
# hash together, and authenticate a new asset against the checksums cli/cli
# publishes for that release before recording its hash here.
GH_VERSION='2.98.0'
GH_SHA256='3b8ac6b30336802fc1a858d7c084e11cdf24ac1a761ca90b68022d7d729208de'
GH_TARBALL='/tmp/gh.tar.gz'

# Each parallel track writes to its own temp log (LOG is reassigned
# subshell-locally, so the log() calls and command output inside a track all
# land in its file); the tracks are concatenated into $LOG after the wait
Expand All @@ -199,24 +215,42 @@ track_a_log="$(mktemp 2>/dev/null || echo "/tmp/melodic-env-track-a.$$")"
track_b_log="$(mktemp 2>/dev/null || echo "/tmp/melodic-env-track-b.$$")"
track_c_log="$(mktemp 2>/dev/null || echo "/tmp/melodic-env-track-c.$$")"

# Track A: apt tools — gh CLI + PowerShell (packages.microsoft.com is on the
# default allowlist).
# Track A: gh CLI (pinned upstream release tarball) + PowerShell (apt;
# packages.microsoft.com is on the default allowlist).
(
LOG="$track_a_log"
if apt-get update -y >>"$LOG" 2>&1; then
log 'apt-get update ok'
else
log 'WARN apt-get update failed'
fi
# gh comes from Ubuntu's own archives: the official cloud-environments
# worked example is exactly `apt update && apt install -y gh`, and
# cli.github.com (the newer upstream apt repo) is NOT on the default
# allowlist. A silent miss is caught by the verification checklist.
if apt-get install -y gh >>"$LOG" 2>&1; then
log 'gh installed'
# gh comes from its checksummed upstream release asset, at the version and
# hash the CI runner image and local dev machines pin. Ubuntu's own archive
# ships a years-stale gh (2.45.0 observed live in a cloud session, 53 minor
# versions behind the other two lanes), and cli.github.com — the upstream
# apt repo — is NOT on the default allowlist, so the release tarball is the
# only install that keeps the three lanes at one version. Direct
# /releases/download/ asset URLs do resolve from this build (the repo
# bootstrap this script bakes in fetches its own hygiene binaries the same
# way); a silent miss is caught by the verification checklist.
# amd64 only, mirroring ci-runner's Dockerfile: the pin above is the hash of
# that one asset, and substituting an unverified hash for another
# architecture would defeat the check it exists to perform.
gh_arch="$(uname -m)"
if [[ "$gh_arch" != 'x86_64' ]]; then
log "WARN gh install skipped: no pinned asset for $gh_arch (amd64 only)"
elif ! curl --fail --location --proto '=https' --tlsv1.2 \
--output "$GH_TARBALL" \
"https://github.com/cli/cli/releases/download/v${GH_VERSION}/gh_${GH_VERSION}_linux_amd64.tar.gz" \
>>"$LOG" 2>&1; then
log "WARN gh $GH_VERSION download failed"
elif ! printf '%s %s\n' "$GH_SHA256" "$GH_TARBALL" |
sha256sum --check --strict >>"$LOG" 2>&1; then
log "WARN gh $GH_VERSION checksum mismatch; refusing to install"
elif ! tar --extract --gzip --file="$GH_TARBALL" --directory=/usr/local/bin \
--strip-components=2 "gh_${GH_VERSION}_linux_amd64/bin/gh" >>"$LOG" 2>&1; then
log "WARN gh $GH_VERSION extract failed"
elif ! chmod 0755 /usr/local/bin/gh 2>>"$LOG"; then
log "WARN gh $GH_VERSION installed but chmod failed"
else
log 'WARN gh install failed'
log "gh $GH_VERSION installed"
fi
rm -f "$GH_TARBALL" 2>/dev/null
ubuntu_ver="$(sed -n 's/^VERSION_ID="\{0,1\}\([0-9.]*\).*/\1/p' /etc/os-release)"
if curl -fsSL "https://packages.microsoft.com/config/ubuntu/${ubuntu_ver}/packages-microsoft-prod.deb" \
-o /tmp/msprod.deb >>"$LOG" 2>&1 &&
Expand Down Expand Up @@ -274,7 +308,7 @@ track_c_log="$(mktemp 2>/dev/null || echo "/tmp/melodic-env-track-c.$$")"

wait

for track in "A apt tools (gh + powershell)|$track_a_log" \
for track in "A gh + powershell|$track_a_log" \
"B .NET SDKs|$track_b_log" "C node|$track_c_log"; do
track_file="${track#*|}"
printf -- '--- track %s ---\n' "${track%%|*}" >>"$LOG"
Expand Down Expand Up @@ -368,7 +402,8 @@ fi
# snapshot and show up in every live session. Runs after the repo bootstrap,
# which reuses /tmp/dotnet-install.sh. Unlinking the running script is safe:
# bash holds its open file descriptor.
rm -f /tmp/msprod.deb /tmp/dotnet-install.sh /tmp/melodic-env-setup.sh 2>/dev/null
rm -f /tmp/msprod.deb /tmp/dotnet-install.sh "$GH_TARBALL" \
/tmp/melodic-env-setup.sh 2>/dev/null

log "done version=$SCRIPT_VERSION"
# Stamp write mirrors the $LOG fallback: /opt unwritable must not present as
Expand Down
32 changes: 32 additions & 0 deletions components/cloud-environment/setup.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,38 @@ else
fi
assert_contains 'README documents the stamp path the script writes' \
"$(cat "$readme")" "$stamp_path"

# gh install contract: the fleet runs one gh across three lanes (this script,
# the ci-runner image, dotfiles/mise). Ubuntu's archive gh is years stale, so
# an apt install here silently reopens that gap — guard the pinned,
# checksum-verified release asset instead.
grep -q 'apt-get install -y gh' "$script"
rc=$?
assert_exit 'setup.sh does not install gh from the Ubuntu archive' 1 "$rc"

gh_pin="$(sed -n "s/^GH_VERSION='\([0-9][0-9.]*\)'\$/\1/p" "$script" | head -n 1)"
if [[ -n "$gh_pin" ]]; then
pass "setup.sh declares a gh pin (GH_VERSION='<version>')"
else
fail "setup.sh declares a gh pin (GH_VERSION='<version>')" \
"no GH_VERSION='<version>' assignment found"
fi

gh_sha="$(sed -n "s/^GH_SHA256='\([0-9a-f]\{64\}\)'\$/\1/p" "$script" | head -n 1)"
if [[ -n "$gh_sha" ]]; then
pass 'setup.sh declares a 64-hex gh asset checksum (GH_SHA256)'
else
fail 'setup.sh declares a 64-hex gh asset checksum (GH_SHA256)' \
"no GH_SHA256='<64 hex chars>' assignment found"
fi

# shellcheck disable=SC2016 # the ${GH_VERSION} is literal text being searched for
assert_contains 'setup.sh fetches gh from the pinned upstream release asset' \
"$(cat "$script")" 'https://github.com/cli/cli/releases/download/v${GH_VERSION}/'
assert_contains 'setup.sh verifies the gh asset before installing it' \
"$(cat "$script")" 'sha256sum --check --strict'
assert_contains 'README documents the gh version the script installs' \
"$(cat "$readme")" "$gh_pin"
assert_contains 'README bootstrap URL matches the component path' \
"$(cat "$readme")" \
'raw.githubusercontent.com/melodic-software/standards/main/components/cloud-environment/setup.sh'
Expand Down