Repository navigation
feat: make task pods restricted-ready - #210
Conversation
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]>
Reviewer's GuideImplementationValidate and apply the new taskmaster and executor pod settings, including merging executor pod security settings with the ConfigMap context.
Apply task CPU and RAM as both executor requests and limits, with task CPU overriding the configured default.
ConfigurationExpose the taskmaster and executor security and resource settings through configuration properties, with defaults supplied by the application configuration.
DocumentationDocument the new settings, restricted-cluster and quota guidance, changed API resource defaults, and upgrade implications.
TestsTest setting validation and merging, generated taskmaster and executor pod settings, resource defaults and limits, and configuration binding.
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 #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. 🚀 New features to boost your workflow:
|
Linked issuesChecked at commit 3f51498 #209 feat: make task pods restricted-ready · 7 of 9 met · 1 to check by hand
|
There was a problem hiding this comment.
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
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]>
Summary
Makes task pods admissible in namespaces that enforce the
restrictedPod Security Standard and/or aResourceQuotaonlimits.cpu(CERIT-SC), opt-in for the security part.New settings (prefix
tesk.api.taskmaster., env varsTESK_API_TASKMASTER_*):pod-security-contextTESK_API_TASKMASTER_POD_SECURITY_CONTEXTsecurity-contextTESK_API_TASKMASTER_SECURITY_CONTEXTresourcesTESK_API_TASKMASTER_RESOURCES{"requests": {"cpu": "100m", "memory": "128Mi"}, "limits": {"cpu": "500m", "memory": "256Mi"}}executor-pod-security-contextTESK_API_TASKMASTER_EXECUTOR_POD_SECURITY_CONTEXTCONFIGMAPcontext, which still works)executor-security-contextTESK_API_TASKMASTER_EXECUTOR_SECURITY_CONTEXTexecutor-default-cpuTESK_API_TASKMASTER_EXECUTOR_DEFAULT_CPU1(request and limit when the task sets nocpu_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:"true","1000"or1.5;JSON
nullcounts as unset. In the executor pod context, it removes the field that comes from the ConfigMap.Executors with
ram_gbalso get it as their memory limit, including whencpu_coresis 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 andFILER_RESOURCESneed 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 ineclipse-temurin:21-jdk), at the head commit: BUILD SUCCESS, all unit and integration tests pass, JaCoCo coverage 100%.mkdocs build --strict: passes.pod-security.kubernetes.io/enforce=restrictedwith aResourceQuotalimits.cpu: 20:FILER_RESOURCESpassed throughTESK_API_TASKMASTER_ENVIRONMENT_FILER_RESOURCES, a task with an HTTP input and an HTTP output reachedCOMPLETEand the output was uploaded. The executor ran as uid 100 (alpine image).cpu_cores: 0.5, ram_gb: 0.5reachedCOMPLETE. The executor gotlimits = requests = {cpu: 500m, memory: 536870912}, and the taskmaster got the defaults 100m/128Mi and 500m/256Mi.allowPrivilegeEscalation != false …), as in 2.0.0. The quota did not refuse it, so the default resources pass the quota.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, …).memory.peak) was about 80 MB.devhas 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-reviewerandquality-reviewer. All high and medium findings were fixed. Declined: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.application.properties.TesKubernetesConverterMinimalTestandTesKubernetesConverterTestloadclasspath:application.properties, and their fixtures assert the default taskmaster resources and the executors' CPU, so a broken default fails them.Integerfields: 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:
Bug Fixes:
Enhancements:
Documentation:
Tests: