SYS_TIME and NET_ADMIN. Each step preserves the original sequence and provides validation commands.
Use
kubectl exec to run whoami or id -u inside a container to determine which user or UID the process is running as. whoami prints a username (if one exists for the UID), while id -u prints the numeric UID.1) Which user is used to execute the sleep process inside the ubuntu-sleeper Pod?
First confirm the Pod exists, then exec into it:whoami may not return a username—use id -u instead:
2) Edit the ubuntu-sleeper Pod so the sleep process runs with UID 1010
Steps to change the Pod to run as UID1010:
- Export the Pod manifest to a file so you can make the required change:
- Edit
ubuntu-sleeper.yaml. Add (or update) the Pod-levelsecurityContext.runAsUserunderspec:
- Delete and recreate the Pod. Many Pod fields cannot be updated in-place, so recreate the Pod after editing the manifest.
Using
--force and immediate deletion can leave the old process running on the node briefly. Prefer graceful deletion when possible.- Validate the numeric UID inside the container:
3) Given multi-pod.yaml: with what user are processes in the web container started?
Inspect the manifest. The Pod-level securityContext sets runAsUser: 1001, but the web container has its own container-level securityContext:
web container runs as UID 1002.
Answer: 1002
Container-level
securityContext overrides Pod-level securityContext for properties such as runAsUser.4) With what user are processes in the sidecar container started?
The sidecar container has no container-level securityContext, so it inherits the Pod-level runAsUser: 1001.
Answer: 1001
5) Update the ubuntu-sleeper Pod to run as root and add the SYS_TIME capability
To run as root and grant theSYS_TIME capability to the container:
- Edit
ubuntu-sleeper.yaml. You can either removerunAsUserso the container uses the default (root), or explicitly set it to0. Add a container-levelsecurityContext.capabilities.addlist that includesSYS_TIME. Example (remove Pod-levelrunAsUserto rely on the default root):
- Recreate the Pod:
- Validate capability and UID as needed. Checking effective capabilities often requires tools inside the image (e.g.,
capsh), or you can verify that operations requiringSYS_TIMEsucceed.
6) Add the NET_ADMIN capability to the Pod
To addNET_ADMIN, include it in the container capabilities.add list alongside SYS_TIME. Example:
Quick answers summary
Validation tips and references
- Use
kubectl exec -it <pod> -- id -uto see the numeric UID. - To inspect capabilities inside a running container you may need utilities like
capshor run a small privileged debug container. - For more details:
- Kubernetes Pod Security Context: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/
- Kubernetes Containers Security Context: https://kubernetes.io/docs/concepts/policy/pod-security-policy/ (and related security docs)
- Linux capabilities overview: https://man7.org/linux/man-pages/man7/capabilities.7.html
SYS_TIME and NET_ADMIN.