Skip to content

Commit 2b3f37d

Browse files
committed
Add support for SELinux-enhanced systems
1 parent cae93aa commit 2b3f37d

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

wireguard-install.sh

+17-2
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,17 @@ function installQuestions() {
185185
read -n1 -r -p "Press any key to continue..."
186186
}
187187
188+
function installSELinuxRules() {
189+
local osid
190+
osid="$1"
191+
192+
if [[ $osid == 'fedora' ]]; then
193+
echo "module se_wg 1.0;require { type wireguard_t; class capability { dac_override dac_read_search }; } allow wireguard_t self:capability { dac_override dac_read_search };" >/tmp/se_wg.te && checkmodule -M -m -o /tmp/se_wg.mod /tmp/se_wg.te && semodule_package -o /tmp/se_wg.pp -m /tmp/se_wg.mod && semodule -i /tmp/se_wg.pp
194+
elif [[ $osid == 'centos' || $osid == 'almalinux' || $osid == 'rocky' ]]; then
195+
echo "module se_wg 1.0; require {type wireguard_t; type cert_t; type firewalld_t; class capability { dac_override dac_read_search }; class dir search; class dbus send_msg;} allow wireguard_t cert_t:dir search; allow wireguard_t firewalld_t:dbus send_msg; allow wireguard_t self:capability { dac_override dac_read_search };" >/tmp/se_wg.te && checkmodule -M -m -o /tmp/se_wg.mod /tmp/se_wg.te && semodule_package -o /tmp/se_wg.pp -m /tmp/se_wg.mod && semodule -i /tmp/se_wg.pp
196+
fi
197+
}
198+
188199
function installWireGuard() {
189200
# Run setup questions first
190201
installQuestions
@@ -206,13 +217,15 @@ function installWireGuard() {
206217
dnf install -y dnf-plugins-core
207218
dnf copr enable -y jdoss/wireguard
208219
dnf install -y wireguard-dkms
220+
dnf install -y checkpolicy
209221
fi
210222
dnf install -y wireguard-tools iptables qrencode
211223
elif [[ ${OS} == 'centos' ]] || [[ ${OS} == 'almalinux' ]] || [[ ${OS} == 'rocky' ]]; then
212224
if [[ ${VERSION_ID} == 8* ]]; then
213225
yum install -y epel-release elrepo-release
214226
yum install -y kmod-wireguard
215227
yum install -y qrencode # not available on release 9
228+
yum install -y checkpolicy
216229
fi
217230
yum install -y wireguard-tools iptables
218231
elif [[ ${OS} == 'oracle' ]]; then
@@ -282,6 +295,8 @@ PostDown = ip6tables -t nat -D POSTROUTING -o ${SERVER_PUB_NIC} -j MASQUERADE" >
282295
echo "net.ipv4.ip_forward = 1
283296
net.ipv6.conf.all.forwarding = 1" >/etc/sysctl.d/wg.conf
284297
298+
installSELinuxRules ${OS}
299+
285300
if [[ ${OS} == 'alpine' ]]; then
286301
sysctl -p /etc/sysctl.d/wg.conf
287302
rc-update add sysctl
@@ -496,13 +511,13 @@ function uninstallWg() {
496511
elif [[ ${OS} == 'debian' ]]; then
497512
apt-get remove -y wireguard wireguard-tools qrencode
498513
elif [[ ${OS} == 'fedora' ]]; then
499-
dnf remove -y --noautoremove wireguard-tools qrencode
514+
dnf remove -y --noautoremove wireguard-tools qrencode checkpolicy
500515
if [[ ${VERSION_ID} -lt 32 ]]; then
501516
dnf remove -y --noautoremove wireguard-dkms
502517
dnf copr disable -y jdoss/wireguard
503518
fi
504519
elif [[ ${OS} == 'centos' ]] || [[ ${OS} == 'almalinux' ]] || [[ ${OS} == 'rocky' ]]; then
505-
yum remove -y --noautoremove wireguard-tools
520+
yum remove -y --noautoremove wireguard-tools checkpolicy
506521
if [[ ${VERSION_ID} == 8* ]]; then
507522
yum remove --noautoremove kmod-wireguard qrencode
508523
fi

0 commit comments

Comments
 (0)