Skip to content

Dockerfile: add CAP_NET_BIND_SERVICE+eip to fabio to allow running as root#938

Merged
tristanmorgan merged 2 commits into
fabiolb:masterfrom
Kamilcuk:my/fix-docker-non-root
Sep 4, 2024
Merged

Dockerfile: add CAP_NET_BIND_SERVICE+eip to fabio to allow running as root#938
tristanmorgan merged 2 commits into
fabiolb:masterfrom
Kamilcuk:my/fix-docker-non-root

Conversation

@Kamilcuk

@Kamilcuk Kamilcuk commented Sep 7, 2023

Copy link
Copy Markdown
Contributor

Without the change, the following fails:

$ docker build -t myfabio . && docker run -e CONSUL_HTTP_ADDR=$CONSUL_HTTP_ADDR -e CONSUL_HTTP_AUTH=$CONSUL_HTTP_AUTH --rm -u nobody:nobody --network=host myfabio -registry.consul.addr=http://192.168.40.1:8500 -proxy.addr=0.0.0.0:80
[+] Building 37.2s (23/23) FINISHED                                                                                        docker:default
.....
2023/09/07 09:52:45 [FATAL] listen: Fail to listen. listen tcp 0.0.0.0:80: bind: permission denied
.....

After the change, it works. This is the only change needed to run fabio as non-root. System administrator can choose the user with docker options.

Related: #369 marco-m@c0391d2 #851

tristanmorgan
tristanmorgan previously approved these changes Sep 3, 2024

@tristanmorgan tristanmorgan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@tristanmorgan

Copy link
Copy Markdown
Member

@Kamilcuk can you do a quick rebase, just realised vendoring changes in #951 made this conflict.

@aaronhurt

Copy link
Copy Markdown
Member

If your using setcap shouldn’t you be running as non-root? The root user already has permissions.

@tristanmorgan tristanmorgan self-requested a review September 3, 2024 03:59
@tristanmorgan

Copy link
Copy Markdown
Member

if you add a USER nobody then also ADD --chown=nobody:nogroup fabio.properties /etc/fabio/fabio.properties or fabio can't read the config.

@Kamilcuk Kamilcuk force-pushed the my/fix-docker-non-root branch 2 times, most recently from 8ac6e18 to 59d773a Compare September 3, 2024 08:10
@tristanmorgan

Copy link
Copy Markdown
Member

Sorry @Kamilcuk, can I ask for the changes to be limited to just one feature?
Upgrades to the go toolchain needs to be done in many places like the workflows files so should be a separate (and welcome) PR.

Comment thread Dockerfile Outdated
Comment thread Dockerfile Outdated
@aaronhurt

Copy link
Copy Markdown
Member

This information is already in the docs as well: https://fabiolb.net/faq/binding-to-low-ports/

@Kamilcuk Kamilcuk force-pushed the my/fix-docker-non-root branch from 59d773a to 3b58d7e Compare September 4, 2024 06:10
@Kamilcuk Kamilcuk force-pushed the my/fix-docker-non-root branch from 3b58d7e to d0058a6 Compare September 4, 2024 06:34
@Kamilcuk

Kamilcuk commented Sep 4, 2024

Copy link
Copy Markdown
Contributor Author

Hi, I am sorry. Should be ok now. I blame my headache.

@tristanmorgan tristanmorgan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing before this change:

$ docker run --rm -it -p 80:80 -u nobody:nogroup --network=host -v ${PWD}/fabio.properties:/etc/fabio/fabio.properties -e FABIO_proxy_addr=":80;proto=http" -e FABIO_registry_consul_addr=${CONSUL_HTTP_ADDR} fabio:before
....
2024/09/04 23:19:28 [FATAL] listen: Fail to listen. listen tcp :80: bind: permission denied

and after changes applied (and dropping the -v parameter too) the listener succeeds.

@tristanmorgan tristanmorgan merged commit fbd256f into fabiolb:master Sep 4, 2024
@tristanmorgan

Copy link
Copy Markdown
Member

related #378

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

Successfully merging this pull request may close these issues.

3 participants