Skip to content

Commit 069df69

Browse files
authored
Switch to su to run telegraf as non-root (#544)
1 parent 792a79d commit 069df69

File tree

12 files changed

+33
-21
lines changed

12 files changed

+33
-21
lines changed

telegraf/1.18/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" && \
3030

3131
EXPOSE 8125/udp 8092/udp 8094
3232

33-
USER telegraf
34-
3533
COPY entrypoint.sh /entrypoint.sh
3634
ENTRYPOINT ["/entrypoint.sh"]
3735
CMD ["telegraf"]

telegraf/1.18/alpine/Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM alpine:3.14
22

33
RUN echo 'hosts: files dns' >> /etc/nsswitch.conf
4-
RUN apk add --no-cache iputils ca-certificates net-snmp-tools procps lm_sensors tzdata && \
4+
RUN apk add --no-cache iputils ca-certificates net-snmp-tools procps lm_sensors tzdata su-exec && \
55
update-ca-certificates
66

77
ENV TELEGRAF_VERSION 1.18.3
@@ -32,8 +32,6 @@ RUN set -ex && \
3232

3333
EXPOSE 8125/udp 8092/udp 8094
3434

35-
USER telegraf
36-
3735
COPY entrypoint.sh /entrypoint.sh
3836
ENTRYPOINT ["/entrypoint.sh"]
3937
CMD ["telegraf"]

telegraf/1.18/alpine/entrypoint.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ if [ "${1:0:1}" = '-' ]; then
55
set -- telegraf "$@"
66
fi
77

8-
exec "$@"
8+
if [ $EUID -ne 0 ]; then
9+
exec "$@"
10+
else
11+
exec su-exec telegraf "$@"
12+
fi

telegraf/1.18/entrypoint.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ if [ "${1:0:1}" = '-' ]; then
55
set -- telegraf "$@"
66
fi
77

8-
exec "$@"
8+
if [ $EUID -ne 0 ]; then
9+
exec "$@"
10+
else
11+
exec setpriv --reuid telegraf --init-groups "$@"
12+
fi

telegraf/1.19/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" && \
3030

3131
EXPOSE 8125/udp 8092/udp 8094
3232

33-
USER telegraf
34-
3533
COPY entrypoint.sh /entrypoint.sh
3634
ENTRYPOINT ["/entrypoint.sh"]
3735
CMD ["telegraf"]

telegraf/1.19/alpine/Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM alpine:3.14
22

33
RUN echo 'hosts: files dns' >> /etc/nsswitch.conf
4-
RUN apk add --no-cache iputils ca-certificates net-snmp-tools procps lm_sensors tzdata && \
4+
RUN apk add --no-cache iputils ca-certificates net-snmp-tools procps lm_sensors tzdata su-exec && \
55
update-ca-certificates
66

77
ENV TELEGRAF_VERSION 1.19.3
@@ -32,8 +32,6 @@ RUN set -ex && \
3232

3333
EXPOSE 8125/udp 8092/udp 8094
3434

35-
USER telegraf
36-
3735
COPY entrypoint.sh /entrypoint.sh
3836
ENTRYPOINT ["/entrypoint.sh"]
3937
CMD ["telegraf"]

telegraf/1.19/alpine/entrypoint.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ if [ "${1:0:1}" = '-' ]; then
55
set -- telegraf "$@"
66
fi
77

8-
exec "$@"
8+
if [ $EUID -ne 0 ]; then
9+
exec "$@"
10+
else
11+
exec su-exec telegraf "$@"
12+
fi

telegraf/1.19/entrypoint.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ if [ "${1:0:1}" = '-' ]; then
55
set -- telegraf "$@"
66
fi
77

8-
exec "$@"
8+
if [ $EUID -ne 0 ]; then
9+
exec "$@"
10+
else
11+
exec setpriv --reuid telegraf --init-groups "$@"
12+
fi

telegraf/1.20/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" && \
3030

3131
EXPOSE 8125/udp 8092/udp 8094
3232

33-
USER telegraf
34-
3533
COPY entrypoint.sh /entrypoint.sh
3634
ENTRYPOINT ["/entrypoint.sh"]
3735
CMD ["telegraf"]

telegraf/1.20/alpine/Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM alpine:3.14
22

33
RUN echo 'hosts: files dns' >> /etc/nsswitch.conf
4-
RUN apk add --no-cache iputils ca-certificates net-snmp-tools procps lm_sensors tzdata && \
4+
RUN apk add --no-cache iputils ca-certificates net-snmp-tools procps lm_sensors tzdata su-exec && \
55
update-ca-certificates
66

77
ENV TELEGRAF_VERSION 1.20.3
@@ -32,8 +32,6 @@ RUN set -ex && \
3232

3333
EXPOSE 8125/udp 8092/udp 8094
3434

35-
USER telegraf
36-
3735
COPY entrypoint.sh /entrypoint.sh
3836
ENTRYPOINT ["/entrypoint.sh"]
3937
CMD ["telegraf"]

0 commit comments

Comments
 (0)