Skip to content

Commit 69d8ad9

Browse files
authored
fix: Respect user supplied groups for Telegraf (#727)
2 parents c60d1eb + 626e34c commit 69d8ad9

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

telegraf/nightly/entrypoint.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ 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+
# ensure HOME is set to the telegraf user's home dir
1415
export HOME=$(getent passwd telegraf | cut -d : -f 6)
15-
exec setpriv --reuid telegraf --regid telegraf --groups telegraf "$@"
16+
17+
# honor groups supplied via 'docker run --group-add ...' but drop 'root' (the sed
18+
# removes 'telegraf' since we unconditionally add it and don't want it listed twice)
19+
groups="telegraf"
20+
extra_groups="$(id -Gn | sed \
21+
-e 's/ /,/g' \
22+
-e 's/,\(root\|telegraf\),/,/g' \
23+
-e 's/^\(root\|telegraf\),//g' \
24+
-e 's/,\(root\|telegraf\)$//g' \
25+
-e 's/^\(root\|telegraf\)$//g')"
26+
if [ -n "$extra_groups" ]; then
27+
groups="$groups,$extra_groups"
28+
fi
29+
exec setpriv --reuid telegraf --regid telegraf --groups "$groups" "$@"
1630
fi

0 commit comments

Comments
 (0)