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
36 changes: 32 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ jobs:
# `pip install pytest` takes whatever PyPI serves that minute.
run: pip install --require-hashes -r scripts/requirements-ci.txt

- name: Set up Kustomize for release transport tests
uses: imranismail/setup-kustomize@53f941b41dca13ed61874bbc6b4b6e1562877530 # v3.0.0
with:
kustomize-version: "5.7.1"

- name: Self-test the drift guard
# Pins that the guard actually FAILS on drift — a guard that can only
# pass is a guard that silently rots.
Expand Down Expand Up @@ -2243,11 +2248,26 @@ jobs:
- name: Create and validate verified image manifest
run: |
set -euo pipefail
# deploy/images.manifest.txt remains the reviewed version catalogue;
# this signed release identity records what every catalogue tag
# resolved to in this CI run. Downstream release paths consume only
# these immutable refs, so a later upstream tag move is irrelevant.
source scripts/release/image-manifest.sh
image_args=(
--image "backend=${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/backend@${{ steps.build-backend.outputs.digest }}"
--image "frontend=${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/frontend@${{ steps.build-frontend.outputs.digest }}"
--image "mcp=${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/mcp@${{ steps.build-mcp.outputs.digest }}"
)
while IFS= read -r ref; do
component="$(manifest_ref_component "$ref")"
digest="$(docker buildx imagetools inspect "$ref" --format '{{json .Manifest}}' | jq -r '.digest')"
[[ "$digest" =~ ^sha256:[0-9a-f]{64}$ ]] \
|| { echo "::error::$ref did not resolve to an immutable sha256 digest"; exit 1; }
image_args+=(--image "$component=$ref@$digest")
done < <(manifest_refs any infra core,llm,external)
python3 scripts/release/release_manifest.py create \
--source-sha "${GITHUB_SHA}" --version "${{ steps.manifest-version.outputs.version }}" \
--image "backend=${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/backend@${{ steps.build-backend.outputs.digest }}" \
--image "frontend=${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/frontend@${{ steps.build-frontend.outputs.digest }}" \
--image "mcp=${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/mcp@${{ steps.build-mcp.outputs.digest }}" \
"${image_args[@]}" \
--output verified-images/release-manifest.json
python3 scripts/release/release_manifest.py validate --manifest verified-images/release-manifest.json --expected-source-sha "${GITHUB_SHA}"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
Expand Down Expand Up @@ -2382,11 +2402,19 @@ jobs:
if manifest["images"][component]["source_ref"] != expected:
raise SystemExit("Build output and verified image manifest disagree")
PY
infra_images=()
while IFS=$'\t' read -r _ ref; do
tagged_ref="${ref%@sha256:*}"
image_name="${tagged_ref%:*}"
infra_images+=("$image_name=$ref")
done < <(python3 scripts/release/release_manifest.py refs \
--manifest verified-images/release-manifest.json --kind infrastructure)
cd k8s/overlays/dev
kustomize edit set image \
"ghcr.io/test-intelligence/testlookup/backend=$REGISTRY/$IMAGE_PREFIX/backend@$BACKEND_DIGEST" \
"ghcr.io/test-intelligence/testlookup/frontend=$REGISTRY/$IMAGE_PREFIX/frontend@$FRONTEND_DIGEST" \
"ghcr.io/test-intelligence/testlookup/mcp=$REGISTRY/$IMAGE_PREFIX/mcp@$MCP_DIGEST"
"ghcr.io/test-intelligence/testlookup/mcp=$REGISTRY/$IMAGE_PREFIX/mcp@$MCP_DIGEST" \
"${infra_images[@]}"

- name: Authenticate read-only registry inspection
if: steps.check-secret.outputs.skip != 'true'
Expand Down
23 changes: 22 additions & 1 deletion .github/workflows/offline-bundle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,27 @@ jobs:
docker tag "$manifest_ref" "testlookup/$component:$BUNDLE_VERSION"
printf '%s\t%s\n' "$component" "$manifest_ref" >> release-images.txt
done
source scripts/release/image-manifest.sh
infra_filter=core
if [ "$WITH_LLM" = true ]; then infra_filter=core,llm; fi
while IFS= read -r tagged_ref; do
component="$(manifest_ref_component "$tagged_ref")"
manifest_ref="$(jq -r ".images.$component.source_ref" verified-images/release-manifest.json)"
[ "${manifest_ref%@sha256:*}" = "$tagged_ref" ] \
|| { echo "::error::signed $component ref '$manifest_ref' does not lock catalogue ref '$tagged_ref'"; exit 1; }
[[ "${manifest_ref##*@sha256:}" =~ ^[0-9a-f]{64}$ ]] \
|| { echo "::error::signed $component ref is not digest-addressed"; exit 1; }
docker pull "$manifest_ref"
docker tag "$manifest_ref" "$tagged_ref"
done < <(manifest_refs any infra "$infra_filter")
if [ "$WITH_TELEMETRY" = true ]; then
# These optional rows are already immutable in the catalogue and
# are not part of the production release manifest. A tagged bundle
# uses --skip-pull below, so preload them on a fresh runner now.
# The helper selects only `telemetry`, never the AGPL
# `telemetry-external` prerequisites.
bash scripts/release/pull-offline-telemetry-images.sh
fi
cat release-images.txt

