From 2af6053079192c36092e61cbd09fbc89fdd38f98 Mon Sep 17 00:00:00 2001 From: Marian Koreniuk Date: Mon, 19 Oct 2026 23:17:50 +0200 Subject: [PATCH] fix(e2e): keep the Proxmox tenant kubeconfig per run and remove it run-proxmox.sh wrote the tenant's super-admin kubeconfig to $TMPDIR with the process umask and never removed it, so it outlived the run on the self-hosted runner, world-readable under the usual umask. dump_diagnostics then read whatever sat at that path, so a run that failed before the fetch reported the previous run's tenant as its own. The file now lives under COZY_PROXMOX_WORKDIR, which the workflow points at runner.temp. It is written under umask 077, removed at the start of apply-tenant so this run never sees a leftover, removed again in the suite's finally, and once more in the workflow's credential cleanup step for a run killed before finally runs. Closes #4806 Signed-off-by: Marian Koreniuk Assisted-by: LLM (cherry picked from commit 61238500dd0bfac800688b8544769e914a6bbabb) Signed-off-by: Myasnikov Daniil --- .github/workflows/e2e-proxmox.yaml | 9 ++++++- hack/e2e-chainsaw/_lib/run-proxmox.sh | 26 ++++++++++++++++--- .../chainsaw-test.yaml.disabled | 6 +++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/.github/workflows/e2e-proxmox.yaml b/.github/workflows/e2e-proxmox.yaml index 621c6d0fe..b5b19756d 100644 --- a/.github/workflows/e2e-proxmox.yaml +++ b/.github/workflows/e2e-proxmox.yaml @@ -49,6 +49,11 @@ jobs: COZY_PVE_SSH: ${{ vars.PROXMOX_SSH }} COZY_PVE_SSH_KEY: ${{ github.workspace }}/.ssh-pve COZY_KEEP_TENANT: ${{ inputs.keep_tenant == true }} + # Where run-proxmox.sh keeps the tenant's super-admin kubeconfig for the + # run. runner.temp is emptied by the runner between jobs, and the cleanup + # step below removes the file as well; see the script for why neither is + # left to /tmp. + COZY_PROXMOX_WORKDIR: ${{ runner.temp }} steps: - name: Checkout uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 @@ -157,4 +162,6 @@ jobs: - name: Remove staged credentials if: always() - run: rm -f "$GITHUB_WORKSPACE/.kubeconfig" "$COZY_PVE_SSH_KEY" + # The tenant kubeconfig is the suite's, fetched by run-proxmox.sh; its + # finally removes it too, but a run killed mid-step never reaches that. + run: rm -f "$GITHUB_WORKSPACE/.kubeconfig" "$COZY_PVE_SSH_KEY" "$COZY_PROXMOX_WORKDIR/proxmox-e2e-tenant.kubeconfig" diff --git a/hack/e2e-chainsaw/_lib/run-proxmox.sh b/hack/e2e-chainsaw/_lib/run-proxmox.sh index 742b69570..4191c4418 100755 --- a/hack/e2e-chainsaw/_lib/run-proxmox.sh +++ b/hack/e2e-chainsaw/_lib/run-proxmox.sh @@ -22,7 +22,15 @@ CLUSTER="${COZY_PROXMOX_CLUSTER:-k8s-e2e}" PVE_SSH="${COZY_PVE_SSH:?COZY_PVE_SSH is required: the ssh destination of the Proxmox host, user@host}" PVE_SSH_KEY="${COZY_PVE_SSH_KEY:-$HOME/.ssh/id_ed25519}" STORAGE="${COZY_PROXMOX_STORAGE:?COZY_PROXMOX_STORAGE is required, the PVE storage id for the PVC probe}" -TENANT_KUBECONFIG="${TMPDIR:-/tmp}/proxmox-e2e-tenant.kubeconfig" +# Where this run keeps the tenant's super-admin kubeconfig. Per run rather than +# a fixed path under /tmp: the file is a credential for the whole tenant, so it +# must not outlive the run on a shared runner, and dump_diagnostics reads +# whatever is at this path, so a file left by a previous run would be reported +# as this run's tenant. The workflow points this at runner.temp, which the +# runner empties between jobs; apply-tenant removes a leftover before it does +# anything else, and the suite's finally removes the file when the run ends. +WORKDIR="${COZY_PROXMOX_WORKDIR:-${RUNNER_TEMP:-${TMPDIR:-/tmp}}}" +TENANT_KUBECONFIG="$WORKDIR/proxmox-e2e-tenant.kubeconfig" FIXTURE="$(cd "$(dirname "$0")/.." && pwd)/kubernetes-proxmox/tenant.yaml" log() { printf '[%s] %s\n' "$(date -u +%H:%M:%S)" "$*"; } @@ -77,6 +85,10 @@ render_tenant() { } apply_tenant() { + # First step of the suite, so this is where a kubeconfig left by an earlier + # run on this runner is removed: from here on the path holds this run's file + # or nothing, and dump_diagnostics cannot pick up another tenant. + rm -f "$TENANT_KUBECONFIG" render_tenant | kubectl apply -f - } @@ -85,8 +97,16 @@ apply_tenant() { # carries the address a runner outside the management cluster can reach; .svc # is the in-cluster Service the management-side controllers use. fetch_tenant_kubeconfig() { - kubectl -n "$NS" get secret "kubernetes-${CLUSTER}-admin-kubeconfig" \ - -o jsonpath='{.data.super-admin\.conf}' | base64 -d > "$TENANT_KUBECONFIG" + # Written under umask 077 in a subshell of its own: the workflow sets that + # umask only in its staging step, and a chainsaw script step runs with the + # runner's default, under which the file would be readable by every local + # user. No pipefail in POSIX sh, so a failed read leaves an empty file, which + # the size check below turns into a failure rather than an empty kubeconfig. + ( + umask 077 + kubectl -n "$NS" get secret "kubernetes-${CLUSTER}-admin-kubeconfig" \ + -o jsonpath='{.data.super-admin\.conf}' | base64 -d > "$TENANT_KUBECONFIG" + ) [ -s "$TENANT_KUBECONFIG" ] || die "tenant kubeconfig is empty — did the control plane come up?" } diff --git a/hack/e2e-chainsaw/kubernetes-proxmox/chainsaw-test.yaml.disabled b/hack/e2e-chainsaw/kubernetes-proxmox/chainsaw-test.yaml.disabled index d0e0fefce..068b70c5d 100644 --- a/hack/e2e-chainsaw/kubernetes-proxmox/chainsaw-test.yaml.disabled +++ b/hack/e2e-chainsaw/kubernetes-proxmox/chainsaw-test.yaml.disabled @@ -124,6 +124,12 @@ spec: - script: content: | set -eu + # The tenant's super-admin kubeconfig that run-proxmox.sh fetched for + # the checks above; the same path the script derives. Removed before + # the keep_tenant exit below, because the file is a credential and + # keeping the tenant is not a reason to keep that on the runner. The + # workflow's cleanup step removes it again, for a run killed here. + rm -f "${COZY_PROXMOX_WORKDIR:-${RUNNER_TEMP:-${TMPDIR:-/tmp}}}/proxmox-e2e-tenant.kubeconfig" # keep_tenant is honoured here as well as in the workflow's own # teardown, or the suite would delete what the operator asked to keep. if [ "${COZY_KEEP_TENANT:-false}" = "true" ]; then