Bug 1977268 - nm-openvpn applies incorrect SELinux labels when importing a VPN profile
Summary: nm-openvpn applies incorrect SELinux labels when importing a VPN profile
Keywords:
Status: CLOSED EOL
Alias: None
Product: Fedora
Classification: Fedora
Component: NetworkManager-openvpn
Version: 34
Hardware: All
OS: Linux
unspecified
unspecified
Target Milestone: ---
Assignee: Lubomir Rintel
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-06-29 11:10 UTC by Vladislav Grigoryev
Modified: 2023-02-21 19:46 UTC (History)
10 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-06-07 23:02:13 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Vladislav Grigoryev 2021-06-29 11:10:41 UTC
Description of problem:
nm-openvpn applies incorrect SELinux labels to certs and keys when importing a VPN profile.
Restoring SELinux labels requires a counter intuitive manual action.

Version-Release number of selected component (if applicable):
NetworkManager-openvpn-1.8.14-1.fc34.x86_64

How reproducible:
Always.

Steps to Reproduce:
```
sudo nmcli connection import type openvpn file client.ovpn 
sudo nmcli connection up id client
```

Actual results:
```
> sudo nmcli connection import type openvpn file client.ovpn 
Connection 'client' (1385e514-b498-4864-99cb-1f9502360de7) successfully added.

> sudo nmcli connection up id client
Error: Connection activation failed: Unknown reason
Hint: use 'journalctl -xe NM_CONNECTION=1385e514-b498-4864-99cb-1f9502360de7 + NM_DEVICE=enp1s0' to get more details.

> journalctl -u NetworkManager.service -S -5m
...
Jun 29 11:40:33 fedora1 nm-openvpn[4150]: Cannot pre-load keyfile (/root/.cert/nm-openvpn/client-tls-crypt.pem)
Jun 29 11:40:33 fedora1 nm-openvpn[4150]: Exiting due to fatal error
...

> journalctl -b -g avc
...
Jun 29 11:40:33 fedora1 audit[4142]: AVC avc:  denied  { read } for  pid=4142 comm="nm-openvpn-serv" name="client-key.pem" dev="vda2" ino=1381588 scontext=system_u:system_r:NetworkManager_t:s0 tcontext=unconfined_u:object_r:admin_home_t:s0 tclass=file permissive=0
...
```

Expected results:
The proper SELinux labels should be applied automatically upon importing a VPN profile.

Additional info:
A manual action is required to restore SELinux labels:
```
> sudo restorecon -R -v /root/.cert
Relabeled /root/.cert from unconfined_u:object_r:admin_home_t:s0 to unconfined_u:object_r:home_cert_t:s0
Relabeled /root/.cert/nm-openvpn from unconfined_u:object_r:admin_home_t:s0 to unconfined_u:object_r:home_cert_t:s0
Relabeled /root/.cert/nm-openvpn/client-tls-crypt.pem from unconfined_u:object_r:admin_home_t:s0 to unconfined_u:object_r:home_cert_t:s0
Relabeled /root/.cert/nm-openvpn/client-key.pem from unconfined_u:object_r:admin_home_t:s0 to unconfined_u:object_r:home_cert_t:s0
Relabeled /root/.cert/nm-openvpn/client-cert.pem from unconfined_u:object_r:admin_home_t:s0 to unconfined_u:object_r:home_cert_t:s0
Relabeled /root/.cert/nm-openvpn/client-ca.pem from unconfined_u:object_r:admin_home_t:s0 to unconfined_u:object_r:home_cert_t:s0
```

Cert and key locations depend on the user performing the connection import:
```
> sudo semanage fcontext -l | grep -e home_cert_t
/home/[^/]+/\.cert(/.*)?                           all files          unconfined_u:object_r:home_cert_t:s0 
/home/[^/]+/\.kde/share/apps/networkmanagement/certificates(/.*)? all files          unconfined_u:object_r:home_cert_t:s0 
/home/[^/]+/\.local/share/networkmanagement/certificates(/.*)? all files          unconfined_u:object_r:home_cert_t:s0 
/home/[^/]+/\.pki(/.*)?                            all files          unconfined_u:object_r:home_cert_t:s0 
/root/\.cert(/.*)?                                 all files          system_u:object_r:home_cert_t:s0 
/root/\.pki(/.*)?                                  all files          system_u:object_r:home_cert_t:s0 
```

Comment 1 Thomas Haller 2021-06-30 06:25:12 UTC
nmcli doesn't explicitly label the files. It relies on the default label to be correct, based on the path (which is also why it chooses to place the file in ~/.cert/).

Unclear why that isn't working...


I also don't understand why restorecon sets them to `unconfined_u:object_r:home_cert_t:s0`, when it seems it should be `system_u:object_r:home_cert_t:s0`...

Comment 2 Ben Cotton 2022-05-12 16:05:00 UTC
This message is a reminder that Fedora Linux 34 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora Linux 34 on 2022-06-07.
It is Fedora's policy to close all bug reports from releases that are no longer
maintained. At that time this bug will be closed as EOL if it remains open with a
'version' of '34'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, change the 'version' 
to a later Fedora Linux version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora Linux 34 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora Linux, you are encouraged to change the 'version' to a later version
prior to this bug being closed.

Comment 3 Ben Cotton 2022-06-07 23:02:13 UTC
Fedora Linux 34 entered end-of-life (EOL) status on 2022-06-07.

Fedora Linux 34 is no longer maintained, which means that it
will not receive any further security or bug fix updates. As a result we
are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release.

Thank you for reporting this bug and we are sorry it could not be fixed.

Comment 4 Nevo Hed 2023-02-21 19:46:15 UTC
Just here to note that I observed with fc36


Details:

- Versions:
  $ uname -a 
  Linux nhed-lt2 6.0.8-200.fc36.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 11 15:03:58 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

  $ rpm -q NetworkManager-openvpn
  NetworkManager-openvpn-1.8.18-1.fc36.x86_64

- Using an openvpn config file with embedded certs with the openvpn client directly - works.

- Importing the same openvpn config file to create a new Network Manager VPN config 
  either through either the Gnome GUI or nmcli and proceeding to use causes a failure
  with an AVC denial log.

- Following the suggestion by @vg.aetera to `sudo restorecon -R -v /root/.cert` 
  immediately after importing the configh and before attempting to use the connection 
  works (a workaround but not a great one for end users)


Note You need to log in before you can comment on or make changes to this bug.