From 3041e430b77d6098b9ef4a1e9934633056fb1e5d Mon Sep 17 00:00:00 2001 From: "stackweaver-release-bot[bot]" <287320289+stackweaver-release-bot@users.noreply.github.com> Date: Sun, 29 Nov 2026 00:58:05 +0000 Subject: [PATCH] Merge pull request #1231 from michielvha/fix/launcher-serviceaccount-scope --- chart/README.md | 2 +- chart/templates/_helpers.tpl | 12 ++++++++++++ chart/templates/launcher/launcher-deployment.yaml | 2 +- chart/templates/launcher/launcher-rbac.yaml | 8 ++++++-- chart/values.yaml | 3 ++- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/chart/README.md b/chart/README.md index ab50e77..371c4cb 100644 --- a/chart/README.md +++ b/chart/README.md @@ -308,7 +308,7 @@ The table below is generated from `values.yaml`. Boilerplate keys (resources, sc | launcher.affinity | object | `{}` | | | launcher.clusterCIDRs | list | `[]` | Pod and service CIDRs job pods may not reach, IPv4 and IPv6 (the API and DNS stay open) | | launcher.createJobNamespace | bool | `false` | Create `jobNamespace`, enforcing the restricted Pod Security Standard | -| launcher.driver | string | `"kubernetes"` | Where jobs run: `kubernetes` (a pod per job in its engine's job image) or `inprocess` (one launcher Deployment per engine, running each job inside its pod, from that engine's job image) | +| launcher.driver | string | `"kubernetes"` | Where jobs run: `kubernetes` (a pod per job in its engine's job image) or `inprocess` (one launcher Deployment per engine, running each job inside its pod, from that engine's job image). Only `kubernetes` mounts the launcher ServiceAccount token and binds its Role in the job namespace | | launcher.env | object | `{}` | Extra environment variables of the launcher | | launcher.extraJobEgress | list | `[]` | Extra egress rules (NetworkPolicy `to` and `ports`) for job pods, appended as given: a destination inside clusterCIDRs that jobs must reach, such as an internal registry | | launcher.healthPort | int | `9090` | Port of the launcher's /healthz and /readyz | diff --git a/chart/templates/_helpers.tpl b/chart/templates/_helpers.tpl index a762f45..af91319 100644 --- a/chart/templates/_helpers.tpl +++ b/chart/templates/_helpers.tpl @@ -592,6 +592,17 @@ rewrite ^{{ $site.basePath }}(/.*)$ $1 last; {{- printf "%s-launcher" (include "stackweaver.fullname" .) }} {{- end }} +{{/* "true" when the launchers place jobs through the Kubernetes driver, "" for the in-process + driver. Only the Kubernetes driver calls the Kubernetes API, so only it gets the launcher + ServiceAccount's token and Role. Any other launcher.driver fails the render. */}} +{{- define "stackweaver.launcher.kubernetesDriver" -}} +{{- $d := .Values.launcher.driver }} +{{- if not (has $d (list "kubernetes" "inprocess")) }} +{{- fail (printf "launcher.driver=%q is not supported by this chart: use kubernetes or inprocess" (toString $d)) }} +{{- end }} +{{- if eq $d "kubernetes" }}true{{ end }} +{{- end }} + {{/* The namespace job pods run in: launcher.jobNamespace, else the release's. */}} {{- define "stackweaver.launcher.jobNamespace" -}} {{- .Values.launcher.jobNamespace | default .Release.Namespace }} @@ -870,6 +881,7 @@ spec: spec: {{- include "stackweaver.imagePullSecrets" $root | nindent 6 }} serviceAccountName: {{ include "stackweaver.launcher.serviceAccountName" $root }} + automountServiceAccountToken: {{ include "stackweaver.launcher.kubernetesDriver" $root | eq "true" }} # Outlasts the launcher's drain, so a rollout lets its jobs finish (launcher.terminationGracePeriodSeconds). terminationGracePeriodSeconds: {{ $root.Values.launcher.terminationGracePeriodSeconds }} securityContext: diff --git a/chart/templates/launcher/launcher-deployment.yaml b/chart/templates/launcher/launcher-deployment.yaml index e1375ac..8324e91 100644 --- a/chart/templates/launcher/launcher-deployment.yaml +++ b/chart/templates/launcher/launcher-deployment.yaml @@ -3,7 +3,7 @@ in a fresh pod of its own in the job namespace through the Kubernetes driver, in that engine's job image. It holds no database, storage, Redis, encryption, OIDC signing or VCS app secret, mounts no volume of jobs, and runs no user code. */}} -{{- if ne .Values.launcher.driver "inprocess" }} +{{- if include "stackweaver.launcher.kubernetesDriver" . }} {{- $l := include "stackweaver.launcher.values" . | fromYaml }} {{- include "stackweaver.launcher.deployment" (dict "root" . "name" (printf "%s-launcher" (include "stackweaver.fullname" .)) "engine" "" "engines" "" "image" (printf "%s:%s" $l.image.repository $l.image.tag) "pullPolicy" $l.image.pullPolicy "tmpSize" "256Mi" "values" $l) }} {{- end }} diff --git a/chart/templates/launcher/launcher-rbac.yaml b/chart/templates/launcher/launcher-rbac.yaml index fe694ac..e61987b 100644 --- a/chart/templates/launcher/launcher-rbac.yaml +++ b/chart/templates/launcher/launcher-rbac.yaml @@ -4,7 +4,9 @@ listed, created by server-side apply (create and patch) and deleted; pod logs and the pod template ConfigMap are read. No exec, and no NetworkPolicy write: the chart owns the job namespace's policies (job-networkpolicy.yaml) and tells the launchers to leave them - (RUNNER_MANAGE_NETWORK_POLICY=false). */}} + (RUNNER_MANAGE_NETWORK_POLICY=false). The in-process driver never calls the Kubernetes API, so + under it the ServiceAccount mounts no token and the Role and RoleBinding are not rendered. */}} +{{- $k8s := include "stackweaver.launcher.kubernetesDriver" . | eq "true" }} apiVersion: v1 kind: ServiceAccount metadata: @@ -12,7 +14,8 @@ metadata: labels: {{- include "stackweaver.labels" . | nindent 4 }} app.kubernetes.io/component: launcher -automountServiceAccountToken: true +automountServiceAccountToken: {{ $k8s }} +{{- if $k8s }} --- apiVersion: rbac.authorization.k8s.io/v1 kind: Role @@ -46,3 +49,4 @@ subjects: - kind: ServiceAccount name: {{ include "stackweaver.launcher.serviceAccountName" . }} namespace: {{ .Release.Namespace }} +{{- end }} diff --git a/chart/values.yaml b/chart/values.yaml index e6c0c3f..cfe2215 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -294,7 +294,8 @@ orchestrator: # job alone. launcher: # -- Where jobs run: `kubernetes` (a pod per job in its engine's job image) or `inprocess` (one - # launcher Deployment per engine, running each job inside its pod, from that engine's job image) + # launcher Deployment per engine, running each job inside its pod, from that engine's job image). + # Only `kubernetes` mounts the launcher ServiceAccount token and binds its Role in the job namespace driver: kubernetes # -- Job network: `platform` (node metadata blocked) or `host-identity` (the node's identity reachable) network: platform