Repository navigation
feat(chart): set the executors' security context - #266
Conversation
Add the opt-in value tesk.executor.securityContext (runAsUser, runAsGroup, fsGroup, runAsNonRoot). When set, the chart renders the ConfigMap <prefix>-executor that tesk-api reads at startup (variable CONFIGMAP, key securityContext) and applies to the executors' pods; a checksum annotation restarts the API's pod when it changes. Empty by default, which leaves the executors as before. The schema accepts only the fields that tesk-api reads, as non-negative integers or a boolean; numbers from values files are rendered as integers. The deployment guide explains the values, how fsGroup gives executors access to the files that the filer stages (#113) and its limits. Closes #264 Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Cap user and group IDs at 2147483647, as Kubernetes does, so that out-of-range IDs fail at install time instead of in every task. - Correct the docs: taskmasters and filers run as UID 100, not root; runAsNonRoot also stops images with a named user; point from each security context value to the other. - Test the empty and null values and the checksum on its own, and compare the rendered fields as YAML. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideConfigurationDefine the allowed executor security-context fields and defaults before reviewing how the chart renders and passes them to tesk-api.
Review the rendering and startup wiring together: create the ConfigMap only when a context is set, pass its name to tesk-api, and restart the API pod when the context changes.
DocumentationExplain the executor value, its generated ConfigMap name, and how it differs from the API security context in the configuration reference.
Document how to run executors as non-root users, including fsGroup behavior and limits, image caveats, and upgrade effects.
TestsCheck default and configured rendering, checksum behavior, values-file integer handling, and invalid security-context values.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #266 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 1
Lines 229 229
=========================================
Hits 229 229 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="charts/tesk/templates/_helpers.tpl" line_range="84-85" />
<code_context>
+{{- end -}}
+{{- end -}}
+{{- if hasKey $context "runAsNonRoot" -}}
+{{- $lines = append $lines (printf "nonRoot: %t" (index $context "runAsNonRoot")) -}}
+{{- end -}}
+{{- join "\n" $lines -}}
+{{- end -}}
</code_context>
<issue_to_address>
**Contradictory root settings break executors**
When `tesk.executor.securityContext` sets both `runAsUser: 0` and `runAsNonRoot: true`, the helper emits `runAsUser: 0` and `nonRoot: true` independently, so Kubernetes refuses to start those executor containers and their tasks fail.
Reject this combination in the schema or fail chart rendering with a clear validation error.
</issue_to_address>
### Comment 2
<location path="charts/tesk/templates/common/tesk-deployment.yaml" line_range="32" />
<code_context>
+ {{- /* tesk-api reads the ConfigMap only at startup */}}
+ {{- with $executorSecurityContext }}
+ annotations:
+ checksum/executor-config: {{ sha256sum . }}
+ {{- end }}
spec:
</code_context>
<issue_to_address>
**Tasks use stale executor settings**
When the executor security context changes and tasks are submitted while the API Deployment is rolling out, the old API pod retains the security context it read at startup and can still receive Service traffic while the new pod becomes ready; it creates executor jobs with the previous settings, so tasks submitted during the rollout can run with a context different from the configured one.
Prevent old and new API pods from serving task-creation requests concurrently during a security-context change, or otherwise ensure requests use the new configuration before the old pod is removed.
</issue_to_address>Linked issues
#264 feat(chart): set the executors' security context · 4 of 4 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Expose an opt-in executor security context that is empty by default and leaves existing deployments unchanged. | ✅ Met | The default is {}; the ConfigMap, CONFIGMAP variable, and checksum annotation are conditional on a non-empty context. |
| 2 | When set, pass the supported fields to tesk-api in a release ConfigMap so it can apply them to executor pods. | ✅ Met | The chart renders <prefix>-executor, maps runAsNonRoot to nonRoot, and sets CONFIGMAP to the ConfigMap name. |
| 3 | Validate the context fields as non-negative integers or a boolean. | ✅ Met | The schema permits only the four supported fields, restricts IDs to 0–2147483647, and requires runAsNonRoot to be boolean. |
| 4 | Document the value in the configuration reference and deployment guide, including its executor-only scope, fsGroup use and limitations, and images that need root. | ✅ Met | Both docs are updated; the deployment guide covers staged files, volume types without ownership management, and image constraints. |
Sourcery assessment
Needs a human reviewer. 2 findings to address first, and when configured, this passes UID, group, and non-root settings to executor pods, changing the identity and volume access under which task commands run; an incorrect setting can let task code run with unintended privileges or leave PVC files with changed ownership. Reverting stops applying the settings to new executor pods, but does not undo effects on tasks or PVCs that already ran.
Blocking findings: charts/tesk/templates/_helpers.tpl:85, charts/tesk/templates/common/tesk-deployment.yaml:32
Co-Authored-By: Claude Opus 5.5 <[email protected]>
runAsUser 0 together with runAsNonRoot true would keep every executor from starting; fail the chart instead. Document that the old API pod keeps the old settings while the new one starts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Adds the opt-in value
tesk.executor.securityContext(runAsUser,runAsGroup,fsGroup,runAsNonRoot) for the executors' pods.<prefix>-executor. tesk-api reads this ConfigMap at startup (envCONFIGMAP, keysecurityContext) and applies it to the executor pods it creates.1000000as1e+06.docs/upgrading.md):docs/configuration.mdgets the value and the object name.docs/deployment.mdgets a new section, "Executors as non-root users". It coversfsGroupfor the files that the filer stages (permission denied on PV files in TESK tasks #113), its limits (NFS, hostPath, CSI drivers withfsGroupPolicy: None), images that need root or have a named user, and how this value differs fromtesk.securityContext.Closes #264
Related:
fsGrouphelps only on volume types whose ownership Kubernetes manages.Verification
REQUIRE_HELM=1 pytest -q(helm v3.22.1): 320 passed. The new tests were written first and failed before the change.helm lint charts/tesk --strict: no failures.ruff check/ruff format --check(0.17.3) andmypy tests: clean.mkdocs build --strict: built without warnings.CI: all checks passed, including Chart install (kind), Docs, Lint, Test and CodeQL.
Reviews: one round each from the adversarial and quality reviewers. I fixed all medium and low findings except those listed below, then ran a second round (adversarial: no findings; quality: cosmetic rewraps, fixed).
Sourcery: 2 threads. Fixed: runAsUser 0 with runAsNonRoot true now fails the chart. Answered and documented: during a rollout the old pod keeps the old settings. CI green again on e0c7605.
Declined review findings
KubernetesObjectsSupplier), and the docs link the value to the schema check.Open questions
None.
🤖 Generated with Claude Code