All of lore.kernel.org
 help / color / mirror / Atom feed
* RE: [PATCH] xen-2.0: privileged port connections
@ 2005-03-23 18:51 Ian Pratt
  2005-03-23 19:27 ` Anthony Liguori
  2005-03-23 21:39 ` Kurt Garloff
  0 siblings, 2 replies; 18+ messages in thread
From: Ian Pratt @ 2005-03-23 18:51 UTC (permalink / raw)
  To: Anthony Liguori, Kurt Garloff; +Cc: xen-devel, ian.pratt

> Would a patch to change Xend to use pty's for consoles be 
> accepted?  xm 
> console can be invoked via ssh to support remote consoles..

I'm in favour of this in principle, but I think we need to think through
precisely how the pty approach would work. 

There are a couple of other issues that we should consider at the same
time. I've heard a couple of users complain that they find our model of
exporting serial consoles confusing: when they quit a console session
and reconnect they find that they are still logged in. Worse, if they
were running vi when they quit the session they get very confused when
connecting back in. I guess if you're not used to a serial console then
you would find the behaviour confusing. Should we be doing some more
complex terminal emulation?

Using something like 'screen' in dom0 might help, so at least upon
reconnecting the console window is 'refreshed' to show its previous
contents.

The other issue we need to consider is VM migration. Ideally, it should
be completely transparent to someone with a console connection open
(just like it is to someone with an ssh connection open). There are two
ways to do this, either have a console server machine for all the nodes
in a cluster, or hide the disconnect/reconnect in the client terminal
program. If we are using a 'standard' program on the client side (e.g.
ssh in an xterm), then the former is preferable. If for some reason we
choose to use a custom program (e.g. son-of-xencons) then we could
reasonably hide the relocation.

I'd like to see a decent discussion of how best to do consoles before
changing the status quo. 

Thanks,
Ian 


 


-------------------------------------------------------
This SF.net email is sponsored by Microsoft Mobile & Embedded DevCon 2005
Attend MEDC 2005 May 9-12 in Vegas. Learn more about the latest Windows
Embedded(r) & Windows Mobile(tm) platforms, applications & content.  Register
by 3/29 & save $300 http://ads.osdn.com/?ad_idh83&alloc_id\x15149&op=click

^ permalink raw reply	[flat|nested] 18+ messages in thread
* RE: [PATCH] xen-2.0: privileged port connections
@ 2005-03-23 17:43 Ian Pratt
  2005-03-23 17:59 ` Ryan Harper
  2005-03-24 19:06 ` Tommi Virtanen
  0 siblings, 2 replies; 18+ messages in thread
From: Ian Pratt @ 2005-03-23 17:43 UTC (permalink / raw)
  To: Kurt Garloff, Anthony Liguori; +Cc: Xen development list, ian.pratt

> > 1) ports < 1024 are reserved although 732 is currently unassigned
> 
> Note that NFS uses such ports without asking prior permission.
> I chose 732 because it's unassigned indeed.

Grabbing any port <1024 should do, there's no need to just go for 732,
but have a series of ports that are tried. 
 
> > 2) unix domain sockets would solve the same problem
> 
> Yes. There's one but: 
> 
> With the patch you can currently configure xend from completely
> open (xend-address '' and xend-privileged-port 0)
> to closed (xend-address 'localhost' and xend-privileged-port 1)
> except for root (and stuff I overlooked or did not do yet).
> 
> If you go for Unix Domain Sockets instead TCP, you lose the ability
> of remote control. Unless you support both.
> 
> I did not investigate how difficult to do that would be.
> If you have a patch, I'd volunteer to review :-)

For Xen 2.x, unix domain sockets would be too much of a pain to
implement over Twisted. Kurt's approach gets us closer toward 'secure by
default'.

Xen 3 will be very different.

> > 4) you still have to find a way to deal with the consoles
> 
> Before I start working on getting the consoles under control, I 
> wanted to see whether this approach is acceptable at all.

I think it's a good band-aid.

Perhaps a better way to handle consoles would be to use 'screend', and
then have incoming ssh connections dispatched to particular screen
sessions.
 
> > 5) you still have to deal with xfrd
> 
> It seems to listen on *:8002 ... 
> Is there no authentication either? Sigh.
> 
> And we probably need to look into the event channel (8001) as well.

