[grid] inherit the Node Pod container securityContext for Dynamic Grid on K8s - #17860
Conversation
…d on K8s Dynamic Grid on Kubernetes inherited only the Node Pod's pod-level securityContext when spawning browser session Pods. Container-level settings such as allowPrivilegeEscalation and capabilities can only be configured on the container securityContext, so spawned Pods could not satisfy the restricted Pod Security Standard. Read the Node Pod's first container securityContext and apply it to the browser and video containers (image mode only, matching how the pod-level securityContext is inherited). Fixes SeleniumHQ#17847 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
PR Summary by Qodo[grid] Inherit Node Pod container SecurityContext for Dynamic Grid sessions on Kubernetes
AI Description
Diagram
High-Level Assessment
Files changed (5)
|
Code Review by Qodo
1. SecurityContext copied wholesale
|
🔗 Related Issues
Fixes #17847
💥 What does this PR do?
When Dynamic Grid scales on Kubernetes, the Node inspects its own Pod and inherits selected spec fields onto the browser session Pods it spawns. Until now only the pod-level
securityContext(PodSecurityContext) was inherited; the container-levelsecurityContextwas left empty.Some settings — notably
allowPrivilegeEscalationandcapabilities— can only be configured on the containersecurityContext, so spawned session Pods could not satisfy arestrictedPod Security Standard.This PR reads the Node Pod's first container
securityContextand applies it to the spawned browser container and the video sidecar, so session Pods can run under therestrictedprofile.🔧 Implementation Notes
KubernetesOptions.inspectNodePodnow readsfirstContainer.getSecurityContext()(container-levelio.fabric8.kubernetes.api.model.SecurityContext) alongside the container fields it already extracts (image pull policy, resource requests/limits).InheritedPodSpeccarries a new@Nullable SecurityContext containerSecurityContextfield (getter + inclusion inhasInheritedFields()). Rather than editing every positional call site, a new constructor overload was added and the existing 15-arg / 17-arg constructors delegate to it withcontainerSecurityContext = null— this keeps their signatures unchanged, matching the incremental-constructor pattern already used in this class fornodePodName/nodePodUid.KubernetesSessionFactoryapplies the inherited containersecurityContextto both thebrowsercontainer and thevideosidecar. All containers in a Pod must comply for therestrictedprofile, so the sidecar is included too.securityContextbehavior: inheritance applies to the auto-generated image mode path only. The template mode path is left fully user-controlled (a user-supplied Job template's containersecurityContextis not overridden).Alternatives considered: exposing a dedicated CLI/config flag to set the container
securityContextexplicitly. Inheritance was chosen to mirror the existing pod-levelsecurityContextbehavior and to make "run the whole Grid underrestricted" work with zero extra configuration. A config override could be layered on later if needed.🤖 AI assistance
securityContext💡 Additional Considerations
securityContextis set only when the Node Pod actually defines one, so default behavior is unchanged (a new test asserts the browser container has nosecurityContextwhen nothing is inherited).securityContext, and documentation for therestrictedPod Security Standard setup.🔄 Types of changes