Skip to content

Commit 7d6a2b9

Browse files
authored
Change default container user to root (#364)
* Change default container user to root * Continuing to use upstream image for the time being * Change default container user to root * Continuing to use upstream image for the time being
1 parent 765c16c commit 7d6a2b9

File tree

7 files changed

+8
-33
lines changed

7 files changed

+8
-33
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ansible-dev-container-codespaces",
33
"image": "ghcr.io/ansible/community-ansible-dev-tools:latest",
4-
"containerUser": "podman",
4+
"containerUser": "root",
55
"runArgs": [
66
"--security-opt",
77
"seccomp=unconfined",

.devcontainer/docker/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ansible-dev-container-docker",
33
"image": "ghcr.io/ansible/community-ansible-dev-tools:latest",
4-
"containerUser": "podman",
4+
"containerUser": "root",
55
"runArgs": [
66
"--security-opt",
77
"seccomp=unconfined",

.devcontainer/podman/devcontainer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
"--security-opt",
1515
"apparmor=unconfined",
1616
"--userns=host",
17-
"--hostname=ansible-dev-container",
18-
"--volume",
19-
"ansible-dev-tools-container-storage:/var/lib/containers"
17+
"--hostname=ansible-dev-container"
2018
],
2119
"customizations": {
2220
"vscode": {

docs/container.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ podman run -it --rm \
9696
--user=root \
9797
--userns=host \
9898
-e SSH_AUTH_SOCK=$SSH_AUTH_SOCK \
99-
-v ansible-dev-tools-container-storage:/var/lib/containers \
10099
-v $HOME/.gitconfig:/root/.gitconfig \
101100
-v $PWD:/workdir \
102101
-v $SSH_AUTH_SOCK:$SSH_AUTH_SOCK \
@@ -111,7 +110,6 @@ Note:
111110
- This command will mount the current directory to `/workdir` in the container
112111
- The SSH agent socket is also mounted to the container to allow for SSH key forwarding.
113112
- The user's `.gitconfig` is mounted to the container to allow for git operations.
114-
- The `ansible-dev-tools-container-storage` volume is mounted to the container to store the nested container images on the host.
115113

116114
### Signing git commits (SSH)
117115

final/Containerfile

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,10 @@ python3-wheel \
5454
&& microdnf clean all \
5555
&& ln -s /usr/bin/vim /usr/bin/vi
5656

57-
RUN useradd podman; \
58-
echo -e "podman:1:999\npodman:1001:64535" > /etc/subuid; \
59-
echo -e "podman:1:999\npodman:1001:64535" > /etc/subgid;
60-
6157
ARG _REPO_URL="https://raw.githubusercontent.com/containers/image_build/main/podman"
6258
ADD $_REPO_URL/containers.conf /etc/containers/containers.conf
63-
ADD $_REPO_URL/podman-containers.conf /home/podman/.config/containers/containers.conf
64-
65-
RUN mkdir -p /home/podman/.local/share/containers && \
66-
chown podman:podman -R /home/podman && \
67-
chmod 644 /etc/containers/containers.conf
6859

69-
# this is done by ansible-builder when changing user and workdir
70-
RUN chgrp 0 /home/podman && chmod -R ug+rwx /home/podman
60+
RUN chmod 644 /etc/containers/containers.conf
7161

7262
# Copy & modify the defaults to provide reference if runtime changes needed.
7363
# Changes here are required for running with fuse-overlay storage inside container.
@@ -80,7 +70,6 @@ RUN sed -e 's|^#mount_program|mount_program|g' \
8070
# Note VOLUME options must always happen after the chown call above
8171
# RUN commands can not modify existing volumes
8272
VOLUME /var/lib/containers
83-
VOLUME /home/podman/.local/share/containers
8473

8574
RUN mkdir -p /var/lib/shared/overlay-images \
8675
/var/lib/shared/overlay-layers \
@@ -125,8 +114,6 @@ RUN \
125114
mkdir -p ~/.ansible/roles /usr/share/ansible/roles /etc/ansible/roles && \
126115
git config --system --add safe.directory /
127116

128-
# The dev container for docker runs as podman
129-
RUN chsh -s $(which zsh) podman
130117
# The dev container for docker runs as root
131118
RUN chsh -s $(which zsh) root
132119

@@ -136,10 +123,7 @@ python3 -m pip install argcomplete
136123
activate-global-python-argcomplete
137124
EOF
138125

139-
# Install oh-my-zsh for both users
140-
USER podman
141-
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
142-
126+
# Install oh-my-zsh
143127
USER root
144128
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
145129

@@ -158,11 +142,9 @@ RUN set -ex \
158142
&& rpm -qa \
159143
&& uname -a
160144

161-
# Make a workdir usable by either the podman or root user
162-
RUN mkdir -p /workdir && chown podman:podman /workdir
145+
# Make a workdir usable by the root user
146+
RUN mkdir -p /workdir
163147

164-
# Set the default user to podman, this will be overridden in the podman dev container
165-
USER podman
166148
WORKDIR /workdir
167149
ENTRYPOINT ["/opt/builder/bin/entrypoint", "dumb-init"]
168150
CMD ["zsh"]

tests/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ def pytest_sessionfinish(session: pytest.Session) -> None:
256256
--security-opt "label=disable"
257257
--security-opt "seccomp=unconfined"
258258
-v $PWD:/workdir
259-
-v ansible-dev-tools-container-test-storage-podman:/var/lib/containers
260259
"""
261260

262261
PODMAN_CMD = """ --user=root

tests/integration/test_container.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_container_in_container(
5757
exec_container: The container executor.
5858
"""
5959
podman_run_container = exec_container(
60-
"podman run -i --rm -d -e ANSIBLE_DEV_TOOLS_CONTAINER=1"
60+
"podman run -i --rm -d -e ANSIBLE_DEV_TOOLS_CONTAINER=1 --user=root"
6161
" -e ANSIBLE_FORCE_COLOR=0 --name ghcr_io_ansible_community_ansible_dev_tools_latest"
6262
" ghcr.io/ansible/community-ansible-dev-tools:latest bash",
6363
)
@@ -93,8 +93,6 @@ def test_user_shell(exec_container: Callable[[str], subprocess.CompletedProcess[
9393
"""
9494
result = exec_container("cat /etc/passwd | grep root | grep zsh")
9595
assert result.returncode == 0, "zsh not found in /etc/passwd"
96-
result = exec_container("cat /etc/passwd | grep podman | grep zsh")
97-
assert result.returncode == 0, "zsh not found in /etc/passwd"
9896

9997

10098
@pytest.mark.container()

0 commit comments

Comments
 (0)