Skip to content

Commit a7fff89

Browse files
Uupdate worker pod configuration: Introduce service account and automount options in env.ts, kubernetes.ts, and helm templates for improved Kubernetes integration.
1 parent ec20edb commit a7fff89

5 files changed

Lines changed: 87 additions & 1 deletion

File tree

apps/supervisor/src/env.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ const Env = z.object({
7373
KUBERNETES_FORCE_ENABLED: BoolEnv.default(false),
7474
KUBERNETES_NAMESPACE: z.string().default("default"),
7575
KUBERNETES_WORKER_NODETYPE_LABEL: z.string().default("v4-worker"),
76+
KUBERNETES_WORKER_SERVICE_ACCOUNT: z.string().optional(), // Service account for worker pods
77+
KUBERNETES_WORKER_AUTOMOUNT_SERVICE_ACCOUNT_TOKEN: BoolEnv.default(false), // Whether to mount SA token
7678
KUBERNETES_IMAGE_PULL_SECRETS: z.string().optional(), // csv
7779
KUBERNETES_EPHEMERAL_STORAGE_SIZE_LIMIT: z.string().default("10Gi"),
7880
KUBERNETES_EPHEMERAL_STORAGE_SIZE_REQUEST: z.string().default("2Gi"),

apps/supervisor/src/workloadManager/kubernetes.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,13 @@ export class KubernetesWorkloadManager implements WorkloadManager {
237237
get #defaultPodSpec(): Omit<k8s.V1PodSpec, "containers"> {
238238
return {
239239
restartPolicy: "Never",
240-
automountServiceAccountToken: false,
240+
// Explicit control over service account token mounting (defaults to false for security)
241+
automountServiceAccountToken: env.KUBERNETES_WORKER_AUTOMOUNT_SERVICE_ACCOUNT_TOKEN,
241242
imagePullSecrets: this.getImagePullSecrets(),
243+
// Optionally specify a service account for the worker pods
244+
...(env.KUBERNETES_WORKER_SERVICE_ACCOUNT
245+
? { serviceAccountName: env.KUBERNETES_WORKER_SERVICE_ACCOUNT }
246+
: {}),
242247
securityContext: {
243248
runAsNonRoot: true,
244249
runAsUser: 1000,

hosting/k8s/helm/templates/supervisor.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ spec:
170170
value: {{ .Values.supervisor.config.kubernetes.forceEnabled | quote }}
171171
- name: KUBERNETES_WORKER_NODETYPE_LABEL
172172
value: {{ .Values.supervisor.config.kubernetes.workerNodetypeLabel | quote }}
173+
- name: KUBERNETES_WORKER_SERVICE_ACCOUNT
174+
value: {{ .Values.supervisor.config.kubernetes.workerServiceAccount | quote }}
175+
- name: KUBERNETES_WORKER_AUTOMOUNT_SERVICE_ACCOUNT_TOKEN
176+
value: {{ .Values.supervisor.config.kubernetes.workerAutomountServiceAccountToken | quote }}
173177
{{- $registryAuthEnabled := false }}
174178
{{- if .Values.registry.deploy }}
175179
{{- $registryAuthEnabled = .Values.registry.auth.enabled }}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{{- if .Values.worker }}
2+
{{- if .Values.worker.serviceAccount }}
3+
{{- if .Values.worker.serviceAccount.create }}
4+
---
5+
# Service Account for worker pods
6+
# Note: By default, the service account token is NOT mounted into pods (automountServiceAccountToken: false)
7+
# This follows the principle of least privilege. Enable token mounting only if pods need K8s API access.
8+
# For cloud IAM integration (AWS IRSA, GCP Workload Identity), you typically don't need the token mounted.
9+
apiVersion: v1
10+
kind: ServiceAccount
11+
metadata:
12+
name: {{ .Values.worker.serviceAccount.name | default "trigger-worker" }}
13+
namespace: {{ default .Release.Namespace .Values.supervisor.config.kubernetes.namespace }}
14+
labels:
15+
{{- include "trigger-v4.labels" . | nindent 4 }}
16+
app.kubernetes.io/component: worker
17+
{{- with .Values.worker.serviceAccount.annotations }}
18+
annotations:
19+
{{- toYaml . | nindent 4 }}
20+
{{- end }}
21+
{{- if .Values.worker.rbac.create }}
22+
---
23+
apiVersion: rbac.authorization.k8s.io/v1
24+
kind: Role
25+
metadata:
26+
name: {{ .Values.worker.serviceAccount.name | default "trigger-worker" }}
27+
namespace: {{ default .Release.Namespace .Values.supervisor.config.kubernetes.namespace }}
28+
labels:
29+
{{- include "trigger-v4.labels" . | nindent 4 }}
30+
app.kubernetes.io/component: worker
31+
rules:
32+
# Add any permissions your worker pods need
33+
# For example, if they need to read ConfigMaps:
34+
- apiGroups: [""]
35+
resources: ["configmaps"]
36+
verbs: ["get", "list"]
37+
# Or if they need to read secrets:
38+
- apiGroups: [""]
39+
resources: ["secrets"]
40+
verbs: ["get"]
41+
---
42+
apiVersion: rbac.authorization.k8s.io/v1
43+
kind: RoleBinding
44+
metadata:
45+
name: {{ .Values.worker.serviceAccount.name | default "trigger-worker" }}
46+
namespace: {{ default .Release.Namespace .Values.supervisor.config.kubernetes.namespace }}
47+
labels:
48+
{{- include "trigger-v4.labels" . | nindent 4 }}
49+
app.kubernetes.io/component: worker
50+
subjects:
51+
- kind: ServiceAccount
52+
name: {{ .Values.worker.serviceAccount.name | default "trigger-worker" }}
53+
namespace: {{ default .Release.Namespace .Values.supervisor.config.kubernetes.namespace }}
54+
roleRef:
55+
kind: Role
56+
name: {{ .Values.worker.serviceAccount.name | default "trigger-worker" }}
57+
apiGroup: rbac.authorization.k8s.io
58+
{{- end }}
59+
{{- end }}
60+
{{- end }}
61+
{{- end }}

hosting/k8s/helm/values.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ supervisor:
261261
forceEnabled: true
262262
namespace: "" # Default: uses release namespace
263263
workerNodetypeLabel: "" # When set, runs will only be scheduled on nodes with "nodetype=<label>"
264+
workerServiceAccount: "trigger-worker" # Service account name for worker pods (e.g. "trigger-worker")
265+
workerAutomountServiceAccountToken: true # Whether to mount the SA token in worker pods. Keep false unless pods need K8s API access
264266
ephemeralStorageSizeLimit: "" # Default: 10Gi
265267
ephemeralStorageSizeRequest: "" # Default: 2Gi´
266268
podCleaner:
@@ -354,6 +356,18 @@ supervisor:
354356
tolerations: []
355357
affinity: {}
356358

359+
# Worker pod configuration
360+
worker:
361+
# Service account for worker pods
362+
serviceAccount:
363+
create: true # Set to true to create a service account for worker pods
364+
name: "trigger-worker" # Name of the service account
365+
annotations: {} # Annotations to add to the service account (e.g., for AWS IRSA, GCP Workload Identity)
366+
367+
# RBAC configuration for worker pods
368+
rbac:
369+
create: false # Set to true to create RBAC resources if worker pods need Kubernetes API access
370+
357371
# PostgreSQL configuration
358372
# Subchart: https://github.com/bitnami/charts/tree/main/bitnami/postgresql
359373
postgres:

0 commit comments

Comments
 (0)