Skip to content

feat: make task pods restricted-ready - #210

Merged
uniqueg merged 5 commits into
devfrom
feat/209-restricted-pods
Nov 21, 2026
Merged

uniqueg merged 5 commits into
devfrom
feat/209-restricted-pods

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Makes task pods admissible in namespaces that enforce the restricted Pod Security Standard and/or a ResourceQuota on limits.cpu (CERIT-SC), opt-in for the security part.

New settings (prefix tesk.api.taskmaster., env vars TESK_API_TASKMASTER_*):

Setting Env var Default
pod-security-context TESK_API_TASKMASTER_POD_SECURITY_CONTEXT none
security-context TESK_API_TASKMASTER_SECURITY_CONTEXT none
resources TESK_API_TASKMASTER_RESOURCES {"requests": {"cpu": "100m", "memory": "128Mi"}, "limits": {"cpu": "500m", "memory": "256Mi"}}
executor-pod-security-context TESK_API_TASKMASTER_EXECUTOR_POD_SECURITY_CONTEXT none (on top of the CONFIGMAP context, which still works)
executor-security-context TESK_API_TASKMASTER_EXECUTOR_SECURITY_CONTEXT none
executor-default-cpu TESK_API_TASKMASTER_EXECUTOR_DEFAULT_CPU 1 (request and limit when the task sets no cpu_cores)
  • JSON objects use the Kubernetes API's fields. An empty value or {} sets none. Invalid values stop the app at startup with a message that names the setting. Invalid means:

    • not strict JSON: duplicate names, trailing content, unquoted names;
    • not a JSON object, or unknown fields (snake_case ones too);
    • wrong types, such as "true", "1000" or 1.5;
    • user or group IDs outside 0..2147483647, or unknown seccomp profile types;
    • invalid or negative quantities, or requests above limits.

    JSON null counts as unset. In the executor pod context, it removes the field that comes from the ConfigMap.

  • Executors with ram_gb also get it as their memory limit, including when cpu_cores is set. This is tesk-api's side of fix: give executors a memory limit when they set CPUs tesk-core#160, and it matters more now: with a default CPU, executors always have limits, so the taskmaster never copies requests to limits.

  • Without the security settings, the taskmaster and executor pods carry the same security contexts as in 2.0.0. The resources change: there are new defaults for the taskmaster and the executors' CPU, and the upgrade notes say so.

  • Docs: rows in the configuration table, a new section "Pod security and resources" (with "Restricted clusters" and "CPU quotas"), the default executor CPU in api.md, and upgrade notes under "To 2.1.0". The docs say that restricted namespaces and FILER_RESOURCES need taskmaster/filer 0.12.0+, because the default image is still 0.11.0. They also warn about LimitRange CPU maxima below the default CPU.

Closes #209

Verification

  • ./mvnw -B spotless:check checkstyle:check clean verify (Java 21 in eclipse-temurin:21-jdk), at the head commit: BUILD SUCCESS, all unit and integration tests pass, JaCoCo coverage 100%.
  • mkdocs build --strict: passes.
  • End to end in kind (Kubernetes 1.37), with the image from this branch, taskmaster/filer 0.12.0, and the namespace labelled pod-security.kubernetes.io/enforce=restricted with a ResourceQuota limits.cpu: 20:
    • With the four security settings (the values from the docs) and FILER_RESOURCES passed through TESK_API_TASKMASTER_ENVIRONMENT_FILER_RESOURCES, a task with an HTTP input and an HTTP output reached COMPLETE and the output was uploaded. The executor ran as uid 100 (alpine image).
    • A second task with cpu_cores: 0.5, ram_gb: 0.5 reached COMPLETE. The executor got limits = requests = {cpu: 500m, memory: 536870912}, and the taskmaster got the defaults 100m/128Mi and 500m/256Mi.
    • Without the security settings, the taskmaster's pod was refused by PodSecurity (allowPrivilegeEscalation != false …), as in 2.0.0. The quota did not refuse it, so the default resources pass the quota.
    • With TESK_API_TASKMASTER_SECURITY_CONTEXT={"allowPrivilegeEscalation": "no"}, the app did not start: Invalid setting tesk.api.taskmaster.security-context: not a valid V1SecurityContext (expected a boolean, …).
    • The taskmaster's peak memory (cgroup memory.peak) was about 80 MB.
    • The e2e ran at the first commit. Later commits only tighten the value checks; the values used in the e2e still pass the unit tests.
    • Manifests are kept outside the repo, because the repo has no kind suite and the smoke test belongs in TESK (follow-up in the chart).
  • CI: all checks passed (Lint, Test, Docs, Smoke test, Scan image, CodeQL, CI passed). Code scanning lists 26 open Trivy alerts for the PR, all medium base-image CVEs (the same CVE IDs repeat; dev has 30 open). This PR changes no dependencies or images, and the scan gate fails only on fixable critical or high findings.

