Using openvpn requires adding SElinux policy

Hi everyone,

I’ve recently setup both Fedora r35 Silverblue as well as Fedora r36 Workstation on my work laptop (I switched because of reasons not pertaining to this topic), and both times I’ve run into the following:

Our company uses OpenVPN as its VPN infrastructure and gives us the necessary key and cert files, as well as a config file.
When I add a VPN connection in the Gnome interface by selecting “import form file” and then selecting the config, the config can be read, but enabling the connection fails.
Looking at the logs I can find out that the problem is insufficient selinux permissions to read the rest of the files, and can create a new module that allows networkmanager to read them. After this, everything works fine.

I have two questions about this:

  • Why is networkmanager able to read the first file but not the rest?
  • While it is easy to fix this problem if you know where to look, I can see many people getting stuck on this step, especially if they are new to linux and selinux. Also it is not a great out of the box experience. Is there a way we could improve this?
1 Like

Can you post the errors you saw and the steps you took to resolve them?

The error in the interface is a rather nondescript “Could not start the VPN connection” popup (i can’t remember the exact wording and don’t want to trash my setup to reproduce it, sorry ^^').

When looking at journalctl, this shows up:

May 17 13:59:59 pia audit[74838]: USER_START pid=74838 uid=1000 auid=1000 ses=3 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 msg='op=PAM:session_open grantors=pam_keyinit,pam_limits,pam_keyinit,pam_limits,pam_systemd,pam_unix acct="root" exe="/usr/bin/sudo" hostname=? addr=? terminal=/dev/pts/0 res=success'
May 17 14:00:02 pia NetworkManager[1292]: <info>  [1652788802.8862] vpn[0x559a8538c870,b1da8b12-2bab-4987-9384-c0108f6a3c3b,"init"]: starting openvpn
May 17 14:00:02 pia NetworkManager[1292]: <info>  [1652788802.8865] audit: op="connection-activate" uuid="b1da8b12-2bab-4987-9384-c0108f6a3c3b" name="init" pid=73986 uid=1000 result="success"
May 17 14:00:02 pia nm-openvpn[74849]: DEPRECATED OPTION: --cipher set to 'AES-256-CBC' but missing in --data-ciphers (AES-256-GCM:AES-128-GCM). Future OpenVPN version will ignore --cipher for cipher negotiations. Add 'AES-256-CBC' to --data-ciphers or change --cipher 'AES-256-CBC' to --data-ciphers-fallback 'AES-256-CBC' to silence this warning.
May 17 14:00:02 pia audit[74849]: AVC avc:  denied  { open } for  pid=74849 comm="openvpn" path="/home/pickl/.local/share/openvpn/ta.key" dev="dm-0" ino=159356 scontext=system_u:system_r:openvpn_t:s0 tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file permissive=0
May 17 14:00:02 pia nm-openvpn[74849]: Cannot pre-load keyfile (/home/pickl/.local/share/openvpn/ta.key)
May 17 14:00:02 pia nm-openvpn[74849]: Exiting due to fatal error
May 17 14:00:02 pia NetworkManager[1292]: <warn>  [1652788802.9015] vpn[0x559a8538c870,b1da8b12-2bab-4987-9384-c0108f6a3c3b,"init"]: dbus: failure: connect-failed (1)
May 17 14:00:02 pia NetworkManager[1292]: <warn>  [1652788802.9016] vpn[0x559a8538c870,b1da8b12-2bab-4987-9384-c0108f6a3c3b,"init"]: dbus: failure: connect-failed (1)

Fixing this is done by running the audit error through audit2allow, resulting in the following rule:

allow openvpn_t user_home_t:file open;

which can then be added as a module using semodule.

This fixes the problem, but may be too broad a rule. I sadly don’t have the most experience with selinux.

Have you tried placing your key and cert files in ~./cert to circumvent the SELinux issue?

2 Likes

No I haven’t. I can try tomorrow. If that’s the preferred fix I would like to find a way to tell people in the error messages though, because by myself I would never guess to try that. Not really for me (my setup works so far) but for anyone who expects a seamless experience when first setting up their Fedora install :slight_smile:

The following steps worked for me:

  1. Create the openvpn client connection using the UI
  2. Connect to the openvpn (this will fail and generate logs in /var/log/audit/audit.log )
  3. Get the logs and pipe them to audit2allow : grep openvpn /var/log/audit/audit.log | audit2allow -M myopenvpn (might need sudo here)
  4. Follow printed instructions: sudo semodule -i myopenvpn.pp
  5. Success
2 Likes

It is best to avoid creating extra policies and instead use one of the appropriate directories to store certificates and keys:

sudo semanage fcontext -l | grep -e home_cert_t
sudo restorecon -F -R /path/to/certs

This should work automatically if you import the VPN profile.

5 Likes

Hi everyone,

I know this topic is a bit old, but I had a similar issue, and I wanted to share what worked for me in case it helps someone else.

After running:

sudo ausearch -m avc -c openvpn

I discovered that the issue was related to my home directory. The problem was that I keep my home directory on a separate drive, and I sometimes experiment with different distros. When I switched back to Fedora, I realized that SELinux was having trouble with the existing contexts.

The solution was to relabel my entire home directory because it came from a non-SELinux distro:

sudo restorecon -v ~/.cert/nm-openvpn

This fixed the issue without needing any further actions. So, if you’re switching between distros and encounter similar problems with Fedora or any other SELinux-enabled distro, try relabeling your home directory after switching back, and then resort to more specific solutions if that doesn’t help.

1 Like

I use Fedora since 1 1/2 year now. I never had this problem. Then, I had to reinstall it on my laptop this week, and suddenly this problem came up. Your steps allowed to fix it. Thank You !!!

2 Likes

Simply running audit2allow is not a good solution at all.

I did this morning :

  1. Get the logs and pipe them to audit2allow : grep openvpn /var/log/audit/audit.log | audit2allow -M myopenvpn (might need sudo here)
  2. Follow printed instructions: sudo semodule -i myopenvpn.pp

And now my OpenVPN connection work perfectly… ? :thinking:

Why this one is not a good solution ? What is a better solution ?

Did you check the rules you added to the Selinux policy for security implications?

Post logs here. It might just be a labeling issue. If this is the case, using the right file labels will be the safer option, without adding arbitrary allow rules to a policy.

I see !! Ok, I deleted the previous rule added, the connection show again the message and wont connect. Which log do you want ? The details in the SETroubleshoot ?

I have this in the details (brut audit)

type=AVC msg=audit(1761322939.76:540): avc: denied { open } for pid=11054 comm=“openvpn” path=“/home/dominic/.local/share/networkmanagement/certificates/nm-openvpn/devinci-UDP4-1195-config-ca.pem” dev=“nvme0n1p3” ino=174753 scontext=system_u:system_r:openvpn_t:s0 tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file permissive=0

EDIT : Dawn ! I fixed the issue following the comment of @vgaetera !

Deleted my OpenVPN Connection, then, did these commands :

sudo semanage fcontext -l | grep -e home_cert_t
sudo restorecon -F -R ~/.cert

But I dont know if is only the first command that fixed it, because after reimporting my OpenVPN connection from file, the certificates are still in the .local folder and not in .cert folder !

Also, the .cert folder did’nt exist, I created it.

Edit 2 : Also, before to do these two commands, I used the one given by @stiky : sudo restorecon -v ~/.local/share/networkmanagement/certificates/nm-openvpn

Maybe I had just to delete and import again my OpenVPN connection after this command ??

Note : when I reinstalled Fedora, I used SaveDesktop app to get back my old desktop (that was also on Fedora 42).

It only shows file context rules for the home_cert_t label. You should really check what the commands do before copy-pasting them. So it was one of the other commands that fixed it.

What did it output?

Since you only used restorecon, this solution is much better than adding arbitrary rules with audit2allow.

The command sudo restorecon -v ~/.local/share/networkmanagement/certificates/nm-openvpn return nothing in the Terminal…?

The question is what it returned back then when you used it the first time to solve your problem, not what it does now.