Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telegraf docker entrypoint script change needed to support deployment from compose script #734

Open
wz2b opened this issue Apr 3, 2024 · 2 comments

Comments

@wz2b
Copy link

wz2b commented Apr 3, 2024

Referencing #724 and #543 I was still having problems with a specific line in the entrypoint script

The line currently reads:

extra_groups="$(id -Gn || true)"

This script doesn't honor UID; rather, if the UID is 0 (root) it just executes as the 'telegraf' user. Unfortunately, if you are root, that id will get the groups associated with root, not telegraf. I think it needs to be changed to:

extra_groups="$(id -Gn telegraf || true)"

With this change, I can specify a service in a compose file:

services: 
  telegraf:
    image: mystack/telegraf
    container_name: telegraf
    volumes: 
      - type: bind
        source: /etc/telegraf
        target: /etc/telegraf
        read_only: true
      - type: bind
        source: /var/run/docker.sock
        target: /var/run/docker.sock
    build:
      context: telegraf

I made this change with a custom entrypoint to test it:

FROM docker.io/telegraf
RUN groupadd -r docker -g 122
RUN usermod -aG docker telegraf
COPY custom-entrypoint.sh /custom-entrypoint.sh
RUN chmod +x /custom-entrypoint.sh
ENTRYPOINT ["/custom-entrypoint.sh"]
CMD ["telegraf"]

and that makes it work.

I think there's about a million ways to solve this problem. I think, though, that the structure of the script really intends to just exec if the uid is not 0, and if the uid is 0 it intends to force you to the 'telegraf' user - that's a strategy and it's fine and reasonably secure, but that id -Gn is going to check the extra groups of user 0, come up with only "root" then promptly remove that group.

If anybody agrees, please respond - I'll happily submit a pull request for this. Or, if you've got another way to pair docker compose + docker build and make this work, that's fine too. Me having to create a custom entrypoint doesn't seem like the right solution unless I'm the only person still having this problem.

@powersj
Copy link
Contributor

powersj commented Apr 3, 2024

Unfortunately, if you are root, that id will get the groups associated with root, not telegraf. I think it needs to be changed to:

hmm doing so would break what was fixed in #724 where the user does the following:

--user root:$(stat -c '%g' /var/run/docker.sock)

@wz2b
Copy link
Author

wz2b commented Apr 3, 2024

Does it? Hmm. Setpriv doesn't just add to the effective groups?

It's weird to me to say --user anybody and the entrypoint.sh believes you, but if you say --user root it hijacks the effective user (to make it "telegraf"), but not necessarily the effective group. The thing is, the 'docker' group is usually empty, and 'root' isn't in it, so to fix it they're trying to force the group to match whatever the docker socket's group is.

I think that's the wrong thing to do:

  • You should run telegraf with least privilege, and for docker it doesn't need to be root
  • You might want to extend this to do other things that require a different group access. The way this guy did it, you can only have one.

I'm thinking the whole thing needs to be reimagined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants