Checking the User of a Running Pod
To determine which user is executing the sleep process inside an Ubuntu sleeper pod, follow these steps:-
List the Pods
Identify the Ubuntu sleeper pod by listing all pods: -
Access the Pod
Usekubectl execto access the pod’s shell: -
Verify the User Inside the Container
Once inside, run the command:The expected output should be:
Updating the Pod to Run as a Specific Non-Root User (UID 1010)
To update the Ubuntu sleeper pod so that the process runs with the user ID 1010, follow these steps:-
Export the Current Pod Configuration
Retrieve the current configuration and save it to a file: -
Edit the Configuration File
Openubuntu-sleeper.yamlin your favorite text editor. Locate the pod’ssecurityContext, which should currently look like: -
Modify the Security Context
Update the file by adding therunAsUserproperty with UID 1010: -
Apply the Updated Configuration
Save the changes, then delete the existing pod (forcing deletion if necessary) and reapply the configuration:
At the container level, the
securityContext settings override those defined at the pod level.Determining the User for Multiple Containers in a Pod
When dealing with pods that contain multiple containers, it’s important to understand how user contexts are inherited. Consider the following pod definition from themulti-pod.yaml file:
- The pod-level security context sets
runAsUserto 1001. - The web container defines its own
securityContextwithrunAsUser: 1002.
Updating the Ubuntu Sleeper Pod to Run as Root with SYS_TIME Capability
To modify the Ubuntu sleeper pod so that:- The process runs as the default root user.
- The pod is granted the
SYS_TIMEcapability,
-
Edit the Pod Configuration
Open the current configuration file (e.g.,ubuntu-sleeper.yaml), and remove any pod-levelsecurityContextthat enforces a non-root user. -
Add Capabilities at the Container Level
Under the container specification responsible for running the sleep command, add asecurityContextthat includes the required capability:
Adding the NET_ADMIN Capability
To enhance the security context further by adding theNET_ADMIN capability in addition to SYS_TIME, follow these steps:
-
Modify the Container’s Security Context
Open theubuntu-sleeper.yamlfile and update thesecurityContextunder the container section to include both capabilities: -
Apply the Changes
Save the file and reapply the pod configuration by deleting the current pod and applying the updated configuration: -
Verify the Update
Optionally, check that the pod is running with the updated capabilities: