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
13 changes: 10 additions & 3 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ ARG JUST_VERSION=1.58.0
ARG KUBECONFORM_VERSION=0.8.0
ARG NODE_VERSION=24.21.0
ARG OPENSPEC_VERSION=1.14.1
ARG COSIGN_VERSION=3.1.3
ARG CRANE_VERSION=0.20.6

# OpenSpec (spec-driven changes, see openspec/) collects usage data unless told not to.
ENV OPENSPEC_TELEMETRY=0 DO_NOT_TRACK=1 NPM_CONFIG_UPDATE_NOTIFIER=false
Expand All @@ -21,8 +23,8 @@ ENV SHELF_K3S_IMAGE=rancher/k3s:v1.36.4-k3s1
RUN set -eux; \
arch="$(dpkg --print-architecture)"; \
case "$arch" in \
arm64) just_arch=aarch64; node_arch=arm64 ;; \
amd64) just_arch=x86_64; node_arch=x64 ;; \
arm64) just_arch=aarch64; node_arch=arm64; crane_arch=arm64 ;; \
amd64) just_arch=x86_64; node_arch=x64; crane_arch=x86_64 ;; \
*) echo "unsupported architecture: $arch" >&2; exit 1 ;; \
esac; \
tmp="$(mktemp -d)"; \
Expand All @@ -41,10 +43,15 @@ RUN set -eux; \
| tar -xz -C /usr/local/bin kubeconform; \
curl -fsSL "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${node_arch}.tar.xz" \
| tar -xJ -C /usr/local --strip-components=1 --exclude='*.md' --exclude=LICENSE; \
curl -fsSL -o /usr/local/bin/cosign \
"https://github.com/sigstore/cosign/releases/download/v${COSIGN_VERSION}/cosign-linux-${arch}"; \
curl -fsSL "https://github.com/google/go-containerregistry/releases/download/v${CRANE_VERSION}/go-containerregistry_Linux_${crane_arch}.tar.gz" \
| tar -xz -C /usr/local/bin crane; \
npm install -g "@fission-ai/openspec@${OPENSPEC_VERSION}"; \
npm cache clean --force; \
chmod 0755 /usr/local/bin/k3d /usr/local/bin/kubectl /usr/local/bin/helm \
/usr/local/bin/flux /usr/local/bin/just /usr/local/bin/kubeconform; \
/usr/local/bin/flux /usr/local/bin/just /usr/local/bin/kubeconform \
/usr/local/bin/cosign /usr/local/bin/crane; \
rm -rf "$tmp"

# A named volume copies ownership and mode from the image directory it is mounted over, but only
Expand Down
5 changes: 3 additions & 2 deletions .github/scripts/select-smokes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# reason to skip.
set -euo pipefail

all=(smoke-secrets smoke-chart smoke-init smoke-apps smoke-agent smoke-previews)
all=(smoke-secrets smoke-chart smoke-init smoke-apps smoke-agent smoke-previews smoke-verify)
declare -A need=()