- name: Set up kustomize
Expand Down Expand Up @@ -198,7 +219,7 @@ jobs:
args=(--version "$BUNDLE_VERSION" --created-at "${{ steps.meta.outputs.created_at }}")
if [ "$WITH_LLM" = true ]; then args+=(--with-llm); fi
if [ "$WITH_TELEMETRY" = true ]; then args+=(--with-telemetry); fi
if [ -n "$RELEASE_TAG" ]; then args+=(--skip-build); fi
if [ -n "$RELEASE_TAG" ]; then args+=(--skip-build --skip-pull); fi
bash scripts/release/offline-bundle.sh "${args[@]}"

# The bundle must carry the pulled digests, not a local build:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,10 @@ k8s-deploy-k3s-update: ## Rebuild images and redeploy to the K3s cluster (skip r
k8s-deploy-openshift-artifactory: ## Air-gapped OpenShift deploy over HTTPS, all images from one Artifactory (config: openshiftsetup/artifactory.env; flags via ARGS)
$(BASH_CMD) openshiftsetup/deploy-openshift-artifactory.sh $(ARGS)

k8s-deploy-openshift-artifactory-update: ## Rebuild app images + redeploy to OpenShift, reuse already-mirrored infra images
k8s-deploy-openshift-artifactory-update: ## Redeploy with --skip-mirror; verified releases still authenticate and check every destination digest
$(BASH_CMD) openshiftsetup/deploy-openshift-artifactory.sh --skip-mirror $(ARGS)

k8s-mirror-images-openshift: ## Pre-seed the configured Artifactory with all third-party infra images (run on an internet-connected host)
k8s-mirror-images-openshift: ## Pre-seed signed third-party digests (ARGS="--manifest ... --provenance ...")
$(BASH_CMD) openshiftsetup/mirror-images.sh $(ARGS)

k8s-status: ## Show Kubernetes deployment status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
The rule: when the ref being installed is a release tag (``vX.Y.Z`` in
``TL_REF`` or ``TESTLOOKUP_VERSION``), the installer authenticates that
release's ``SHA256SUMS`` and immutable image manifest, compares every file it
fetched, verifies each application-image digest, and generates a Compose
override BEFORE it writes into the install directory or runs anything it
fetched, verifies the complete application-and-infrastructure digest set, and
generates a Compose override BEFORE it writes into the install directory or runs anything it
downloaded. A mismatch or missing release asset stops the install. For an untagged ref
(``TL_REF=main``, the unreleased tip, only when asked for) there is nothing to
compare with, and it says so. With no ref and no version given, the installer
Expand Down Expand Up @@ -40,7 +40,29 @@
TAG = "v9.9.9"
FILES = ("docker-compose.release.yml", ".env.example", "scripts/gen-dev-env.sh", "scripts/init-db.sql")
SOURCE_SHA = "a" * 40
DIGESTS = {"backend": "1" * 64, "frontend": "2" * 64, "mcp": "3" * 64}
APP_COMPONENTS = ("backend", "frontend", "mcp")
INFRA_NAMES = {
"postgres": "postgres:16-alpine",
"valkey": "valkey/valkey:8.1-alpine",
"mongo": "mongo:7",
"versitygw": "ghcr.io/versity/versitygw:v1.8.0",
"busybox": "busybox:1.36",
"ollama": "ollama/ollama:0.40.10",
"chroma": "chromadb/chroma:1.5.9",
}
COMPONENTS = APP_COMPONENTS + tuple(INFRA_NAMES)
DIGESTS = {component: format(index, "x") * 64 for index, component in enumerate(COMPONENTS, start=1)}


def _image(component: str) -> str:
name = (
f"ghcr.io/test-intelligence/testlookup/{component}"
if component in APP_COMPONENTS
else INFRA_NAMES[component]
)
return f"{name}@sha256:{DIGESTS[component]}"


#: Stands in for the real generator: proves whether a downloaded script ran.
FAKE_GENERATOR = '#!/usr/bin/env bash\ncd "$(dirname "$0")/.."\necho "MARKER=the-downloaded-script-ran" > .env\n'
_TIMEOUT_S = 300 # a hang guard, not a speed bound: process start-up is slow on Windows
Expand Down Expand Up @@ -82,14 +104,12 @@ def _release(tmp_path: Path, ref: str, *, sums: bool = True, tamper: str | None
published.mkdir(parents=True)
(published / "SHA256SUMS").write_bytes("".join(lines).encode())
manifest = {
"schema_version": 1,
"schema_version": 2,
"source_sha": SOURCE_SHA,
"version": ref,
"images": {
component: {
"source_ref": f"ghcr.io/test-intelligence/testlookup/{component}@sha256:{DIGESTS[component]}"
}
for component in ("backend", "frontend", "mcp")
component: {"source_ref": _image(component)}
for component in COMPONENTS
},
}
(published / "release-manifest.json").write_text(
Expand Down Expand Up @@ -150,7 +170,7 @@ def test_a_release_install_checks_every_file_then_runs(tmp_path):
assert "docker compose -f docker-compose.release.yml -f docker-compose.images.yml" in result.stdout


def test_a_release_uses_only_authenticated_digest_refs_for_every_application_service(tmp_path):
def test_a_release_uses_only_authenticated_digest_refs_for_every_release_service(tmp_path):
env = _release(tmp_path, TAG)
env["TL_REF"] = TAG
result = _install(tmp_path, env)
Expand All @@ -161,22 +181,28 @@ def test_a_release_uses_only_authenticated_digest_refs_for_every_application_ser
expected_components = {}
for service, definition in release["services"].items():
image_ref = definition.get("image", "")
for component in ("backend", "frontend", "mcp"):
for component in APP_COMPONENTS:
if f"/{component}:${{TESTLOOKUP_VERSION:-latest}}" in image_ref:
expected_components[service] = component
expected_components.update({
"postgres": "postgres",
"mongo": "mongo",
"redis": "valkey",
"minio": "versitygw",
"ollama": "ollama",
"chromadb": "chroma",
})
assert set(override["services"]) == set(expected_components), (
"every tag-addressed application service in the release Compose file needs a digest override"
"every tag-addressed release service in the Compose file needs a digest override"
)
for service, component in expected_components.items():
assert override["services"][service]["image"] == (
f"ghcr.io/test-intelligence/testlookup/{component}@sha256:{DIGESTS[component]}"
)
assert override["services"][service]["image"] == _image(component)
assert all("@sha256:" in service["image"] for service in override["services"].values())

checks = (tmp_path / "gh.log").read_text(encoding="utf-8")
assert "attestation verify" in checks
assert "SHA256SUMS" in checks and "release-manifest.json" in checks
for component in ("backend", "frontend", "mcp"):
for component in APP_COMPONENTS:
assert f"oci://ghcr.io/test-intelligence/testlookup/{component}@sha256:{DIGESTS[component]}" in checks
assert f"--source-digest {SOURCE_SHA}" in checks

Expand All @@ -193,6 +219,22 @@ def test_a_manifest_without_trusted_provenance_stops_before_installing_or_runnin
assert not (tmp_path / "install" / "docker-compose.images.yml").exists()


def test_an_incomplete_signed_image_set_stops_before_installing_or_running(tmp_path):
env = _release(tmp_path, TAG)
env["TL_REF"] = TAG
manifest_path = tmp_path / "served" / "releases" / TAG / "release-manifest.json"
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
manifest["images"].pop("postgres")
manifest_path.write_text(json.dumps(manifest, indent=2, sort_keys=True) + "\n", encoding="utf-8")

result = _install(tmp_path, env)

assert result.returncode != 0
assert "exactly ten application and infrastructure image references" in result.stderr
assert not (tmp_path / "install" / ".env").exists()
assert not (tmp_path / "install" / "docker-compose.images.yml").exists()


def test_a_custom_registry_keeps_the_authenticated_digests(tmp_path):
env = _release(tmp_path, TAG)
env["TL_REF"] = TAG
Expand All @@ -208,6 +250,9 @@ def test_a_custom_registry_keeps_the_authenticated_digests(tmp_path):
)
assert services["frontend"]["image"].endswith(f"/frontend@sha256:{DIGESTS['frontend']}")
assert services["mcp"]["image"].endswith(f"/mcp@sha256:{DIGESTS['mcp']}")
for service, component in (("postgres", "postgres"), ("mongo", "mongo"), ("redis", "valkey"),
("minio", "versitygw"), ("ollama", "ollama"), ("chromadb", "chroma")):
assert services[service]["image"] == _image(component)


def test_release_files_and_requested_image_release_must_match(tmp_path):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,22 @@ def test_a_first_install_needs_no_running_server(run):
assert "mongo-fresh: MONGO_AUTH_JUST_ENABLED=true" in stdout


def test_the_script_sets_the_credentials_before_it_applies():
@pytest.mark.parametrize(
"apply_command",
[
r"""printf '%s\n' "$RENDERED_OVERLAY" | "$KCLI" apply -f -""",
'"$KCLI" apply -k "$OVERLAY_DIR"',
],
ids=["verified-release", "local-build"],
)
def test_the_script_sets_the_credentials_before_it_applies(apply_command: str):
script = SCRIPT.read_text(encoding="utf-8")
main = script[script.index("# <<< secret helpers"):]
apply_at = re.search(r'^"\$KCLI" apply -k "\$OVERLAY_DIR"$', main, re.MULTILINE).start()
apply_call = re.search(rf"^[ \t]*{re.escape(apply_command)}$", main, re.MULTILINE)
assert apply_call, f"missing deployment command: {apply_command}"
for call in ("ensure_redis_credentials", "ensure_mongo_credentials"):
called_at = re.search(rf"^\s*{call}$", main, re.MULTILINE)
assert called_at and called_at.start() < apply_at, f"{call} does not run before the apply"
called_at = re.search(rf"^[ \t]*{call}$", main, re.MULTILINE)
assert called_at and called_at.start() < apply_call.start(), f"{call} does not run before {apply_command}"


def test_a_dry_run_changes_no_credentials():
Expand Down
9 changes: 9 additions & 0 deletions backend/tests/test_verified_release_promotion.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ def test_manifest_tool_is_present_for_workflow_validation_and_materialization():
assert command in text, f"release manifest tool must expose {command!r}"
for component in COMPONENTS:
assert component in text, f"release manifest tool must require the {component} digest"
for component in ("postgres", "valkey", "mongo", "versitygw", "busybox", "ollama", "chroma"):
assert component in text, f"release manifest tool must require the {component} digest"
assert "@sha256:" in text, "release manifest tool must reject mutable tag-only references"


Expand Down Expand Up @@ -230,6 +232,9 @@ def test_main_image_manifest_resolves_version_file_before_publishing_images():
create_run = str(step_by_name["Create and validate verified image manifest"].get("run", ""))
assert "steps.manifest-version.outputs.version" in create_run
assert "GITHUB_REF_NAME" not in create_run
assert "manifest_refs any infra core,llm,external" in create_run
assert "docker buildx imagetools inspect" in create_run
assert 'image_args+=(--image "$component=$ref@$digest")' in create_run


def test_dev_migration_and_backend_rollout_use_the_same_immutable_digest():
Expand All @@ -251,6 +256,8 @@ def test_dev_migration_and_backend_rollout_use_the_same_immutable_digest():
assert 'release_manifest.py validate --manifest verified-images/release-manifest.json --expected-source-sha "$GITHUB_SHA"' in pin["run"]
assert 'expected = f"{root}/{component}@{os.environ[component.upper() + \'_DIGEST\']}"' in pin["run"]
assert 'manifest["images"][component]["source_ref"] != expected' in pin["run"]
assert "--kind infrastructure" in pin["run"]
assert 'infra_images+=("$image_name=$ref")' in pin["run"]
assert backend_ref in migrate
assert "run-k8s-migrations.sh testlookup-dev" in migrate
assert "verify_kubernetes_rollout.py" in verify
Expand All @@ -264,6 +271,8 @@ def test_deploy_helper_preserves_the_complete_kustomize_resource_tree():
assert 'cp -r k8s "$TMP_ROOT/k8s"' in script
assert 'TMP_OVERLAY="$TMP_ROOT/$OVERLAY"' in script
assert 'cp -r "$OVERLAY" "$TMP_OVERLAY"' not in script
assert "for img in backend frontend mcp postgres valkey mongo versitygw busybox ollama chroma" in script
assert 'kubectl kustomize edit set image "$source_name=$ref"' in script


def test_airgap_override_routes_the_migration_service_to_the_private_registry():
Expand Down
6 changes: 5 additions & 1 deletion deploy/images.manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
# read), Python (stdlib only) and the CI drift guard can all parse it without
# PyYAML — the drift guard has to run in a job that installs nothing.
#
# 1. ref full image reference incl. tag. App images use the literal
# 1. ref reviewed version-catalogue reference incl. tag. Release CI
# resolves every production infra row to @sha256 and records
# the complete set in signed release-manifest.json; installers
# and mirror scripts reject infra refs outside that digest set.
# App images use the literal
# tag `@APP_TAG`, resolved at build time (bundle version /
# build-YYYYMMDD-HHMMSS / BUILD_TAG_PLACEHOLDER depending on
# the deploy path) — only their NAMES are drift-checked.
Expand Down
Loading
Loading