fix(server,k8s): propagate template container securityContext to pods - #1564
Merged
Pangjiping merged 3 commits intoAug 19, 2026
Conversation
The template container's securityContext was dropped when creating BatchSandbox workloads: merge_with_runtime_values replaces the runtime containers list wholesale, and only volumeMounts were carried forward. Extract the template main container's securityContext and merge it into the generated pod's main container, supplementing the runtime securityContext key-by-key so network-policy/isolation wiring keeps precedence. Closes opensandbox-group#1556 Co-Authored-By: Claude <noreply@anthropic.com>
gegemeimingzi
requested review from
Generalwin,
Pangjiping,
hittyt,
jwx0925 and
ninan-nn
as code owners
August 18, 2026 14:52
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b50a029365
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
The previous merge only setdefault'd at the top level, so when the runtime container already had a securityContext (e.g. capabilities.drop from network-policy wiring), a template's nested members such as capabilities.add never reached the generated Pod. Merge nested dicts recursively, keeping runtime precedence on actual conflicting leaves. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1556
Problem
When creating a
BatchSandboxworkload from a template, the pod-levelsecurityContextfrom the template is applied, but the container-levelsecurityContextis silently dropped from the generated Pod.Root cause:
merge_with_runtime_values→_deep_mergereplaces lists wholesale, so the runtime manifest's owncontainerslist replaces the template's containers entirely._merge_pod_spec_extrasonly carried forward the template container'svolumeMounts, so any other container-level fields (includingsecurityContext) were lost.Fix
Extract the template main container's
securityContextalongside the existing volumes/mounts and merge it back into the generated pod's main container.securityContextis applied when the runtime container has none (the reported case).securityContext(e.g. thecapabilities.drop: [NET_ADMIN]set by network-policy wiring), template keys supplement it key-by-key and runtime keys keep precedence — same "supplement, don't override" philosophy the code already uses forvolumeMounts.Tests
test_create_workload_applies_template_container_security_context— template container securityContext now reaches the generated Pod's main container (template image still does not override the runtime image).test_create_workload_merges_template_security_context_with_runtime_network_policy— template keys supplement, network-policy capabilities keep precedence.Verified: full
server/tests/k8s/suite passes (584 tests),ruff checkclean.