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 <moriarti@cp.if.ua>
Assisted-by: LLM
(cherry picked from commit 61238500dd)
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
This commit is contained in:
Marian Koreniuk authored and Myasnikov Daniil committed 2026-11-10 12:40:52 +00:00
1 parent a6a157df27
commit 2af6053079
3 files changed
+37 -4

No files matched your search

+8 -1
View File
@@ -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"
+23 -3
View File
@@ -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?"
}
@@ -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