This adds another serial console type socat support. Change-Id: Ic443d050790aee2ea2e27daf165310f8e292fda7 Implements: bp socat-consolechanges/36/493836/8
parent
30a16bc608
commit
dead07444c
@ -0,0 +1,4 @@
|
||||
{
|
||||
"protocol": "serial",
|
||||
"type": "shellinabox"
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
{
|
||||
"protocol": "serial",
|
||||
"type": "shellinabox",
|
||||
"url": "http://127.0.0.1:8866/?token=b4f5cb4a-8b01-40ea-ae46-67f0db4969b3"
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
{
|
||||
"console": {
|
||||
"url": "http://127.0.0.1:8866/?token=b4f5cb4a-8b01-40ea-ae46-67f0db4969b3"
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
.. -*- rst -*-
|
||||
|
||||
========================
|
||||
Server Remote Consoles
|
||||
========================
|
||||
|
||||
Create server remote console.
|
||||
|
||||
Create Remote Console
|
||||
=====================
|
||||
|
||||
.. rest_method:: POST /v1/servers/{server_uuid}/remote_consoles
|
||||
|
||||
The API provides a unified request for creating a remote console. The user can
|
||||
get a URL to connect the console from this API. The URL includes the token
|
||||
which is used to get permission to access the console. Servers may support
|
||||
different console protocols. To return a remote console using a specific
|
||||
protocol, such as serial, set the ``protocol`` parameter to ``serial``. For the
|
||||
same protocol, there may be different connection types such as ``serial protocal
|
||||
and socat type`` or ``serial protocol and shellinabox type``.
|
||||
|
||||
Normal response code: 200
|
||||
|
||||
Error response codes: badRequest(400), unauthorized(401), forbidden(403), itemNotFound(404),
|
||||
conflict(409), notImplemented(501)
|
||||
|
||||
Request
|
||||
-------
|
||||
|
||||
.. rest_parameters:: parameters.yaml
|
||||
|
||||
- server_uuid: server_ident
|
||||
- protocol: remote_console_protocol
|
||||
- type: remote_console_type
|
||||
|
||||
**Example Create Remote Socat Console: JSON request**
|
||||
|
||||
.. literalinclude:: samples/remote_consoles/create-shellinabox-console-req.json
|
||||
|
||||
Response
|
||||
--------
|
||||
|
||||
.. rest_parameters:: parameters.yaml
|
||||
|
||||
- protocol: remote_console_protocol
|
||||
- type: remote_console_type
|
||||
- url: remote_console_url
|
||||
|
||||
**Example Create Remote Socat Console: JSON response**
|
||||
|
||||
.. literalinclude:: samples/remote_consoles/create-shellinabox-console-resp.json
|
@ -1,36 +0,0 @@
|
||||
.. -*- rst -*-
|
||||
|
||||
========================
|
||||
Server Serial Console
|
||||
========================
|
||||
|
||||
Servers Serial Console can be managed through serial_console sub-resource.
|
||||
|
||||
|
||||
Server Serial Console Summary
|
||||
===============================
|
||||
|
||||
.. rest_method:: GET /v1/servers/{server_uuid}/serial_console
|
||||
|
||||
Get the console url info of the Server.
|
||||
|
||||
Normal response code: 200
|
||||
|
||||
Request
|
||||
-------
|
||||
|
||||
.. rest_parameters:: parameters.yaml
|
||||
|
||||
- server_uuid: server_ident
|
||||
|
||||
Response
|
||||
--------
|
||||
|
||||
.. rest_parameters:: parameters.yaml
|
||||
|
||||
- console: console_info
|
||||
- url: console_url
|
||||
|
||||
**Example server network:**
|
||||
|
||||
.. literalinclude:: samples/server_console/server-serial-console-get.json
|
@ -0,0 +1,31 @@
|
||||
# Copyright 2017 Huawei Technologies Co.,LTD.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
create_console = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'protocol': {
|
||||
'type': 'string',
|
||||
'enum': ['serial'],
|
||||
},
|
||||
'type': {
|
||||
'type': 'string',
|
||||
'enum': ['shellinabox', 'socat'],
|
||||
},
|
||||
},
|
||||
'required': ['protocol', 'type'],
|
||||
'additionalProperties': False
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import sys
|
||||
|
||||
from mogan.common import service as mogan_service
|
||||
from mogan.conf import CONF
|
||||
from mogan.conf import serial_console
|
||||
from mogan.console import websocketproxy
|
||||
|
||||
serial_console.register_cli_opts(CONF)
|
||||
|
||||
|
||||
def main():
|
||||
mogan_service.prepare_service(sys.argv)
|
||||
websocketproxy.MoganWebSocketProxy(
|
||||
listen_host=CONF.serial_console.socatproxy_host,
|
||||
listen_port=CONF.serial_console.socatproxy_port,
|
||||
file_only=True,
|
||||
RequestHandlerClass=websocketproxy.MoganProxyRequestHandler
|
||||
).start_server()
|
@ -0,0 +1,182 @@
|
||||
# Copyright 2015 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
serial_console_group = cfg.OptGroup(
|
||||
"serial_console",
|
||||
title="The serial console options",
|
||||
help="""
|
||||
The serial console feature allows you to connect to a guest.""")
|
||||
|
||||
opts = [
|
||||
cfg.URIOpt('shellinabox_base_url',
|
||||
default='http://127.0.0.1:8866/',
|
||||
help="""
|
||||
The URL an end user would use to connect to the ``mogan-shellinaboxproxy``
|
||||
service.
|
||||
|
||||
The ``mogan-shellinaboxproxy`` service is called with this token enriched URL
|
||||
and establishes the connection to the proper server.
|
||||
|
||||
Possible values:
|
||||
|
||||
* <scheme><IP-address><port-number>
|
||||
|
||||
Services which consume this:
|
||||
|
||||
* ``mogan-engine``
|
||||
|
||||
Interdependencies to other options:
|
||||
|
||||
* The IP address must be identical to the address to which the
|
||||
``mogan-shellinaboxproxy`` service is listening (see option
|
||||
``shellinaboxproxy_host``in this section).
|
||||
* The port must be the same as in the option ``shellinaboxproxy_port`` of this
|
||||
section.
|
||||
"""),
|
||||
|
||||
# TODO(macsz) check if WS protocol is still being used
|
||||
cfg.URIOpt('socat_base_url',
|
||||
default='ws://127.0.0.1:8867/',
|
||||
help="""
|
||||
The URL an end user would use to connect to the ``mogan-socatproxy`` service.
|
||||
|
||||
The ``mogan-socatproxy`` service is called with this token enriched URL
|
||||
and establishes the connection to the proper server.
|
||||
|
||||
Related options:
|
||||
|
||||
* The IP address must be identical to the address to which the
|
||||
``mogan-socatproxy`` service is listening (see option ``socatproxy_host``
|
||||
in this section).
|
||||
* The port must be the same as in the option ``socatproxy_port`` of this
|
||||
section.
|
||||
* If you choose to use a secured websocket connection, then start this option
|
||||
with ``wss://`` instead of the unsecured ``ws://``. The options ``cert``
|
||||
and ``key`` in the ``[DEFAULT]`` section have to be set for that.
|
||||
"""),
|
||||
]
|
||||
|
||||
cli_opts = [
|
||||
cfg.IPOpt('shellinaboxproxy_host',
|
||||
default='0.0.0.0',
|
||||
help="""
|
||||
The IP address which is used by the ``mogan-shellinaboxproxy`` service to
|
||||
listen for incoming requests.
|
||||
|
||||
The ``mogan-shellinaboxproxy`` service listens on this IP address for incoming
|
||||
connection requests to servers which expose shellinabox serial console.
|
||||
|
||||
Possible values:
|
||||
|
||||
* An IP address
|
||||
|
||||
Services which consume this:
|
||||
|
||||
* ``mogan-shellinaboxproxy``
|
||||
|
||||
Interdependencies to other options:
|
||||
|
||||
* Ensure that this is the same IP address which is defined in the option
|
||||
``shellinabox_base_url`` of this section or use ``0.0.0.0`` to listen on
|
||||
all addresses.
|
||||
"""),
|
||||
|
||||
cfg.PortOpt('shellinaboxproxy_port',
|
||||
default=8866,
|
||||
min=1,
|
||||
max=65535,
|
||||
help="""
|
||||
The port number which is used by the ``mogan-shellinaboxproxy`` service to
|
||||
listen for incoming requests.
|
||||
|
||||
The ``mogan-shellinaboxproxy`` service listens on this port number for incoming
|
||||
connection requests to servers which expose shellinabox serial console.
|
||||
|
||||
Possible values:
|
||||
|
||||
* A port number
|
||||
|
||||
Services which consume this:
|
||||
|
||||
* ``mogan-shellinaboxproxy``
|
||||
|
||||
Interdependencies to other options:
|
||||
|
||||
* Ensure that this is the same port number which is defined in the option
|
||||
``shellinabox_base_url`` of this section.
|
||||
"""),
|
||||
|
||||
cfg.IPOpt('socatproxy_host',
|
||||
default='0.0.0.0',
|
||||
help="""
|
||||
The IP address which is used by the ``mogan-socatproxy`` service to
|
||||
listen for incoming requests.
|
||||
|
||||
The ``mogan-socatproxy`` service listens on this IP address for incoming
|
||||
connection requests to servers which expose socat serial console.
|
||||
|
||||
Possible values:
|
||||
|
||||
* An IP address
|
||||
|
||||
Services which consume this:
|
||||
|
||||
* ``mogan-socatproxy``
|
||||
|
||||
Interdependencies to other options:
|
||||
|
||||
* Ensure that this is the same IP address which is defined in the option
|
||||
``socat_base_url`` of this section or use ``0.0.0.0`` to listen on
|
||||
all addresses.
|
||||
"""),
|
||||
|
||||
cfg.PortOpt('socatproxy_port',
|
||||
default=8867,
|
||||
min=1,
|
||||
max=65535,
|
||||
help="""
|
||||
The port number which is used by the ``mogan-socatproxy`` service to
|
||||
listen for incoming requests.
|
||||
|
||||
The ``mogan-socatproxy`` service listens on this port number for incoming
|
||||
connection requests to servers which expose socat serial console.
|
||||
|
||||
Possible values:
|
||||
|
||||
* A port number
|
||||
|
||||
Services which consume this:
|
||||
|
||||
* ``mogan-socatproxy``
|
||||
|
||||
Interdependencies to other options:
|
||||
|
||||
* Ensure that this is the same port number which is defined in the option
|
||||
``socat_base_url`` of this section.
|
||||
"""),
|
||||
]
|
||||
|
||||
opts.extend(cli_opts)
|
||||
|
||||
|
||||
def register_opts(conf):
|
||||
conf.register_group(serial_console_group)
|
||||
conf.register_opts(opts, group=serial_console_group)
|
||||
|
||||
|
||||
def register_cli_opts(conf):
|
||||
conf.register_cli_opts(cli_opts, group=serial_console_group)
|
@ -1,111 +0,0 @@
|
||||
# Copyright 2015 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
shellinabox_opt_group = cfg.OptGroup("shellinabox_console",
|
||||
title="The shellinabox console feature",
|
||||
help="""
|
||||
The shellinabox console feature allows you to connect to a guest in case a
|
||||
graphical console like VNC, RDP or SPICE is not available. This is only
|
||||
currently supported for the Ironic driver.""")
|
||||
|
||||
shellinaboxproxy_host_opt = cfg.IPOpt('shellinaboxproxy_host',
|
||||
default='0.0.0.0',
|
||||
help="""
|
||||
The IP address which is used by the ``mogan-shellinaboxproxy`` service to
|
||||
listen for incoming requests.
|
||||
|
||||
The ``mogan-shellinaboxproxy`` service listens on this IP address for incoming
|
||||
connection requests to servers which expose shellinabox serial console.
|
||||
|
||||
Possible values:
|
||||
|
||||
* An IP address
|
||||
|
||||
Services which consume this:
|
||||
|
||||
* ``mogan-shellinaboxproxy``
|
||||
|
||||
Interdependencies to other options:
|
||||
|
||||
* Ensure that this is the same IP address which is defined in the option
|
||||
``shellinabox_base_url`` of this section or use ``0.0.0.0`` to listen on
|
||||
all addresses.
|
||||
""")
|
||||
|
||||
shellinaboxproxy_port_opt = cfg.PortOpt('shellinaboxproxy_port',
|
||||
default=8866,
|
||||
min=1,
|
||||
max=65535,
|
||||
help="""
|
||||
The port number which is used by the ``mogan-shellinaboxproxy`` service to
|
||||
listen for incoming requests.
|
||||
|
||||
The ``mogan-shellinaboxproxy`` service listens on this port number for incoming
|
||||
connection requests to servers which expose shellinabox serial console.
|
||||
|
||||
Possible values:
|
||||
|
||||
* A port number
|
||||
|
||||
Services which consume this:
|
||||
|
||||
* ``mogan-shellinaboxproxy``
|
||||
|
||||
Interdependencies to other options:
|
||||
|
||||
* Ensure that this is the same port number which is defined in the option
|
||||
``shellinabox_base_url`` of this section.
|
||||
""")
|
||||
|
||||
shellinabox_base_url_opt = cfg.URIOpt('shellinabox_base_url',
|
||||
default='http://127.0.0.1:8866/',
|
||||
help="""
|
||||
The URL an end user would use to connect to the ``mogan-shellinaboxproxy``
|
||||
service.
|
||||
|
||||
The ``mogan-shellinaboxproxy`` service is called with this token enriched URL
|
||||
and establishes the connection to the proper server.
|
||||
|
||||
Possible values:
|
||||
|
||||
* <scheme><IP-address><port-number>
|
||||
|
||||
Services which consume this:
|
||||
|
||||
* ``mogan-engine``
|
||||
|
||||
Interdependencies to other options:
|
||||
|
||||
* The IP address must be identical to the address to which the
|
||||
``mogan-shellinaboxproxy`` service is listening (see option
|
||||
``shellinaboxproxy_host``in this section).
|
||||
* The port must be the same as in the option ``shellinaboxproxy_port`` of this
|
||||
section.
|
||||
""")
|
||||
|
||||
shellinabox_opts = [shellinaboxproxy_host_opt, shellinaboxproxy_port_opt,
|
||||
shellinabox_base_url_opt]
|
||||
|
||||
|
||||
def register_opts(conf):
|
||||
conf.register_group(shellinabox_opt_group)
|
||||
conf.register_opts(shellinabox_opts, group=shellinabox_opt_group)
|
||||
|
||||
|
||||
def register_cli_opts(conf):
|
||||
conf.register_group(shellinabox_opt_group)
|
||||
conf.register_cli_opts(shellinabox_opts, shellinabox_opt_group)
|
@ -0,0 +1,147 @@
|
||||
# Copyright (c) 2012 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
'''
|
||||
Websocket proxy that is compatible with OpenStack Mogan.
|
||||
Leverages websockify.py by Joel Martin
|
||||
'''
|
||||
|
||||
import socket
|
||||
import sys
|
||||
|
||||
from oslo_context import context
|
||||
from oslo_log import log
|
||||
from six.moves import http_cookies as Cookie
|
||||
import six.moves.urllib.parse as urlparse
|
||||
import websockify
|
||||
|
||||
from mogan.common import exception
|
||||
from mogan.common.i18n import _
|
||||
from mogan.consoleauth import rpcapi as consoleauth_rpcapi
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class MoganProxyRequestHandler(websockify.ProxyRequestHandler):
|
||||
def socket(self, *args, **kwargs):
|
||||
return websockify.WebSocketServer.socket(*args, **kwargs)
|
||||
|
||||
def address_string(self):
|
||||
# NOTE(rpodolyaka): override the superclass implementation here and
|
||||
# explicitly disable the reverse DNS lookup, which might fail on some
|
||||
# deployments due to DNS configuration and break VNC access completely
|
||||
return str(self.client_address[0])
|
||||
|
||||
def verify_origin_proto(self, connection_info, origin_proto):
|
||||
access_url = connection_info.get('access_url')
|
||||
if not access_url:
|
||||
detail = _("No access_url in connection_info. "
|
||||
"Cannot validate protocol")
|
||||
raise exception.ValidationError(detail=detail)
|
||||
expected_protos = [urlparse.urlparse(access_url).scheme]
|
||||
# NOTE: For serial consoles the expected protocol could be ws or
|
||||
# wss which correspond to http and https respectively in terms of
|
||||
# security.
|
||||
if 'ws' in expected_protos:
|
||||
expected_protos.append('http')
|
||||
if 'wss' in expected_protos:
|
||||
expected_protos.append('https')
|
||||
|
||||
return origin_proto in expected_protos
|
||||
|
||||
def new_websocket_client(self):
|
||||
"""Called after a new WebSocket connection has been established."""
|
||||
# Reopen the eventlet hub to make sure we don't share an epoll
|
||||
# fd with parent and/or siblings, which would be bad
|
||||
from eventlet import hubs
|
||||
hubs.use_hub()
|
||||
|
||||
# The expected behavior is to have token
|
||||
# passed to the method GET of the request
|
||||
parse = urlparse.urlparse(self.path)
|
||||
if parse.scheme not in ('http', 'https'):
|
||||
# From a bug in urlparse in Python < 2.7.4 we cannot support
|
||||
# special schemes (cf: http://bugs.python.org/issue9374)
|
||||
if sys.version_info < (2, 7, 4):
|
||||
raise exception.NovaException(
|
||||
_("We do not support scheme '%s' under Python < 2.7.4, "
|
||||
"please use http or https") % parse.scheme)
|
||||
|
||||
query = parse.query
|
||||
token = urlparse.parse_qs(query).get("token", [""]).pop()
|
||||
if not token:
|
||||
# NoVNC uses it's own convention that forward token
|
||||
# from the request to a cookie header, we should check
|
||||
# also for this behavior
|
||||
hcookie = self.headers.get('cookie')
|
||||
if hcookie:
|
||||
cookie = Cookie.SimpleCookie()
|
||||
for hcookie_part in hcookie.split(';'):
|
||||
hcookie_part = hcookie_part.lstrip()
|
||||
try:
|
||||
cookie.load(hcookie_part)
|
||||
except Cookie.CookieError:
|
||||
# NOTE(stgleb): Do not print out cookie content
|
||||
# for security reasons.
|
||||
LOG.warning('Found malformed cookie')
|
||||
else:
|
||||
if 'token' in cookie:
|
||||
token = cookie['token'].value
|
||||
|
||||
ctxt = context.get_admin_context()
|
||||
rpcapi = consoleauth_rpcapi.ConsoleAuthAPI()
|
||||
connect_info = rpcapi.check_token(ctxt, token=token)
|
||||
|
||||
if not connect_info:
|
||||
raise exception.InvalidToken(token=token)
|
||||
|
||||
self.msg(_('connect info: %s'), str(connect_info))
|
||||
host = connect_info['host']
|
||||
port = int(connect_info['port'])
|
||||
|
||||
# Connect to the target
|
||||
self.msg(_("connecting to: %(host)s:%(port)s") % {'host': host,
|
||||
'port': port})
|
||||
tsock = self.socket(host, port, connect=True)
|
||||
|
||||
# Handshake as necessary
|
||||
if connect_info.get('internal_access_path'):
|
||||
tsock.send("CONNECT %s HTTP/1.1\r\n\r\n" %
|
||||
connect_info['internal_access_path'])
|
||||
while True:
|
||||
data = tsock.recv(4096, socket.MSG_PEEK)
|
||||
if data.find("\r\n\r\n") != -1:
|
||||
if data.split("\r\n")[0].find("200") == -1:
|
||||
raise exception.InvalidConnectionInfo()
|
||||
tsock.recv(len(data))
|
||||
break
|
||||
|
||||
# Start proxying
|
||||
try:
|
||||
self.do_proxy(tsock)
|
||||
except Exception:
|
||||
if tsock:
|
||||
tsock.shutdown(socket.SHUT_RDWR)
|
||||
tsock.close()
|
||||
self.vmsg(_("%(host)s:%(port)s: "
|
||||
"Websocket client or target closed") %
|
||||
{'host': host, 'port': port})
|
||||
raise
|
||||
|
||||
|
||||
class MoganWebSocketProxy(websockify.WebSocketProxy):
|
||||
@staticmethod
|
||||
def get_logger():
|
||||
return LOG
|
Loading…
Reference in new issue