vegardit / docker-traefik-logrotate

Lightweight Docker image to be used in conjunction with a dockerized Traefik instance to rotate Traefik's access logs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: Change owner of log file

modem7 opened this issue · comments

commented

Would it be possible to have the ability to change the owner of the log file after rotation?

Currently, it defaults to root:root as that's what the container runs as.

My Traefik logs are currently owned by a different user and group.

An env var to override the create 0644 root root section would probably do it quite nicely.

Please give it a try.

commented

Works great, thank you!

commented

Hi, and thanks for this nice project. I've tried setting my username and group as env variable and it did'nt worked:
error: /etc/logrotate.conf:13 unknown user 'my_user'
I've also tried with my uid and gid (1026 - 100), no luck either.
It's working if I use root:root but I'd rather avoid it.

Is there something I can try to make it work ?

As of logrotate 3.18 it should be possible to use numerical gid/uid instead of names. Alpine 3 currently comes with version 3.21 so it should actually work. what is the error message you get when you use uid/gid instead of username/groupname?

commented

It was the same error message: error: /etc/logrotate.conf:13 unknown user '1026'

You can try this and see if it works:

  1. Create a bash file in which the required user/group with the correct uid/gid are created following https://wiki.alpinelinux.org/wiki/Setting_up_a_new_user
  2. Mount the bash file into the container
  3. Define a container environment variable INIT_SH_FILE with the path to the mounted bash file.
  4. Now this bash file will be executed automatically as part of the container start.
commented

If that works for you we can generalize it and extend the container's run script with the respective logic.

commented

Thanks for the idea, I've started to work on it from inside the container and the first command (addgroup) already raised a problem: what to do if the desired GID (or UID) is already used ? I think the "standard" docker approach for this is by using S6-overlay. Images built by LinuxServer are using it, here is the script adding the user: https://github.com/linuxserver/docker-baseimage-alpine/blob/466a927f405f69aa6aea77d7ffa42b75de3ed671/root/etc/s6-overlay/s6-rc.d/init-adduser/run#L5
If you're willing to go this way I think there is two approaches:

  • extract the minimum needed from linuxserver to perform just that
  • use linuxserver alpine base image instead of original alpine image
    The first option may be optimized but may required a bit of work, the second seems more straightforward. What do you think ?

I fixed it with 3364294 If it is not sufficient for your use case please open a separate issue.