diff --git a/.github/dependabot.yml b/.github/dependabot.yml index b4b2547..d547748 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -75,7 +75,6 @@ updates: - /helper - /providers/azure/eventgrid - /providers/azure/node-setup - - /upstream schedule: interval: monthly cooldown: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c9b5e16..d603c6b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -168,10 +168,8 @@ jobs: - name: Prepare the helper image context run: just helper::prepare-image - # Builds what the cluster suites install in place of the published - # controller inputs: the stock fiberd, helper and fiberd-k8s-controller - # images and the controller's manifest, from upstream/pins.env's commits - # and this checkout's helper, once for every suite. + # Pulls the signed upstream images and builds this checkout's helper. + # Each cluster suite installs the same pinned controller inputs. cluster-inputs: runs-on: ubuntu-latest timeout-minutes: 45 @@ -204,37 +202,10 @@ jobs: with: name: lampyr-ci-cache - - name: Check out the pinned fiberd - run: just upstream::prepare-fiberd-image - - # The cluster inputs build fiberd as go.mod's version, which fiberd - # -version prints, so the cache is warmed with it too. - - name: Read the fiberd version - id: fiberd-version - # A failure inside $(...) as an argument would not stop the step. - run: | - version=$(just upstream::fiberd-version) - [[ -n $version ]] || { echo "just upstream::fiberd-version printed nothing" >&2; exit 1; } - printf 'version=%s\n' "$version" >>"$GITHUB_OUTPUT" - - # fiberd's image builds criu and its zygote library, so keep every - # stage; the pin changes rarely. - - name: Warm the stock fiberd build cache - uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0 - with: - builder: lampyr-ci-cache - context: build/upstream/fiberd - file: build/upstream/fiberd/docker/fiberd/Dockerfile - target: fiberd - build-args: VERSION=${{ steps.fiberd-version.outputs.version }} - platforms: linux/amd64 - provenance: false - cache-from: type=gha,scope=ci-upstream-fiberd,timeout=2m - cache-to: type=gha,mode=max,scope=ci-upstream-fiberd,ignore-error=true,timeout=2m - - name: Build the cluster suites' controller inputs env: BUILDX_BUILDER: lampyr-ci-cache + GH_TOKEN: ${{ github.token }} run: just upstream::cluster-inputs build/cluster-inputs - name: Upload the cluster suites' controller inputs diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 517c00d..c315cae 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -389,6 +389,8 @@ jobs: # ly cluster install from a release needs none of them, and # zygoteRegistries defaults to the Kind or k3d local registry. - name: Write the default controller inputs + env: + GH_TOKEN: ${{ github.token }} run: | image() { local digest @@ -400,8 +402,9 @@ jobs: printf '%s/%s@%s\n' "$IMAGE_PREFIX" "$1" "$digest" } # A failure inside $(...) as an argument would not stop the step. - controller=$(image fiberd-k8s-controller) - grant=$(image upstream-fiberd) + . upstream/pins.env + controller=$CONTROLLER_IMAGE + grant=$FIBERD_IMAGE helper=$(image hluk-helper) just upstream::controller-inputs "$controller" "$grant" "$helper" @@ -579,24 +582,6 @@ jobs: build_args: BINARY=eventgrid-adapter title: Lampyr Event Grid adapter description: Lampyr Event Grid adapter - # Built from the upstream commits upstream/pins.env pins until - # fiberd and fiberd-k8s-controller publish images of their own. - - image: upstream-fiberd - prepare: upstream::prepare-fiberd-image - context: build/upstream/fiberd - dockerfile: build/upstream/fiberd/docker/fiberd/Dockerfile - target: fiberd - build_args: "" - title: fiberd - description: Stock fiberd, which grant Pods run, from the commit upstream/pins.env pins - - image: fiberd-k8s-controller - prepare: upstream::prepare-controller-image - context: . - dockerfile: upstream/controller.Dockerfile - target: "" - build_args: "" - title: fiberd-k8s-controller - description: fiberd-k8s-controller from the commit upstream/pins.env pins steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -628,22 +613,6 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - # The upstream images' descriptions name the repository and commit - # pins.env gives, so an image says which source it was built from. - - name: Read the upstream source - id: upstream - if: matrix.image == 'upstream-fiberd' || matrix.image == 'fiberd-k8s-controller' - env: - IMAGE: ${{ matrix.image }} - run: | - . upstream/pins.env - if [[ $IMAGE == upstream-fiberd ]]; then - description="Stock fiberd, which grant Pods run, from $FIBERD_REPOSITORY@$FIBERD_COMMIT" - else - description="fiberd-k8s-controller from $CONTROLLER_REPOSITORY@$CONTROLLER_COMMIT" - fi - printf 'description=%s\n' "$description" >>"$GITHUB_OUTPUT" - - name: Extract image metadata id: meta uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0 @@ -652,21 +621,11 @@ jobs: tags: type=raw,value=${{ needs.version.outputs.image-tag }} labels: | org.opencontainers.image.title=${{ matrix.title }} - org.opencontainers.image.description=${{ steps.upstream.outputs.description || matrix.description }} + org.opencontainers.image.description=${{ matrix.description }} org.opencontainers.image.source=https://github.com/hyperlight-dev/lampyr org.opencontainers.image.revision=${{ github.sha }} org.opencontainers.image.version=${{ needs.version.outputs.image-tag }} - # fiberd -version prints the version the image is built as. - - name: Read the fiberd version - id: fiberd-version - if: matrix.image == 'upstream-fiberd' - # A failure inside $(...) as an argument would not stop the step. - run: | - version=$(just upstream::fiberd-version) - [[ -n $version ]] || { echo "just upstream::fiberd-version printed nothing" >&2; exit 1; } - printf 'build-args=VERSION=%s\n' "$version" >>"$GITHUB_OUTPUT" - - name: Build and push image id: build uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0 @@ -674,7 +633,7 @@ jobs: context: ${{ matrix.context }} file: ${{ matrix.dockerfile }} target: ${{ matrix.target }} - build-args: ${{ steps.fiberd-version.outputs.build-args || matrix.build_args }} + build-args: ${{ matrix.build_args }} platforms: linux/amd64 push: true tags: ${{ steps.meta.outputs.tags }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 58827dd..48be8d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), ## [Prerelease] - Unreleased +### Changed + +- Releases use the signed, digest-pinned Azure/fiberd v0.4.0 and Azure/fiberd-k8s-controller v0.1.0 images. Lampyr no longer builds or publishes copies of these images. Platform archives keep the matching controller install manifest and template tools. + ## [0.1.1] - 2026-11-07 ### Fixed diff --git a/Justfile b/Justfile index 7f58fe0..2b6bdee 100644 --- a/Justfile +++ b/Justfile @@ -85,7 +85,7 @@ build-dev-supervisor: build-eventgrid: azure::build-eventgrid # Prepare every Linux/amd64 preview image context without publishing it. -prepare-preview-images: prepare-fiberd-image prepare-fiber-router-image helper::prepare-image upstream::prepare-fiberd-image upstream::prepare-controller-image azure::prepare-preview-images +prepare-preview-images: prepare-fiberd-image prepare-fiber-router-image helper::prepare-image azure::prepare-preview-images python3 "{{repo-root}}/scripts/check_preview_images.py" --root "{{repo-root}}" --require-binaries # Package all preview release assets, including the verified installer entrypoint. diff --git a/cli/src/bootstrap.rs b/cli/src/bootstrap.rs index 85fe730..fdde0f7 100644 --- a/cli/src/bootstrap.rs +++ b/cli/src/bootstrap.rs @@ -864,10 +864,9 @@ fn install_controller( "fiberd-k8s-controller", "180s", )?; - // The policy admits the fiberd and helper images and the templates only - // from listed repositories, each in a list of its own, and the - // hyperlight runtime runs privileged, which it allows only in a listed - // namespace. + // The runtime ceiling admits only Hyperlight. No runtime is allowed by + // default; only the tenant namespace gets the Hyperlight exception. + // The pinned controller does not allow privileged grant Pods. let policy = json!({ "apiVersion": "fiberd.io/v1alpha1", "kind": "GrantPolicy", "metadata": { "name": "default" }, @@ -876,10 +875,16 @@ fn install_controller( "helperImages": [image_repository("helperImage", options.helper_image)?], "registries": options.zygote_registries, "runtimes": ["hyperlight"], - "privilegedNamespaces": ["default"], + "defaultRuntimes": [], } }); apply_recorded_manifest(kube, options.installation_id, &policy, inventory)?; + kube.patch( + "default", + "namespace", + "default", + &json!({ "metadata": { "labels": { "runtimes.fiberd.io/hyperlight": "true" } } }), + )?; let tenant = options.root.join("k8s/fiberd-tenant.yaml"); apply_recorded_source( kube, diff --git a/docs/cli/cluster.md b/docs/cli/cluster.md index d709399..dbd5d1e 100644 --- a/docs/cli/cluster.md +++ b/docs/cli/cluster.md @@ -182,6 +182,10 @@ GrantPolicy lists their repositories. `ly cluster install` checks all three before the provider creates anything. A reinstall applies cert-manager only to a cluster without it, so Lampyr never upgrades a cert-manager it installed. +Lampyr adds `runtimes.fiberd.io/hyperlight=true` only to namespace `default`. +The GrantPolicy permits only Hyperlight. It allows no runtime in a namespace +without a runtime label. + ## Fiberd templates `ly deploy` pushes every Revision's fiberd template to one repository per diff --git a/docs/contributing.md b/docs/contributing.md index c89ca45..a5e2d29 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -125,8 +125,7 @@ the VM contracts. Both run in CI and through `just test`. The cluster suites (`just test-kind-integration` and its prebuilt variants, `just test-k3d-integration`, `just test-existing-kind-integration`, `just test-knative-portability` and `just test-azure-eventgrid-integration`) -install fiberd-k8s-controller, which has no -release yet. They read its installation inputs from the environment and stop +install fiberd-k8s-controller. They read its installation inputs from the environment and stop before creating anything when one is missing: | Variable | Value | @@ -151,9 +150,9 @@ just upstream::cluster-inputs build/cluster-inputs LAMPYR_CLUSTER_INPUTS="$PWD/build/cluster-inputs" just test-existing-kind-integration ``` -The recipe builds the stock fiberd image and fiberd-k8s-controller from the -commits `upstream/pins.env` pins, and the helper, its image, `zygotectl` and -`grant-issuer` from this checkout and that fiberd. Its buildx builder must +The recipe verifies and pulls the upstream image digests in +`upstream/pins.env`. It builds the helper and its image from this checkout, +and `zygotectl` and `grant-issuer` from the pinned fiberd source. Its buildx builder must export OCI layouts, as a `docker-container` one does. A suite pushes the fiberd and helper images to its own registry, keeping their digests, and has its provider load the controller image, which the manifest names by a @@ -209,13 +208,14 @@ all attested against `refs/tags/vX.Y.Z`. Source keeps `:preview` image tags; the release build stamps `X.Y.Z` into the CLI's default images and the packaged platform manifests. Install it with `scripts/install-ly.sh vX.Y.Z`. -fiberd and fiberd-k8s-controller publish no images or install manifest yet, -so every preview and versioned release builds them from the commits -`upstream/pins.env` pins, as `upstream-fiberd` and `fiberd-k8s-controller`. -Packaging then writes `build/fiberd-k8s-controller.yaml`, the controller's -`config/default` running its published image by digest, and -`build/controller-inputs.json`, which names that manifest and the published -`upstream-fiberd` and `hluk-helper` digests, into both platform archives +Releases use the signed upstream images for fiberd v0.4.0, with its Hyperlight +backend, and fiberd-k8s-controller v0.1.0. `upstream/pins.env` pins their image +digests and source commits. `just upstream::verify-images` verifies each image's +provenance against its upstream release workflow and source commit. +Packaging writes `build/fiberd-k8s-controller.yaml`, the controller release's +`config/default` running its upstream image by digest, and +`build/controller-inputs.json`, which names that manifest, the upstream fiberd +digest and the published `hluk-helper` digest, into both platform archives (`just upstream::controller-inputs`). `ly cluster install` takes `controllerManifest`, `grantImage` and `helperImage` from them when an install is not given them, and `zygoteRegistries` defaults to the Kind or k3d @@ -227,8 +227,8 @@ are made, and `build/zygotectl` and `build/grant-issuer`, which run on the user's machine, built from the pinned fiberd for each archive's own target into `build/template-tools/TARGET` (`just upstream::template-tools`). To move -to new upstream commits, change `upstream/pins.env`, and `go.mod`'s -`github.com/Azure/fiberd` with `FIBERD_COMMIT`. +to new upstream releases, verify their image provenance and Hyperlight support, +then update `upstream/pins.env` and `go.mod`'s `github.com/Azure/fiberd` together. ## Preview images @@ -241,8 +241,6 @@ The workflow publishes these canonical GHCR image tags, where - `ghcr.io/hyperlight-dev/lampyr/azure-node-setup:preview-` - `ghcr.io/hyperlight-dev/lampyr/eventgrid-controller:preview-` - `ghcr.io/hyperlight-dev/lampyr/eventgrid-adapter:preview-` -- `ghcr.io/hyperlight-dev/lampyr/upstream-fiberd:preview-` -- `ghcr.io/hyperlight-dev/lampyr/fiberd-k8s-controller:preview-` The workflow also updates `:preview` convenience aliases. Those aliases move and are not the consistency boundary for a release, so do not use them for @@ -256,9 +254,8 @@ checksummed and attested release asset; it similarly checks strict SHA-256 files and exact-commit GitHub attestations for the CLI and platform archives before installation. -To consume the images from another registry, authenticate `gh` for -attestations, authenticate Docker to the destination registry, and use Docker -Buildx: +To consume the images from another registry, install `jq`, authenticate `gh` +for attestations, and authenticate Docker to the destination registry. Use Docker Buildx: ```bash gh auth status --hostname github.com @@ -270,12 +267,12 @@ docker login REGISTRY just preview-mirror-images destination=REGISTRY/lampyr ``` -The mirror resolves the commit behind `preview-release`, selects all eight +The mirror resolves the commit behind `preview-release`, selects all six canonical `preview-` tags automatically, and verifies -every source digest's GitHub attestation before copying it. Those include the -platform's default controller inputs, `upstream-fiberd`, `fiberd-k8s-controller` -and `hluk-helper`. It also downloads the preview's Linux platform archive, -verifies its attestation, and checks that every image its fiberd-k8s-controller +every Lampyr source digest's GitHub attestation. It reads the upstream fiberd +and controller digests from the verified Linux platform archive and verifies +their attestations against the Azure release workflows before copying them. +It checks that every image its fiberd-k8s-controller manifest pulls is one of the verified images. It then writes destination digest references to the Kind provider config at `build/preview-kind.yaml` and the Azure image-settings fragment at `build/preview-azure.yaml`, and the manifest, diff --git a/docs/designs/knative-fiber-serving.md b/docs/designs/knative-fiber-serving.md index 86e6ca5..2de0f44 100644 --- a/docs/designs/knative-fiber-serving.md +++ b/docs/designs/knative-fiber-serving.md @@ -149,8 +149,8 @@ Lampyr runs a Revision only from a fiberd template sealed to the cluster's fleet key, so the proof first deploys the service with `ly deploy` to build, seal and push one, deletes it, and gives the shared Knative Service that template's `lampyr.dev/fiberd-template`, which stock Knative ignores. -fiberd-k8s-controller has no release yet, so the proof, like every cluster -suite, needs its installation inputs: `LAMPYR_CONTROLLER_MANIFEST`, +The proof, like every cluster suite, needs its installation inputs: +`LAMPYR_CONTROLLER_MANIFEST`, `LAMPYR_GRANT_IMAGE` and `LAMPYR_HELPER_IMAGE`, and, unless `build/zygotectl` and `build/grant-issuer` exist, `LAMPYR_FIBERD_SRC` naming the fiberd checkout that builds them. In place of all four, `LAMPYR_CLUSTER_INPUTS` may name the diff --git a/go.mod b/go.mod index 728e9e3..5d6763b 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ toolchain go1.26.7 require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v1.23.3 github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.15.0 - github.com/Azure/fiberd v0.2.1-0.20261106172642-549f6168ca09 + github.com/Azure/fiberd v0.4.0 github.com/cert-manager/cert-manager v1.16.3 github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 github.com/prometheus/client_golang v1.25.0 diff --git a/go.sum b/go.sum index 256f9af..0ad9d23 100644 --- a/go.sum +++ b/go.sum @@ -7,8 +7,8 @@ github.com/Azure/azure-sdk-for-go/sdk/azidentity/cache v0.4.0 h1:xFaZZ+IubdftrDH github.com/Azure/azure-sdk-for-go/sdk/azidentity/cache v0.4.0/go.mod h1:mCBhUhlMjLLJKr5aqw2TNS/VqJOie8MzWq3DAMJeKso= github.com/Azure/azure-sdk-for-go/sdk/internal v1.13.0 h1:Terj1CMW4+NY5CpWjSRkqLoxh2DkYDdv/FH2z0897Uc= github.com/Azure/azure-sdk-for-go/sdk/internal v1.13.0/go.mod h1:7Ut2Qw9vcwpLW5Q4MBy43uSxXS7tK2yjs94OJ6j5thE= -github.com/Azure/fiberd v0.2.1-0.20261106172642-549f6168ca09 h1:SPvsfxxHldgfGO1RyU3CkPujdPoQPdbSG9KRZemaZ84= -github.com/Azure/fiberd v0.2.1-0.20261106172642-549f6168ca09/go.mod h1:hvIM6EAUZaduTf1oUiK5iosUiqT2k6dmpjXH17ectog= +github.com/Azure/fiberd v0.4.0 h1:oVgSYygZJMnsdDhQPehA6xxsUm4u0T379zVLGTz8Zf8= +github.com/Azure/fiberd v0.4.0/go.mod h1:hvIM6EAUZaduTf1oUiK5iosUiqT2k6dmpjXH17ectog= github.com/AzureAD/microsoft-authentication-extensions-for-go/cache v0.1.1 h1:WJTmL004Abzc5wDB5VtZG2PJk5ndYDgVacGqfirKxjM= github.com/AzureAD/microsoft-authentication-extensions-for-go/cache v0.1.1/go.mod h1:tCcJZ0uHAmvjsVYzEFivsRTN00oz5BEsRgQHu5JZ9WE= github.com/AzureAD/microsoft-authentication-library-for-go v1.10.1 h1:0O6j18nQDoIff6/mtosT5LNU2WehEwp+LqfX6699oqY= diff --git a/scripts/check_preview_images.py b/scripts/check_preview_images.py index 39f9b2d..610bd90 100644 --- a/scripts/check_preview_images.py +++ b/scripts/check_preview_images.py @@ -43,13 +43,6 @@ class Image: (), ("build/hluk-helper",), ), - Image( - "fiberd-k8s-controller", - ".", - "upstream/controller.Dockerfile", - (), - ("build/fiberd-k8s-controller",), - ), Image( "azure-node-setup", "providers/azure/node-setup", diff --git a/scripts/fiberd-controller-inputs.sh b/scripts/fiberd-controller-inputs.sh index cefd919..1725603 100644 --- a/scripts/fiberd-controller-inputs.sh +++ b/scripts/fiberd-controller-inputs.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash -# Shared by the cluster integration suites. fiberd-k8s-controller has no -# release yet, so its manifest, the stock fiberd image grant Pods run and -# Lampyr's helper image are installation inputs, as for ly cluster install: +# Shared by the cluster integration suites. The controller manifest, the +# upstream fiberd image and Lampyr's helper image are installation inputs, +# as for ly cluster install: # # LAMPYR_CONTROLLER_MANIFEST the controller's install manifest, a path or # an https:// URL diff --git a/scripts/mirror-preview-images.sh b/scripts/mirror-preview-images.sh index 6383f75..43af7f2 100755 --- a/scripts/mirror-preview-images.sh +++ b/scripts/mirror-preview-images.sh @@ -6,23 +6,20 @@ readonly REPOSITORY="hyperlight-dev/lampyr" readonly SIGNER_WORKFLOW="${REPOSITORY}/.github/workflows/release.yml" readonly SOURCE_REF="refs/heads/main" readonly PREVIEW_RELEASE="preview-release" -# The last three are the platform's default controller inputs: the fiberd -# image grant Pods run, the controller the manifest below runs, and the -# helper image. -readonly -a IMAGES=( +# The upstream grant and controller images are read from the signed platform. +declare -a IMAGES=( fiberd fiber-router azure-node-setup eventgrid-controller eventgrid-adapter - upstream-fiberd - fiberd-k8s-controller hluk-helper ) # The preview platform carries fiberd-k8s-controller's manifest, which # pulls the controller image by digest. readonly PLATFORM_ARCHIVE="lampyr-platform-linux-amd64-preview.tar.gz" readonly CONTROLLER_MANIFEST="build/fiberd-k8s-controller.yaml" +readonly CONTROLLER_INPUTS="build/controller-inputs.json" die() { echo "preview mirror: $*" >&2 @@ -64,6 +61,8 @@ gh auth status --hostname github.com >/dev/null 2>&1 || die "gh must be authenticated to github.com" command -v docker >/dev/null 2>&1 || die "docker is required" +command -v jq >/dev/null 2>&1 || + die "jq is required" docker buildx version >/dev/null 2>&1 || die "Docker Buildx is required" @@ -92,6 +91,7 @@ cleanup() { trap cleanup EXIT declare -a source_references=() +declare -a source_names=() declare -a source_digests=() declare -a destination_references=() @@ -99,6 +99,7 @@ for image in "${IMAGES[@]}"; do source="${SOURCE_PREFIX}/${image}:${source_tag}" digest=$(inspect_digest "$source") source_references+=("$source") + source_names+=("${SOURCE_PREFIX}/${image}") source_digests+=("$digest") if ! gh attestation verify "oci://${source}@${digest}" \ @@ -125,8 +126,8 @@ if ! gh attestation verify "${work}/${PLATFORM_ARCHIVE}" \ die "attestation verification failed for ${PLATFORM_ARCHIVE}" fi tar --extract --gzip --file "${work}/${PLATFORM_ARCHIVE}" \ - --directory "$work" "$CONTROLLER_MANIFEST" || - die "${PLATFORM_ARCHIVE} has no ${CONTROLLER_MANIFEST}" + --directory "$work" "$CONTROLLER_MANIFEST" "$CONTROLLER_INPUTS" || + die "${PLATFORM_ARCHIVE} has no controller manifest or inputs" manifest=$(<"${work}/${CONTROLLER_MANIFEST}") # Every image the manifest pulls must be one mirrored here, by the digest @@ -138,11 +139,45 @@ mapfile -t manifest_images < <( ) (( ${#manifest_images[@]} > 0 )) || die "${CONTROLLER_MANIFEST} pulls no image" + +grant=$(jq -er '.grantImage' "${work}/${CONTROLLER_INPUTS}") || + die "${CONTROLLER_INPUTS} has no grantImage" +[[ "$grant" =~ ^ghcr.io/azure/fiberd@sha256:[0-9a-f]{64}$ ]] || + die "grantImage is not a digest-pinned upstream fiberd image" +controller= +for reference in "${manifest_images[@]}"; do + if [[ "$reference" =~ ^ghcr.io/azure/fiberd-k8s-controller@sha256:[0-9a-f]{64}$ ]]; then + [[ -z "$controller" ]] || die "controller manifest pulls several controller images" + controller=$reference + fi +done +[[ -n "$controller" ]] || + die "${CONTROLLER_MANIFEST} does not pull a verified upstream controller image" + +for image in upstream-fiberd fiberd-k8s-controller; do + if [[ "$image" == upstream-fiberd ]]; then + reference=$grant + repository=Azure/fiberd + else + reference=$controller + repository=Azure/fiberd-k8s-controller + fi + gh attestation verify "oci://$reference" \ + --repo "$repository" \ + --signer-workflow "$repository/.github/workflows/release.yml" \ + --deny-self-hosted-runners >/dev/null || + die "attestation verification failed for $reference" + IMAGES+=("$image") + source_names+=("${reference%@*}") + source_references+=("${reference%@*}") + source_digests+=("${reference#*@}") +done + declare -a manifest_indexes=() for reference in "${manifest_images[@]}"; do found= for index in "${!IMAGES[@]}"; do - if [[ "$reference" == "${SOURCE_PREFIX}/${IMAGES[$index]}@${source_digests[$index]}" ]]; then + if [[ "$reference" == "${source_names[$index]}@${source_digests[$index]}" ]]; then found=$index fi done @@ -173,7 +208,7 @@ azure_tmp="${build_dir}/.preview-azure.yaml.$$" manifest_tmp="${build_dir}/.preview-fiberd-k8s-controller.yaml.$$" for index in "${manifest_indexes[@]}"; do - source="${SOURCE_PREFIX}/${IMAGES[$index]}@${source_digests[$index]}" + source="${source_names[$index]}@${source_digests[$index]}" manifest=${manifest//"$source"/"${destination_references[$index]}"} done printf '%s\n' "$manifest" > "$manifest_tmp" diff --git a/scripts/publish-preview-release.sh b/scripts/publish-preview-release.sh index e1f4a55..71d97c6 100755 --- a/scripts/publish-preview-release.sh +++ b/scripts/publish-preview-release.sh @@ -16,8 +16,6 @@ readonly -a images=( azure-node-setup eventgrid-controller eventgrid-adapter - upstream-fiberd - fiberd-k8s-controller ) readonly -a assets=( build/dist/lampyr-cli-linux-amd64-preview.tar.gz @@ -82,8 +80,6 @@ gh release create "$PREVIEW_TAG" \ "- ${IMAGE_PREFIX}/azure-node-setup:preview-${GITHUB_SHA}" \ "- ${IMAGE_PREFIX}/eventgrid-controller:preview-${GITHUB_SHA}" \ "- ${IMAGE_PREFIX}/eventgrid-adapter:preview-${GITHUB_SHA}" \ - "- ${IMAGE_PREFIX}/upstream-fiberd:preview-${GITHUB_SHA}" \ - "- ${IMAGE_PREFIX}/fiberd-k8s-controller:preview-${GITHUB_SHA}" \ "" \ "The :preview tags are post-release convenience aliases.")" \ --prerelease diff --git a/scripts/publish-version-release.sh b/scripts/publish-version-release.sh index ace4470..f69770d 100755 --- a/scripts/publish-version-release.sh +++ b/scripts/publish-version-release.sh @@ -16,7 +16,7 @@ tag="${GITHUB_REF#refs/tags/}" } version="${tag#v}" readonly tag version -readonly -a images=(fiberd fiber-router hluk-helper azure-node-setup eventgrid-controller eventgrid-adapter upstream-fiberd fiberd-k8s-controller) +readonly -a images=(fiberd fiber-router hluk-helper azure-node-setup eventgrid-controller eventgrid-adapter) readonly -a assets=( "build/dist/lampyr-cli-linux-amd64-${version}.tar.gz" "build/dist/lampyr-cli-linux-amd64-${version}.tar.gz.sha256" diff --git a/scripts/tests/test_cluster_inputs.py b/scripts/tests/test_cluster_inputs.py index 1bc68cd..2107c75 100644 --- a/scripts/tests/test_cluster_inputs.py +++ b/scripts/tests/test_cluster_inputs.py @@ -13,6 +13,7 @@ UPSTREAM_JUSTFILE = ROOT / "upstream/Justfile" USE_CLUSTER_INPUTS = ROOT / "scripts/use-cluster-inputs.sh" DIGEST = "sha256:" + "ab" * 32 +CONTROLLER_PLATFORM_DIGEST = "sha256:" + "cd" * 32 def recipe(name): @@ -31,6 +32,119 @@ def bash(script, *args, cwd=None, **env): class ClusterInputsTests(unittest.TestCase): + def test_upstream_images_are_pulled_and_only_the_helper_is_built(self): + body = recipe("cluster-inputs") + for fail in ("", "pull"): + with self.subTest(fail=fail), tempfile.TemporaryDirectory(dir=ROOT) as directory: + work = Path(directory) + (work / "bin").mkdir() + (work / "build/tools").mkdir(parents=True) + pins = work / "pins.env" + pins.write_text( + "CONTROLLER_COMMIT=" + "1" * 40 + "\n" + f"CONTROLLER_IMAGE=ghcr.io/azure/fiberd-k8s-controller@{DIGEST}\n" + f"FIBERD_IMAGE=ghcr.io/azure/fiberd@{DIGEST}\n" + ) + docker = work / "bin/docker" + docker.write_text( + '#!/bin/bash\nset -euo pipefail\n' + 'printf "%s\\n" "$*" >> "$COMMANDS"\n' + 'case $1 in\n' + 'pull) [[ -z "$FAIL_PULL" ]] ;;\n' + 'tag) ;;\n' + 'save) touch "$3" ;;\n' + 'buildx)\n' + ' while (($#)); do\n' + ' if [[ $1 == --output ]]; then output=$2; break; fi\n' + ' shift\n' + ' done\n' + ' path=${output#type=oci,dest=}; path=${path%,tar=false}\n' + ' mkdir -p "$path"\n' + ' printf \'{"manifests":[{"digest":"%s"}]}\' "$DIGEST" > "$path/index.json"\n' + ' ;;\n' + '*) exit 92 ;;\n' + 'esac\n' + ) + just = work / "bin/just" + just.write_text( + '#!/bin/bash\nset -euo pipefail\nshift 2\n' + 'case $1 in\n' + 'fiberd-template-tools)\n' + ' for tool in hluk-helper zygotectl grant-issuer; do\n' + ' printf "#!/bin/sh\\n" > "$ROOT/build/$tool"\n' + ' done ;;\n' + 'providers::install-oras) ;;\n' + 'controller-manifest) printf "image: %s\\n" "$2" > "$3" ;;\n' + '*) exit 93 ;;\n' + 'esac\n' + ) + oras = work / "build/tools/oras" + oras.write_text( + '#!/bin/bash\nset -euo pipefail\n' + 'printf "%s\\n" "$*" >> "$COMMANDS"\n' + 'if [[ $1 == resolve ]]; then\n' + ' printf "%s\\n" "$CONTROLLER_PLATFORM_DIGEST"\n' + ' exit 0\n' + 'fi\n' + 'for destination; do :; done\n' + 'path=${destination%:ci}; mkdir -p "$path"\n' + 'printf \'{"manifests":[{"digest":"%s"}]}\' "$DIGEST" > "$path/index.json"\n' + ) + for command in (docker, just, oras): + command.chmod(0o755) + script = body + for placeholder, value in { + "repo-root": work, "project-root": work / "upstream", + "sources": work / "build/upstream", "pins": pins, + }.items(): + script = script.replace("{{" + placeholder + "}}", str(value)) + output = work / "cluster-inputs" + output.mkdir() + (output / "inputs.json").write_text('{"earlier":true}') + commands = work / "commands" + result = bash( + script, str(output), cwd=work, ROOT=str(work), DIGEST=DIGEST, + CONTROLLER_PLATFORM_DIGEST=CONTROLLER_PLATFORM_DIGEST, + COMMANDS=str(commands), FAIL_PULL=fail, + PATH=f"{work / 'bin'}:{os.environ['PATH']}", + ) + if fail: + self.assertNotEqual(result.returncode, 0) + self.assertEqual(json.loads((output / "inputs.json").read_text()), {"earlier": True}) + self.assertFalse(any(work.glob(".cluster-inputs.*"))) + continue + self.assertEqual(result.returncode, 0, result.stderr) + inputs = json.loads((output / "inputs.json").read_text()) + self.assertEqual(inputs, { + "controllerImage": "lampyr.local/fiberd-k8s-controller:" + "1" * 12, + "grantDigest": DIGEST, + "helperDigest": DIGEST, + }) + self.assertTrue((output / "images/fiberd-k8s-controller.tar").is_file()) + calls = commands.read_text().splitlines() + self.assertEqual(calls[0], ( + "resolve --platform linux/amd64 " + f"ghcr.io/azure/fiberd-k8s-controller@{DIGEST}" + )) + # Importers request all platforms. Pull and tag the child + # manifest, not an index whose other platforms are absent. + controller = ( + "ghcr.io/azure/fiberd-k8s-controller@" + + CONTROLLER_PLATFORM_DIGEST + ) + self.assertIn(f"pull --platform linux/amd64 {controller}", calls) + self.assertIn( + f"tag {controller} lampyr.local/fiberd-k8s-controller:" + "1" * 12, + calls, + ) + builds = [line for line in calls if line.startswith("buildx build")] + self.assertEqual(len(builds), 1) + self.assertIn("helper/ci.Dockerfile", builds[0]) + self.assertTrue(any( + f"cp --platform linux/amd64 --to-oci-layout ghcr.io/azure/fiberd@{DIGEST}" in line + for line in calls + )) + def test_digest_takes_only_one_sha256_manifest(self): body = recipe("cluster-inputs") program = re.search(r"jq -er '([^']*select\(length == 1\)[^']*)'", body) diff --git a/scripts/tests/test_package_platform.py b/scripts/tests/test_package_platform.py index 83e5001..375688d 100644 --- a/scripts/tests/test_package_platform.py +++ b/scripts/tests/test_package_platform.py @@ -308,7 +308,7 @@ def test_platform_archive_carries_written_controller_inputs(self): manifest.write_text("kind: Deployment\n") valid = { "controllerManifest": "build/fiberd-k8s-controller.yaml", - "grantImage": f"ghcr.io/hyperlight-dev/lampyr/upstream-fiberd@{digest}", + "grantImage": f"ghcr.io/azure/fiberd@{digest}", "helperImage": f"ghcr.io/hyperlight-dev/lampyr/hluk-helper@{digest}", } inputs.write_text(json.dumps(valid)) diff --git a/scripts/tests/test_preview_mirror.py b/scripts/tests/test_preview_mirror.py index 4e6002b..216c3ab 100755 --- a/scripts/tests/test_preview_mirror.py +++ b/scripts/tests/test_preview_mirror.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 """Fixture tests for verified preview image mirroring.""" +import json import os from pathlib import Path import subprocess @@ -17,10 +18,11 @@ "azure-node-setup", "eventgrid-controller", "eventgrid-adapter", + "hluk-helper", "upstream-fiberd", "fiberd-k8s-controller", - "hluk-helper", ) +LAMPYR_IMAGES = IMAGES[:-2] SOURCE_DIGITS = { "fiberd": "1", "fiber-router": "2", @@ -41,7 +43,8 @@ "fiberd-k8s-controller": "9", "hluk-helper": "0", } -CONTROLLER = f"{SOURCE}/fiberd-k8s-controller@sha256:{'7' * 64}" +GRANT = f"ghcr.io/azure/fiberd@sha256:{'6' * 64}" +CONTROLLER = f"ghcr.io/azure/fiberd-k8s-controller@sha256:{'7' * 64}" MANIFEST = f"""apiVersion: apps/v1 kind: Deployment spec: @@ -62,14 +65,17 @@ "auth status") exit 0 ;; "api repos/hyperlight-dev/lampyr/commits/preview-release") printf '%s\n' "$COMMIT"; exit 0 ;; - "attestation verify") exit 0 ;; + "attestation verify") + if [[ -n ${FAIL_VERIFY:-} && $3 == *"$FAIL_VERIFY"* ]]; then exit 32; fi + exit 0 ;; "release download") while (($#)); do [[ $1 == --dir ]] && dir=$2; shift; done root=$(mktemp -d "${FAKE_LOG%/*}/archive.XXXXXX") mkdir -p "$root/build" printf '%s' "$FAKE_MANIFEST" > "$root/build/fiberd-k8s-controller.yaml" + printf '%s' "$FAKE_INPUTS" > "$root/build/controller-inputs.json" tar --create --gzip --file "$dir/lampyr-platform-linux-amd64-preview.tar.gz" \ - --directory "$root" build/fiberd-k8s-controller.yaml + --directory "$root" build/fiberd-k8s-controller.yaml build/controller-inputs.json rm -rf "$root" exit 0 ;; esac @@ -126,6 +132,7 @@ def run_script(self, destination="registry.example.com/team/lampyr", **extra): "FAKE_LOG": str(self.log), "COMMIT": COMMIT, "FAKE_MANIFEST": MANIFEST, + "FAKE_INPUTS": json.dumps({"grantImage": GRANT}), } | extra return subprocess.run( ["bash", str(self.script), destination], @@ -146,8 +153,8 @@ def test_fixed_sources_and_attestation_policy(self): self.assertEqual(result.returncode, 0, result.stderr) inspects = self.calls("docker", ("buildx", "imagetools", "inspect")) self.assertEqual( - [call[3] for call in inspects[:len(IMAGES)]], - [f"{SOURCE}/{image}:{SOURCE_TAG}" for image in IMAGES]) + [call[3] for call in inspects[:len(LAMPYR_IMAGES)]], + [f"{SOURCE}/{image}:{SOURCE_TAG}" for image in LAMPYR_IMAGES]) self.assertEqual( self.calls("gh", ("api",)), [["api", "repos/hyperlight-dev/lampyr/commits/preview-release", @@ -160,17 +167,30 @@ def test_fixed_sources_and_attestation_policy(self): "--deny-self-hosted-runners"] verified = self.calls("gh", ("attestation", "verify")) self.assertEqual( - verified[:-1], + verified[:len(LAMPYR_IMAGES)], [ ["attestation", "verify", f"oci://{SOURCE}/{image}:{SOURCE_TAG}@sha256:{SOURCE_DIGITS[image] * 64}", *policy] - for image in IMAGES]) + for image in LAMPYR_IMAGES]) # The platform archive carrying the controller manifest is verified # under the same policy. - self.assertEqual(verified[-1][3:], policy) + archive = verified[len(LAMPYR_IMAGES)] + self.assertEqual(archive[3:], policy) self.assertTrue( - verified[-1][2].endswith("/lampyr-platform-linux-amd64-preview.tar.gz")) + archive[2].endswith("/lampyr-platform-linux-amd64-preview.tar.gz")) + for call, reference, repository in zip( + verified[len(LAMPYR_IMAGES) + 1:], + (GRANT, CONTROLLER), + ("Azure/fiberd", "Azure/fiberd-k8s-controller"), + strict=True, + ): + self.assertEqual(call, [ + "attestation", "verify", f"oci://{reference}", + "--repo", repository, + "--signer-workflow", f"{repository}/.github/workflows/release.yml", + "--deny-self-hosted-runners", + ]) self.assertEqual( [call[:6] for call in self.calls("gh", ("release", "download"))], [["release", "download", "preview-release", @@ -179,8 +199,25 @@ def test_fixed_sources_and_attestation_policy(self): self.assertTrue(all(call[3:5] == ["--platform", "linux/amd64"] for call in creates)) self.assertEqual( [call[7] for call in creates], - [f"{SOURCE}/{image}:{SOURCE_TAG}@sha256:{SOURCE_DIGITS[image] * 64}" - for image in IMAGES]) + [*(f"{SOURCE}/{image}:{SOURCE_TAG}@sha256:{SOURCE_DIGITS[image] * 64}" + for image in LAMPYR_IMAGES), GRANT, CONTROLLER]) + + def test_upstream_attestation_failure_copies_nothing(self): + for reference in (GRANT, CONTROLLER): + with self.subTest(reference=reference): + result = self.run_script(FAIL_VERIFY=reference) + self.assertNotEqual(result.returncode, 0) + self.assertIn("attestation verification failed", result.stderr) + self.assertEqual(self.calls("docker", ("buildx", "imagetools", "create")), []) + self.log.unlink() + + def test_platform_cannot_substitute_a_non_upstream_grant_image(self): + result = self.run_script( + FAKE_INPUTS=json.dumps({"grantImage": f"{SOURCE}/upstream-fiberd@sha256:{'6' * 64}"}) + ) + self.assertNotEqual(result.returncode, 0) + self.assertIn("not a digest-pinned upstream fiberd image", result.stderr) + self.assertEqual(self.calls("docker", ("buildx", "imagetools", "create")), []) def test_invalid_destinations_run_no_commands(self): invalid = ( @@ -213,7 +250,7 @@ def test_a_manifest_pulling_an_unmirrored_image_copies_nothing(self): with self.subTest(image=image): result = self.run_script(FAKE_MANIFEST=MANIFEST.replace(CONTROLLER, image)) self.assertNotEqual(result.returncode, 0) - self.assertIn("not a verified preview image", result.stderr) + self.assertIn("verified upstream controller image", result.stderr) self.assertEqual(self.calls("docker", ("buildx", "imagetools", "create")), []) self.log.unlink() @@ -226,7 +263,7 @@ def test_destination_digests_and_yaml_order(self): for image in IMAGES} inspects = self.calls("docker", ("buildx", "imagetools", "inspect")) self.assertEqual( - [call[3] for call in inspects[len(IMAGES):]], + [call[3] for call in inspects[len(LAMPYR_IMAGES):]], [f"{destination}/{image}:preview" for image in IMAGES]) manifest = self.root / "build" / "preview-fiberd-k8s-controller.yaml" self.assertEqual( diff --git a/scripts/tests/test_preview_workflow.py b/scripts/tests/test_preview_workflow.py index 314555f..1f4a93b 100644 --- a/scripts/tests/test_preview_workflow.py +++ b/scripts/tests/test_preview_workflow.py @@ -47,10 +47,6 @@ "azure-node-setup": ("azure::prepare-node-setup-image", "providers/azure/node-setup", "providers/azure/node-setup/Dockerfile", "", ""), "eventgrid-controller": ("azure::prepare-eventgrid-controller-image", "providers/azure", "providers/azure/eventgrid/ci.Dockerfile", "", "BINARY=eventgrid-controller"), "eventgrid-adapter": ("azure::prepare-eventgrid-adapter-image", "providers/azure", "providers/azure/eventgrid/ci.Dockerfile", "", "BINARY=eventgrid-adapter"), - # Built from upstream/pins.env's commits: fiberd's own Dockerfile from its - # checkout, and the controller's manager in Lampyr's. - "upstream-fiberd": ("upstream::prepare-fiberd-image", "build/upstream/fiberd", "build/upstream/fiberd/docker/fiberd/Dockerfile", "fiberd", ""), - "fiberd-k8s-controller": ("upstream::prepare-controller-image", ".", "upstream/controller.Dockerfile", "", ""), } PINS_FILE = ROOT / "upstream/pins.env" HOSTED_ARCHIVE_KINDS = ( @@ -386,16 +382,8 @@ def test_image_matrix_and_buildkit_policy(self): self.assertEqual( tuple(build["with"][key] for key in ("context", "file", "target", "build-args")), ("${{ matrix.context }}", "${{ matrix.dockerfile }}", "${{ matrix.target }}", - "${{ steps.fiberd-version.outputs.build-args || matrix.build_args }}"), + "${{ matrix.build_args }}"), ) - # upstream-fiberd alone is built as go.mod's fiberd version, which - # fiberd -version prints. - version = next( - step for step in self.images["steps"] if step.get("id") == "fiberd-version" - ) - self.assertEqual(version["if"], "matrix.image == 'upstream-fiberd'") - self.assertIn("just upstream::fiberd-version", version["run"]) - self.assertEqual(MATRIX["upstream-fiberd"][4], "") self.assertEqual(build["with"]["platforms"], "linux/amd64") self.assertEqual( tuple(build["with"][key] for key in ("push", "provenance", "sbom")), @@ -888,7 +876,7 @@ def test_dependabot_covers_actions_and_docker(self): self.assertIn("github-actions", updates) self.assertEqual(set(updates["docker"]["directories"]), { "/activator", "/fiberd", "/helper", "/providers/azure/eventgrid", - "/providers/azure/node-setup", "/upstream", + "/providers/azure/node-setup", }) def test_upstream_pins_are_full_commits_and_match_go_mod(self): @@ -900,6 +888,8 @@ def test_upstream_pins_are_full_commits_and_match_go_mod(self): self.assertEqual(set(pins), { "FIBERD_REPOSITORY", "FIBERD_COMMIT", "CONTROLLER_REPOSITORY", "CONTROLLER_COMMIT", + "FIBERD_VERSION", "FIBERD_IMAGE", + "CONTROLLER_VERSION", "CONTROLLER_IMAGE", }) self.assertEqual(pins["FIBERD_REPOSITORY"], "Azure/fiberd") self.assertEqual(pins["CONTROLLER_REPOSITORY"], "Azure/fiberd-k8s-controller") @@ -909,42 +899,56 @@ def test_upstream_pins_are_full_commits_and_match_go_mod(self): go_mod = (ROOT / "go.mod").read_text(encoding="utf-8") version = re.search(r"^\s*github\.com/Azure/fiberd (\S+)$", go_mod, re.M) self.assertIsNotNone(version) - self.assertEqual(version.group(1).rsplit("-", 1)[1], pins["FIBERD_COMMIT"][:12]) - # upstream-fiberd is built as that version. - self.assertIn( - """@awk '$1 == "github.com/Azure/fiberd" {print $2; found=1} END {exit !found}' "{{repo-root}}/go.mod""", - (ROOT / "upstream/Justfile").read_text(encoding="utf-8"), - ) + self.assertEqual(version.group(1), f"v{pins['FIBERD_VERSION']}") + for prefix, repository in ( + ("FIBERD", "ghcr.io/azure/fiberd"), + ("CONTROLLER", "ghcr.io/azure/fiberd-k8s-controller"), + ): + self.assertRegex( + pins[f"{prefix}_IMAGE"], + rf"^{re.escape(repository)}@sha256:[0-9a-f]{{64}}$", + ) - def test_upstream_images_describe_the_pinned_source(self): - metadata = next(step for step in self.images["steps"] if step.get("id") == "meta") - self.assertIn( - "org.opencontainers.image.description=" - "${{ steps.upstream.outputs.description || matrix.description }}", - metadata["with"]["labels"], - ) - upstream = named(self.images, "Read the upstream source") - names = [step.get("name") for step in self.images["steps"]] - self.assertLess(names.index("Read the upstream source"), names.index("Extract image metadata")) + def test_upstream_image_provenance_matches_source_pins(self): pins = dict( line.split("=", 1) - for line in (ROOT / "upstream/pins.env").read_text(encoding="utf-8").splitlines() + for line in PINS_FILE.read_text(encoding="utf-8").splitlines() if line and not line.startswith("#") ) - expected = { - "upstream-fiberd": f"{pins['FIBERD_REPOSITORY']}@{pins['FIBERD_COMMIT']}", - "fiberd-k8s-controller": f"{pins['CONTROLLER_REPOSITORY']}@{pins['CONTROLLER_COMMIT']}", - } - for image, source in expected.items(): - with self.subTest(image=image), tempfile.TemporaryDirectory() as work: - output = Path(work) / "output" - subprocess.run( - ["bash", "--noprofile", "--norc", "-eo", "pipefail", "-c", upstream["run"]], - cwd=ROOT, check=True, capture_output=True, text=True, - env={**os.environ, "IMAGE": image, "GITHUB_OUTPUT": str(output)}, + for fail in ("", "FIBERD", "CONTROLLER"): + with self.subTest(fail=fail), tempfile.TemporaryDirectory(dir=ROOT) as work: + work = Path(work) + gh = work / "gh" + gh.write_text( + '#!/bin/sh\nprintf "%s\\n" "$*" >> "$GH_LOG"\n' + 'if [ -n "$FAIL_IMAGE" ] && [ "$3" = "oci://$FAIL_IMAGE" ]; ' + 'then exit 1; fi\n' ) - description = output.read_text().removeprefix("description=").strip() - self.assertIn(source, description) + gh.chmod(0o755) + output = work / "commands" + result = subprocess.run( + ["just", "--justfile", str(ROOT / "upstream/Justfile"), "verify-images"], + cwd=ROOT, capture_output=True, text=True, + env={ + **os.environ, "PATH": f"{work}:{os.environ['PATH']}", + "GH_LOG": str(output), + "FAIL_IMAGE": pins[f"{fail}_IMAGE"] if fail else "", + }, + ) + self.assertEqual(result.returncode == 0, not fail, result.stderr) + expected = [] + for prefix in ("FIBERD", "CONTROLLER"): + repository = pins[f"{prefix}_REPOSITORY"] + expected.append( + f"attestation verify oci://{pins[f'{prefix}_IMAGE']} " + f"--repo {repository} " + f"--signer-workflow {repository}/.github/workflows/release.yml " + f"--source-digest {pins[f'{prefix}_COMMIT']} " + "--deny-self-hosted-runners" + ) + if prefix == fail: + break + self.assertEqual(output.read_text().splitlines(), expected) def test_packages_pin_the_controller_inputs_to_the_published_images(self): images = self.images["steps"] @@ -962,7 +966,12 @@ def test_packages_pin_the_controller_inputs_to_the_published_images(self): self.assertIs(download["with"]["merge-multiple"], True) write = named(self.jobs["packages"], "Write the default controller inputs")["run"] self.assertIn("just upstream::controller-inputs", write) - images = ("fiberd-k8s-controller", "upstream-fiberd", "hluk-helper") + images = ("hluk-helper",) + pins = dict( + line.split("=", 1) + for line in PINS_FILE.read_text(encoding="utf-8").splitlines() + if line and not line.startswith("#") + ) for image in images: self.assertIn(f"$(image {image})", write) self.assertIn(image, MATRIX) @@ -972,6 +981,8 @@ def test_packages_pin_the_controller_inputs_to_the_published_images(self): for bad in (None, *images): with self.subTest(bad=bad), tempfile.TemporaryDirectory() as work: work = Path(work) + (work / "upstream").mkdir() + (work / "upstream/pins.env").write_bytes(PINS_FILE.read_bytes()) (work / "build/image-digests").mkdir(parents=True) for image in images: (work / "build/image-digests" / image).write_text( @@ -992,7 +1003,9 @@ def test_packages_pin_the_controller_inputs_to_the_published_images(self): self.assertEqual(result.returncode, 0, result.stderr) self.assertEqual(log.read_text().splitlines(), [ "upstream::controller-inputs", - *(f"ghcr.io/team/{image}@{digest}" for image in images), + pins["CONTROLLER_IMAGE"], + pins["FIBERD_IMAGE"], + f"ghcr.io/team/hluk-helper@{digest}", ]) else: self.assertNotEqual(result.returncode, 0) @@ -1003,6 +1016,53 @@ def test_packages_pin_the_controller_inputs_to_the_published_images(self): self.assertLess(names.index("Write the default controller inputs"), names.index("Package release archives")) + def test_upstream_images_are_not_published_by_lampyr(self): + published = { + entry["image"] + for entry in self.images["strategy"]["matrix"]["include"] + } + self.assertTrue( + published.isdisjoint({"upstream-fiberd", "fiberd-k8s-controller"}), + "Use the signed upstream releases instead of publishing copies", + ) + + def test_packages_use_upstream_images_without_lampyr_upstream_digest_artifacts(self): + write = named(self.jobs["packages"], "Write the default controller inputs")["run"] + digest = "sha256:" + "a" * 64 + grant = "ghcr.io/azure/fiberd@sha256:" + "b" * 64 + controller = "ghcr.io/azure/fiberd-k8s-controller@sha256:" + "c" * 64 + with tempfile.TemporaryDirectory(dir=ROOT) as directory: + work = Path(directory) + (work / "build/image-digests").mkdir(parents=True) + (work / "build/image-digests/hluk-helper").write_text(digest) + (work / "upstream").mkdir() + (work / "upstream/pins.env").write_text( + PINS_FILE.read_text(encoding="utf-8") + + f"\nFIBERD_IMAGE={grant}\nCONTROLLER_IMAGE={controller}\n" + ) + (work / "bin").mkdir() + just = work / "bin/just" + just.write_text('#!/bin/sh\nprintf "%s\\n" "$@" > "$JUST_LOG"\n') + just.chmod(0o755) + log = work / "just.log" + result = subprocess.run( + ["bash", "--noprofile", "--norc", "-eo", "pipefail", "-c", write], + cwd=work, capture_output=True, text=True, + env={ + **os.environ, + "PATH": f"{work / 'bin'}:{os.environ['PATH']}", + "IMAGE_PREFIX": "ghcr.io/team", + "JUST_LOG": str(log), + }, + ) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(log.read_text().splitlines(), [ + "upstream::controller-inputs", + controller, + grant, + f"ghcr.io/team/hluk-helper@{digest}", + ]) + def test_cluster_suites_install_the_built_controller_inputs(self): jobs = self.ci["jobs"] build = jobs["cluster-inputs"] @@ -1010,13 +1070,10 @@ def test_cluster_suites_install_the_built_controller_inputs(self): named(build, "Build the cluster suites' controller inputs")["run"], "just upstream::cluster-inputs build/cluster-inputs", ) - # The cache is warmed for the VERSION the inputs build fiberd as. - warm = named(build, "Warm the stock fiberd build cache") - self.assertEqual( - warm["with"]["build-args"], "VERSION=${{ steps.fiberd-version.outputs.version }}" - ) - self.assertIn( - "just upstream::fiberd-version", named(build, "Read the fiberd version")["run"] + self.assertFalse( + any(step.get("uses", "").startswith("docker/build-push-action@") + for step in build["steps"]), + "Cluster inputs pull upstream images; only the helper is built locally", ) upload = named(build, "Upload the cluster suites' controller inputs") self.assertEqual(upload["with"]["name"], "cluster-inputs-${{ github.sha }}") diff --git a/upstream/Justfile b/upstream/Justfile index 2ac441d..f346983 100644 --- a/upstream/Justfile +++ b/upstream/Justfile @@ -5,9 +5,8 @@ repo-root := project-root / ".." pins := project-root / "pins.env" sources := repo-root / "build/upstream" -# Neither fiberd nor fiberd-k8s-controller publishes images or an install -# manifest yet, so Lampyr builds them from the commits pins.env pins. The -# sources are checked out under build/upstream. +# Sources supply the template tools and the controller install manifest. +# Images come from the signed upstream releases in pins.env. # Check out the pinned fiberd or fiberd-k8s-controller under build/upstream. [positional-arguments] @@ -28,17 +27,17 @@ source name: git -C "$checkout" -c advice.detachedHead=false checkout --quiet FETCH_HEAD; \ [[ $(git -C "$checkout" rev-parse HEAD) == "$commit" ]] -# The upstream-fiberd image is fiberd's own docker/fiberd build, so its -# context is the checkout. Its VERSION build arg is what fiberd -version -# prints: go.mod's github.com/Azure/fiberd, the pseudo-version of the -# pinned commit, which the release tests keep on FIBERD_COMMIT. - -# Print the version the upstream-fiberd image is built as. -fiberd-version: - @awk '$1 == "github.com/Azure/fiberd" {print $2; found=1} END {exit !found}' "{{repo-root}}/go.mod" - -# Check out the source the upstream-fiberd image builds from. -prepare-fiberd-image: (source "fiberd") +# Verify the signed image digests against their release source commits. +verify-images: + . "{{pins}}"; \ + gh attestation verify "oci://$FIBERD_IMAGE" \ + --repo "$FIBERD_REPOSITORY" \ + --signer-workflow "$FIBERD_REPOSITORY/.github/workflows/release.yml" \ + --source-digest "$FIBERD_COMMIT" --deny-self-hosted-runners; \ + gh attestation verify "oci://$CONTROLLER_IMAGE" \ + --repo "$CONTROLLER_REPOSITORY" \ + --signer-workflow "$CONTROLLER_REPOSITORY/.github/workflows/release.yml" \ + --source-digest "$CONTROLLER_COMMIT" --deny-self-hosted-runners # ly deploy runs zygotectl and grant-issuer on the user's machine, so a # platform package carries them built for its own target, from the pinned @@ -56,17 +55,6 @@ template-tools: (source "fiberd") done; \ done -# The controller's go.mod may ask for a newer Go than Lampyr's, which -# GOTOOLCHAIN=auto fetches. actions/setup-go exports GOTOOLCHAIN=local, so -# the recipe sets auto for its own go build. - -# Prepare the Linux/amd64 fiberd-k8s-controller image context without publishing it. -prepare-controller-image: (source "fiberd-k8s-controller") - mkdir -p "{{repo-root}}/build" - GOTOOLCHAIN=auto GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go -C "{{sources}}/fiberd-k8s-controller" build \ - -trimpath -ldflags="-s -w -buildid=" -o "{{repo-root}}/build/fiberd-k8s-controller" ./cmd/fiberd-k8s-controller - python3 "{{repo-root}}/scripts/check_preview_images.py" --root "{{repo-root}}" --image fiberd-k8s-controller --require-binaries - # The controller's install manifest is its config/default: the CRDs, RBAC, # fiberd CA, admission policies and the Deployment, which runs `image`. @@ -96,7 +84,7 @@ controller-manifest image output: (source "fiberd-k8s-controller") # Write the controller inputs a platform package installs by default. [positional-arguments] -controller-inputs controller-image grant-image helper-image: +controller-inputs controller-image grant-image helper-image: verify-images for image in "$1" "$2" "$3"; do \ [[ $image =~ ^[^@[:space:]]+@sha256:[0-9a-f]{64}$ ]] || { echo "not pinned by a sha256 digest: $image" >&2; exit 1; }; \ done @@ -106,7 +94,7 @@ controller-inputs controller-image grant-image helper-image: > "{{repo-root}}/build/controller-inputs.json" # The cluster suites take this directory as LAMPYR_CLUSTER_INPUTS in place -# of published inputs: the upstream-fiberd and helper images as OCI layouts +# of published inputs: the upstream fiberd and helper images as OCI layouts # a suite pushes to its registry, the controller image as a Docker archive # its provider loads, the manifest running it, and the helper, zygotectl # and grant-issuer that ly build and ly deploy seal templates with. @@ -118,10 +106,13 @@ controller-inputs controller-image grant-image helper-image: # the directory it points to, which would then be replaced. # Build the cluster suites' controller inputs into `output`. +# Resolve the controller's platform manifest before Docker pulls it. A +# partial multi-platform index fails Kind and k3d's all-platform imports. [no-cd] [positional-arguments] -cluster-inputs output: prepare-fiberd-image prepare-controller-image +cluster-inputs output: verify-images (source "fiberd") just --justfile "{{repo-root}}/Justfile" fiberd-template-tools "{{sources}}/fiberd" + just --justfile "{{repo-root}}/Justfile" providers::install-oras . "{{pins}}"; \ name=$(basename -- "$1"); \ [[ $name != . && $name != .. && $name != / ]] || { \ @@ -139,19 +130,17 @@ cluster-inputs output: prepare-fiberd-image prepare-controller-image trap 'rm -rf -- "$staging"' EXIT; \ chmod 0755 "$staging"; \ mkdir -p "$staging/images" "$staging/bin"; \ - fiberd_version=$(just --justfile "{{project-root}}/Justfile" fiberd-version); \ - [[ -n $fiberd_version ]] || { echo "fiberd-version printed nothing" >&2; exit 1; }; \ controller="lampyr.local/fiberd-k8s-controller:${CONTROLLER_COMMIT:0:12}"; \ - docker buildx build --platform linux/amd64 --provenance=false --tag "$controller" \ - --output "type=docker,dest=$staging/images/fiberd-k8s-controller.tar" \ - --file "{{project-root}}/controller.Dockerfile" "{{repo-root}}"; \ + controller_digest=$("{{repo-root}}/build/tools/oras" resolve --platform linux/amd64 "$CONTROLLER_IMAGE"); \ + controller_source="${CONTROLLER_IMAGE%@*}@$controller_digest"; \ + docker pull --platform linux/amd64 "$controller_source"; \ + docker tag "$controller_source" "$controller"; \ + docker save --output "$staging/images/fiberd-k8s-controller.tar" "$controller"; \ docker buildx build --platform linux/amd64 --provenance=false \ --output "type=oci,dest=$staging/images/hluk-helper,tar=false" \ --file "{{repo-root}}/helper/ci.Dockerfile" "{{repo-root}}"; \ - docker buildx build --platform linux/amd64 --provenance=false --target fiberd \ - --build-arg "VERSION=$fiberd_version" \ - --output "type=oci,dest=$staging/images/upstream-fiberd,tar=false" \ - --file "{{sources}}/fiberd/docker/fiberd/Dockerfile" "{{sources}}/fiberd"; \ + "{{repo-root}}/build/tools/oras" cp --platform linux/amd64 --to-oci-layout \ + "$FIBERD_IMAGE" "$staging/images/upstream-fiberd:ci"; \ digest() { \ jq -er '.manifests | select(length == 1) | .[0].digest | select(test("^sha256:[0-9a-f]{64}$"))' \ "$staging/images/$1/index.json"; \ diff --git a/upstream/controller.Dockerfile b/upstream/controller.Dockerfile deleted file mode 100644 index 3597c8d..0000000 --- a/upstream/controller.Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -# The fiberd-k8s-controller image, which Lampyr publishes until the -# controller has a Dockerfile and release of its own -# (Azure/fiberd-k8s-controller#26). just -# upstream::prepare-controller-image builds the manager from the commit -# upstream/pins.env pins; the image's description names it. It runs as -# the nonroot user, 65532, which the controller's Deployment requires, and -# its arguments come from that Deployment. -FROM gcr.io/distroless/static-debian12:nonroot@sha256:afa5c872c891853ca7fcf1f12c3edb23f7eeef36189728842dd51042ff57f7ab - -COPY build/fiberd-k8s-controller /fiberd-k8s-controller -USER 65532:65532 - -ENTRYPOINT ["/fiberd-k8s-controller"] diff --git a/upstream/pins.env b/upstream/pins.env index f5cd201..8d5a2a1 100644 --- a/upstream/pins.env +++ b/upstream/pins.env @@ -1,17 +1,17 @@ -# The upstream commits Lampyr builds fiberd's image and -# fiberd-k8s-controller's image and install manifest from, until those -# projects publish releases of their own. Bump a commit here and every -# build follows it. Keep to plain NAME=value lines: bash sources this file -# and the release tests parse it. +# Upstream releases. Image indexes have signed GitHub provenance from each +# repository's release workflow. Keep plain NAME=value lines for bash and tests. # The fiberd grant Pods run, and whose zygotectl and grant-issuer seal # templates. go.mod's github.com/Azure/fiberd must be this commit too, # since the router's client speaks its protocol. FIBERD_REPOSITORY=Azure/fiberd -FIBERD_COMMIT=549f6168ca09b61da6686338efb27644d7fc33a0 +FIBERD_COMMIT=582d65676908569f27be209689a45a34a7fbd875 +FIBERD_VERSION=0.4.0 +FIBERD_IMAGE=ghcr.io/azure/fiberd@sha256:672ff23e18557076bee7c6a1f6da3e95802eab1cafcd4720d62a2f7466779305 -# Azure/fiberd-k8s-controller main at #39's merge, which serves grant -# Pods over mutual TLS, issues caller grants and leaves a CPU request -# without a limit. +# Build the install manifest from this release's source, with the same +# image digest. The manifest includes both Grant CRDs and admission policies. CONTROLLER_REPOSITORY=Azure/fiberd-k8s-controller -CONTROLLER_COMMIT=5d57bd8312c4fe6cf4446c474ad7d4a3166967d2 +CONTROLLER_COMMIT=8f799dff34ddc00c333f763c34c643ce8829ec29 +CONTROLLER_VERSION=0.1.0 +CONTROLLER_IMAGE=ghcr.io/azure/fiberd-k8s-controller@sha256:f5c638fb08314ed1ea29e01eb113ad6abf1e8f999980d57d426975ba4dbf5d51