Skip to content
Open

Caps #1814

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions src/bash_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ fix_capabilities() {
capsh --has-p=cap_sys_nice 2>/dev/null && CAP_STR+=',CAP_SYS_NICE'
capsh --has-p=cap_sys_time 2>/dev/null && CAP_STR+=',CAP_SYS_TIME'

if [[ $DHCP_READY == false ]] && [[ $FTLCONF_dhcp_active == true ]]; then
# DHCP is requested but NET_ADMIN is not available.
echo "ERROR: DHCP requested but NET_ADMIN is not available. DHCP will not be started."
echo " Please add cap_net_admin to the container's capabilities or disable DHCP."
setFTLConfigValue dhcp.active false
fi

if [[ ${CAP_STR} ]]; then
# We have the (some of) the above caps available to us - apply them to pihole-FTL
echo " [i] Applying the following caps to pihole-FTL:"
Expand All @@ -244,22 +251,18 @@ fix_capabilities() {

setcap "${CAP_STR:1}"+ep "$(which pihole-FTL)" || ret=$?

if [[ $DHCP_READY == false ]] && [[ $FTLCONF_dhcp_active == true ]]; then
# DHCP is requested but NET_ADMIN is not available.
echo "ERROR: DHCP requested but NET_ADMIN is not available. DHCP will not be started."
echo " Please add cap_net_admin to the container's capabilities or disable DHCP."
setFTLConfigValue dhcp.active false
fi

if [[ $ret -ne 0 && "${DNSMASQ_USER:-pihole}" != "root" ]]; then
echo " [!] ERROR: Unable to set capabilities for pihole-FTL. Cannot run as non-root."
echo " If you are seeing this error, please set the environment variable 'DNSMASQ_USER' to the value 'root'"
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
fi
else
echo " [!] ERROR: Unable to set capabilities for pihole-FTL."
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."
exit 1
fi
echo ""
}