In Kubernetes, each Pod runs with a specific User ID (UID) and Group ID (GID) to ensure security and proper access control. By default, Pods may run as the root user (UID 0), which can pose security risks. To enhance security, it's recommended to assign non-root UIDs and GIDs to Pods.
ACP allows to auto assign a namespace with specific UID and GID ranges to ensure that all Pods within the namespace run with the designated user and group IDs.
To enable UID/GID assignment for a namespace, follow these steps:
security.cpaas.io/enabled
and value true
, click Update. (To disable, remove this label or set the value to false
.)In the namespace details page, you can view the assigned UID and GID ranges in the Annotations.
The security.cpaas.io/uid-range annotation specifies the range of UID/GIDs that can be assigned to Pods in the namespace, e.g. security.cpaas.io/uid-range=1000002000-1000011999, means the uid/gid range is between 1000002000 to 1000011999.
If the pod does not specify runAsUser
and fsGroup
in the securityContext
, the platform will automatically assign the first value from the assigned uid range.
Create a Pod in the namespace with the following YAML configuration:
After the Pod is created, get the Pod yaml to check the assigned UID and GID:
the Pod YAML will show the assigned UID and GID in the securityContext
section:
If the pod specifies runAsUser and fsGroup in the securityContext, the platform will validate if the specified UID/GID are within the assigned range. If they are not, the Pod creation will fail.
Create a Pod in the namespace with the following YAML configuration:
After applying the YAML, the Pod creation will fail with an error message indicating that the specified UID/GID are outside the assigned range.