Answers: <p>maybe overrides can be helpful here</p>
  <pre><code>kubectl --kubeconfig ./kubeconfig run curly --image=curlimages/curl --rm -it --restart=Never --overrides='
  {
    &quot;apiVersion&quot;: &quot;v1&quot;,
    &quot;spec&quot;: {
      &quot;securityContext&quot;: {
        &quot;allowPrivilegeEscalation&quot;: false,
        &quot;runAsNonRoot&quot;: true
      }
    }
  }' -- /bin/sh
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2024-03-27T08:45:15.827Z
Answers: That gave a CreateContainerConfigError  container has runAsNonRoot and image has non-numeric user. but yeah I did not know you could override the run command
Answers: Serve Laurijssen
Answers: CC BY-SA 4.0
Answers: 2024-03-27T07:59:18.513Z
Answers: 2024-03-27T07:59:18.513Z
Answers: Eladik
Body: <p>I often use curl image to test out connectivity inside clusters:</p>
  <p><code>kubectl --kubeconfig ./kubeconfig run curly --image=curlimages/curl --rm -it --restart=Never -- /bin/sh  </code></p>
  <p>However, with k8s v1.27+ a warning is emitted:</p>
  <pre><code>Warning: would violate PodSecurity &quot;restricted:latest&quot;: allowPrivilegeEscalation != false 
  (container &quot;curly&quot; must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container &quot;curly&quot; must set securityContext.capabilities.drop=[&quot;ALL&quot;]), 
  runAsNonRoot != true (pod or container &quot;curly&quot; must set securityContext.runAsNonRoot=true), seccompProfile (pod or container &quot;curly&quot; must set securityContext.seccompProfile.type to &quot;RuntimeDefault&quot; or &quot;Localhost&quot;)
  </code></pre>
  <p>I cant create a pod.yaml to set all these values as the pod needs to be interactive so how can I get rid of this warning?</p>
  
Tags: <kubernetes>
Title: get rid of PodSecurity warnings
UserDisplayName: Serve Laurijssen
ThreadText: # get rid of PodSecurity warnings
  
  (Asked by: username_0 on 2024-03-26)
  
  I often use curl image to test out connectivity inside clusters:
  
  `kubectl --kubeconfig ./kubeconfig run curly --image=curlimages/curl --rm -it --restart=Never -- /bin/sh`
  
  However, with k8s v1.27+ a warning is emitted:
  
  ```
  Warning: would violate PodSecurity "restricted:latest": allowPrivilegeEscalation != false 
  (container "curly" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "curly" must set securityContext.capabilities.drop=["ALL"]), 
  runAsNonRoot != true (pod or container "curly" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container "curly" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
  
  ```
  
  I cant create a pod.yaml to set all these values as the pod needs to be interactive so how can I get rid of this warning?
  
  **Tags:** kubernetes
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-03-27. Score: 1
  
  maybe overrides can be helpful here
  
  ```
  kubectl --kubeconfig ./kubeconfig run curly --image=curlimages/curl --rm -it --restart=Never --overrides='
  {
    "apiVersion": "v1",
    "spec": {
      "securityContext": {
        "allowPrivilegeEscalation": false,
        "runAsNonRoot": true
      }
    }
  }' -- /bin/sh
  
  ```
  
  > **Comments:**
  > **username_0**: That gave a CreateContainerConfigError  container has runAsNonRoot and image has non-numeric user. but yeah I did not know you could override the run command  
  
  ---
  
  