diff --git a/.agents/skills/helm-dev-environment/SKILL.md b/.agents/skills/helm-dev-environment/SKILL.md index 170bdd7c16..e204b94438 100644 --- a/.agents/skills/helm-dev-environment/SKILL.md +++ b/.agents/skills/helm-dev-environment/SKILL.md @@ -32,7 +32,8 @@ When the named cluster already exists, the task starts any stopped containers an same-named kubeconfig entries so a recreated load balancer's current API port takes effect. Also applies the upstream agent-sandbox CRDs/controller (pinned via `AGENT_SANDBOX_VERSION` in `tasks/scripts/helm-k3s-local.sh`, fetched from `github.com/kubernetes-sigs/agent-sandbox` -releases), enables its OTLP tracing on v0.5 and later, installs an OTLP trace +releases, checked against the checksums pinned in `e2e/support/install-agent-sandbox.sh`, and +kept in `~/.cache/openshell/agent-sandbox`), enables its OTLP tracing on v0.5 and later, installs an OTLP trace collector and UI in the `observability` namespace, and preloads the default sandbox image into k3d so the first sandbox create does not wait on a large registry pull. Traefik is disabled at cluster creation time. diff --git a/.github/actions/setup-agent-sandbox-manifests/action.yml b/.github/actions/setup-agent-sandbox-manifests/action.yml new file mode 100644 index 0000000000..edcd5bfebc --- /dev/null +++ b/.github/actions/setup-agent-sandbox-manifests/action.yml @@ -0,0 +1,41 @@ +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +name: Setup Agent Sandbox manifests +description: >- + Restore the pinned Agent Sandbox release manifests that + e2e/support/install-agent-sandbox.sh applies. Branch Checks and Branch E2E + never run on main, so Rust Cache saves them there for PRs to restore. + +inputs: + save: + description: Download every pinned manifest and save the cache on a miss + required: false + default: "false" + +runs: + using: composite + steps: + - name: Select Agent Sandbox manifest directory + shell: bash + run: | # zizmor: ignore[github-env] the value is fixed beneath the runner-controlled HOME + echo "AGENT_SANDBOX_MANIFEST_DIR=$HOME/.cache/openshell/agent-sandbox" >> "$GITHUB_ENV" + + - name: Restore Agent Sandbox manifests + id: cache + uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0 + with: + path: ~/.cache/openshell/agent-sandbox + key: agent-sandbox-manifests-${{ hashFiles('e2e/support/install-agent-sandbox.sh') }} + + - name: Download Agent Sandbox manifests + if: inputs.save == 'true' && steps.cache.outputs.cache-hit != 'true' + shell: bash + run: bash e2e/support/install-agent-sandbox.sh --download-only + + - name: Save Agent Sandbox manifests + if: inputs.save == 'true' && steps.cache.outputs.cache-hit != 'true' + uses: actions/cache/save@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0 + with: + path: ~/.cache/openshell/agent-sandbox + key: ${{ steps.cache.outputs.cache-primary-key }} diff --git a/.github/actions/setup-e2e-kind/action.yml b/.github/actions/setup-e2e-kind/action.yml index 6ea02cd757..2dc98d59db 100644 --- a/.github/actions/setup-e2e-kind/action.yml +++ b/.github/actions/setup-e2e-kind/action.yml @@ -38,6 +38,8 @@ runs: with: version: ${{ inputs.mise-version }} + - uses: ./.github/actions/setup-agent-sandbox-manifests + - name: Log in to GHCR shell: bash env: @@ -62,13 +64,21 @@ runs: YAML echo "path=$config" >> "$GITHUB_OUTPUT" + # kind comes from mise (pinned in mise.lock) rather than a fresh download. - name: Create kind cluster - uses: helm/kind-action@ef37e7f390d99f746eb8b610417061a60e82a6cc # v1.14.0 - with: - cluster_name: ${{ inputs.cluster-name }} + shell: bash + env: + CLUSTER_NAME: ${{ inputs.cluster-name }} # Nodes cannot become Ready until the following CNI installation. - wait: ${{ inputs.enforce-network-policy == 'true' && '0s' || '120s' }} - config: ${{ steps.kind-config.outputs.path }} + WAIT: ${{ inputs.enforce-network-policy == 'true' && '0s' || '120s' }} + CONFIG: ${{ steps.kind-config.outputs.path }} + run: | + set -euo pipefail + args=(create cluster --name "$CLUSTER_NAME" --wait "$WAIT") + if [[ -n "$CONFIG" ]]; then + args+=(--config "$CONFIG") + fi + kind "${args[@]}" - name: Install policy-enforcing CNI if: inputs.enforce-network-policy == 'true' diff --git a/.github/workflows/rust-cache.yml b/.github/workflows/rust-cache.yml index 3b6fef0238..94a379e51f 100644 --- a/.github/workflows/rust-cache.yml +++ b/.github/workflows/rust-cache.yml @@ -67,6 +67,24 @@ jobs: cargo nextest run --locked --config-file .config/nextest.toml --profile ci --manifest-path examples/supervisor-middleware-content-guard/Cargo.toml --no-run cargo nextest run --locked --config-file .config/nextest.toml --profile ci --manifest-path tests/testkit/Cargo.toml --no-run + # Restored by the Kubernetes, Podman, and VM E2E jobs through setup-mise and + # setup-agent-sandbox-manifests, so PRs that don't change mise.lock or the + # pinned manifests don't download them from GitHub. + e2e-tools: + name: E2E tools cache (Linux X64) + runs-on: ubuntu-24.04 + timeout-minutes: 20 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - uses: ./.github/actions/setup-mise + + - uses: ./.github/actions/setup-agent-sandbox-manifests + with: + save: "true" + # Restored by build-e2e-bundles in branch-e2e.yml. e2e-bundles: name: E2E suite bundles cache (x86_64-unknown-linux-musl) diff --git a/CI.md b/CI.md index e5bf40de38..ad56b1494a 100644 --- a/CI.md +++ b/CI.md @@ -756,7 +756,7 @@ Maintainers should add ready PRs to the queue rather than pressing a direct merg | `.github/workflows/helm-lint.yml` | Helm chart validation. PRs skip lint jobs unless Helm inputs changed; merge groups always validate Helm because they represent the final integration state. | | `.github/actions/setup-nix/action.yml` | Installs Nix and configures the OpenShell Cachix cache, using read-only cache access when no authentication token is available. | | `.github/actions/setup-rust/action.yml` | Restores the Rust target and registry cache. Other branches can restore only their own caches and `main`'s, so per-binary release build caches are saved only on `main`. | -| `.github/workflows/rust-cache.yml` | Builds the Branch Checks test targets on each push to `main` to save the `rust-checks` cache that PRs and merge groups restore. Skips the build when the cache already matches. | +| `.github/workflows/rust-cache.yml` | Builds the Branch Checks test targets on each push to `main` to save the `rust-checks` cache that PRs and merge groups restore. Skips the build when the cache already matches. Also saves the mise tools and pinned Agent Sandbox manifests that E2E jobs restore, so those jobs download them from GitHub only when a PR changes them. | | `.github/workflows/required-ci-gates.yml` | Posts required PR-head and merge-group statuses for gated CI workflows, including for fork PRs. This is what branch protection and merge queue should require. | | `.github/workflows/review-readiness.yml` | Labels newly opened accepted-work PRs using the shared read-only acceptance library, including drafts; routes matching reviewers when a PR is ready and classified. | | `.github/workflows/workflow-security.yml` | Runs informational Actionlint and High-severity Zizmor reports on GitHub-hosted runners. | diff --git a/e2e/support/install-agent-sandbox.sh b/e2e/support/install-agent-sandbox.sh index 2ff93c12af..4557a5fff1 100644 --- a/e2e/support/install-agent-sandbox.sh +++ b/e2e/support/install-agent-sandbox.sh @@ -4,16 +4,74 @@ # Install the upstream Agent Sandbox CRDs and controller. Pass any kubectl # context arguments (for example, --context kind-e2e) as script arguments. +# +# The release manifest is verified against the checksum pinned below and kept +# in AGENT_SANDBOX_MANIFEST_DIR. CI restores that directory from a cache saved +# on main (.github/workflows/rust-cache.yml), which runs this script with +# --download-only to fetch every pinned release. set -euo pipefail agent_sandbox_version="${AGENT_SANDBOX_VERSION:-v1.0.3}" +manifest_dir="${AGENT_SANDBOX_MANIFEST_DIR:-${XDG_CACHE_HOME:-${HOME}/.cache}/openshell/agent-sandbox}" -# Agent Sandbox renamed its core release manifest after v0.5.1. Keep the -# v1alpha1 compatibility lane on the asset published with that release. -case "${agent_sandbox_version}" in - v0.[0-4].*|v0.5.[01]) agent_sandbox_manifest="manifest.yaml" ;; - *) agent_sandbox_manifest="sandbox.yaml" ;; -esac +# Releases this repository tests, with the SHA-256 of their core manifest. +# Agent Sandbox renamed that manifest after v0.5.1. +pinned_versions=(v0.4.6 v0.5.0 v1.0.3) +release_manifest() { + case "$1" in + v0.4.6) echo "manifest.yaml db8424b2901cef57f71757b5ae5499eda0b6ef0dfd71a50dffeeb44326517967" ;; + v0.5.0) echo "manifest.yaml ccfe3649de8b33f0ee0ec635e2c7b40e1c468ad9fde6aac7c7379501327d9c4c" ;; + v1.0.3) echo "sandbox.yaml 725fafdabe6aac202a89dc57f1cfe0e2e92f3164c8c2bd343fffca52f7039d96" ;; + *) + echo "Agent Sandbox $1 has no pinned checksum; add it to $0" >&2 + return 1 + ;; + esac +} + +sha256_of() { + if command -v sha256sum >/dev/null 2>&1; then + sha256sum "$1" | cut -d' ' -f1 + else + shasum -a 256 "$1" | cut -d' ' -f1 + fi +} + +# Print the path of the verified manifest for a release, downloading it if the +# directory doesn't hold a copy with the pinned checksum. +fetch_manifest() { + local version="$1" entry name sha256 path tmp + entry="$(release_manifest "${version}")" || return 1 + read -r name sha256 <<< "${entry}" + path="${manifest_dir}/${version}/${name}" + if [ -f "${path}" ] && [ "$(sha256_of "${path}")" = "${sha256}" ]; then + echo "${path}" + return 0 + fi + + mkdir -p "${manifest_dir}/${version}" || return 1 + tmp="$(mktemp "${path}.XXXXXX")" || return 1 + echo "Downloading Agent Sandbox ${version} ${name}..." >&2 + if ! curl -fsSL --output "${tmp}" \ + "https://github.com/kubernetes-sigs/agent-sandbox/releases/download/${version}/${name}"; then + rm -f "${tmp}" + return 1 + fi + if [ "$(sha256_of "${tmp}")" != "${sha256}" ]; then + echo "Agent Sandbox ${version} ${name} does not match its pinned checksum ${sha256}" >&2 + rm -f "${tmp}" + return 1 + fi + mv "${tmp}" "${path}" || return 1 + echo "${path}" +} + +if [ "${1:-}" = "--download-only" ]; then + for version in "${pinned_versions[@]}"; do + fetch_manifest "${version}" >/dev/null || exit 1 + done + exit 0 +fi wait_for_agent_sandbox_crd() { local deadline @@ -37,9 +95,9 @@ wait_for_agent_sandbox_crd() { return 1 } +manifest="$(fetch_manifest "${agent_sandbox_version}")" || exit 1 echo "Installing agent-sandbox CRDs and controller (${agent_sandbox_version})..." -agent_sandbox_base="https://github.com/kubernetes-sigs/agent-sandbox/releases/download/${agent_sandbox_version}" -kubectl "$@" apply -f "${agent_sandbox_base}/${agent_sandbox_manifest}" +kubectl "$@" apply -f "${manifest}" wait_for_agent_sandbox_crd "$@" kubectl "$@" -n agent-sandbox-system rollout status \ deployment/agent-sandbox-controller --timeout=300s diff --git a/mise.lock b/mise.lock index ced14da38d..6398c235e8 100644 --- a/mise.lock +++ b/mise.lock @@ -380,6 +380,38 @@ checksum = "sha256:655d2aadcb1f0a0dd196c5cbc564687ba945a9547c8e82c9fc532051fb260 url = "https://github.com/k3d-io/k3d/releases/download/v5.8.3/k3d-windows-amd64.exe" url_api = "https://api.github.com/repos/k3d-io/k3d/releases/assets/229450011" +[[tools.kind]] +version = "0.31.0" +backend = "aqua:kubernetes-sigs/kind" + +[tools.kind.options] +"vars.version_prefix" = "v" + +[tools.kind."platforms.linux-arm64"] +checksum = "sha256:8e1014e87c34901cc422a1445866835d1e666f2a61301c27e722bdeab5a1f7e4" +url = "https://github.com/kubernetes-sigs/kind/releases/download/v0.31.0/kind-linux-arm64" +url_api = "https://api.github.com/repos/kubernetes-sigs/kind/releases/assets/330009872" + +[tools.kind."platforms.linux-x64"] +checksum = "sha256:eb244cbafcc157dff60cf68693c14c9a75c4e6e6fedaf9cd71c58117cb93e3fa" +url = "https://github.com/kubernetes-sigs/kind/releases/download/v0.31.0/kind-linux-amd64" +url_api = "https://api.github.com/repos/kubernetes-sigs/kind/releases/assets/330009836" + +[tools.kind."platforms.macos-arm64"] +checksum = "sha256:88bf554fe9da6311c9f8c2d082613c002911a476f6b5090e9420b35d84e70c5c" +url = "https://github.com/kubernetes-sigs/kind/releases/download/v0.31.0/kind-darwin-arm64" +url_api = "https://api.github.com/repos/kubernetes-sigs/kind/releases/assets/330009824" + +[tools.kind."platforms.windows-arm64"] +checksum = "sha256:2c3a9ff954de16244380778683cf99e271bfc2fac9c6c4e797e4623c45e59d9d" +url = "https://github.com/kubernetes-sigs/kind/releases/download/v0.31.0/kind-windows-amd64" +url_api = "https://api.github.com/repos/kubernetes-sigs/kind/releases/assets/330009913" + +[tools.kind."platforms.windows-x64"] +checksum = "sha256:2c3a9ff954de16244380778683cf99e271bfc2fac9c6c4e797e4623c45e59d9d" +url = "https://github.com/kubernetes-sigs/kind/releases/download/v0.31.0/kind-windows-amd64" +url_api = "https://api.github.com/repos/kubernetes-sigs/kind/releases/assets/330009913" + [[tools.kubectl]] version = "1.36.1" backend = "aqua:kubernetes/kubernetes/kubectl" diff --git a/mise.toml b/mise.toml index 42470bb824..7952f95571 100644 --- a/mise.toml +++ b/mise.toml @@ -30,6 +30,8 @@ helm = { version = "4.2.0", version_prefix = "v" } helm-docs = "1.14.2" yq = "4.53.6" skaffold = { version = "2.20.0", os = ["linux", "macos"], version_prefix = "v" } +# Creates the Kubernetes E2E cluster in CI (.github/actions/setup-e2e-kind). +kind = { version = "0.31.0", os = ["linux", "macos"], version_prefix = "v" } # Keep k3d out of Linux CI images until upstream ships a release rebuilt with # patched Go/container dependencies. Linux Kubernetes E2E uses kind or an # externally provided cluster context. diff --git a/tests/tmachine/ansible/playbooks/k3s.yaml b/tests/tmachine/ansible/playbooks/k3s.yaml index 07b0de85d8..50b7eb15f0 100644 --- a/tests/tmachine/ansible/playbooks/k3s.yaml +++ b/tests/tmachine/ansible/playbooks/k3s.yaml @@ -8,7 +8,6 @@ gather_facts: false vars: helm_version: 4.2.0 - k3s_version: 1.33.13+k3s2 tasks: - name: Wait for SSH ansible.builtin.wait_for_connection: @@ -21,12 +20,18 @@ state: present update_cache: true - # get.k3s.io serves the latest script, so pin the one from the k3s_version - # release tag. Update the checksum whenever k3s_version changes. - - name: Download K3s installer - ansible.builtin.get_url: - url: "https://raw.githubusercontent.com/k3s-io/k3s/v{{ k3s_version | urlencode }}/install.sh" - checksum: sha256:9ca7930c31179d83bc13de20078fd8ad3e1ee00875b31f39a7e524ca4ef7d9de + # The host provides the K3s binary and the install script from the same + # release (`k3s_binary` and `k3s_installer`, pinned and checksummed in + # tests/tmachine/config.nix), so the script doesn't download anything. + - name: Copy K3s binary + ansible.builtin.copy: + src: "{{ k3s_binary }}" + dest: /usr/local/bin/k3s + mode: "0755" + + - name: Copy K3s installer + ansible.builtin.copy: + src: "{{ k3s_installer }}" dest: /tmp/install-k3s.sh mode: "0755" @@ -37,9 +42,9 @@ - server - --disable=servicelb - --disable=traefik - creates: /usr/local/bin/k3s + creates: /etc/systemd/system/k3s.service environment: - INSTALL_K3S_VERSION: "v{{ k3s_version }}" + INSTALL_K3S_SKIP_DOWNLOAD: "true" - name: Wait for K3s ansible.builtin.command: diff --git a/tests/tmachine/ansible/playbooks/openshell-k3s.yaml b/tests/tmachine/ansible/playbooks/openshell-k3s.yaml index 7a1fab8ed1..a45d045ac6 100644 --- a/tests/tmachine/ansible/playbooks/openshell-k3s.yaml +++ b/tests/tmachine/ansible/playbooks/openshell-k3s.yaml @@ -137,6 +137,14 @@ mode: "0600" content: "{{ openshell_k3s_helm_values_overlay | default('{}') }}" + # The host provides the release manifest (`agent_sandbox_manifest`, pinned + # and checksummed in tests/tmachine/config.nix). + - name: Copy Agent Sandbox manifest + ansible.builtin.copy: + src: "{{ agent_sandbox_manifest }}" + dest: /var/lib/openshell/artifacts/agent-sandbox.yaml + mode: "0600" + - name: Install Agent Sandbox ansible.builtin.command: argv: @@ -144,7 +152,7 @@ - kubectl - apply - --filename - - "https://github.com/kubernetes-sigs/agent-sandbox/releases/download/v{{ agent_sandbox_version }}/manifest.yaml" + - /var/lib/openshell/artifacts/agent-sandbox.yaml - name: Wait for Agent Sandbox CRD ansible.builtin.command: diff --git a/tests/tmachine/config.nix b/tests/tmachine/config.nix index bf591ef161..9e1428bbd3 100644 --- a/tests/tmachine/config.nix +++ b/tests/tmachine/config.nix @@ -23,10 +23,37 @@ let OVMF = firmwarePkgs.OVMF; }; qemu = qemuPkgs.qemu.override { hostCpuOnly = true; }; + # Release files the K3s setup installs. The host fetches them (or substitutes + # them from the binary cache) and the setup copies them in, so guests don't + # download them from GitHub, whose release-asset redirects intermittently fail. + k3sVersion = "1.33.13+k3s2"; + k3sRelease = "https://github.com/k3s-io/k3s/releases/download/v${pkgs.lib.escapeURL k3sVersion}"; + k3sSetupInputs = { + k3s_binary = "${pkgs.fetchurl ( + if isAarch64 then + { + url = "${k3sRelease}/k3s-arm64"; + sha256 = "cf6afb3944f9ecf120fa2837b542479018c08f9ea1d1d181d4a68445e7717a8d"; + } + else + { + url = "${k3sRelease}/k3s"; + sha256 = "1572f0f23bd5a844bd405b71875877aacacc7ab79e279d3d73735654c37c7735"; + } + )}"; + # The install script from the same release tag (get.k3s.io serves the latest). + k3s_installer = "${pkgs.fetchurl { + url = "https://raw.githubusercontent.com/k3s-io/k3s/v${pkgs.lib.escapeURL k3sVersion}/install.sh"; + sha256 = "9ca7930c31179d83bc13de20078fd8ad3e1ee00875b31f39a7e524ca4ef7d9de"; + }}"; + }; # Every installer loads the sandbox workload image tests run python3 in. e2ePythonImage = "../../artifacts/images/openshell-e2e-python-dev.tar"; k3sInputs = { - agent_sandbox_version = "0.5.0"; + agent_sandbox_manifest = "${pkgs.fetchurl { + url = "https://github.com/kubernetes-sigs/agent-sandbox/releases/download/v0.5.0/manifest.yaml"; + sha256 = "ccfe3649de8b33f0ee0ec635e2c7b40e1c468ad9fde6aac7c7379501327d9c4c"; + }}"; openshell_cli_binary = "../../artifacts/binaries/${muslTarget}/openshell"; openshell_e2e_python_image = e2ePythonImage; openshell_gateway_image = "../../artifacts/images/openshell-gateway-tmachine.tar"; @@ -46,7 +73,7 @@ let ]; }; # Base environments, keyed by name: a machine and the playbooks that set up - # its container engine (or k3s). + # its container engine (or k3s), with the inputs they read. bases = { ubuntu-docker-rootful = { machine = "ubuntu"; @@ -68,6 +95,7 @@ let "ansible/playbooks/test-tools.yaml" "ansible/playbooks/k3s.yaml" ]; + inputs = k3sSetupInputs; }; fedora-podman-rootful = fedoraPodman "rootful"; fedora-podman-rootless = fedoraPodman "rootless"; @@ -93,7 +121,8 @@ let inherit (parent) use_galaxy; playbooks = parent.playbooks ++ setup.playbooks; inputs = - (if parent ? driver then { environment_driver = parent.driver; } else { }) + (parent.inputs or { }) + // (if parent ? driver then { environment_driver = parent.driver; } else { }) // (setup.inputs or { }); }; }; @@ -159,6 +188,7 @@ let inherit (base) machine; setup = { inherit (base) use_galaxy playbooks; + inputs = base.inputs or { }; }; }) bases ++ featureEnvironments