Bug 1078345 - Don't rely on PATH for su and runuser in postgresql-setup
Summary: Don't rely on PATH for su and runuser in postgresql-setup
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: postgresql
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Pavel Raiskup
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-03-19 16:03 UTC by Nicolas Chauvet (kwizart)
Modified: 2014-05-17 20:03 UTC (History)
6 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2014-05-17 20:03:56 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
This fix failure of the script when PATH is unset (648 bytes, patch)
2014-03-19 16:05 UTC, Nicolas Chauvet (kwizart)
no flags Details | Diff
Set PATH if it is unset and don't expect /sbin/runuser exists. (587 bytes, patch)
2014-05-07 12:41 UTC, Pavel Raiskup
no flags Details | Diff

Description Nicolas Chauvet (kwizart) 2014-03-19 16:03:24 UTC
Description of problem:
Some configuration script don't rely on any PATH to be set when they are run.


Version-Release number of selected component (if applicable):
9.3.3-2.fc21

How reproducible:
always

Steps to Reproduce:
1. run postgresl-setup with PATH unset
2.
3.

Actual results: 
Initializing database ... failed, see /var/lib/pgsql/initdb.log
usr/bin/postgresql-setup: line 88: runuser: command not found

Expected results:
postgresql-setup should have initialized the database.

Additional info:
This was encountered with an ansible playbook on f19.

Comment 1 Nicolas Chauvet (kwizart) 2014-03-19 16:05:25 UTC
Created attachment 876405 [details]
This fix failure of the script when PATH is unset

Comment 2 Nicolas Chauvet (kwizart) 2014-04-09 14:12:23 UTC
Ping ? Any issue with the patch ?

Comment 3 Pavel Raiskup 2014-04-09 15:35:30 UTC
Nicolas, thanks for your report and patch.  Sorry for the delay.

> Some configuration script don't rely on any PATH to be set when they are
> run.

You claim that when you do this change, the postgresql-setup script perfectly
works with $PATH unset?  That does not seem to be truth - other binaries
residing "somewhere" in $PATH are also used..

The vast majority of shell scripts definitely rely on PATH, postgresql-setup
is not an exception.  What is wrong IMO is that the script checks for
/sbin/runuser existence (that binary could calmly be put in some other
directory).

Comment 4 Nicolas Chauvet (kwizart) 2014-05-07 09:48:44 UTC
I don't know for the whole scripts on any systems of course.
This bug is only about a dedicated case when using ansible remotly, not from a running system.

Taking another common example as the /etc/init.d/functions, and there cannot be more generic example. The runuser is used without a full path, but at the same time, the PATH is explicitly set at the beginning of the script.

I really think the content of the PATH shouldn't be implicitly expected
And when initscripts was commonly used it was common to set the PATH explicitly to avoid trivial error like such

So there is indeed two options:
- Either explicitly set a working PATH
- Or use the full path of each command.

I've only tested fixing runuser and it worked with initdb, but indeed, others command silently failed.

Comment 5 Pavel Raiskup 2014-05-07 12:41:11 UTC
Created attachment 893257 [details]
Set PATH if it is unset and don't expect /sbin/runuser exists.

Nicolas, thanks for your comment.  I don't think playing much with PATH in
postgresql-setup makes sense (appending, removing, checking whether any part
exists already) but setting the PATH variable only when the variable is empty
should be safe and I believe it will help you.

Dunno whether this is correct from the Ansible POV.

Trivial patch is attached, any comment welcome.  Anybody: Please stop me if
you don't want this patch to be applied in Rawhide.

Pavel

Comment 6 Nicolas Chauvet (kwizart) 2014-05-07 16:02:23 UTC
/etc/init.d/functions uses that:
---------------
# Set up a default search path.
PATH="/sbin:/usr/sbin:/bin:/usr/bin"
export PATH
---------------
So it doesn't worry of what was actually set or not. but use that for all subsequent processes.

In the worst case, one could call /usr/bin/postgresl-setup with the wrong PATH such as PATH=/opt/fedora/tomcat8/bin/ (when using Software Collection).
I don't know how it behave with scl anyway, just had that in mind.

Comment 7 Pavel Raiskup 2014-05-14 12:26:46 UTC
(In reply to Nicolas Chauvet (kwizart) from comment #6)
> /etc/init.d/functions uses that:
> ---------------
> # Set up a default search path.
> PATH="/sbin:/usr/sbin:/bin:/usr/bin"
> export PATH
> ---------------
> So it doesn't worry of what was actually set or not. but use that for all
> subsequent processes.

/etc/init.d/functions is a special "starting" point.  I don't think this would
be OK also for postgresql-setup.

> In the worst case, one could call /usr/bin/postgresl-setup with the wrong
> PATH such as PATH=/opt/fedora/tomcat8/bin/ (when using Software Collection).
> I don't know how it behave with scl anyway, just had that in mind.

In case of Software Collections, PATH is just "extended" with some additional
pathnames (with higher priority).  If the PATH variable was broken with SCL,
it is most probably packager mistake and we are not able to fix such situation
from the script -- it must be fixed in particular collection.

Comment 8 Pavel Raiskup 2014-05-17 20:03:56 UTC
Fix is in Rawhide, thanks for this bugreport!

http://pkgs.fedoraproject.org/cgit/postgresql.git/commit/?id=533a1efbb6


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