Bug 1673825

Summary: CommandRunner.run() does not prepend pacemaker_binaries directory [RHEL 8]
Product: Red Hat Enterprise Linux 8 Reporter: Tomas Jelinek <tojeline>
Component: pcsAssignee: Tomas Jelinek <tojeline>
Status: CLOSED ERRATA QA Contact: cluster-qe <cluster-qe>
Severity: medium Docs Contact:
Priority: high    
Version: 8.0CC: cfeist, cluster-maint, idevat, mlisik, mmazoure, nwahl, omular, tojeline
Target Milestone: rc   
Target Release: 8.0   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: pcs-0.10.1-6.el8 Doc Type: Bug Fix
Doc Text:
Cause: User runs pcs in an environment with PATH variable empty or not set. Consequence: Some pcs commands fail as they are unable to run pacemaker tools. Fix: Always specify a full path to external executables when running them from pcs. Result: Pcs works even if environment variable PATH is empty or not set.
Story Points: ---
Clone Of: 1671174 Environment:
Last Closed: 2019-11-05 20:39:40 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:
Bug Depends On: 1682129    
Bug Blocks:    
Attachments:
Description Flags
proposed fix
none
additional fix none

Description Tomas Jelinek 2019-02-08 09:01:47 UTC
+++ This bug was initially created as a clone of Bug #1671174 +++

Description of problem:

The now-deprecated utils.run() function ran crm*, corosync*, and ccs* commands by their absolute path by prepending the appropriate binaries directory.

1011 # Run command, with environment and return (output, retval)
1012 # DEPRECATED, please use lib.external.CommandRunner via utils.cmd_runner()
1013 def run(
1014     args, ignore_stderr=False, string_for_stdin=None, env_extend=None,
1015     binary_output=False
1016 ):
...
1027     if command[0:3] == "crm" or command in ["cibadmin", "cman_tool", "iso8601"]:
1028         args[0] = settings.pacemaker_binaries + command
1029     elif command[0:8] == "corosync":
1030         args[0] = settings.corosync_binaries + command
1031     elif command == "ccs":
1032         args[0] = settings.ccs_binaries + command


The CommandRunner.run() method (called by `utils.cmd_runner().run()`) does not prepend the binaries directory and instead runs commands by their base name, forcing a search through the directories in the PATH environment variable.


Below is an example of execution using `pcs cluster status` (the cluster_status function still uses the deprecated utils.run) and `pcs status` (the full_status function uses utils.cmd_runner().run).

[root@fastvm-rhel-7-5-22 pcs]# pcs cluster status --debug | head -1
Running: /usr/sbin/crm_mon -1 -r

[root@fastvm-rhel-7-5-22 pcs]# pcs status --debug | head -1
Running: crm_mon --one-shot --inactive

--------------------

Version-Release number of selected component (if applicable):

pcs-0.9.165-6.el7.x86_64

--------------------

How reproducible:

Always

--------------------

Steps to Reproduce:
1. Run `pcs cluster status --debug`. The cluster_status function uses utils.run.

2. Run `pcs status --debug`. The full_status function uses utils.cmd_runner().run.

--------------------

Actual results:

`pcs cluster status` calls /usr/sbin/crm_mon (absolute path).
`pcs status` calls crm_mon (relative path or base name).

--------------------

Expected results:

Both commands call /usr/sbin/crm_mon (absolute path).

--------------------

Additional info:

This can interfere with certain privilege escalation methods. One customer escalates user privileges via the suexec command provided by BoKS. The root environment is not getting set, so `crm_mon` is not found without an absolute path.

--- Additional comment from Tomas Jelinek on 2019-02-06 16:11:44 CET ---

It is intentional that CommandRunner.run() does not modify any path it is given. It is up to its caller to determine what should be run. The bug is not in the runner. The bug is in the code calling it. We should check all places calling the CommandRunner and make sure full paths are specified in all of them.

Comment 2 Tomas Jelinek 2019-03-21 13:54:48 UTC
Created attachment 1546506 [details]
proposed fix

Test:
pcs should work even if environment variable PATH is empty / not set

Commands fixed by the patch:
* pcs cluster cib push diff-against=
* pcs cluster destroy
* pcs cluster kill
* pcs config restore --local
* pcs status
* pcs stonith fence

Comment 3 Tomas Jelinek 2019-03-21 15:10:04 UTC
'pcs stonith confirm' is also fixed by the patch.

Comment 4 Tomas Jelinek 2019-03-21 16:00:12 UTC
'pcs qdevice kill net' is also fixed by the patch.

Comment 5 Tomas Jelinek 2019-03-21 16:47:24 UTC
Created attachment 1546623 [details]
additional fix

Comment 6 Ondrej Mular 2019-05-02 12:13:03 UTC
After fix:
[root@rhel81-node1 ~]# rpm -q pcs
pcs-0.10.1-6.el8.x86_64

[root@rhel81-node1 ~]# PATH="" /usr/sbin/pcs cluster destroy
Shutting down pacemaker/corosync services...
Killing any remaining services...
Removing all cluster configuration files...
[root@rhel81-node1 ~]# pcs status
Error: cluster is not currently running on this node

Comment 10 errata-xmlrpc 2019-11-05 20:39:40 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, 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/RHEA-2019:3311