mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 18:02:01 +00:00
Merge pull request #116366 from ardaguclu/fix-shareprocess-explicit
kubectl debug: Not share process namespace if user explicitly disables it
This commit is contained in:
commit
3ed9c61864
@ -1201,6 +1201,46 @@ func TestGeneratePodCopyWithDebugContainer(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "baseline profile not share process when user explicitly disables it",
|
||||||
|
opts: &DebugOptions{
|
||||||
|
CopyTo: "debugger",
|
||||||
|
Container: "debugger",
|
||||||
|
Image: "busybox",
|
||||||
|
PullPolicy: corev1.PullIfNotPresent,
|
||||||
|
Profile: ProfileBaseline,
|
||||||
|
ShareProcesses: false,
|
||||||
|
shareProcessedChanged: true,
|
||||||
|
},
|
||||||
|
havePod: &corev1.Pod{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "target",
|
||||||
|
},
|
||||||
|
Spec: corev1.PodSpec{
|
||||||
|
Containers: []corev1.Container{
|
||||||
|
{
|
||||||
|
Name: "debugger",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
NodeName: "node-1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantPod: &corev1.Pod{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "debugger",
|
||||||
|
},
|
||||||
|
Spec: corev1.PodSpec{
|
||||||
|
Containers: []corev1.Container{
|
||||||
|
{
|
||||||
|
Name: "debugger",
|
||||||
|
Image: "busybox",
|
||||||
|
ImagePullPolicy: corev1.PullIfNotPresent,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ShareProcessNamespace: pointer.Bool(false),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "restricted profile",
|
name: "restricted profile",
|
||||||
opts: &DebugOptions{
|
opts: &DebugOptions{
|
||||||
|
@ -250,8 +250,10 @@ func useHostNamespaces(p *corev1.Pod) {
|
|||||||
// shareProcessNamespace configures all containers in the pod to share the
|
// shareProcessNamespace configures all containers in the pod to share the
|
||||||
// process namespace.
|
// process namespace.
|
||||||
func shareProcessNamespace(p *corev1.Pod) {
|
func shareProcessNamespace(p *corev1.Pod) {
|
||||||
|
if p.Spec.ShareProcessNamespace == nil {
|
||||||
p.Spec.ShareProcessNamespace = pointer.Bool(true)
|
p.Spec.ShareProcessNamespace = pointer.Bool(true)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// clearSecurityContext clears the security context for the container.
|
// clearSecurityContext clears the security context for the container.
|
||||||
func clearSecurityContext(p *corev1.Pod, containerName string) {
|
func clearSecurityContext(p *corev1.Pod, containerName string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user