Skip to content

Commit 8add217

Browse files
authored
Merge pull request #83 from thin-edge/fix-preserve-sudoers-file
fix: preserve tedge's default sudoers rules
2 parents 9d7ddfa + 160731e commit 8add217

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

Dockerfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,13 @@ RUN usermod -u "$USERID" tedge \
6363
&& mkdir -p /etc/tedge/credentials \
6464
&& chown -R tedge:tedge /etc/tedge \
6565
&& chown -R tedge:tedge /var/tedge \
66-
&& echo "tedge ALL = (ALL) NOPASSWD:SETENV: /usr/bin/tedge, /etc/tedge/sm-plugins/[a-zA-Z0-9]*, /bin/sync, /sbin/init, /usr/bin/tedgectl, /bin/kill, /usr/bin/tedge-container, /usr/bin/docker, /usr/bin/podman, /usr/bin/podman-remote, /usr/bin/podman-compose" >/etc/sudoers.d/tedge \
67-
&& echo "tedge ALL = (ALL) NOPASSWD:SETENV: /usr/bin/tedge-write /etc/*" >> /etc/sudoers.d/tedge \
66+
# original tedge settings
67+
&& echo "tedge ALL = (ALL) NOPASSWD:SETENV: /usr/bin/tedge, /etc/tedge/sm-plugins/[a-zA-Z0-9]*, /bin/sync, /sbin/init" > /etc/sudoers.d/tedge \
68+
&& echo "tedge ALL = (ALL) NOPASSWD:SETENV: /usr/bin/tedge-write /etc/*" >> /etc/sudoers.d/tedge \
69+
&& echo "tedge ALL = (ALL) NOPASSWD:SETENV: /usr/share/tedge/log-plugins/[a-zA-Z0-9]*" >> /etc/sudoers.d/tedge \
70+
# additional sudoers rules
71+
&& echo "tedge ALL = (ALL) NOPASSWD:SETENV: /bin/sync, /sbin/init, /usr/bin/tedgectl, /bin/kill" >/etc/sudoers.d/tedge-system \
72+
&& echo "tedge ALL = (ALL) NOPASSWD:SETENV: /usr/bin/tedge-container, /usr/bin/docker, /usr/bin/podman, /usr/bin/podman-remote, /usr/bin/podman-compose" >/etc/sudoers.d/tedge-containers \
6873
&& echo "tedge ALL = (ALL) NOPASSWD:SETENV: /usr/bin/fix-permissions.sh" >> /etc/sudoers.d/tedge-fix-permissions
6974
# Custom init. scripts - e.g. write env variables data to files
7075
COPY cont-init.d/* /etc/cont-init.d/

test-images/common/container-bundle.sh

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,17 @@ bootstrap_certificate() {
172172
tedge cert upload c8y
173173
}
174174

175+
wait_for_path() {
176+
path="$1"
177+
wait_seconds="${2:-30}"
178+
waited=0
179+
while [ ! -e "$path" ] && [ "$waited" -lt "$wait_seconds" ]; do
180+
echo "Waiting for $path ($waited/$wait_seconds)..."
181+
sleep 1
182+
waited=$((waited + 1))
183+
done
184+
}
185+
175186
start() {
176187
CONTAINER_OPTIONS=""
177188

@@ -184,10 +195,13 @@ start() {
184195
podman)
185196
# Mount socket to a path expected by the container under test
186197
# In podman, host.containers.internal is accessible by default
187-
if [ -e /run/podman/podman.sock ]; then
188-
CONTAINER_OPTIONS="$CONTAINER_OPTIONS -v /run/podman/podman.sock:/var/run/docker.sock:rw"
198+
SOCKET_PATH="/run/podman/podman.sock"
199+
# Wait for the podman socket to exist, up to 30 seconds
200+
wait_for_path "$SOCKET_PATH" 30
201+
if [ -e "$SOCKET_PATH" ]; then
202+
CONTAINER_OPTIONS="$CONTAINER_OPTIONS -v $SOCKET_PATH:/var/run/docker.sock:rw"
189203
else
190-
echo "Could not the podman socket"
204+
echo "The podman socket does not exist. path=$SOCKET_PATH"
191205
exit 1
192206
fi
193207
;;

test-images/podman-v4/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
FROM quay.io/containers/podman:v4.4
22
RUN systemctl enable podman.socket \
3+
&& echo "enable podman.socket" > /usr/lib/systemd/system-preset/95-podman.preset \
34
# create systemd-tmpfiles config to create a symlink for docker to the podman socket
45
# which allows using docker and docker compose without having to set the DOCKER_HOST variable
56
# Source: podman-docker debian package

test-images/podman-v5/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
FROM quay.io/containers/podman:v5
22
RUN systemctl enable podman.socket \
3+
&& echo "enable podman.socket" > /usr/lib/systemd/system-preset/95-podman.preset \
34
# create systemd-tmpfiles config to create a symlink for docker to the podman socket
45
# which allows using docker and docker compose without having to set the DOCKER_HOST variable
56
# Source: podman-docker debian package
67
&& echo 'L+ %t/docker.sock - - - - %t/podman/podman.sock' | tee /usr/lib/tmpfiles.d/podman-docker-socket.conf \
7-
&& systemd-tmpfiles --create podman-docker.conf >/dev/null || true
8+
&& systemd-tmpfiles --create podman-docker-socket.conf >/dev/null || true
89
ENTRYPOINT [ "/lib/systemd/systemd" ]

0 commit comments

Comments
 (0)