Declined review findings

Two rounds of adversarial-reviewer and quality-reviewer. All high and medium findings were fixed. Declined:

  • Validating resource names and claims, or a server-side dry run of sample jobs at startup. If such values are wrong, the API server refuses them when it creates the jobs, and the docs say so. A dry run at startup would need extra RBAC and depends on the cluster.
  • Bumping the default taskmaster/filer image to 0.12.0. That is release prep and belongs to its own PR; the docs state the requirement instead.
  • A separate binding test for the defaults in application.properties. TesKubernetesConverterMinimalTest and TesKubernetesConverterTest load classpath:application.properties, and their fixtures assert the default taskmaster resources and the executors' CPU, so a broken default fails them.
  • Refactoring the boilerplate in the supplier's constructor, and strictness for Integer fields: the security-context models have none.

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Enable taskmaster and executor pods to run in restricted Kubernetes namespaces and CPU-quota environments with configurable security contexts and resource limits.

New Features:

  • Add opt-in Kubernetes pod and container security context settings for taskmaster and executor pods, including restricted Pod Security Standard support.
  • Add configurable taskmaster resources and default executor CPU settings to support namespaces with CPU quotas.

Bug Fixes:

  • Ensure executor memory specified by a task is applied as both a request and a limit, including when CPU is also specified.

Enhancements:

  • Validate configured Kubernetes objects and resource quantities strictly at startup, including types, fields, IDs, seccomp profiles, non-negative quantities, and request/limit relationships.
  • Merge executor pod security settings with the existing ConfigMap context while preserving compatibility with previous defaults.

Documentation:

  • Document the new pod security, resource, CPU quota, restricted namespace, and upgrade behavior configuration.

Tests:

  • Add coverage for Kubernetes setting validation, security-context merging, resource defaults, executor limits, and environment-variable binding.

uniqueg and others added 4 commits November 21, 2026 17:17
Make task pods admissible in namespaces that enforce the restricted
Pod Security Standard or a ResourceQuota on limits.cpu (#209):

- tesk.api.taskmaster.pod-security-context, .security-context and
  .resources: security contexts and resources of the taskmaster's
  pod, as JSON objects of Kubernetes' objects. No security contexts
  by default, as before; resources default to CPU 100m/500m and
  memory 128Mi/256Mi (requests/limits).
- tesk.api.taskmaster.executor-pod-security-context (on top of the
  ConfigMap CONFIGMAP) and .executor-security-context for the
  executors' pods; none by default.
- tesk.api.taskmaster.executor-default-cpu: CPU request and limit of
  executors whose task sets no cpu_cores (default 1).
- Executors with ram_gb get it as the memory limit too, as the
  taskmaster fills in limits only if there are none at all.

Invalid values (not JSON objects, unknown fields, other types,
invalid quantities, requests above limits) stop the app at startup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Document the new settings (configuration table, a section on pod
security and resources with the values for restricted namespaces and
CPU quotas) and the behaviour changes in the upgrade notes (#209).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refuse duplicate names and non-strict JSON, user and group IDs
outside 0..2147483647, unknown seccomp profile types, and negative
quantities at startup. Document that restricted namespaces and
FILER_RESOURCES need taskmaster 0.12.0, the default CPU vs LimitRange
maxima, and the executors' default CPU in the API docs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Treat JSON null as unset in the value checks of security contexts and
resources (null drops a field of the ConfigMap context in the merge),
refuse content after the JSON object, and cover the checks for
container security contexts too. Review round 2 of #209.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Validate and apply the new taskmaster and executor pod settings, including merging executor pod security settings with the ConfigMap context.

  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/KubernetesObjectsSupplier.java L47-67, L88-128, L274-286 (+4 small edits)
  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/PodSettings.java L1-283

Apply task CPU and RAM as both executor requests and limits, with task CPU overriding the configured default.

  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverter.java L297, L306-319

Configuration

Expose the taskmaster and executor security and resource settings through configuration properties, with defaults supplied by the application configuration.

  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/TaskmasterEnvProperties.java L46-82, L143-190
  • src/main/resources/application.properties L32-43

Documentation

Document the new settings, restricted-cluster and quota guidance, changed API resource defaults, and upgrade implications.

  • docs/api.md L194-200
  • docs/configuration.md L29-34, L50-135
  • docs/deployment.md L73-76
  • docs/upgrading.md L14-51

Tests

Test setting validation and merging, generated taskmaster and executor pod settings, resource defaults and limits, and configuration binding.

  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/KubernetesObjectsSupplierTest.java L4-23, L46-82, L152-380 (+1 small edits)
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/PodSettingsTest.java L1-241
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/TaskmasterEnvPropertiesTest.java L5-15, L50-83
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverterMinimalTest.java L234, L257-264, L292-296
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverterTest.java L1134-1183
  • src/test/resources/fromTesToK8s/job.json L80-90
  • src/test/resources/fromTesToK8s/taskmaster_param.json L76-77, L156-157
  • src/test/resources/fromTesToK8s_minimal/job.json L29-32
  • src/test/resources/fromTesToK8s_minimal/taskmaster_param.json L40-45

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 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (66a1d7b) to head (3f51498).

Additional details and impacted files
@@            Coverage Diff             @@
##               dev      #210    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           53        54     +1     
  Lines         2340      2506   +166     
  Branches       274       291    +17     
==========================================
+ Hits          2340      2506   +166     

☔ 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 21, 2026 19:38
@sourcery-ai

sourcery-ai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Linked issues

Checked at commit 3f51498

#209 feat: make task pods restricted-ready · 7 of 9 met · 1 to check by hand

# Requirement Status Notes
1 Configure pod and container security contexts for taskmaster pods; default to none. ✅ Met The new taskmaster settings are applied to the job pod and container, and empty settings leave them unset.
2 Configure executor pod and container security contexts on top of the existing ConfigMap context; keep the defaults unchanged. ✅ Met The executor pod setting merges over the ConfigMap context, including null-field removal; empty settings preserve the ConfigMap context, and container settings default to none.
3 Document the security settings and test defaults, overrides, empty objects, and invalid values. ✅ Met Configuration and restricted-cluster guidance are documented, and tests cover unset and empty values, overrides, ConfigMap merging, and invalid settings.
4 Add the TESK chart settings, chart documentation, and a restricted-kind smoke test as a follow-up. ❌ Not addressed The change does not include the TESK chart or smoke test; the PR description says the smoke test belongs in TESK as a follow-up.
5 Complete a task with input and output in a namespace enforcing restricted and a limits.cpu quota. 👀 Check by hand (runtime) The PR description reports a successful kind end-to-end run, but a person must independently verify task completion against a real restricted namespace and quota.
6 Without security settings, preserve the taskmaster and executor pod security contexts from 2.0.0. ✅ Met Tests confirm that unset settings leave the taskmaster contexts unset and preserve the executor's existing ConfigMap-based behavior.
7 Give taskmaster pods configurable resource requests and limits with small defaults so they pass a CPU quota. ✅ Met Taskmaster resources default to CPU 100m/500m and memory 128Mi/256Mi, are configurable, and are documented with quota guidance.
8 Give executors a configurable default CPU request and limit when cpu_cores is absent, and make ram_gb both the memory request and limit. ✅ Met The executor template supplies the default CPU, task cpu_cores replaces it, and the converter sets the memory request and limit from ram_gb.
9 Test and document resource defaults and overrides. ✅ Met Tests cover executor default CPU, task-specified CPU and RAM limits, and taskmaster resource settings; the configuration and upgrade documentation describe the defaults and overrides.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 4 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/PodSettings.java" line_range="105" />
<code_context>
+        if (present(json, "supplementalGroups")) {
+            json.getAsJsonArray("supplementalGroups").asList().stream()
+                    .filter(id -> !id.isJsonNull())
+                    .forEach(id -> checkId("supplementalGroups", id));
+        }
+        if (present(json, "seccompProfile")) {
</code_context>
<issue_to_address>
**Null groups become GID zero**

When `supplementalGroups` contains a null element, `checkValues` skips null entries without removing them, and `fromJson` preserves them in `supplementalGroups`; Kubernetes decodes the null as GID 0, potentially granting root-group access or causing admission to reject the pod.

Reject null `supplementalGroups` entries during validation instead of skipping them.
</issue_to_address>

### Comment 2
<location path="src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/PodSettings.java" line_range="115" />
<code_context>
+                throw new IllegalArgumentException(
+                        "seccompProfile.type must be one of " + SECCOMP_TYPES);
+            }
+            if ("Localhost".equals(profileType) != present(profile, "localhostProfile")) {
+                throw new IllegalArgumentException(
+                        "seccompProfile.localhostProfile must be set with the type Localhost only");
</code_context>
<issue_to_address>
**Empty profile paths reach Kubernetes**

When a security-context setting has `seccompProfile.type` set to `Localhost` and `localhostProfile` set to `""`, `present` treats the empty string as set, so `PodSettings.object` accepts the profile and Kubernetes rejects the affected pod when it is created; tasks using that context fail.

Require `localhostProfile` to be non-empty when `seccompProfile.type` is `Localhost`.
</issue_to_address>

### Comment 3
<location path="src/main/resources/application.properties" line_range="38" />
<code_context>
+#No security contexts by default; see docs/configuration.md for those of the restricted Pod Security Standard
+tesk.api.taskmaster.pod-security-context=
+tesk.api.taskmaster.security-context=
+tesk.api.taskmaster.resources={"requests": {"cpu": "100m", "memory": "128Mi"}, "limits": {"cpu": "500m", "memory": "256Mi"}}
+tesk.api.taskmaster.executor-pod-security-context=
+tesk.api.taskmaster.executor-security-context=
</code_context>
<issue_to_address>
**LimitRange rejects taskmaster pods**

When the namespace has a `LimitRange` whose minimum exceeds a configured request or whose maximum is below a configured limit, the default taskmaster resources request 100m CPU and 128Mi memory and limit CPU to 500m and memory to 256Mi. Kubernetes rejects the taskmaster pod when those values conflict with the namespace’s `LimitRange`, leaving tasks queued; TESK API does not check or adapt the defaults.

Make the taskmaster resource defaults compatible with the namespace’s `LimitRange`, or let operators configure them to match its constraints.
</issue_to_address>

### Comment 4
<location path="src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/KubernetesObjectsSupplier.java" line_range="279" />
<code_context>
+        if (this.executorDefaultCpu != null) {
+            resources
+                    .putRequestsItem(RESOURCE_CPU_KEY, this.executorDefaultCpu)
+                    .putLimitsItem(RESOURCE_CPU_KEY, this.executorDefaultCpu);
+        }
+        V1Container container =
</code_context>
<issue_to_address>
**Deployment guidance misstates executor limits**

When the default executor CPU is enabled, `executorDefaultCpu` defaults to `1`, so `executorTemplate` includes a CPU limit in executor jobs sent to the taskmaster. A deployment operator following the older guidance may expect limits to be omitted and copied from requests, but that no longer describes the default job shape.

Update `docs/deployment.md` to explain that the default executor jobs include a CPU limit, and that the taskmaster copies requests to limits only when no limits are present.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 3 findings to address first, and the new CPU and memory settings can constrain or prevent task pods from running, and configured security contexts change how those pods run. Reverting stops these settings from being applied to new jobs, but jobs already created keep them; affected tasks can generally be cancelled and rerun.

Blocking findings: src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/PodSettings.java:105, src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/PodSettings.java:115, src/main/resources/application.properties:38


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

Address automated review of #210: refuse null supplementalGroups
elements and an empty localhostProfile, and document LimitRange
bounds for the taskmaster defaults and the executors' limits in the
deployment guide.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit b87b051 into dev Nov 21, 2026
25 checks passed
@uniqueg
uniqueg deleted the feat/209-restricted-pods branch November 21, 2026 20:02
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: make task pods restricted-ready

1 participant