Repository navigation
Conversation
|
@ngrigoriev - could you give this branch a go and see if it solves the issues you mentioned in #1085? To test, please clone the repository locally, and run the following from within the directory https://docs.pi-hole.net/docker/build-image/#using-the-built-image |
|
@dschaper any review news? |
|
The only way to trigger this is to set the However, that causes a lot more problems than just being unable to set the caps... |
You can simulate it by setting In your compose file. It will give some errors, but Using the current I'm not saying it is a good idea to start FTL without the caps, but some users might have reasons to do so (see here) |
|
I'm still not really sure how to test this. Rebasing on latest |
42f9faf to
78ffcbe
Compare
…ested capability Signed-off-by: yubiuser <github@yubiuser.dev>
Signed-off-by: yubiuser <github@yubiuser.dev>
Signed-off-by: yubiuser <github@yubiuser.dev>
Co-authored-by: Adam Warner <me@adamwarner.co.uk> Signed-off-by: yubiuser <github@yubiuser.dev>
| echo " Cannot run as non-root." | ||
| echo " If you are seeing this error, please set the environment variable 'DNSMASQ_USER' to the value 'root'" |
There was a problem hiding this comment.
Do we need so many spaces here?
I suggest to use 8 spaces for indentation:
| echo " Cannot run as non-root." | |
| echo " If you are seeing this error, please set the environment variable 'DNSMASQ_USER' to the value 'root'" | |
| echo " Cannot run as non-root." | |
| echo " If you are seeing this error, please set the environment variable 'DNSMASQ_USER' to the value 'root'" |
| echo " [!] WARNING: No capabilities for pihole-FTL available." | ||
| echo " Pi-hole functions may not work as expected." | ||
| echo " Please ensure that the container has the required capabilities." |
There was a problem hiding this comment.
Same here.
Use 8 spaces for indentation:
| echo " [!] WARNING: No capabilities for pihole-FTL available." | |
| echo " Pi-hole functions may not work as expected." | |
| echo " Please ensure that the container has the required capabilities." | |
| echo " [!] WARNING: No capabilities for pihole-FTL available." | |
| echo " Pi-hole functions may not work as expected." | |
| echo " Please ensure that the container has the required capabilities." |
PromoFaux
left a comment
There was a problem hiding this comment.
Moving the NET_ADMIN/DHCP check ahead of the CAP_STR branch is a good change. Previously, with no capabilities available at all, dhcp.active was never switched off.
Needs changing: exit 1 is no longer conditional on the user
if [[ $ret -ne 0 ]]; then
echo " [!] ERROR: Unable to set capabilities for pihole-FTL. "
if [[ "${DNSMASQ_USER:-pihole}" != "root" ]]; then
echo " Cannot run as non-root."
echo " If you are seeing this error, please set the environment variable 'DNSMASQ_USER' to the value 'root'"
fi
exit 1
fiOn development the container only exits when ret != 0 and DNSMASQ_USER != root, which is what makes DNSMASQ_USER=root a working workaround. Here exit 1 sits outside the inner if, so a root user whose setcap fails (e.g. a filesystem without xattr support) now gets a container that refuses to start. The message also still tells non-root users to set DNSMASQ_USER=root, which would no longer help them.
The PR description says this change only splits the return-code check from the user check, so I assume this is unintentional. Moving exit 1 inside the non-root branch should fix it:
if [[ $ret -ne 0 ]]; then
echo " [!] ERROR: Unable to set capabilities for pihole-FTL."
if [[ "${DNSMASQ_USER:-pihole}" != "root" ]]; then
echo " Cannot run as non-root."
echo " If you are seeing this error, please set the environment variable 'DNSMASQ_USER' to the value 'root'"
exit 1
fi
fiQuestion: starting with an empty CAP_STR
I agree the old message was misleading, since an empty CAP_STR means the capabilities were never available, not that setting them failed. I'm less sure that continuing is helpful when the container runs as the default pihole user.
When I followed the cap_drop reproduction from the comments above on a rebased branch, the container did not start properly. It logged dnsmasq: cannot open log /var/log/pihole/pihole.log: Permission denied and then stopped after the 30 second FTL started timeout. A non-root FTL without CAP_NET_BIND_SERVICE also cannot bind port 53. So the user gets a timeout in place of the current immediate error.
Would it make sense to only warn and continue when DNSMASQ_USER=root, and keep the hard exit otherwise? If there is a concrete use case for running non-root with no capabilities (the #1085 comment?), it would be good to document that and ideally add a test, as I'm still not sure how to exercise it.
Nits
- Indentation of the new
echolines is inconsistent (11 and 12 spaces). rdwebdesign's suggestions use 8 spaces to match the rest of the file; please apply them. - Trailing space in
"Unable to set capabilities for pihole-FTL. ". retis never initialised. It works because an unset variable evaluates as 0 in[[ -ne ]](and that was already the case), butret=0would be clearer while this block is being touched.
Improves the capability check. Inspired by #1085 (comment)
It does three things
NET_ADMINeven when this would be the only cap that would be checked and could not be granted.CAP_STRis empty. See the linked comment above. The error was wrong in the first place, as it did not check if we failed to grant the caps but ifCAP_STRis empty. And it is empty if the caps are not available to the container.pihole-FTLfrom checking the user. This should be a two-step process.