Skip to content

Commit dc05897

Browse files
bpareesadellape
authored andcommitted
better uid permissions example
1 parent 5130615 commit dc05897

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

creating_images/guidelines.adoc

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -267,21 +267,29 @@ xref:s2i.adoc#creating-images-s2i[S2I Requirements] topic.
267267
[[use-uid]]
268268
*Support Arbitrary User IDs*
269269

270-
In order to support running containers with volumes mounted in a secure fashion,
271-
images should be capable of being run as any arbitrary user ID. When
272-
{product-title} mounts volumes for a container, it configures the volume so it
273-
can only be written to be a particular user ID, and then runs the image using
274-
that same user ID. This ensures the volume is only accessible to the appropriate
275-
container, but requires the image be able to run as an arbitrary user ID.
276-
277-
Running a container with an arbitrary user ID also has the benefit of ensuring
278-
that a process which is able to escape the container due to a vulnerability in
279-
the container framework will not have specific user permissions on the host
280-
system.
281-
282-
To accomplish this, directories that must be written to by processes in the
283-
image should be world-writable. In addition, the processes running in the
284-
container must not listen on privileged ports (ports below 1024).
270+
To provide additional security against processes escaping the container due
271+
to a container engine vulnerability and thereby achieving escalated permissions
272+
on the host node, {product-title} runs containers using an arbitrarily assigned uid by default.
273+
274+
For an image to support running as an arbitray user, directories and files that may be
275+
written to by processes in the image should be owned by the root group and read/writable
276+
by that group. Files to be executed should also have group execute permissions. The following
277+
Dockerfile fragment sets root group ownership and permissions for *_/some/directory_* and all child
278+
directories:
279+
280+
----
281+
RUN chgrp -R 0 /some/directory
282+
RUN chmod -R g+rw /some/directory
283+
RUN find /some/directory -type d -exec chmod g+x {} +
284+
----
285+
286+
Adding these commands to your Dockerfile sets the directory and file permissions to allow users
287+
in the root group to access them in the built image. Because the container user is always a member
288+
of the root group, the container user can read and write these files. The root group does not have
289+
any special permissions (unlike the root user) so there are no security concerns with this arrangement.
290+
291+
In addition, the processes running in the container must not listen on privileged ports (ports below
292+
1024), since they are not running as a privileged user.
285293

286294
Because the user ID of the container is generated dynamically, it will not have
287295
an associated entry in *_/etc/passwd_*. This can cause problems for applications

install_config/persistent_storage/pod_security_context.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ It may not be immediately obvious which SCC was matched by a pod, so the command
127127
above can be very useful in understanding the UID, supplemental groups, and
128128
SELinux relabeling in a live container.
129129

130-
Any SCC with a strategy set to *RunAsAny* allows arbitrary values for that
130+
Any SCC with a strategy set to *RunAsAny* allows specific values for that
131131
strategy to be defined in the pod definition (and/or image). When this applies
132132
to the user ID (`*runAsUser*`) it is prudent to restrict access to the SCC to
133133
prevent a container from being able to run as root.
@@ -305,7 +305,7 @@ general, containers should not run as root, so in this NFS example, containers
305305
which are not run as UID *65534* or are not members the group *5555* will not be
306306
able to access the NFS export.
307307

308-
Often, the SCC matching the pod does not allow an arbitrary user ID to be
308+
Often, the SCC matching the pod does not allow a specific user ID to be
309309
specified, thus using supplemental groups is a more flexible way to grant
310310
storage access to a pod. For example, to grant NFS access to the export above,
311311
the group *5555* can be defined in the pod definition:

0 commit comments

Comments
 (0)