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
41 changes: 34 additions & 7 deletions scripts/check-installer-hash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# still match the immutable upstream checksum manifests.
#
# Checked artifacts:
# 1. OpenShell archives — scripts/install-openshell.sh release-asset table
# 1. OpenShell archives/formula — scripts/install-openshell.sh release-asset table
# 2. Brev OpenShell CLI — scripts/brev-launchable-ci-cpu.sh release-asset table
#
# Usage:
Expand Down Expand Up @@ -88,11 +88,11 @@ sha256_file() {
check_openshell_release_assets() {
local installer="${REPO_ROOT}/scripts/install-openshell.sh"
local brev_installer="${REPO_ROOT}/scripts/brev-launchable-ci-cpu.sh"
local release_base workspace manifests spec manifest expected actual source asset pinned upstream
local release_base workspace manifests spec manifest expected actual source asset pinned upstream formula_asset
local matches required_manifest required_matches
local pin_records parser_error parser_errors parsed_version release_version="" record_extra
local allowlist_entry allowlist_version allowlist_extra
local count=0 brev_count=0 published_count=0 failures=0
local count=0 brev_count=0 published_count=0 expected_published_count=0 failures=0
local -a manifest_specs=()
workspace=$(mktemp -d)
manifests="${workspace}/published-sha256.txt"
Expand Down Expand Up @@ -147,8 +147,11 @@ check_openshell_release_assets() {
esac
done <<<"$pin_records"

if [[ "$count" -ne 8 ]]; then
echo " STALE: expected 8 pinned OpenShell v${release_version:-unknown} assets, found ${count}."
# Transitional trust anchor: accept the current archive set and the same set
# plus openshell.rb. Tighten this to nine assets when the formula consumer
# lands. The base-trusted parser still rejects every other asset set.
if [[ "$count" -ne 8 && "$count" -ne 9 ]]; then
echo " STALE: expected 8 or 9 pinned OpenShell v${release_version:-unknown} assets, found ${count}."
failures=$((failures + 1))
fi
if [[ "$brev_count" -ne 2 ]]; then
Expand Down Expand Up @@ -224,6 +227,29 @@ check_openshell_release_assets() {
done

while IFS=$'\t' read -r parsed_version source asset pinned record_extra; do
if [[ "$asset" == "openshell.rb" ]]; then
formula_asset="${workspace}/${asset}"
if ! fetch_file "${release_base}/${asset}" "$formula_asset"; then
echo " STALE: unable to download ${source} ${asset}."
failures=$((failures + 1))
continue
fi
if ! actual=$(sha256_file "$formula_asset"); then
echo " STALE: unable to hash ${source} ${asset}."
failures=$((failures + 1))
continue
fi
if [[ "$actual" == "$pinned" ]]; then
published_count=$((published_count + 1))
echo " OK: ${source} ${asset} (${pinned})"
else
echo " STALE: ${source} ${asset} digest does not match the pinned v${release_version} release asset."
echo " pinned: ${pinned}"
echo " upstream: ${actual}"
failures=$((failures + 1))
fi
continue
fi
matches=$(awk -v asset="$asset" '$2 == asset { count++ } END { print count + 0 }' "$manifests")
upstream=$(awk -v asset="$asset" '$2 == asset { print $1; exit }' "$manifests")
if [[ "$matches" -eq 1 && "$pinned" == "$upstream" ]]; then
Expand All @@ -238,8 +264,9 @@ check_openshell_release_assets() {
fi
done <<<"$pin_records"

if [[ "$published_count" -ne 10 ]]; then
echo " STALE: expected all 10 pinned asset references in the v${release_version} checksum manifests, matched ${published_count}."
expected_published_count=$((count + brev_count))
if [[ "$published_count" -ne "$expected_published_count" ]]; then
echo " STALE: expected all ${expected_published_count} pinned asset references for v${release_version}, matched ${published_count}."
failures=$((failures + 1))
fi
return "$failures"
Expand Down
51 changes: 40 additions & 11 deletions scripts/checks/extract-installer-pins.mts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,22 @@ const MAX_INSTALLER_INPUT_BYTES = 1024 * 1024;
// only in a prerequisite trust-anchor PR that keeps the currently selected
// release; the later pin PR may then change release data without authorizing
// any operational installer change. A mismatch reports the candidate hash.
const TRUSTED_INSTALLER_TEMPLATE_SHA256 =
// This transition accepts the current installer and the reviewed formula
// installer. Tighten this back to the formula installer hash when its consumer
// lands; accepting both is necessary because base-trusted CI validates both
// the prerequisite branch and the dependent pull request. Each trusted hash is
// coupled below to the exact asset set consumed by that template.
const TRUSTED_ARCHIVE_INSTALLER_TEMPLATE_SHA256 =
"a101f002bd8e02aa7b38960ddcb76c9fca419bc3766f6870446f6a7e99e14d78";
const TRUSTED_BREV_TEMPLATE_SHA256 =
"c0a4ddf25a02a9fe02b2df53a60942ea887610f04d4ce16a121b6e79a5aeff1a";
const TRUSTED_FORMULA_INSTALLER_TEMPLATE_SHA256 =
"2b6a6195241d6b946fe29503d8d2d99d5b864864458f510ca129e3396248ac58";
const TRUSTED_INSTALLER_TEMPLATE_SHA256_ALLOWLIST = [
TRUSTED_ARCHIVE_INSTALLER_TEMPLATE_SHA256,
TRUSTED_FORMULA_INSTALLER_TEMPLATE_SHA256,
] as const;
const TRUSTED_BREV_TEMPLATE_SHA256_ALLOWLIST = [
"c0a4ddf25a02a9fe02b2df53a60942ea887610f04d4ce16a121b6e79a5aeff1a",
] as const;
const EXPECTED_INSTALLER_ASSETS = [
"openshell-x86_64-unknown-linux-musl.tar.gz",
"openshell-aarch64-unknown-linux-musl.tar.gz",
Expand All @@ -61,6 +73,14 @@ const EXPECTED_INSTALLER_ASSETS = [
"openshell-sandbox-x86_64-unknown-linux-gnu.tar.gz",
"openshell-sandbox-aarch64-unknown-linux-gnu.tar.gz",
] as const;
const TRANSITIONAL_INSTALLER_ASSET = "openshell.rb";
const EXPECTED_INSTALLER_ASSETS_BY_TEMPLATE_SHA256 = new Map<string, readonly string[]>([
[TRUSTED_ARCHIVE_INSTALLER_TEMPLATE_SHA256, EXPECTED_INSTALLER_ASSETS],
[
TRUSTED_FORMULA_INSTALLER_TEMPLATE_SHA256,
[...EXPECTED_INSTALLER_ASSETS, TRANSITIONAL_INSTALLER_ASSET],
],
]);
const EXPECTED_BREV_ASSETS = [
"openshell-x86_64-unknown-linux-musl.tar.gz",
"openshell-aarch64-unknown-linux-musl.tar.gz",
Expand Down Expand Up @@ -164,6 +184,14 @@ function assertExactAssetSet(
}
}

function assertInstallerAssetSet(pins: InstallerPin[], templateSha256: string): void {
// extractInstallerPins rejects duplicate assets before this transition check.
const expectedAssets =
EXPECTED_INSTALLER_ASSETS_BY_TEMPLATE_SHA256.get(templateSha256) ??
fail(`installer template ${templateSha256} has no trusted asset contract`);
assertExactAssetSet(pins, expectedAssets, "installer pin table");
}

// invalidState: the blueprint and stable runtime selectors request a newer
// OpenShell release while both embedded hash tables still name an older,
// independently valid release, so separate dependency and hash checks pass but
Expand Down Expand Up @@ -655,22 +683,23 @@ function assertTrustedTemplate(
source: string,
functionNames: readonly string[],
selectorPatterns: readonly RegExp[],
expectedSha256: string,
expectedSha256: readonly string[],
label: string,
): void {
): string {
const normalized = normalizeTrustedInstallerTemplate(
source,
functionNames,
selectorPatterns,
label,
);
const actualSha256 = createHash("sha256").update(normalized).digest("hex");
if (actualSha256 !== expectedSha256) {
if (!expectedSha256.includes(actualSha256)) {
fail(
`${label} operational template is not base-trusted; ` +
`expected_sha256=${expectedSha256}, actual_sha256=${actualSha256}`,
`expected_sha256=[${expectedSha256.join(", ")}], actual_sha256=${actualSha256}`,
);
}
return actualSha256;
}

function skipSeparators(tokens: Token[], start: number): number {
Expand Down Expand Up @@ -931,7 +960,6 @@ function runCli(): void {
functionName: "openshell_cli_pinned_sha256",
sourceLabel: "Brev launchable",
});
assertExactAssetSet(installerPins, EXPECTED_INSTALLER_ASSETS, "installer pin table");
assertExactAssetSet(brevPins, EXPECTED_BREV_ASSETS, "Brev pin table");
const pins = [...installerPins, ...brevPins];
const releaseVersions = [...new Set(pins.map((pin) => pin.releaseVersion))].sort();
Expand All @@ -947,22 +975,23 @@ function runCli(): void {
`pinned_sandbox_build_version must contain at least one digest for release ${releaseVersion}`,
);
}
assertTrustedTemplate(
const installerTemplateSha256 = assertTrustedTemplate(
installerSource,
["openshell_pinned_sha256", "pinned_sandbox_build_version"],
[
/^MIN_VERSION="([0-9]+\.[0-9]+\.[0-9]+)"$/gm,
/^MAX_VERSION="([0-9]+\.[0-9]+\.[0-9]+)"$/gm,
/^DEV_MIN_VERSION="([0-9]+\.[0-9]+\.[0-9]+)"$/gm,
],
TRUSTED_INSTALLER_TEMPLATE_SHA256,
TRUSTED_INSTALLER_TEMPLATE_SHA256_ALLOWLIST,
"installer",
);
assertInstallerAssetSet(installerPins, installerTemplateSha256);
assertTrustedTemplate(
brevInstallerSource,
["openshell_cli_pinned_sha256"],
[/^\s*stable\s*\|\s*auto\)\s*OPENSHELL_VERSION="v([0-9]+\.[0-9]+\.[0-9]+)"\s*;;\s*$/gm],
TRUSTED_BREV_TEMPLATE_SHA256,
TRUSTED_BREV_TEMPLATE_SHA256_ALLOWLIST,
"Brev launchable",
);
for (const [label, runtimeVersion] of [
Expand Down
Loading