Skip to content

feat(chart): set the executors' security context - #266

Merged
uniqueg merged 5 commits into
devfrom
feat/chart-executor-security-context
Nov 7, 2026
Merged

uniqueg merged 5 commits into
devfrom
feat/chart-executor-security-context

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds the opt-in value tesk.executor.securityContext (runAsUser, runAsGroup, fsGroup, runAsNonRoot) for the executors' pods.

  • When it is set, the chart renders the ConfigMap <prefix>-executor. tesk-api reads this ConfigMap at startup (env CONFIGMAP, key securityContext) and applies it to the executor pods it creates.
  • A checksum annotation restarts the API's pod when the value changes.
  • It is empty by default, so existing deployments render as before.
  • The schema accepts only the fields that tesk-api reads, with IDs from 0 to 2147483647.
  • Numbers from values files are rendered as integers. Without that, Helm would render 1000000 as 1e+06.
  • Docs (also an entry in docs/upgrading.md):
    • docs/configuration.md gets the value and the object name.
    • docs/deployment.md gets a new section, "Executors as non-root users". It covers fsGroup for the files that the filer stages (permission denied on PV files in TESK tasks #113), its limits (NFS, hostPath, CSI drivers with fsGroupPolicy: None), images that need root or have a named user, and how this value differs from tesk.securityContext.

Closes #264

Related:

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) and mypy 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

  • Naming the tesk-api version in the docs that "reads only these four fields" was verified against: I left this out. The field list lives in the schema and one helper comment (which names KubernetesObjectsSupplier), and the docs link the value to the schema check.
  • (Resolved) An upgrade note: added to docs/upgrading.md, like the other new values there.

Open questions

None.

🤖 Generated with Claude Code

uniqueg and others added 3 commits November 7, 2026 21:58
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]>
@sourcery-ai

sourcery-ai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Configuration

Define the allowed executor security-context fields and defaults before reviewing how the chart renders and passes them to tesk-api.

  • charts/tesk/values.schema.json L124-160
  • charts/tesk/values.yaml L54-65

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.

  • charts/tesk/templates/_helpers.tpl L43-46, L64-91
  • charts/tesk/templates/common/executor-cm.yaml L1-14
  • charts/tesk/templates/common/tesk-deployment.yaml L13, L29-33, L55-58

Documentation

Explain the executor value, its generated ConfigMap name, and how it differs from the API security context in the configuration reference.

  • docs/configuration.md L46, L56, L171

Document how to run executors as non-root users, including fsGroup behavior and limits, image caveats, and upgrade effects.

  • docs/deployment.md L292-336
  • docs/upgrading.md L209-217

Tests

Check default and configured rendering, checksum behavior, values-file integer handling, and invalid security-context values.

  • tests/test_chart.py L326-475 (+3 small edits)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2ec16c0) to head (e0c7605).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 7, 2026 21:23

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread charts/tesk/templates/_helpers.tpl Resolved
uniqueg and others added 2 commits November 7, 2026 22:29
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]>
@uniqueg
uniqueg merged commit 918fe7b into dev Nov 7, 2026
28 checks passed
@uniqueg
uniqueg deleted the feat/chart-executor-security-context branch November 7, 2026 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(chart): set the executors' security context

1 participant