IpNetnsExecFilter does not qualify the path of nested commands

Bug #1417331 reported by Maru Newby
30
This bug affects 4 people
Affects Status Importance Assigned to Milestone
oslo.rootwrap
Confirmed
Undecided
Unassigned

Bug Description

When invoking a command via IpNetnsExecFilter, the 'ip' command is automatically qualified depending on where it has been found via exec_dirs (e.g. the 'ip' command is found at '/sbin/ip' and that qualified command is executed). However, a command invoked by ip netns is not similarly qualified such that it being found is entirely dependent on the PATH environment. This is causing problems for neutron functional testing where the target command is in a venv bin directory and a qualified path is required, e.g.

The following command is executed:

sudo /usr/local/bin/neutron-rootwrap /etc/neutron/rootwrap.conf ip netns exec mynamespace neutron-ns-metadata-proxy

Resulting in:

exec of "neutron-ns-metadata-proxy" failed: No such file or directory

This despite exec_dirs including the path of the neutron-ns-metadata-proxy command.

What should be executed: /sbin/ip netns exec mynamespace /[path to proxy]/neutron-ns-metadata-proxy

What is being executed: /sbin/ip netns exec mynamespace neutron-ns-metadata-proxy

Maru Newby (maru)
Changed in oslo.rootwrap:
assignee: nobody → Maru Newby (maru)
description: updated
Revision history for this message
Miguel Angel Ajo (mangelajo) wrote :

I suppose we may need to extend IpNetnsExecFilter to actually qualify the path for the ip netns exec wrapped executable.

I will look at that tomorrow morning.

Changed in oslo.rootwrap:
assignee: Maru Newby (maru) → Miguel Angel Ajo (mangelajo)
Revision history for this message
Miguel Angel Ajo (mangelajo) wrote :

There is a similar bug, in this case for the KillFilter: https://bugs.launchpad.net/oslo.rootwrap/+bug/1394279

I was talking to ttx, and a possible solution for this would be to modify the secure_path of sudo config
https://bugs.launchpad.net/oslo.rootwrap/+bug/1394279/comments/1

Maru, are we able to alter the sudo configuration for the functional testing case?

Revision history for this message
Miguel Angel Ajo (mangelajo) wrote :

Not sure if we're targeting here too the ability to run the functional tests in the development environment
without doing an install to the system.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to oslo.rootwrap (master)

Fix proposed to branch: master
Review: https://review.openstack.org/152902

Changed in oslo.rootwrap:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on oslo.rootwrap (master)

Change abandoned by Miguel Angel Ajo (<email address hidden>) on branch: master
Review: https://review.openstack.org/152902
Reason: We found a workaround to do this, so this is left abandoned as reference for just in case we need to take this path back.

Revision history for this message
Miguel Angel Ajo (mangelajo) wrote :

The workaround was including PATH=$(external_sudo_path):$PATH in front of the exec, and adding a rootwrap rule to allow it.

So the final execution is...

sudo rootwrap /etc/my-rootwrap-filters PATH=/my/external_path:$PATH my-exec params

and we're able to inject a path.

Our use case is testing, so we're not very worried about security implications, we could understand other use cases may be more worried and may need to work on a proper rootwrap fix.

Revision history for this message
Joe Julian (joe.julian) wrote :

I discovered an additional workaround that may be considered more secure and doesn't require any patching.

In the neutron sudoers file, I added a secure_path that included my installation bin directory:

  Defaults:neutron secure_path = /opt/openstack/neutron/bin:/sbin:/bin:/usr/sbin:/usr/bin

Revision history for this message
Maru Newby (maru) wrote :

Setting the path in the sudo invocation doesn't work if the target host sets secure_path (can't set the path in that case). The neutron functional setup already sets secure_path as suggested in the previous comment:

https://github.com/openstack/neutron/blob/master/tools/configure_for_func_testing.sh#L195

This is a hacky solution at best, and rootwrap should really be fixed to be able to resolve a command targeted for nested (ip netns exec) execution within its exec_dirs search path. Since non-nested commands are already resolved in this manner, I don't think it can be considered a potential security problem.

Revision history for this message
Miguel Angel Ajo (mangelajo) wrote :

Thanks for the clarifications,

I would work in it if we find agreement from the project cores, it sounds reasonable to me to have it fixed.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to oslo.rootwrap (master)

Fix proposed to branch: master
Review: https://review.openstack.org/185250

Changed in oslo.rootwrap:
assignee: Miguel Angel Ajo (mangelajo) → Stephen Ma (stephen-ma)
Changed in oslo.rootwrap:
status: In Progress → Confirmed
Changed in oslo.rootwrap:
assignee: Stephen Ma (stephen-ma) → nobody
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on oslo.rootwrap (master)

Change abandoned by stephen-ma (<email address hidden>) on branch: master
Review: https://review.openstack.org/185250

Revision history for this message
Ebbex (eb4x) wrote :

We ran into this problem yesterday.

On our compute host we have venvs for both neutron and nova, and under
/etc/sudoers.d/ we had a file for each projects rootwrap. And in those files
we specified a secure path.

/etc/sudoers.d/neutron-rootwrap
Defaults secure_path="/opt/openstack/neutron/venv/bin:..."
neutron ALL=(root) NOPASSWD: /opt/openstack/neutron/venv/bin/neutron-rootwrap /etc/neutron/rootwrap.conf *

/etc/sudoers.d/nova-rootwrap
Defaults secure_path="/opt/openstack/nova/venv/bin:..."
nova ALL=(root) NOPASSWD: /opt/openstack/nova/venv/bin/nova-rootwrap /etc/nova/rootwrap.conf *

But only one of those 'secure_path' takes preference, in our case nova which
meant that 'neutron-ns-metadata-proxy' was out of our path again.

Wouldn't it just be better if we just set the environment PATH to the
exec_dirs, since that's where we'll be searching for the executables.
This would also result in less places to maintain your paths.

oslo_rootwrap/wrapper.py
if config.has_option("DEFAULT", "exec_dirs"):
  self.exec_dirs = config.get("DEFAULT", "exec_dirs").split(",")
  # Replace PATH with exec_dirs if specified
  os.putenv("PATH", ":".join(self.exec_dirs))

Revision history for this message
Ebbex (eb4x) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.