Bug 1857396

Summary: SELinux issue when using secure communication to remote pmcd
Product: Red Hat Enterprise Linux 8 Reporter: Jan Kurik <jkurik>
Component: pcpAssignee: Mark Goodwin <mgoodwin>
Status: CLOSED ERRATA QA Contact: Jan Kurik <jkurik>
Severity: low Docs Contact:
Priority: low    
Version: 8.3CC: agerstmayr, b.prins, jkurik, mgoodwin, nathans, patrickm
Target Milestone: rcKeywords: Bugfix, Triaged
Target Release: 8.4Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: pcp-5.2.2-1.el8 Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-05-18 15:19:32 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Audit log containing the AVC records generated by pmcd none

Description Jan Kurik 2020-07-15 19:23:17 UTC
Description of problem:
This is a follow-up of bz1826047

When communication to a remote pmcd is secured as described in https://pcp.io/docs/lab.secureclient.html , the pmcd on the remote host generates AVC records.

Version-Release number of selected component (if applicable):
This is reproducible on pcp <= 5.1.1-3.el8 (including pcp ~ 4.x)

How reproducible:
Always

Steps to Reproduce:
1. Install pcp and other required packages on a fresh RHEL system
# yum install -y nss-tools openssl pcp pcp-system-tools /usr/sbin/semanage

2. Configure the secure communication as described in https://pcp.io/docs/lab.secureclient.html

3. Test if the secure communication works

# PCP_SECURE_SOCKETS=enforce PCP_ALLOW_BAD_CERT_DOMAIN=1 \
PCP_ALLOW_SERVER_SELF_CERT=1 PCP_SECURE_DB_PATH=/etc/pcp/nssdb \
pminfo -h remote-host -f kernel.uname.nodename

kernel.uname.nodename
    value "remote.host"

Actual results:
The pminfo works as expected, however the remote pmcd generates AVC records.


Expected results:
No AVC records are generated


Additional info:
The suspicious part of the code is in src/libpcp/src/secureserver.c
Function "__pmIsSecureserverLock()" is calling "NSS_InitReadWrite()" and there is a fallback to "NSS_Init()" if "NSS_InitReadWrite()" fails.
IMO the "NSS_InitReadWrite()" should be removed from the code as there is no reason why pmcd needs to write to the NSS database.

Comment 1 Jan Kurik 2020-07-15 19:31:23 UTC
Created attachment 1701293 [details]
Audit log containing the AVC records generated by pmcd

Comment 7 Mark Goodwin 2020-07-23 10:52:52 UTC
In pmproxy/src/deprecated.c: VerifyClient() .. __pmSecureServerHandshake() .. __pmSecureServerIPCFlags() .. __pmSecureServerInit() .. NSS_InitReadWrite()

So pmproxy's use of NSS_InitReadWrite() is deprecated. The only other caller is pmcd, which does not require RW. But if you think pmproxy's use might be resurrected one day, then we could allow RW access to the db via an SELinux policy update. The usual recommendation is not to grant access unless it's actually required but afaict we have no clients needing RW access to the cert db.

Comment 9 Mark Goodwin 2020-07-24 02:38:00 UTC
hmm. well in that case 'deprecated' is a misnomer because it isn't. So we need to fix the selinux issue too. So I think 'deprecated' mode should call a new libpcp function to open in RW mode. It would be preferable for pmcd to open in RO mode (as per the current patch).

I'll update the deprecated code in pmproxy, add the new function to libpcp and fix the selinux issue. unless anyone has a better suggestion ... like are the UOB people really still likely to be using this? (minnus (name?) has moved on hasn't he?)

Comment 12 Mark Goodwin 2020-10-09 07:44:07 UTC
I have a new patch for this BZ that does not require an SELinux policy update - basically I don't think we should add a rule for pmcd like "allow [pcp_pmcd_t] [etc_t] : [file] { write };" unnecessarily. Instead my new patch changes  __pmSecureServerInit() in libpcp to check an environment variable and if set, only call NSS_Init() rather than NSS_InitReadWrite(). pmcd would set this environment variable (because it only requires read-only access to the NSS db), but pmproxy would not set it. The default behaviour (when the envar is not set) remains unchanged, so no changes needed for pmproxy or any other libpcp apps.

Comment 13 Mark Goodwin 2020-10-13 00:16:07 UTC
Fixed upstream for pcp-5.2.2. This avoid the AVC and also changes pmcd to initialize NSS read-only instead of read-write when using secure connections.

commit c85528b1865336ad108a211a87f24132cf45d554
Author: Mark Goodwin <mgoodwin>
Date:   Tue Oct 13 10:58:49 2020 +1100

    pmcd/libpcp: pmcd init NSS read-only when using secure connections
    
    Use an environment variable to specify whether to initialize NSS in
    read-only or read-write mode in libpcp:__pmSecureServerInit(),
    defaulting to read-write if not set (i.e. no change for existing apps
    that do not set the variable).
    
    For pmcd, set PCP_NSS_INIT_MODE=readonly in $PCP_SYSCONFIG_DIR/pmcd
    because pmcd does not need read-write access to the NSS certificate
    database (though some future DSO/PMDA might).
    
    New test qa/1876 checks pmcd's environment. Document the new variable
    in PCPINTRO(1).
    
    Resolves: RHBZ#1857396

Comment 19 errata-xmlrpc 2021-05-18 15:19:32 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (pcp bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2021:1754