Skip to content

Commit

Permalink
Add missing filters for new root commands
Browse files Browse the repository at this point in the history
Add missing rootwrap filters for 'ovs-ofctl', 'cp' and 'mkfs'.
Do not run 'rm' as root since it's unnecessary.
Add documentation to try to prevent future misses.
Fixes bug 943293.

Change-Id: Ia680048a28a75f661a136d8447ff0aaf195649ba
  • Loading branch information
ttx committed Feb 29, 2012
1 parent 5f44c8f commit 5bcbb65
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
9 changes: 9 additions & 0 deletions nova/rootwrap/compute.py
Expand Up @@ -73,6 +73,9 @@
# nova/virt/disk/api.py: 'chmod', 755, netdir
filters.CommandFilter("/bin/chmod", "root"),

# nova/virt/disk/api.py: 'cp', os.path.join(fs...
filters.CommandFilter("/bin/cp", "root"),

# nova/virt/libvirt/vif.py: 'ip', 'tuntap', 'add', dev, 'mode', 'tap'
# nova/virt/libvirt/vif.py: 'ip', 'link', 'set', dev, 'up'
# nova/virt/libvirt/vif.py: 'ip', 'link', 'delete', dev
Expand Down Expand Up @@ -102,6 +105,9 @@
# nova/network/linux_net.py: 'ovs-vsctl', ....
filters.CommandFilter("/usr/bin/ovs-vsctl", "root"),

# nova/network/linux_net.py: 'ovs-ofctl', ....
filters.CommandFilter("/usr/bin/ovs-ofctl", "root"),

# nova/virt/libvirt/connection.py: 'dd', "if=%s" % virsh_output, ...
filters.CommandFilter("/bin/dd", "root"),

Expand Down Expand Up @@ -169,6 +175,9 @@
# nova/virt/xenapi/vm_utils.py: 'mkswap'
filters.CommandFilter("/sbin/mkswap", "root"),

# nova/virt/xenapi/vm_utils.py: 'mkfs'
filters.CommandFilter("/sbin/mkfs", "root"),

# nova/virt/libvirt/connection.py:
filters.ReadFileFilter("/etc/iscsi/initiatorname.iscsi"),
]
3 changes: 3 additions & 0 deletions nova/rootwrap/network.py
Expand Up @@ -83,4 +83,7 @@

# nova/network/linux_net.py: 'ovs-vsctl', ....
filters.CommandFilter("/usr/bin/ovs-vsctl", "root"),

# nova/network/linux_net.py: 'ovs-ofctl', ....
filters.CommandFilter("/usr/bin/ovs-ofctl", "root"),
]
2 changes: 2 additions & 0 deletions nova/utils.py
Expand Up @@ -164,6 +164,8 @@ def fetchfile(url, target):
def execute(*cmd, **kwargs):
"""
Helper method to execute command with optional retry.
If you add a run_as_root=True command, don't forget to add the
corresponding filter to nova.rootwrap !
:cmd Passed to subprocess.Popen.
:process_input Send to opened process.
Expand Down
4 changes: 2 additions & 2 deletions nova/virt/disk/api.py
Expand Up @@ -373,10 +373,10 @@ def _inject_admin_password_into_fs(admin_passwd, fs, execute=None):
_set_passwd(admin_user, admin_passwd, tmp_passwd, tmp_shadow)
utils.execute('cp', tmp_passwd, os.path.join(fs, 'etc', 'passwd'),
run_as_root=True)
utils.execute('rm', tmp_passwd, run_as_root=True)
os.unlink(tmp_passwd)
utils.execute('cp', tmp_shadow, os.path.join(fs, 'etc', 'shadow'),
run_as_root=True)
utils.execute('rm', tmp_shadow, run_as_root=True)
os.unlink(tmp_shadow)


def _set_passwd(username, admin_passwd, passwd_file, shadow_file):
Expand Down

0 comments on commit 5bcbb65

Please sign in to comment.