for_path() {
Expand All @@ -26,8 +26,9 @@ for_path() {
hack/smoke/agent.* | internal/cli/json* | internal/cli/open* | internal/cli/wait* | internal/cli/tenant_test.go)
echo smoke-agent ;;
hack/smoke/previews.sh | internal/cli/previews* | internal/ops/previews*) echo smoke-previews ;;
hack/smoke/verify.sh | internal/cli/verification*) echo smoke-verify ;;
internal/cli/* | internal/ops/* | internal/progress/* | internal/secrets/* | internal/hostcfg/*)
echo smoke-apps smoke-agent smoke-previews ;;
echo smoke-apps smoke-agent smoke-previews smoke-verify ;;
*) echo "${all[@]}" ;;
esac
}
Expand Down
86 changes: 84 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# permissions:
# contents: read
# packages: write
# id-token: write
# jobs:
# shelf:
# uses: tweinmann/shelf/.github/workflows/build.yml@v0
Expand All @@ -28,6 +29,15 @@
# Image layers are cached in the registry as <image>:buildcache: every run reads the cache, and
# every run that publishes writes it back.
#
# A run that publishes signs every built image and the deploy artifact with keyless cosign (the
# job's GitHub OIDC token, hence `id-token: write`; the identity is this workflow, and the
# signature is recorded in the public Rekor log, repository name and commit included). It scans
# every image the rendered app.yaml names with Trivy, attaches the report to each built image as
# a `vuln` attestation, and writes the counts of CRITICAL and HIGH findings per image digest into
# the deploy artifact as the annotation dev.shelf.scan, which the artifact's signature covers.
# Findings never fail the build. The channel tag (main or branch-<slug>) moves only to a signed
# artifact. Signatures use cosign's classic format, which the Sigstore policy-controller reads.
#
# A caller that keeps `branches: [main]` and no `delete` keeps working; it gets no previews.
#
# The package is not the app: shelf names an app when it is added (shelf app add <app> <artifact>),
Expand All @@ -47,6 +57,13 @@ on:
needs a release with `shelf build-plan --branch`.
type: string
default: latest
platforms:
description: >-
Platforms to build the images for, comma-separated. linux/arm64 matches the hosts shelf
runs on; add linux/amd64 for a cloud target. Platforms other than the runner's are
built through QEMU, which is several times slower.
type: string
default: linux/arm64
outputs:
artifact:
description: The deploy artifact, oci://ghcr.io/<owner>/<package>:<main or branch-slug>; empty unless published.
Expand All @@ -61,10 +78,14 @@ jobs:
permissions:
contents: read
packages: write
id-token: write
outputs:
artifact: ${{ steps.publish.outputs.artifact }}
env:
APP_FILE: ${{ inputs.app-file }}
PLATFORMS: ${{ inputs.platforms }}
COSIGN_VERSION: v3.1.3
TRIVY_VERSION: 0.75.0
PUBLISH: ${{ github.event_name == 'push' }}
DEFAULT_BRANCH: ${{ github.ref_name == github.event.repository.default_branch }}
steps:
Expand Down Expand Up @@ -92,12 +113,42 @@ jobs:
- name: Validate app.yaml
run: shelf validate "$APP_FILE"

- name: Install cosign and Trivy
if: env.PUBLISH == 'true'
run: |
tmp="$(mktemp -d)"
cosign=https://github.com/sigstore/cosign/releases/download/$COSIGN_VERSION
curl -fsSL -o "$tmp/cosign-linux-arm64" "$cosign/cosign-linux-arm64"
curl -fsSL -o "$tmp/cosign_checksums.txt" "$cosign/cosign_checksums.txt"
(cd "$tmp" && grep ' cosign-linux-arm64$' cosign_checksums.txt | sha256sum -c -)
sudo install "$tmp/cosign-linux-arm64" /usr/local/bin/cosign
trivy=https://github.com/aquasecurity/trivy/releases/download/v$TRIVY_VERSION
curl -fsSL -o "$tmp/trivy_${TRIVY_VERSION}_Linux-ARM64.tar.gz" "$trivy/trivy_${TRIVY_VERSION}_Linux-ARM64.tar.gz"
curl -fsSL -o "$tmp/trivy_checksums.txt" "$trivy/trivy_${TRIVY_VERSION}_checksums.txt"
(cd "$tmp" && grep " trivy_${TRIVY_VERSION}_Linux-ARM64.tar.gz\$" trivy_checksums.txt | sha256sum -c -)
tar -xzf "$tmp/trivy_${TRIVY_VERSION}_Linux-ARM64.tar.gz" -C "$tmp" trivy
sudo install "$tmp/trivy" /usr/local/bin/trivy
cosign version
trivy --version
echo "TRIVY_DAY=$(date -u +%Y-%m-%d)" >>"$GITHUB_ENV"

# Trivy's vulnerability database is downloaded once a day and shared between runs.
- uses: actions/cache@v4
if: env.PUBLISH == 'true'
with:
path: ~/.cache/trivy
key: trivy-db-${{ env.TRIVY_DAY }}
restore-keys: trivy-db-

- uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- uses: docker/setup-qemu-action@v4
if: inputs.platforms != 'linux/arm64'

- uses: docker/setup-buildx-action@v4

- name: Build the images of this repository
Expand All @@ -116,7 +167,7 @@ jobs:
images=()
while read -r component context; do
image="ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/$package/$component"
args=(--platform linux/arm64
args=(--platform "$PLATFORMS"
--tag "$image:sha-${GITHUB_SHA::7}" --tag "$image:$channel"
--cache-from "type=registry,ref=$image:buildcache"
--label "org.opencontainers.image.source=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY"
Expand All @@ -134,9 +185,12 @@ jobs:
# With the commit tag in front of the digest, the rendered app.yaml shows which
# commit built the image; shelf pins it to the digest either way.
images+=("--image" "$component=$image:sha-${GITHUB_SHA::7}@$digest")
echo "$digest" >>"$RUNNER_TEMP/built"
cosign sign --yes --use-signing-config=false --new-bundle-format=false "$image@$digest"
fi
done < <(jq -r '.builds[] | "\(.component) \(.context)"' <<<"$plan")
: >"$RUNNER_TEMP/image-args"
touch "$RUNNER_TEMP/built"
if (( ${#images[@]} )); then
printf '%s\n' "${images[@]}" >"$RUNNER_TEMP/image-args"
fi
Expand All @@ -153,12 +207,40 @@ jobs:
mapfile -t image_args <"$RUNNER_TEMP/image-args"
mkdir -p "$RUNNER_TEMP/deploy"
shelf render "$APP_FILE" "${image_args[@]}" >"$RUNNER_TEMP/deploy/configmap.yaml"

# Scan every image the rendered app.yaml pins, built and third-party. shelf renders
# each one as <reference>@sha256:<digest>.
scanned_at="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
scan='{}'
while read -r ref; do
echo "::group::scan $ref"
trivy image --quiet --scanners vuln --platform "${PLATFORMS%%,*}" --format json \
--output "$RUNNER_TEMP/report.json" "$ref"
echo "::endgroup::"
counts="$(jq -c '[.Results[]?.Vulnerabilities[]?.Severity]
| {critical: map(select(. == "CRITICAL")) | length, high: map(select(. == "HIGH")) | length}' \
"$RUNNER_TEMP/report.json")"
scan="$(jq -c --arg d "${ref##*@}" --argjson c "$counts" '. + {($d): $c}' <<<"$scan")"
if grep -qxF "${ref##*@}" "$RUNNER_TEMP/built"; then
trivy convert --quiet --format cosign-vuln --output "$RUNNER_TEMP/vuln.json" "$RUNNER_TEMP/report.json"
cosign attest --yes --use-signing-config=false --new-bundle-format=false \
--type vuln --predicate "$RUNNER_TEMP/vuln.json" "$ref"
fi
done < <(grep -oE '[^[:space:]]+@sha256:[0-9a-f]{64}' "$RUNNER_TEMP/deploy/configmap.yaml" | sort -u)
summary="$(jq -c --arg s "trivy $TRIVY_VERSION" --arg t "$scanned_at" \
'{scanner: $s, scannedAt: $t, images: .}' <<<"$scan")"

repo="ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/$package"
flux push artifact "oci://$repo:sha-${GITHUB_SHA::7}" \
--path "$RUNNER_TEMP/deploy" \
--source "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \
--revision "$GITHUB_REF_NAME@sha1:$GITHUB_SHA" \
--annotations "dev.shelf.package=$package"
--annotations "dev.shelf.package=$package" \
--annotations "dev.shelf.scan=$summary" \
--output json >"$RUNNER_TEMP/pushed.json"
# The channel tag moves only to a signed artifact.
cosign sign --yes --use-signing-config=false --new-bundle-format=false \
"$repo@$(jq -r .digest "$RUNNER_TEMP/pushed.json")"
flux tag artifact "oci://$repo:sha-${GITHUB_SHA::7}" --tag "$channel"
echo "artifact=oci://$repo:$channel" >>"$GITHUB_OUTPUT"
{
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }}
BASE: ${{ github.event.pull_request.base.sha }}
run: |
all='["smoke-secrets","smoke-chart","smoke-init","smoke-apps","smoke-agent","smoke-previews"]'
all='["smoke-secrets","smoke-chart","smoke-init","smoke-apps","smoke-agent","smoke-previews","smoke-verify"]'
has() { jq -e --arg l "$1" 'index($l) != null' <<<"$LABELS" >/dev/null; }
smokes='[]' full=0
if [[ "$EVENT" == push ]]; then
Expand Down
36 changes: 31 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,15 @@ jobs:
needs: gate
runs-on: ubuntu-24.04-arm
timeout-minutes: 30
# id-token: keyless cosign signs the chart and the platform artifact with this workflow's
# identity, which clusters verify before they install either.
permissions:
contents: write
packages: write
id-token: write
env:
VERSION: ${{ github.ref_name }}
COSIGN_VERSION: v3.1.3
steps:
- uses: actions/checkout@v7

Expand Down Expand Up @@ -77,22 +84,41 @@ jobs:
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Push the chart
- name: Install cosign
run: |
tmp="$(mktemp -d)"
cosign=https://github.com/sigstore/cosign/releases/download/$COSIGN_VERSION
curl -fsSL -o "$tmp/cosign-linux-arm64" "$cosign/cosign-linux-arm64"
curl -fsSL -o "$tmp/cosign_checksums.txt" "$cosign/cosign_checksums.txt"
(cd "$tmp" && grep ' cosign-linux-arm64$' cosign_checksums.txt | sha256sum -c -)
sudo install "$tmp/cosign-linux-arm64" /usr/local/bin/cosign
cosign version

# Signatures use cosign's classic format, which both Flux and the Sigstore policy-controller
# read.
- name: Push and sign the chart
run: |
# Helm versions are semver without a leading v; shelf init cluster expects that.
helm package charts/shelf-app --version "${VERSION#v}" --destination dist
helm push "dist/shelf-app-${VERSION#v}.tgz" "oci://ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/shelf/charts"
charts="ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/shelf/charts"
helm push "dist/shelf-app-${VERSION#v}.tgz" "oci://$charts" 2>&1 | tee "$RUNNER_TEMP/helm-push.txt"
digest="$(awk '/^Digest:/ {print $2}' "$RUNNER_TEMP/helm-push.txt")"
cosign sign --yes --use-signing-config=false --new-bundle-format=false "$charts/shelf-app@$digest"

- uses: fluxcd/flux2/action@v2.9.5
with:
version: 2.9.5

- name: Push the platform artifact
- name: Push and sign the platform artifact
run: |
flux push artifact "oci://ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/shelf/platform:$VERSION" \
platform="ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/shelf/platform"
flux push artifact "oci://$platform:$VERSION" \
--path platform \
--source "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \
--revision "$VERSION@sha1:$GITHUB_SHA"
--revision "$VERSION@sha1:$GITHUB_SHA" \
--output json >"$RUNNER_TEMP/platform.json"
cosign sign --yes --use-signing-config=false --new-bundle-format=false \
"$platform@$(jq -r .digest "$RUNNER_TEMP/platform.json")"

# Workflow and binary switch together: the major tag first, then the release becomes latest.
# A tenant build that starts in the seconds between the two still gets matching versions
Expand Down
Loading
Loading