FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Fedora/Linux Management Tools

 
 
LinkBack Thread Tools
 
Old 12-03-2008, 01:26 AM
 
Default Least privilege support

# HG changeset patch
# User john.levon@sun.com
# Date 1228271172 28800
# Node ID 2771f870b247df02b16a4d79cdf549a1ad0132aa
# Parent a4538c6c2d6690526d80c011b46b4700c23a9ffd
Least privilege support

On Solaris, which users can run virt-install depends on their effective
privilege set, not their effective UID.

Signed-off-by: John Levon <john.levon@sun.com>

diff --git a/virt-clone b/virt-clone
--- a/virt-clone
+++ b/virt-clone
@@ -185,7 +185,7 @@ def main():
logging.debug("start clone with HV " + options.connect)

if options.connect is None or options.connect.lower()[0:3] == "xen":
- if os.geteuid() != 0:
+ if not virtinst.util.privileged_user():
fail(_("Must be root to clone Xen guests"))

conn = cli.getConnection(options.connect)
diff --git a/virtinst/DistroManager.py b/virtinst/DistroManager.py
--- a/virtinst/DistroManager.py
+++ b/virtinst/DistroManager.py
@@ -193,7 +193,7 @@ class DistroInstaller(Guest.Installer):
"or FTP network install source, or an existing "
"local file/device"))

- if os.geteuid() != 0 and val.startswith("nfs:"):
+ if val.startswith("nfs:") and not util.privileged_user():
raise ValueError(_("NFS installations are only supported as root"))

self._location = val
diff --git a/virtinst/Guest.py b/virtinst/Guest.py
--- a/virtinst/Guest.py
+++ b/virtinst/Guest.py
@@ -28,6 +28,7 @@ import urlgrabber.progress as progress
import urlgrabber.progress as progress
import util
import libvirt
+import platform
import __builtin__
import CapabilitiesParser
import VirtualDevice
@@ -347,9 +348,11 @@ class Installer(object):
os_type = property(get_os_type, set_os_type)

def get_scratchdir(self):
+ if platform.system() == 'SunOS':
+ return '/var/tmp'
if self.type == "xen" and os.path.exists(XEN_SCRATCH):
return XEN_SCRATCH
- if os.getuid() == 0 and os.path.exists(LIBVIRT_SCRATCH):
+ if util.privileged_user() and os.path.exists(LIBVIRT_SCRATCH):
return LIBVIRT_SCRATCH
else:
return os.path.expanduser("~/.virtinst/boot")
@@ -476,7 +479,7 @@ class Installer(object):
fd = os.open(guest.disks[0].path, os.O_RDONLY)
except OSError, (err, msg):
logging.debug("Failed to open guest disk: %s" % msg)
- if err == errno.EACCES and os.geteuid() != 0:
+ if err == errno.EACCES and not util.privileged_user():
return True # non root might not have access to block devices
else:
raise
diff --git a/virtinst/cli.py b/virtinst/cli.py
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -118,7 +118,7 @@ def nice_exit():

