Skip to content

Commit 99d9bd9

Browse files
authored
Merge pull request #815 from influxdata/telegraf
chore: Replace su-exec with setpriv for Telegraf alpine
2 parents 98c1460 + 3c5e8d4 commit 99d9bd9

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

telegraf/1.35/alpine/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
FROM alpine:3.20
1+
FROM alpine:3.22
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 su-exec libcap && \
4+
RUN apk add --no-cache iputils ca-certificates net-snmp-tools procps lm_sensors tzdata setpriv libcap && \
55
update-ca-certificates
66

77
ENV TELEGRAF_VERSION 1.35.1

telegraf/1.35/alpine/entrypoint.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,19 @@ else
1111
# Allow telegraf to send ICMP packets and bind to privliged ports
1212
setcap cap_net_raw,cap_net_bind_service+ep /usr/bin/telegraf || echo "Failed to set additional capabilities on /usr/bin/telegraf"
1313

14-
exec su-exec telegraf "$@"
14+
# ensure HOME is set to the telegraf user's home dir
15+
export HOME=$(getent passwd telegraf | cut -d : -f 6)
16+
17+
# honor groups supplied via 'docker run --group-add ...' but drop 'root'
18+
# (also removes 'telegraf' since we unconditionally add it and don't want it listed twice)
19+
# see https://github.com/influxdata/influxdata-docker/issues/724
20+
groups="telegraf"
21+
extra_groups="$(id -Gn || true)"
22+
for group in $extra_groups; do
23+
case "$group" in
24+
root | telegraf) ;;
25+
*) groups="$groups,$group" ;;
26+
esac
27+
done
28+
exec setpriv --reuid telegraf --regid telegraf --groups "$groups" "$@"
1529
fi

0 commit comments

Comments
 (0)