Xfrd needs an option to listen only on localhost. (It's still needed for
save/restore even if you don't use migrate).

The event channel only ever needs to be localhost (and could probably be
turned into a unix domain socket quite easily).


Ian


-------------------------------------------------------
This SF.net email is sponsored by Microsoft Mobile & Embedded DevCon 2005
Attend MEDC 2005 May 9-12 in Vegas. Learn more about the latest Windows
Embedded(r) & Windows Mobile(tm) platforms, applications & content.  Register
by 3/29 & save $300 http://ads.osdn.com/?ad_idh83&alloc_id\x15149&op=click

^ permalink raw reply	[flat|nested] 18+ messages in thread
* [PATCH] xen-2.0: privileged port connections
@ 2005-03-23 12:36 Kurt Garloff
  2005-03-23 15:41 ` Anthony Liguori
  2005-03-24  7:31 ` David Hopwood
  0 siblings, 2 replies; 18+ messages in thread
From: Kurt Garloff @ 2005-03-23 12:36 UTC (permalink / raw)
  To: Xen development list


[-- Attachment #1.1: Type: text/plain, Size: 935 bytes --]

Hi,

as discussed previously, I went ahead and introduced a setting that
allows you to restrict the stuff you can when controlling xen by
connecting to the port 8000 unless you connect from a privileged
port.

I did not yet bother to look at the event port nor did I try to address
the consoles. The consoles will be done in a second patch if this 
approach is deemed appropriate. 

Note that I also do still allow unprivileged connections still to gather
most of the information. This can be debated, but I'm not such a big fan
of security by obscurity.

I hope I did not miss anything important for the control stuff.

The patch also fixes one typo (missing ") in SrvNode.py.

Regards,
-- 
Kurt Garloff                   <kurt@garloff.de>             [Koeln, DE]
Physics:Plasma modeling <garloff@plasimo.phys.tue.nl> [TU Eindhoven, NL]
Linux: SUSE Labs (Director)    <garloff@suse.de>            [Novell Inc]

[-- Attachment #1.2: xen-secure.diff --]
[-- Type: text/plain, Size: 13610 bytes --]

Signed-off-by: Kurt Garloff <garloff@suse.de>

diff -uNrp xen-2.0-testing/tools/examples/xend-config.sxp xen-2.0-testing.secure/tools/examples/xend-config.sxp
--- xen-2.0-testing/tools/examples/xend-config.sxp	2005-03-21 04:58:08.000000000 +0100
+++ xen-2.0-testing.secure/tools/examples/xend-config.sxp	2005-03-23 13:18:01.167841981 +0100
@@ -11,6 +11,15 @@
 # Specifying the empty string '' allows all connections.
 (xend-address      'localhost')
 
+# Set this to 1 to restrict the access to the xend port
+# to connections from a privileged port (<1024); together
+# with binding to localhost, this will restrict xen control
+# to the root user in domain0.
+# Note that the protection is not yet complete, consoles
+# are not yet protected. Also, most read-only information
+# ist still readable.
+(xend-privileged-port   1)
+
 # The port xend should start from when allocating a port
 # for a domain console.
 (console-port-base 9600)
diff -uNrp xen-2.0-testing/tools/python/xen/xend/XendProtocol.py xen-2.0-testing.secure/tools/python/xen/xend/XendProtocol.py
--- xen-2.0-testing/tools/python/xen/xend/XendProtocol.py	2005-03-21 04:58:03.000000000 +0100
+++ xen-2.0-testing.secure/tools/python/xen/xend/XendProtocol.py	2005-03-23 13:13:25.686990578 +0100
@@ -1,6 +1,7 @@
 # Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
 
 import httplib
+import socket
 import types
 
 from encode import *
@@ -122,6 +123,43 @@ class XendClientProtocol:
         """
         raise NotImplementedError()
 
+class xenhttpconn(httplib.HTTPConnection):
+    """A httplib class with slightly modified connect function that
+    tries to grab a privileged source port.
+    """
+
+    def connect(self):
+        """Connect to the host and port specified in __init__."""
+        msg = "getaddrinfo returns an empty list"
+        for res in socket.getaddrinfo(self.host, self.port, 0,
+                                      socket.SOCK_STREAM):
+            af, socktype, proto, canonname, sa = res
+            try:
+                self.sock = socket.socket(af, socktype, proto)
+                if self.debuglevel > 0:
+                    print "connect: (%s, %s)" % (self.host, self.port)
+                # Try to get a src port below 1024
+                port = 732
+                while port < 1024:
+                    try:
+                        self.sock.bind(("", port))
+                    except socket.error, msg:
+			port += 1
+                    else:
+                        break
+                self.sock.connect(sa)
+            except socket.error, msg:
+                if self.debuglevel > 0:
+                    print 'connect fail:', (self.host, self.port)
+                if self.sock:
+                    self.sock.close()
+                self.sock = None
+                continue
+            break
+        if not self.sock:
+            raise socket.error, msg
+
+
 class SynchXendClientProtocol(XendClientProtocol):
     """A synchronous xend client. This will make a request, wait for
     the reply and return the result.
@@ -137,7 +175,7 @@ class SynchXendClientProtocol(XendClient
         @param args:   request arguments (dict)
         """
         self.request = XendRequest(url, method, args)
-        conn = httplib.HTTPConnection(url.location())
+        conn = xenhttpconn(url.location())
         if DEBUG: conn.set_debuglevel(1)
         conn.request(method, url.fullpath(), self.request.data, self.request.headers)
         resp = conn.getresponse()
diff -uNrp xen-2.0-testing/tools/python/xen/xend/XendRoot.py xen-2.0-testing.secure/tools/python/xen/xend/XendRoot.py
--- xen-2.0-testing/tools/python/xen/xend/XendRoot.py	2005-03-21 04:58:04.000000000 +0100
+++ xen-2.0-testing.secure/tools/python/xen/xend/XendRoot.py	2005-03-23 13:18:56.085242803 +0100
@@ -47,6 +47,9 @@ class XendRoot:
     """Default interface address xend listens at. """
     xend_address_default      = ''
 
+    """Default for xend-privileged """
+    xend_privileged_port_default   = 1
+
     """Default port xend serves HTTP at. """
     xend_port_default         = '8000'
 
@@ -236,6 +239,12 @@ class XendRoot:
         """
         return self.get_config_value('xend-address', self.xend_address_default)
 
+    def get_xend_privileged_port(self):
+	"""Get the setting that controls whether xend only accepts connections
+	from privileged ports.
+	"""
+	return self.get_config_value('xend-privileged-port', self.xend_privileged_port_default)
+
     def get_console_address(self):
         """Get the address xend listens at for its console ports.
         This defaults to the empty string which allows all hosts to connect.
diff -uNrp xen-2.0-testing/tools/python/xen/xend/server/SrvConsole.py xen-2.0-testing.secure/tools/python/xen/xend/server/SrvConsole.py
--- xen-2.0-testing/tools/python/xen/xend/server/SrvConsole.py	2005-03-21 04:58:07.000000000 +0100
+++ xen-2.0-testing.secure/tools/python/xen/xend/server/SrvConsole.py	2005-03-23 13:13:25.634999664 +0100
@@ -17,9 +17,6 @@ class SrvConsole(SrvDir):
         val = self.xc.console_disconnect(self.info.console_port)
         return val
 
-    def render_POST(self, req):
-        return self.perform(req)
-        
     def render_GET(self, req):
         try:
             if self.use_sxp(req):
@@ -32,7 +29,8 @@ class SrvConsole(SrvDir):
                 req.write('<p>%s</p>' % self.info)
                 req.write('<p><a href="%s">Connect to domain %d</a></p>'
                           % (self.info.uri(), self.info.dom))
-                self.form(req)
+		if self.isAuthorized(req):
+		    self.form(req)
                 req.write('</body></html>')
             return ''
         except Exception, ex:
diff -uNrp xen-2.0-testing/tools/python/xen/xend/server/SrvDir.py xen-2.0-testing.secure/tools/python/xen/xend/server/SrvDir.py
--- xen-2.0-testing/tools/python/xen/xend/server/SrvDir.py	2005-03-21 04:58:04.000000000 +0100
+++ xen-2.0-testing.secure/tools/python/xen/xend/server/SrvDir.py	2005-03-23 13:19:35.073427804 +0100
@@ -8,6 +8,9 @@ from xen.xend.XendError import XendError
 
 from SrvBase import SrvBase
 
+from xen.xend import XendRoot
+xroot = XendRoot.instance()
+
 class SrvError(error.ErrorPage):
 
     def render(self, request):
@@ -84,7 +87,8 @@ class SrvDir(SrvBase):
                 req.write('<html><head></head><body>')
                 self.print_path(req)
                 self.ls(req)
-                self.form(req)
+		if self.isAuthorized(req):
+                    self.form(req)
                 req.write('</body></html>')
             return ''
         except Exception, ex:
@@ -109,3 +113,22 @@ class SrvDir(SrvBase):
 
     def form(self, req):
         pass
+
+    def render_POST(self, req):
+	if self.isAuthorized(req):
+		return self.perform(req)
+	else:
+		return self.unauthPage(req, "You need admin power.")
+
+    def isAuthorized(self, req):
+	return (req.transport.client[1] < 1024 
+		or not int(xroot.get_xend_privileged_port()))
+
+    def unauthPage(self, req, msg):
+	msg1 = "<p>Connected from %s:%i\n" % \
+		(req.transport.client[0], req.transport.client[1])
+	msg1 += "<Br>Need to connect from privileged port "
+	msg1 += "or set (xend-privileged 0) in xend-config.sxp\n"
+        err = SrvError(http.UNAUTHORIZED, "UNAUTHORIZED", msg + msg1)
+	return err.render(req)
+
diff -uNrp xen-2.0-testing/tools/python/xen/xend/server/SrvDmesg.py xen-2.0-testing.secure/tools/python/xen/xend/server/SrvDmesg.py
--- xen-2.0-testing/tools/python/xen/xend/server/SrvDmesg.py	2005-03-21 04:58:06.000000000 +0100
+++ xen-2.0-testing.secure/tools/python/xen/xend/server/SrvDmesg.py	2005-03-23 13:13:25.647997393 +0100
@@ -15,10 +15,8 @@ class SrvDmesg(SrvDir):
         SrvDir.__init__(self)
         self.xd = XendDmesg.instance()
 
-    def render_POST(self, req):
-        self.perform(req)
-
     def render_GET(self, req):
+	# No access restriction for now    
         try:
             if self.use_sxp(req):
                 req.setHeader("Content-Type", "text/plain")
diff -uNrp xen-2.0-testing/tools/python/xen/xend/server/SrvDomain.py xen-2.0-testing.secure/tools/python/xen/xend/server/SrvDomain.py
--- xen-2.0-testing/tools/python/xen/xend/server/SrvDomain.py	2005-03-21 04:58:10.000000000 +0100
+++ xen-2.0-testing.secure/tools/python/xen/xend/server/SrvDomain.py	2005-03-23 13:13:25.615003159 +0100
@@ -193,9 +193,6 @@ class SrvDomain(SrvDir):
         val = fn(req.args, {'dom': self.dom.id})
         return val
 
-    def render_POST(self, req):
-        return self.perform(req)
-        
     def render_GET(self, req):
         op = req.args.get('op')
         if op and op[0] in ['vifs', 'vif', 'vbds', 'vbd', 'mem_target_set']:
@@ -220,7 +217,8 @@ class SrvDomain(SrvDir):
                 req.write("<code><pre>")
                 PrettyPrint.prettyprint(self.dom.config, out=req)
                 req.write("</pre></code>")
-            self.form(req)
+            if self.isAuthorized(req):
+                self.form(req)
             req.write('</body></html>')
         return ''
 
diff -uNrp xen-2.0-testing/tools/python/xen/xend/server/SrvDomainDir.py xen-2.0-testing.secure/tools/python/xen/xend/server/SrvDomainDir.py
--- xen-2.0-testing/tools/python/xen/xend/server/SrvDomainDir.py	2005-03-21 04:58:10.000000000 +0100
+++ xen-2.0-testing.secure/tools/python/xen/xend/server/SrvDomainDir.py	2005-03-23 13:13:25.597006304 +0100
@@ -116,9 +116,6 @@ class SrvDomainDir(SrvDir):
             out.close()
             return val
 
-    def render_POST(self, req):
-        return self.perform(req)
-
     def render_GET(self, req):
         try:
             if self.use_sxp(req):
@@ -129,7 +126,8 @@ class SrvDomainDir(SrvDir):
                 self.print_path(req)
                 self.ls(req)
                 self.ls_domain(req)
-                self.form(req)
+		if self.isAuthorized(req):
+                    self.form(req)
                 req.write("</body></html>")
             return ''
         except Exception, ex:
diff -uNrp xen-2.0-testing/tools/python/xen/xend/server/SrvNode.py xen-2.0-testing.secure/tools/python/xen/xend/server/SrvNode.py
--- xen-2.0-testing/tools/python/xen/xend/server/SrvNode.py	2005-03-21 04:58:09.000000000 +0100
+++ xen-2.0-testing.secure/tools/python/xen/xend/server/SrvNode.py	2005-03-23 13:14:34.391982867 +0100
@@ -37,9 +37,6 @@ class SrvNode(SrvDir):
         val = fn(req.args, {})
         return val
     
-    def render_POST(self, req):
-        return self.perform(req)
-
     def render_GET(self, req):
         try:
             if self.use_sxp(req):
@@ -54,8 +51,9 @@ class SrvNode(SrvDir):
                 req.write('<ul>')
                 for d in self.info():
                     req.write('<li> %10s: %s' % (d[0], str(d[1])))
+                #if self.isAuthorized(req):
                 req.write('<li><a href="%sdmesg">Xen dmesg output</a>' % url)
-                req.write('<li><a href="%slog>Xend log</a>' % url)
+                req.write('<li><a href="%slog">Xend log</a>' % url)
                 req.write('</ul>')
                 req.write('</body></html>')
             return ''
diff -uNrp xen-2.0-testing/tools/python/xen/xend/server/SrvVnetDir.py xen-2.0-testing.secure/tools/python/xen/xend/server/SrvVnetDir.py
--- xen-2.0-testing/tools/python/xen/xend/server/SrvVnetDir.py	2005-03-21 04:58:11.000000000 +0100
+++ xen-2.0-testing.secure/tools/python/xen/xend/server/SrvVnetDir.py	2005-03-23 13:13:25.641998441 +0100
@@ -18,9 +18,6 @@ class SrvVnet(SrvDir):
         val = self.xvnet.vnet_delete(self.vnetinfo.id)
         return val
 
-    def render_POST(self, req):
-        return self.perform(req)
-        
     def render_GET(self, req):
         if self.use_sxp(req):
             req.setHeader("Content-Type", sxp.mime_type)
@@ -32,7 +29,8 @@ class SrvVnet(SrvDir):
             req.write("<code><pre>")
             PrettyPrint.prettyprint(self.vnetinfo.sxpr(), out=req)
             req.write("</pre></code>")
-            self.form(req)
+	    if self.isAuthorized(req):
+                self.form(req)
             req.write('</body></html>')
         return ''
 
@@ -71,9 +69,6 @@ class SrvVnetDir(SrvDir):
         val = fn(req.args, {})
         return val
         
-    def render_POST(self, req):
-        return self.perform(req)
-
     def render_GET(self, req):
         try:
             if self.use_sxp(req):
@@ -84,7 +79,8 @@ class SrvVnetDir(SrvDir):
                 self.print_path(req)
                 self.ls(req)
                 self.ls_vnet(req)
-                self.form(req)
+		if self.isAuthorized(req):
+		    self.form(req)
                 req.write("</body></html>")
             return ''
         except Exception, ex:
diff -uNrp xen-2.0-testing/tools/python/xen/xend/server/SrvXendLog.py xen-2.0-testing.secure/tools/python/xen/xend/server/SrvXendLog.py
--- xen-2.0-testing/tools/python/xen/xend/server/SrvXendLog.py	2005-03-21 04:58:11.000000000 +0100
+++ xen-2.0-testing.secure/tools/python/xen/xend/server/SrvXendLog.py	2005-03-23 13:13:25.654996170 +0100
@@ -18,6 +18,7 @@ class SrvXendLog(SrvDir):
         self.logfile.encoding = None
 
     def render_GET(self, req):
+	# No access restriction for now    
         try:
             return self.logfile.render(req)
         except Exception, ex:

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2005-03-24 19:56 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-23 18:51 [PATCH] xen-2.0: privileged port connections Ian Pratt
2005-03-23 19:27 ` Anthony Liguori
2005-03-23 21:37   ` Christian Limpach
2005-03-23 23:58     ` Kurt Garloff
2005-03-23 21:39 ` Kurt Garloff
  -- strict thread matches above, loose matches on Subject: below --
2005-03-23 17:43 Ian Pratt
2005-03-23 17:59 ` Ryan Harper
2005-03-24 19:06 ` Tommi Virtanen
2005-03-24 19:56   ` Anthony Liguori
2005-03-23 12:36 Kurt Garloff
2005-03-23 15:41 ` Anthony Liguori
2005-03-23 16:57   ` Kurt Garloff
2005-03-23 17:03     ` Anthony Liguori
2005-03-23 17:23       ` Kurt Garloff
2005-03-23 17:45         ` Anthony Liguori
2005-03-23 18:06         ` Rik van Riel
2005-03-23 17:36     ` Nivedita Singhvi
2005-03-24  7:31 ` David Hopwood

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.