def getConnection(connect):
if connect and connect.lower()[0:3] == "xen":
- if os.geteuid() != 0:
+ if not util.privileged_user():
fail(_("Must be root to create Xen guests"))
if connect is None:
fail(_("Could not find usable default libvirt connection."))
@@ -307,7 +307,7 @@ def digest_networks(conn, macs, bridges,
# Create extra networks up to the number of nics requested
if len(macs) < nics:
for dummy in range(len(macs),nics):
- if os.getuid() == 0:
+ if util.privileged_user():
net = util.default_network(conn)
networks.append(net[0] + ":" + net[1])
else:
diff --git a/virtinst/util.py b/virtinst/util.py
--- a/virtinst/util.py
+++ b/virtinst/util.py
@@ -93,7 +93,7 @@ def default_connection():
os.path.exists("/usr/bin/qemu-kvm") or
os.path.exists("/usr/bin/kvm") or
os.path.exists("/usr/bin/xenner"):
- if os.getuid() == 0:
+ if privileged_user():
return "qemu:///system"
else:
return "qemu:///session"
@@ -509,6 +509,14 @@ def lookup_pool_by_path(conn, path):
return pool
return None

+def privileged_user():
+ """
+ Return true if the user is privileged enough. On Linux, this
+ equates to being root. On Solaris, it's more complicated, so we
+ just assume we're OK.
+ """
+ return os.uname()[0] == 'SunOS' or os.geteuid() == 0
+
def _test():
import doctest
doctest.testmod()

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 12-04-2008, 11:13 AM
"Daniel P. Berrange"
 
Default Least privilege support

On Tue, Dec 02, 2008 at 06:26:23PM -0800, john.levon@sun.com wrote:
> # HG changeset patch
> # User john.levon@sun.com
> # Date 1228271172 28800
> # Node ID 2771f870b247df02b16a4d79cdf549a1ad0132aa
> # Parent a4538c6c2d6690526d80c011b46b4700c23a9ffd
> Least privilege support
>
> On Solaris, which users can run virt-install depends on their effective
> privilege set, not their effective UID.

ACK this looks reasonable. Hopefully more of these checks will go
away as we move code out of virtinst and into formal libvirt APIs.

Daniel
--
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 12-04-2008, 11:41 AM
Atsushi SAKAI
 
Default Least privilege support

Hi, John

I have a question about this patch.
(because of my understanding)

It seems check "SunOS" only for Solaris.
(It will be added some code in future?)

Thanks
Atsushi SAKAI


john.levon@sun.com wrote:

> # HG changeset patch
> # User john.levon@sun.com
> # Date 1228271172 28800
> # Node ID 2771f870b247df02b16a4d79cdf549a1ad0132aa
> # Parent a4538c6c2d6690526d80c011b46b4700c23a9ffd
> Least privilege support
>
> On Solaris, which users can run virt-install depends on their effective
> privilege set, not their effective UID.
>
> Signed-off-by: John Levon <john.levon@sun.com>
>
> diff --git a/virt-clone b/virt-clone
> --- a/virt-clone
> +++ b/virt-clone
> @@ -185,7 +185,7 @@ def main():
> logging.debug("start clone with HV " + options.connect)
>
> if options.connect is None or options.connect.lower()[0:3] == "xen":
> - if os.geteuid() != 0:
> + if not virtinst.util.privileged_user():
> fail(_("Must be root to clone Xen guests"))
>
> conn = cli.getConnection(options.connect)
> diff --git a/virtinst/DistroManager.py b/virtinst/DistroManager.py
> --- a/virtinst/DistroManager.py
> +++ b/virtinst/DistroManager.py
> @@ -193,7 +193,7 @@ class DistroInstaller(Guest.Installer):
> "or FTP network install source, or an existing "
> "local file/device"))
>
> - if os.geteuid() != 0 and val.startswith("nfs:"):
> + if val.startswith("nfs:") and not util.privileged_user():
> raise ValueError(_("NFS installations are only supported as root"))
>
> self._location = val
> diff --git a/virtinst/Guest.py b/virtinst/Guest.py
> --- a/virtinst/Guest.py
> +++ b/virtinst/Guest.py
> @@ -28,6 +28,7 @@ import urlgrabber.progress as progress
> import urlgrabber.progress as progress
> import util
> import libvirt
> +import platform
> import __builtin__
> import CapabilitiesParser
> import VirtualDevice
> @@ -347,9 +348,11 @@ class Installer(object):
> os_type = property(get_os_type, set_os_type)
>
> def get_scratchdir(self):
> + if platform.system() == 'SunOS':
> + return '/var/tmp'
> if self.type == "xen" and os.path.exists(XEN_SCRATCH):
> return XEN_SCRATCH
> - if os.getuid() == 0 and os.path.exists(LIBVIRT_SCRATCH):
> + if util.privileged_user() and os.path.exists(LIBVIRT_SCRATCH):
> return LIBVIRT_SCRATCH
> else:
> return os.path.expanduser("~/.virtinst/boot")
> @@ -476,7 +479,7 @@ class Installer(object):
> fd = os.open(guest.disks[0].path, os.O_RDONLY)
> except OSError, (err, msg):
> logging.debug("Failed to open guest disk: %s" % msg)
> - if err == errno.EACCES and os.geteuid() != 0:
> + if err == errno.EACCES and not util.privileged_user():
> return True # non root might not have access to block devices
> else:
> raise
> diff --git a/virtinst/cli.py b/virtinst/cli.py
> --- a/virtinst/cli.py
> +++ b/virtinst/cli.py
> @@ -118,7 +118,7 @@ def nice_exit():
>
> def getConnection(connect):
> if connect and connect.lower()[0:3] == "xen":
> - if os.geteuid() != 0:
> + if not util.privileged_user():
> fail(_("Must be root to create Xen guests"))
> if connect is None:
> fail(_("Could not find usable default libvirt connection."))
> @@ -307,7 +307,7 @@ def digest_networks(conn, macs, bridges,
> # Create extra networks up to the number of nics requested
> if len(macs) < nics:
> for dummy in range(len(macs),nics):
> - if os.getuid() == 0:
> + if util.privileged_user():
> net = util.default_network(conn)
> networks.append(net[0] + ":" + net[1])
> else:
> diff --git a/virtinst/util.py b/virtinst/util.py
> --- a/virtinst/util.py
> +++ b/virtinst/util.py
> @@ -93,7 +93,7 @@ def default_connection():
> os.path.exists("/usr/bin/qemu-kvm") or
> os.path.exists("/usr/bin/kvm") or
> os.path.exists("/usr/bin/xenner"):
> - if os.getuid() == 0:
> + if privileged_user():
> return "qemu:///system"
> else:
> return "qemu:///session"
> @@ -509,6 +509,14 @@ def lookup_pool_by_path(conn, path):
> return pool
> return None
>
> +def privileged_user():
> + """
> + Return true if the user is privileged enough. On Linux, this
> + equates to being root. On Solaris, it's more complicated, so we
> + just assume we're OK.
> + """
> + return os.uname()[0] == 'SunOS' or os.geteuid() == 0
> +
> def _test():
> import doctest
> doctest.testmod()
>
> _______________________________________________
> et-mgmt-tools mailing list
> et-mgmt-tools@redhat.com
> https://www.redhat.com/mailman/listinfo/et-mgmt-tools


_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 12-04-2008, 12:26 PM
John Levon
 
Default Least privilege support

On Thu, Dec 04, 2008 at 09:41:19PM +0900, Atsushi SAKAI wrote:

> I have a question about this patch.
> (because of my understanding)
>
> It seems check "SunOS" only for Solaris.
> (It will be added some code in future?)

Possibly. There's no generally available Python interface to test for
effective Solaris privileges right now.

regards
john

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 12-07-2008, 03:24 AM
Cole Robinson
 
Default Least privilege support

john.levon@sun.com wrote:
> # HG changeset patch
> # User john.levon@sun.com
> # Date 1228271172 28800
> # Node ID 2771f870b247df02b16a4d79cdf549a1ad0132aa
> # Parent a4538c6c2d6690526d80c011b46b4700c23a9ffd
> Least privilege support
>
> On Solaris, which users can run virt-install depends on their effective
> privilege set, not their effective UID.
>
> Signed-off-by: John Levon <john.levon@sun.com>
>
>

Thanks, applied:

http://hg.et.redhat.com/virt/applications/virtinst--devel?cs=4ff5f60b8f52

- Cole

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 

Thread Tools




All times are GMT. The time now is 01:23 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org