From 0fa841dc5ca08285b2a9b863e16736273ab6f14b Mon Sep 17 00:00:00 2001 From: Mohit Nagaraj Date: Tue, 1 Sep 2026 13:45:38 +0530 Subject: [PATCH 1/2] feat(release): publish attested multi-architecture UI image Signed-off-by: Mohit Nagaraj --- .github/scripts/mock-core.mjs | 50 +++++++ .github/scripts/smoke-browser.mjs | 46 +++++++ .github/scripts/smoke-container.sh | 135 +++++++++++++++++++ .github/workflows/docker-publish.yml | 192 +++++++++++++++++++++++++-- .github/workflows/frontend.yml | 54 +++++++- Dockerfile | 3 +- README.md | 4 + app/layout.tsx | 4 + app/runtime-config.js/route.ts | 27 ++++ components/auth/LoginForm.tsx | 3 +- components/auth/RegisterForm.tsx | 3 +- docs/DEVELOPMENT.md | 12 +- docs/RELEASE.md | 82 ++++++++++++ hooks/useNotificationSSE.ts | 4 +- lib/__tests__/runtime-config.test.ts | 97 ++++++++++++++ lib/api.ts | 6 +- lib/hooks/useBuildStream.ts | 4 +- lib/hooks/useImportStream.ts | 4 +- lib/hooks/useLogStream.ts | 4 +- lib/hooks/useResourceStatusStream.ts | 4 +- lib/hooks/useTerminal.ts | 4 +- lib/hooks/useWorkflowStatusStream.ts | 4 +- lib/runtime-config.server.ts | 29 ++++ lib/runtime-config.ts | 69 ++++++++++ package-lock.json | 142 +++++++++++++++----- package.json | 1 + 26 files changed, 915 insertions(+), 72 deletions(-) create mode 100644 .github/scripts/mock-core.mjs create mode 100644 .github/scripts/smoke-browser.mjs create mode 100755 .github/scripts/smoke-container.sh create mode 100644 app/runtime-config.js/route.ts create mode 100644 docs/RELEASE.md create mode 100644 lib/__tests__/runtime-config.test.ts create mode 100644 lib/runtime-config.server.ts create mode 100644 lib/runtime-config.ts diff --git a/.github/scripts/mock-core.mjs b/.github/scripts/mock-core.mjs new file mode 100644 index 0000000..1c31dd3 --- /dev/null +++ b/.github/scripts/mock-core.mjs @@ -0,0 +1,50 @@ +import { createServer } from "node:http"; + +const port = Number.parseInt(process.argv[2] ?? "", 10); +const allowedOrigin = process.argv[3]; + +if (!Number.isInteger(port) || port < 1 || !allowedOrigin) { + throw new Error("usage: node mock-core.mjs "); +} + +const server = createServer((request, response) => { + const requestUrl = new URL( + request.url ?? "/", + `http://${request.headers.host}` + ); + + response.setHeader("Access-Control-Allow-Origin", allowedOrigin); + response.setHeader("Access-Control-Allow-Headers", "content-type"); + response.setHeader("Access-Control-Allow-Methods", "GET, OPTIONS"); + response.setHeader("Vary", "Origin"); + + if (request.method === "OPTIONS") { + response.writeHead(204).end(); + return; + } + + if ( + request.method === "GET" && + requestUrl.pathname === "/v1/api/auth/methods" + ) { + console.log(`${request.method} ${requestUrl.pathname}`); + response.writeHead(200, { "Content-Type": "application/json" }).end( + JSON.stringify({ + builtin: { enabled: true, signupEnabled: true }, + providers: [], + }) + ); + return; + } + + console.error(`Unexpected request: ${request.method} ${requestUrl.pathname}`); + response.writeHead(404).end(); +}); + +server.listen(port, "127.0.0.1", () => { + console.log(`Mock Core listening on http://127.0.0.1:${port}`); +}); + +for (const signal of ["SIGINT", "SIGTERM"]) { + process.on(signal, () => server.close(() => process.exit(0))); +} diff --git a/.github/scripts/smoke-browser.mjs b/.github/scripts/smoke-browser.mjs new file mode 100644 index 0000000..2cb971b --- /dev/null +++ b/.github/scripts/smoke-browser.mjs @@ -0,0 +1,46 @@ +import { chromium } from "playwright"; + +const [uiUrl, apiUrl] = process.argv.slice(2); + +if (!uiUrl || !apiUrl) { + throw new Error("usage: node smoke-browser.mjs "); +} + +const expectedRequestUrl = `${apiUrl}/auth/methods`; +const browser = await chromium.launch({ headless: true }); +const page = await browser.newPage(); + +try { + const apiResponsePromise = page.waitForResponse( + response => + response.url() === expectedRequestUrl && + response.request().method() === "GET", + { timeout: 30_000 } + ); + + await page.goto(`${uiUrl}/login`, { + waitUntil: "domcontentloaded", + timeout: 30_000, + }); + + const apiResponse = await apiResponsePromise; + if (!apiResponse.ok()) { + throw new Error( + `Configured Core request returned HTTP ${apiResponse.status()}` + ); + } + + const runtimeApiUrl = await page.evaluate( + () => window.__KUBEORCH_RUNTIME_CONFIG__?.apiUrl + ); + if (runtimeApiUrl !== apiUrl) { + throw new Error( + `Browser received API URL ${runtimeApiUrl ?? ""}; expected ${apiUrl}` + ); + } + + await page.getByText("Welcome back", { exact: true }).waitFor(); + console.log(`Browser requested ${expectedRequestUrl}`); +} finally { + await browser.close(); +} diff --git a/.github/scripts/smoke-container.sh b/.github/scripts/smoke-container.sh new file mode 100755 index 0000000..dda6dc8 --- /dev/null +++ b/.github/scripts/smoke-container.sh @@ -0,0 +1,135 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +image="${1:?usage: smoke-container.sh }" +expected_arch="${2:?usage: smoke-container.sh }" + +case "$expected_arch" in + amd64) + expected_node_arch="x64" + ;; + arm64) + expected_node_arch="arm64" + ;; + *) + echo "Unsupported architecture: $expected_arch" >&2 + exit 2 + ;; +esac + +ui_port="${UI_SMOKE_PORT:-31081}" +core_port="${CORE_SMOKE_PORT:-31080}" +ui_origin="http://127.0.0.1:${ui_port}" +api_url="http://127.0.0.1:${core_port}/v1/api" +container="kubeorch-ui-smoke-${expected_arch}-${RANDOM}" +log_dir="${RUNNER_TEMP:-${TMPDIR:-/tmp}}/kubeorch-ui-smoke-${expected_arch}" +mock_pid="" + +mkdir -p "$log_dir" + +cleanup() { + docker rm --force "$container" >/dev/null 2>&1 || true + if [[ -n "$mock_pid" ]]; then + kill "$mock_pid" >/dev/null 2>&1 || true + wait "$mock_pid" >/dev/null 2>&1 || true + fi +} +trap cleanup EXIT + +report_failure() { + exit_code="$?" + set +e + echo "UI smoke test failed for linux/$expected_arch" >&2 + if docker inspect "$container" >/dev/null 2>&1; then + docker logs "$container" >&2 + fi + if [[ -f "$log_dir/mock-core.log" ]]; then + cat "$log_dir/mock-core.log" >&2 + fi + exit "$exit_code" +} +trap report_failure ERR + +actual_arch="$(docker image inspect "$image" --format '{{.Architecture}}')" +if [[ "$actual_arch" != "$expected_arch" ]]; then + echo "Image architecture is $actual_arch, expected $expected_arch" >&2 + exit 1 +fi + +runtime_uid="$( + docker run --rm --platform "linux/$expected_arch" --entrypoint id "$image" -u +)" +if [[ "$runtime_uid" != "1001" ]]; then + echo "UI image runs as uid $runtime_uid, expected 1001" >&2 + exit 1 +fi + +node_arch="$( + docker run --rm --platform "linux/$expected_arch" \ + --entrypoint node "$image" -p 'process.arch' +)" +if [[ "$node_arch" != "$expected_node_arch" ]]; then + echo "Node architecture is $node_arch, expected $expected_node_arch" >&2 + exit 1 +fi + +node .github/scripts/mock-core.mjs "$core_port" "$ui_origin" \ + >"$log_dir/mock-core.log" 2>&1 & +mock_pid="$!" + +mock_ready=false +for _ in $(seq 1 15); do + if curl --fail --silent --output /dev/null \ + -X OPTIONS "$api_url/auth/methods"; then + mock_ready=true + break + fi + sleep 1 +done +if [[ "$mock_ready" != true ]]; then + echo "Mock Core did not start" >&2 + cat "$log_dir/mock-core.log" >&2 + exit 1 +fi + +docker run --detach \ + --name "$container" \ + --platform "linux/$expected_arch" \ + --publish "127.0.0.1:${ui_port}:3000" \ + --env "NEXT_PUBLIC_API_URL=$api_url" \ + --health-interval 2s \ + --health-timeout 5s \ + --health-start-period 1s \ + --health-retries 15 \ + "$image" >/dev/null + +ui_ready=false +for _ in $(seq 1 45); do + health_status="$( + docker inspect "$container" --format '{{if .State.Health}}{{.State.Health.Status}}{{end}}' + )" + if [[ "$health_status" == "healthy" ]]; then + ui_ready=true + break + fi + if [[ "$(docker inspect "$container" --format '{{.State.Running}}')" != "true" ]]; then + break + fi + sleep 2 +done +if [[ "$ui_ready" != true ]]; then + echo "UI did not become healthy" >&2 + docker inspect "$container" >&2 + docker logs "$container" >&2 + exit 1 +fi + +node .github/scripts/smoke-browser.mjs "$ui_origin" "$api_url" + +if ! grep -F 'GET /v1/api/auth/methods' "$log_dir/mock-core.log" >/dev/null; then + echo "Mock Core did not observe the configured browser request" >&2 + cat "$log_dir/mock-core.log" >&2 + exit 1 +fi + +echo "Smoke test passed for linux/$expected_arch as uid $runtime_uid" diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index d315aef..f9dc2f3 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -3,24 +3,111 @@ name: Release on: push: tags: - - 'v*' + - "v*" + +concurrency: + group: ui-release + cancel-in-progress: false + queue: max permissions: contents: write packages: write + id-token: write + attestations: write + artifact-metadata: write + +env: + IMAGE_NAME: ghcr.io/kubeorch/ui jobs: + validate: + name: Validate release ref + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - name: Checkout code + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + with: + fetch-depth: 0 + + - name: Require a commit from main + run: | + git fetch origin main + git merge-base --is-ancestor "$GITHUB_SHA" origin/main + + smoke: + name: Smoke (${{ matrix.platform }}) + needs: validate + runs-on: ubuntu-latest + timeout-minutes: 45 + permissions: + contents: read + strategy: + fail-fast: false + matrix: + include: + - platform: linux/amd64 + arch: amd64 + - platform: linux/arm64 + arch: arm64 + steps: + - name: Checkout code + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + + - name: Set up Node.js + uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0 + with: + node-version: "20" + cache: "npm" + + - name: Install smoke dependencies + run: | + npm ci + npx playwright install --with-deps chromium + + - name: Set up QEMU + uses: docker/setup-qemu-action@96fe6ef7f33517b61c61be40b68a1882f3264fb8 # v4.2.0 + with: + platforms: arm64 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4.3.0 + + - name: Build platform image + uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0 + with: + context: . + load: true + platforms: ${{ matrix.platform }} + tags: kubeorch/ui:release-smoke-${{ matrix.arch }} + cache-from: type=gha,scope=ui-container-${{ matrix.arch }} + cache-to: type=gha,mode=max,scope=ui-container-${{ matrix.arch }} + provenance: false + sbom: false + + - name: Smoke-test platform image + run: .github/scripts/smoke-container.sh "kubeorch/ui:release-smoke-${{ matrix.arch }}" "${{ matrix.arch }}" + release: + name: Publish attested image + needs: smoke runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v6 + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + + - name: Set up QEMU + uses: docker/setup-qemu-action@96fe6ef7f33517b61c61be40b68a1882f3264fb8 # v4.2.0 + with: + platforms: arm64 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v4 + uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4.3.0 - name: Log in to GitHub Container Registry - uses: docker/login-action@v4 + uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0 with: registry: ghcr.io username: ${{ github.actor }} @@ -28,16 +115,15 @@ jobs: - name: Extract version from tag id: version - run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT + run: echo "VERSION=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT" - name: Build and push Docker image - uses: docker/build-push-action@v7 + id: push + uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0 with: context: . push: true - tags: | - ghcr.io/kubeorch/ui:latest - ghcr.io/kubeorch/ui:${{ steps.version.outputs.VERSION }} + tags: ${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }} labels: | org.opencontainers.image.title=KubeOrch UI org.opencontainers.image.version=${{ steps.version.outputs.VERSION }} @@ -45,23 +131,101 @@ jobs: org.opencontainers.image.revision=${{ github.sha }} cache-from: type=gha cache-to: type=gha,mode=max - platforms: linux/amd64 - provenance: false + platforms: linux/amd64,linux/arm64 + provenance: mode=max + sbom: true + + - name: Attest the release index + uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2 + with: + subject-name: ${{ env.IMAGE_NAME }} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true + + - name: Verify platforms and attestations + env: + GH_TOKEN: ${{ github.token }} + IMAGE_REF: ${{ env.IMAGE_NAME }}@${{ steps.push.outputs.digest }} + run: | + docker buildx imagetools inspect "$IMAGE_REF" --raw > image-index.json + actual_platforms="$( + jq -r '[ + .manifests[] + | .platform + | select(.os != "unknown") + | "\(.os)/\(.architecture)" + ] | unique | sort | join(",")' image-index.json + )" + if [ "$actual_platforms" != "linux/amd64,linux/arm64" ]; then + echo "Unexpected runnable platforms: $actual_platforms" >&2 + exit 1 + fi + + docker buildx imagetools inspect "$IMAGE_REF" \ + --format '{{ json .SBOM }}' > sbom.json + jq -e 'type == "object" and length > 0' sbom.json >/dev/null + + docker buildx imagetools inspect "$IMAGE_REF" \ + --format '{{ json .Provenance.SLSA }}' > provenance.json + jq -e 'type == "object" and length > 0' provenance.json >/dev/null + jq -e --arg sha "$GITHUB_SHA" \ + '[.. | strings | select(. == $sha)] | length > 0' \ + provenance.json >/dev/null + jq -e --arg repository "https://github.com/$GITHUB_REPOSITORY" \ + '[.. | strings | select(contains($repository))] | length > 0' \ + provenance.json >/dev/null + + gh attestation verify "oci://$IMAGE_REF" \ + --repo "$GITHUB_REPOSITORY" \ + --bundle-from-oci \ + --signer-workflow "$GITHUB_REPOSITORY/.github/workflows/docker-publish.yml" \ + --source-digest "$GITHUB_SHA" + + - name: Promote verified digest to latest + env: + IMAGE_REF: ${{ env.IMAGE_NAME }}@${{ steps.push.outputs.digest }} + EXPECTED_DIGEST: ${{ steps.push.outputs.digest }} + run: | + docker buildx imagetools create \ + --tag "${IMAGE_NAME}:latest" \ + "$IMAGE_REF" + promoted_digest="$( + docker buildx imagetools inspect "${IMAGE_NAME}:latest" \ + --format '{{.Manifest.Digest}}' + )" + if [ "$promoted_digest" != "$EXPECTED_DIGEST" ]; then + echo "latest points to $promoted_digest, expected $EXPECTED_DIGEST" >&2 + exit 1 + fi - name: Create GitHub Release - uses: softprops/action-gh-release@v3 + uses: softprops/action-gh-release@efb35369e0ad2afab669f228072c1b0d510eae64 # v3.0.3 with: tag_name: ${{ steps.version.outputs.VERSION }} name: ${{ steps.version.outputs.VERSION }} generate_release_notes: true body: | - ## Docker Image + ## Container Image + + `${{ env.IMAGE_NAME }}@${{ steps.push.outputs.digest }}` + + Supported platforms: `linux/amd64`, `linux/arm64` ```bash - docker pull ghcr.io/kubeorch/ui:${{ steps.version.outputs.VERSION }} + docker pull ${{ env.IMAGE_NAME }}@${{ steps.push.outputs.digest }} + ``` + + ## Verification + + ```bash + docker buildx imagetools inspect ${{ env.IMAGE_NAME }}@${{ steps.push.outputs.digest }} + docker buildx imagetools inspect ${{ env.IMAGE_NAME }}@${{ steps.push.outputs.digest }} --format '{{ json .SBOM }}' + docker buildx imagetools inspect ${{ env.IMAGE_NAME }}@${{ steps.push.outputs.digest }} --format '{{ json .Provenance.SLSA }}' + gh attestation verify oci://${{ env.IMAGE_NAME }}@${{ steps.push.outputs.digest }} --repo ${{ github.repository }} --bundle-from-oci --signer-workflow ${{ github.repository }}/.github/workflows/docker-publish.yml --source-digest ${{ github.sha }} ``` Run with `orchcli`: + ```bash orchcli init && orchcli start -d ``` diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index 4229112..e3bce1d 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -13,8 +13,8 @@ jobs: node: ["20"] steps: - - uses: actions/checkout@v6 - - uses: actions/setup-node@v6 + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + - uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0 with: node-version: ${{ matrix.node }} cache: "npm" @@ -33,3 +33,53 @@ jobs: - name: Run build run: npm run build + + container: + name: Container (${{ matrix.platform }}) + runs-on: ubuntu-latest + timeout-minutes: 45 + strategy: + fail-fast: false + matrix: + include: + - platform: linux/amd64 + arch: amd64 + - platform: linux/arm64 + arch: arm64 + steps: + - name: Checkout code + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + + - name: Set up Node.js + uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0 + with: + node-version: "20" + cache: "npm" + + - name: Install smoke dependencies + run: | + npm ci + npx playwright install --with-deps chromium + + - name: Set up QEMU + uses: docker/setup-qemu-action@96fe6ef7f33517b61c61be40b68a1882f3264fb8 # v4.2.0 + with: + platforms: arm64 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4.3.0 + + - name: Build platform image + uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0 + with: + context: . + load: true + platforms: ${{ matrix.platform }} + tags: kubeorch/ui:pr-smoke-${{ matrix.arch }} + cache-from: type=gha,scope=ui-container-${{ matrix.arch }} + cache-to: type=gha,mode=max,scope=ui-container-${{ matrix.arch }} + provenance: false + sbom: false + + - name: Smoke-test platform image + run: .github/scripts/smoke-container.sh "kubeorch/ui:pr-smoke-${{ matrix.arch }}" "${{ matrix.arch }}" diff --git a/Dockerfile b/Dockerfile index c94799b..b3962d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,6 +34,7 @@ USER nextjs EXPOSE 3000 HEALTHCHECK --interval=30s --timeout=5s --retries=3 \ - CMD wget --spider -q http://localhost:3000/ || exit 1 + CMD wget --spider -q http://127.0.0.1:3000/runtime-config.js && \ + wget --spider -q http://127.0.0.1:3000/ || exit 1 CMD ["node", "server.js"] diff --git a/README.md b/README.md index f4d7b2a..a0c8fb5 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,10 @@ npm run dev Open http://localhost:3001 +Production container platforms, runtime API configuration, immutable digest +verification, and attestations are documented in +[docs/RELEASE.md](docs/RELEASE.md). + ## 📁 Project Structure ``` diff --git a/app/layout.tsx b/app/layout.tsx index f35efb2..95d24e9 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,5 +1,6 @@ import type { Metadata } from "next"; import { Geist, Geist_Mono } from "next/font/google"; +import Script from "next/script"; import "./globals.css"; import { ThemeProvider } from "@/components/providers/ThemeProvider"; import { ErrorBoundary } from "@/components/providers/ErrorBoundary"; @@ -28,6 +29,9 @@ export default function RootLayout({ }>) { return ( + + ", + }); + + expect(script).not.toContain(""); + expect(script).toContain("\\u003c/script>"); + }); + + it("reads the injected browser configuration", () => { + window.__KUBEORCH_RUNTIME_CONFIG__ = { + apiUrl: "https://core.example/v1/api", + }; + + expect(getApiBaseUrl()).toBe("https://core.example/v1/api"); + }); + + it("fails clearly before browser configuration is initialized", () => { + expect(() => getApiBaseUrl()).toThrow( + "KubeOrch runtime configuration was not initialized" + ); + }); + + it("serves runtime configuration without cacheable headers", async () => { + process.env.NEXT_PUBLIC_API_URL = "https://runtime.example/v1/api/"; + + const response = getRuntimeConfigScript(); + + expect(response.status).toBe(200); + expect(response.headers.get("cache-control")).toBe("no-store, max-age=0"); + expect(await response.text()).toContain( + '"apiUrl":"https://runtime.example/v1/api"' + ); + }); + + it("returns a failed initialization script for invalid configuration", async () => { + vi.spyOn(console, "error").mockImplementation(() => undefined); + delete process.env.NEXT_PUBLIC_API_URL; + + const response = getRuntimeConfigScript(); + + expect(response.status).toBe(500); + expect(await response.text()).toContain("runtime configuration is invalid"); + }); +}); diff --git a/lib/api.ts b/lib/api.ts index 8bd410e..322da91 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -1,9 +1,9 @@ import axios from "axios"; import { toast } from "sonner"; import { useAuthStore } from "@/stores/AuthStore"; +import { getApiBaseUrl } from "@/lib/runtime-config"; const api = axios.create({ - baseURL: process.env.NEXT_PUBLIC_API_URL, headers: { "Content-Type": "application/json", }, @@ -13,10 +13,12 @@ const api = axios.create({ // Flag to prevent multiple redirects and refresh loops let isRedirecting = false; let isRefreshing = false; -let refreshPromise: Promise | null = null; +let refreshPromise: Promise | null = null; api.interceptors.request.use( async config => { + config.baseURL ??= getApiBaseUrl(); + // Skip token for auth endpoints if (config.url?.includes("/auth/")) { return config; diff --git a/lib/hooks/useBuildStream.ts b/lib/hooks/useBuildStream.ts index 804a3c4..591e173 100644 --- a/lib/hooks/useBuildStream.ts +++ b/lib/hooks/useBuildStream.ts @@ -1,6 +1,7 @@ import { useEffect, useState, useRef, useCallback } from "react"; import { useAuthStore } from "@/stores/AuthStore"; import { Build, BuildLog, BuildStatus } from "@/lib/services/build"; +import { getApiBaseUrl } from "@/lib/runtime-config"; export interface UseBuildStreamResult { build: Build | null; @@ -78,8 +79,7 @@ export function useBuildStream( activeConnections.add(connectionKey); connectionKeyRef.current = connectionKey; - const baseUrl = - process.env.NEXT_PUBLIC_API_URL || "http://localhost:3000/v1/api"; + const baseUrl = getApiBaseUrl(); const url = `${baseUrl}/builds/${buildId}/stream`; // Get token from Zustand store diff --git a/lib/hooks/useImportStream.ts b/lib/hooks/useImportStream.ts index 514184f..cba611d 100644 --- a/lib/hooks/useImportStream.ts +++ b/lib/hooks/useImportStream.ts @@ -1,5 +1,6 @@ import { useEffect, useState, useRef, useCallback } from "react"; import { useAuthStore } from "@/stores/AuthStore"; +import { getApiBaseUrl } from "@/lib/runtime-config"; export interface ImportLog { timestamp: string; @@ -125,8 +126,7 @@ export function useImportStream( activeConnections.add(connectionKey); connectionKeyRef.current = connectionKey; - const baseUrl = - process.env.NEXT_PUBLIC_API_URL || "http://localhost:3000/v1/api"; + const baseUrl = getApiBaseUrl(); const url = `${baseUrl}/import/${sessionId}/stream`; // Get token from Zustand store diff --git a/lib/hooks/useLogStream.ts b/lib/hooks/useLogStream.ts index 7e5322c..1176c99 100644 --- a/lib/hooks/useLogStream.ts +++ b/lib/hooks/useLogStream.ts @@ -1,5 +1,6 @@ import { useEffect, useState, useRef, useCallback } from "react"; import { useAuthStore } from "@/stores/AuthStore"; +import { getApiBaseUrl } from "@/lib/runtime-config"; export interface LogStreamMetadata { pod: string; @@ -55,8 +56,7 @@ export function useLogStream( const abortController = new AbortController(); - const baseUrl = - process.env.NEXT_PUBLIC_API_URL || "http://localhost:3000/v1/api"; + const baseUrl = getApiBaseUrl(); const url = `${baseUrl}/resources/${resourceId}/logs/stream?follow=${follow}&tail=${tailLines}`; const token = useAuthStore.getState().token; diff --git a/lib/hooks/useResourceStatusStream.ts b/lib/hooks/useResourceStatusStream.ts index 3c2d968..2188ead 100644 --- a/lib/hooks/useResourceStatusStream.ts +++ b/lib/hooks/useResourceStatusStream.ts @@ -1,5 +1,6 @@ import { useEffect, useState, useRef, useCallback } from "react"; import { useAuthStore } from "@/stores/AuthStore"; +import { getApiBaseUrl } from "@/lib/runtime-config"; export interface ResourceStatus { state: string; @@ -102,8 +103,7 @@ export function useResourceStatusStream( activeConnections.add(connectionKey); connectionKeyRef.current = connectionKey; - const baseUrl = - process.env.NEXT_PUBLIC_API_URL || "http://localhost:3000/v1/api"; + const baseUrl = getApiBaseUrl(); const url = `${baseUrl}/resources/${resourceId}/stream`; // Get token from Zustand store diff --git a/lib/hooks/useTerminal.ts b/lib/hooks/useTerminal.ts index c8c9f4d..b28ba44 100644 --- a/lib/hooks/useTerminal.ts +++ b/lib/hooks/useTerminal.ts @@ -1,5 +1,6 @@ import { useEffect, useState, useRef, useCallback } from "react"; import { useAuthStore } from "@/stores/AuthStore"; +import { getApiBaseUrl } from "@/lib/runtime-config"; export interface TerminalMessage { type: "input" | "output" | "resize" | "error" | "close" | "metadata"; @@ -133,8 +134,7 @@ export function useTerminal( connectionKeyRef.current = connectionKey; // Build WebSocket URL - const baseUrl = - process.env.NEXT_PUBLIC_API_URL || "http://localhost:3000/v1/api"; + const baseUrl = getApiBaseUrl(); // Convert http(s) to ws(s) const wsBaseUrl = baseUrl.replace(/^http/, "ws"); diff --git a/lib/hooks/useWorkflowStatusStream.ts b/lib/hooks/useWorkflowStatusStream.ts index 1ca4914..b8d7a57 100644 --- a/lib/hooks/useWorkflowStatusStream.ts +++ b/lib/hooks/useWorkflowStatusStream.ts @@ -1,5 +1,6 @@ import { useEffect, useState, useRef, useCallback } from "react"; import { useAuthStore } from "@/stores/AuthStore"; +import { getApiBaseUrl } from "@/lib/runtime-config"; export interface NodeStatus { state: string; @@ -88,8 +89,7 @@ export function useWorkflowStatusStream( activeConnections.add(connectionKey); connectionKeyRef.current = connectionKey; - const baseUrl = - process.env.NEXT_PUBLIC_API_URL || "http://localhost:3000/v1/api"; + const baseUrl = getApiBaseUrl(); const url = `${baseUrl}/workflows/${workflowId}/status/stream`; // Get token from Zustand store diff --git a/lib/runtime-config.server.ts b/lib/runtime-config.server.ts new file mode 100644 index 0000000..ed9ff6b --- /dev/null +++ b/lib/runtime-config.server.ts @@ -0,0 +1,29 @@ +import { + normalizeApiBaseUrl, + type PublicRuntimeConfig, +} from "@/lib/runtime-config"; + +export function loadPublicRuntimeConfig( + env: Record = process.env +): PublicRuntimeConfig { + const apiUrl = env.NEXT_PUBLIC_API_URL; + + if (!apiUrl) { + throw new Error( + "NEXT_PUBLIC_API_URL must be configured when the UI server starts" + ); + } + + return { apiUrl: normalizeApiBaseUrl(apiUrl) }; +} + +export function serializePublicRuntimeConfig( + config: PublicRuntimeConfig +): string { + const serialized = JSON.stringify(config) + .replace(/=20" + } + }, "node_modules/@radix-ui/number": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/@radix-ui/number/-/number-1.1.1.tgz", @@ -3346,6 +3363,40 @@ "node": ">=14.0.0" } }, + "node_modules/@rolldown/binding-wasm32-wasi/node_modules/@emnapi/core": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.9.1.tgz", + "integrity": "sha512-mukuNALVsoix/w1BJwFzwXBN/dHeejQtuVzcDsfOEsdpCumXb/E9j8w11h5S54tT1xhifGfbbSm/ICrObRb3KA==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "@emnapi/wasi-threads": "1.2.0", + "tslib": "^2.4.0" + } + }, + "node_modules/@rolldown/binding-wasm32-wasi/node_modules/@emnapi/runtime": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.9.1.tgz", + "integrity": "sha512-VYi5+ZVLhpgK4hQ0TAjiQiZ6ol0oe4mBx7mVv7IflsiEp0OWoVsp/+f9Vc1hOhE0TtkORVrI1GvzyreqpgWtkA==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@rolldown/binding-wasm32-wasi/node_modules/@emnapi/wasi-threads": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.0.tgz", + "integrity": "sha512-N10dEJNSsUx41Z6pZsXU8FjPjpBEplgH24sfkmITrBED1/U2Esum9F3lfLrMjKHHjmi557zQn7kR9R+XWXu5Rg==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, "node_modules/@rolldown/binding-wasm32-wasi/node_modules/@napi-rs/wasm-runtime": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.1.2.tgz", @@ -3564,9 +3615,6 @@ "node": ">= 20" } }, - "node_modules/@tailwindcss/oxide-linux-arm64": { - "optional": true - }, "node_modules/@tailwindcss/oxide-linux-arm64-gnu": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm64-gnu/-/oxide-linux-arm64-gnu-4.2.2.tgz", @@ -3601,9 +3649,6 @@ "node": ">= 20" } }, - "node_modules/@tailwindcss/oxide-linux-x64": { - "optional": true - }, "node_modules/@tailwindcss/oxide-linux-x64-gnu": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-x64-gnu/-/oxide-linux-x64-gnu-4.2.2.tgz", @@ -3732,9 +3777,6 @@ "license": "0BSD", "optional": true }, - "node_modules/@tailwindcss/oxide-win32-arm64": { - "optional": true - }, "node_modules/@tailwindcss/oxide-win32-arm64-msvc": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-win32-arm64-msvc/-/oxide-win32-arm64-msvc-4.2.2.tgz", @@ -3752,9 +3794,6 @@ "node": ">= 20" } }, - "node_modules/@tailwindcss/oxide-win32-x64": { - "optional": true - }, "node_modules/@tailwindcss/oxide-win32-x64-msvc": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-win32-x64-msvc/-/oxide-win32-x64-msvc-4.2.2.tgz", @@ -8183,9 +8222,6 @@ "url": "https://opencollective.com/parcel" } }, - "node_modules/lightningcss-linux-arm64": { - "optional": true - }, "node_modules/lightningcss-linux-arm64-gnu": { "version": "1.32.0", "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.32.0.tgz", @@ -8228,9 +8264,6 @@ "url": "https://opencollective.com/parcel" } }, - "node_modules/lightningcss-linux-x64": { - "optional": true - }, "node_modules/lightningcss-linux-x64-gnu": { "version": "1.32.0", "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.32.0.tgz", @@ -8273,9 +8306,6 @@ "url": "https://opencollective.com/parcel" } }, - "node_modules/lightningcss-win32-arm64": { - "optional": true - }, "node_modules/lightningcss-win32-arm64-msvc": { "version": "1.32.0", "resolved": "https://registry.npmjs.org/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.32.0.tgz", @@ -8297,9 +8327,6 @@ "url": "https://opencollective.com/parcel" } }, - "node_modules/lightningcss-win32-x64": { - "optional": true - }, "node_modules/lightningcss-win32-x64-msvc": { "version": "1.32.0", "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.32.0.tgz", @@ -9053,6 +9080,53 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/playwright": { + "version": "1.62.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.62.1.tgz", + "integrity": "sha512-0M+L3LAD8/nm554LOla9Ayx0j0tmFZ0FBcoQ7F1VuVHpM/XpiC8RcDzBQB8W5+hA8L22THxELzeF+2WcUzvcLg==", + "devOptional": true, + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.62.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=20" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, + "node_modules/playwright-core": { + "version": "1.62.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.62.1.tgz", + "integrity": "sha512-wPYSwEBJY9GHraISXqyqtx0na0LpO3XEX7jNDhntbex7tzUS7kLnZsOlFruFJB4Hi/rhDMjXGqHewDZ68nYZVw==", + "devOptional": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/playwright/node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/possible-typed-array-names": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.1.0.tgz", diff --git a/package.json b/package.json index 9440c66..212ef0f 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ }, "devDependencies": { "@eslint/eslintrc": "^3", + "@playwright/test": "^1.62.1", "@tailwindcss/postcss": "^4", "@testing-library/jest-dom": "^6.9.1", "@testing-library/react": "^16.3.2", From cbf5877d46845c1f87cc24f1e242bff3d2728256 Mon Sep 17 00:00:00 2001 From: Mohit Nagaraj Date: Tue, 1 Sep 2026 13:59:47 +0530 Subject: [PATCH 2/2] fix(release): address multiarch review feedback Signed-off-by: Mohit Nagaraj --- .github/workflows/docker-publish.yml | 36 +++++++++++++++++----------- .github/workflows/frontend.yml | 7 ++++++ docs/RELEASE.md | 19 ++++++++------- lib/__tests__/runtime-config.test.ts | 3 +++ lib/runtime-config.ts | 6 +++++ 5 files changed, 48 insertions(+), 23 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index f9dc2f3..65fc677 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -31,6 +31,7 @@ jobs: uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 with: fetch-depth: 0 + persist-credentials: false - name: Require a commit from main run: | @@ -55,6 +56,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + with: + persist-credentials: false - name: Set up Node.js uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0 @@ -97,6 +100,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + with: + persist-credentials: false - name: Set up QEMU uses: docker/setup-qemu-action@96fe6ef7f33517b61c61be40b68a1882f3264fb8 # v4.2.0 @@ -117,13 +122,13 @@ jobs: id: version run: echo "VERSION=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT" - - name: Build and push Docker image + - name: Build and push release candidate id: push uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0 with: context: . push: true - tags: ${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }} + tags: ${{ env.IMAGE_NAME }}:build-${{ github.run_id }}-${{ github.run_attempt }} labels: | org.opencontainers.image.title=KubeOrch UI org.opencontainers.image.version=${{ steps.version.outputs.VERSION }} @@ -181,22 +186,25 @@ jobs: --signer-workflow "$GITHUB_REPOSITORY/.github/workflows/docker-publish.yml" \ --source-digest "$GITHUB_SHA" - - name: Promote verified digest to latest + - name: Promote verified digest to release tags env: IMAGE_REF: ${{ env.IMAGE_NAME }}@${{ steps.push.outputs.digest }} EXPECTED_DIGEST: ${{ steps.push.outputs.digest }} + VERSION: ${{ steps.version.outputs.VERSION }} run: | - docker buildx imagetools create \ - --tag "${IMAGE_NAME}:latest" \ - "$IMAGE_REF" - promoted_digest="$( - docker buildx imagetools inspect "${IMAGE_NAME}:latest" \ - --format '{{.Manifest.Digest}}' - )" - if [ "$promoted_digest" != "$EXPECTED_DIGEST" ]; then - echo "latest points to $promoted_digest, expected $EXPECTED_DIGEST" >&2 - exit 1 - fi + for tag in "$VERSION" latest; do + docker buildx imagetools create \ + --tag "${IMAGE_NAME}:${tag}" \ + "$IMAGE_REF" + promoted_digest="$( + docker buildx imagetools inspect "${IMAGE_NAME}:${tag}" \ + --format '{{.Manifest.Digest}}' + )" + if [ "$promoted_digest" != "$EXPECTED_DIGEST" ]; then + echo "$tag points to $promoted_digest, expected $EXPECTED_DIGEST" >&2 + exit 1 + fi + done - name: Create GitHub Release uses: softprops/action-gh-release@efb35369e0ad2afab669f228072c1b0d510eae64 # v3.0.3 diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index e3bce1d..33a9e24 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -5,6 +5,9 @@ on: branches: - main +permissions: + contents: read + jobs: build: runs-on: ubuntu-latest @@ -14,6 +17,8 @@ jobs: steps: - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + with: + persist-credentials: false - uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0 with: node-version: ${{ matrix.node }} @@ -49,6 +54,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + with: + persist-credentials: false - name: Set up Node.js uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0 diff --git a/docs/RELEASE.md b/docs/RELEASE.md index 24146bf..368bd0d 100644 --- a/docs/RELEASE.md +++ b/docs/RELEASE.md @@ -36,10 +36,11 @@ container, sends API requests to the host-published Core port. ## Published Evidence -The versioned image index includes BuildKit-generated SPDX SBOM and SLSA -provenance attestations. The workflow also creates a GitHub build attestation -for the immutable index digest. After all evidence checks pass, the same index -is promoted to `latest` and its digest is recorded in the GitHub Release. +The workflow first pushes a uniquely named release candidate containing +BuildKit-generated SPDX SBOM and SLSA provenance attestations. It also creates a +GitHub build attestation for the immutable index digest. After all evidence +checks pass, the same index is promoted to the version tag and `latest`, and its +digest is recorded in the GitHub Release. Use the digest from the GitHub Release instead of trusting a mutable tag: @@ -75,8 +76,8 @@ pass its container and browser smoke test. Logs identify the failing platform and include UI or mock Core logs only on failure. The smoke environment uses no production credentials. -If publication succeeds but manifest or attestation verification fails, the -workflow does not update `latest` or create the GitHub Release. Inspect the -`Verify platforms and attestations` step for an unexpected platform set, -missing SBOM/provenance data, source revision mismatch, or GitHub attestation -verification error. +If candidate publication succeeds but manifest or attestation verification +fails, the workflow does not create the version tag, update `latest`, or create +the GitHub Release. Inspect the `Verify platforms and attestations` step for an +unexpected platform set, missing SBOM/provenance data, source revision mismatch, +or GitHub attestation verification error. diff --git a/lib/__tests__/runtime-config.test.ts b/lib/__tests__/runtime-config.test.ts index fcfbaf6..aef3a38 100644 --- a/lib/__tests__/runtime-config.test.ts +++ b/lib/__tests__/runtime-config.test.ts @@ -35,6 +35,9 @@ describe("runtime configuration", () => { "https://user:secret@core.example/v1/api", "https://core.example/v1/api?token=secret", "https://core.example/v1/api#fragment", + "/\\core.example/v1/api", + "/foo\\bar", + "https://core.example/v1/api\nheader", ])("rejects an unsafe API URL: %s", value => { expect(() => normalizeApiBaseUrl(value)).toThrow(); }); diff --git a/lib/runtime-config.ts b/lib/runtime-config.ts index c1cf16f..0b47e77 100644 --- a/lib/runtime-config.ts +++ b/lib/runtime-config.ts @@ -15,6 +15,12 @@ export function normalizeApiBaseUrl(value: string): string { throw new Error("NEXT_PUBLIC_API_URL must not be empty"); } + if (/[\u0000-\u001f\u007f\\]/.test(trimmed)) { + throw new Error( + "NEXT_PUBLIC_API_URL must not include control characters or backslashes" + ); + } + if (trimmed.startsWith("/")) { if (trimmed.startsWith("//")) { throw new Error("NEXT_PUBLIC_API_URL must not be protocol-relative");