Skip to contentSkip to conversation

support/docker/Dockerfile: make $HOME folder read-only

PATCH Applied Thomas Petazzoni via buildroot 2 participants 3 messages Dec 26, 2025 – Oct 16

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 support/docker/Dockerfile: make $HOME folder read-only

The $HOME folder of the br-user inside the container is currently read-write for the br-user. However, practically speaking, it is only read-write when the UID of the user running the container from the host machine is 1000, equal to the UID of the br-user inside the container. For any other UID on the host machine, the $HOME folder is in fact already read-only.

Because we do not expect Buildroot to write into $HOME, and in order to have a consistent behavior regardless of the UID of the user on the host machine, we change our Docker image to make the $HOME folder of the br-user entirely non-writable.

---
Of course, once this is accepted, follow-up patches will be submitted to update our reference Docker image.

---
 support/docker/Dockerfile | 4 ++++
 1 file changed, 4 insertions(+)
support/docker/Dockerfile +4 -0
index e7677ac6a9..cb3fdba151 100644
@@ -92,6 +92,10 @@ RUN sed -i 's/# \(en_US.UTF-8\)/\1/' /etc/locale.gen && \
 RUN useradd -ms /bin/bash br-user && \
     chown -R br-user:br-user /home/br-user
 
+# Make the br-user home directory not writable, even for br-user
+# itself, to catch builds writing into $HOME
+RUN chmod 555 /home/br-user
+
 USER br-user
 WORKDIR /home/br-user
 ENV HOME=/home/br-user
Signature · 6 lines
2.52.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

On 12/26/25 15:59, Thomas Petazzoni wrote:

Hi,

Quoted 7 lines

The $HOME folder of the br-user inside the container is currently read-write for the br-user. However, practically speaking, it is only read-write when the UID of the user running the container from the host machine is 1000, equal to the UID of the br-user inside the container. For any other UID on the host machine, the $HOME folder is in fact already read-only.

Quoted 7 lines

Because we do not expect Buildroot to write into $HOME, and in order to have a consistent behavior regardless of the UID of the user on the host machine, we change our Docker image to make the $HOME folder of the br-user entirely non-writable.

Sorry for the delay. Committed, thanks.

--
Bye, Peter Korsgaard

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#2 lore raw
In reply to Thomas Petazzoni via buildroot

In reply of:

Quoted 7 lines

The $HOME folder of the br-user inside the container is currently read-write for the br-user. However, practically speaking, it is only read-write when the UID of the user running the container from the host machine is 1000, equal to the UID of the br-user inside the container. For any other UID on the host machine, the $HOME folder is in fact already read-only.

Quoted 7 lines

Because we do not expect Buildroot to write into $HOME, and in order to have a consistent behavior regardless of the UID of the user on the host machine, we change our Docker image to make the $HOME folder of the br-user entirely non-writable.

Applied to 2025.02.x, 2026.08.x. Thanks

Quoted 12 lines

---
Of course, once this is accepted, follow-up patches will be submitted to update our reference Docker image.

---
 support/docker/Dockerfile | 4 ++++
 1 file changed, 4 insertions(+)
support/docker/Dockerfile +0 -0
index e7677ac6a9..cb3fdba151 100644

support/docker/Dockerfile RUN sed -i 's/# \(en_US.UTF-8\)/\1/' /etc/locale.gen && \ · line 101

Quoted 10 lines
support/docker/Dockerfile +4 -0
@@ -92,6 +92,10 @@ RUN sed -i 's/# \(en_US.UTF-8\)/\1/' /etc/locale.gen && \
 RUN useradd -ms /bin/bash br-user && \
     chown -R br-user:br-user /home/br-user
 
+# Make the br-user home directory not writable, even for br-user
+# itself, to catch builds writing into $HOME
+RUN chmod 555 /home/br-user
+
 USER br-user
 WORKDIR /home/br-user
 ENV HOME=/home/br-user

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot