mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-22 00:26:29 +00:00
commit
5716324934
@ -60,6 +60,7 @@ PRIVILEGED_ALL = [
|
|||||||
"NET_ADMIN",
|
"NET_ADMIN",
|
||||||
"SYS_ADMIN",
|
"SYS_ADMIN",
|
||||||
"SYS_RAWIO",
|
"SYS_RAWIO",
|
||||||
|
"IPC_LOCK",
|
||||||
"SYS_TIME",
|
"SYS_TIME",
|
||||||
"SYS_NICE"
|
"SYS_NICE"
|
||||||
]
|
]
|
||||||
|
@ -13,7 +13,7 @@ from .proxy import APIProxy
|
|||||||
from .supervisor import APISupervisor
|
from .supervisor import APISupervisor
|
||||||
from .snapshots import APISnapshots
|
from .snapshots import APISnapshots
|
||||||
from .services import APIServices
|
from .services import APIServices
|
||||||
from .security import security_layer
|
from .security import SecurityMiddleware
|
||||||
from ..coresys import CoreSysAttributes
|
from ..coresys import CoreSysAttributes
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -25,16 +25,14 @@ class RestAPI(CoreSysAttributes):
|
|||||||
def __init__(self, coresys):
|
def __init__(self, coresys):
|
||||||
"""Initialize docker base wrapper."""
|
"""Initialize docker base wrapper."""
|
||||||
self.coresys = coresys
|
self.coresys = coresys
|
||||||
|
self.security = SecurityMiddleware(coresys)
|
||||||
self.webapp = web.Application(
|
self.webapp = web.Application(
|
||||||
middlewares=[security_layer], loop=self._loop)
|
middlewares=[self.security.token_validation], loop=self._loop)
|
||||||
|
|
||||||
# service stuff
|
# service stuff
|
||||||
self._handler = None
|
self._handler = None
|
||||||
self.server = None
|
self.server = None
|
||||||
|
|
||||||
# middleware
|
|
||||||
self.webapp['coresys'] = coresys
|
|
||||||
|
|
||||||
async def load(self):
|
async def load(self):
|
||||||
"""Register REST API Calls."""
|
"""Register REST API Calls."""
|
||||||
self._register_supervisor()
|
self._register_supervisor()
|
||||||
|
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
@ -83,7 +83,7 @@ class APIProxy(CoreSysAttributes):
|
|||||||
if not data:
|
if not data:
|
||||||
await response.write_eof()
|
await response.write_eof()
|
||||||
break
|
break
|
||||||
response.write(data)
|
await response.write(data)
|
||||||
|
|
||||||
except aiohttp.ClientError:
|
except aiohttp.ClientError:
|
||||||
await response.write_eof()
|
await response.write_eof()
|
||||||
|
@ -6,6 +6,7 @@ from aiohttp.web import middleware
|
|||||||
from aiohttp.web_exceptions import HTTPUnauthorized
|
from aiohttp.web_exceptions import HTTPUnauthorized
|
||||||
|
|
||||||
from ..const import HEADER_TOKEN, REQUEST_FROM
|
from ..const import HEADER_TOKEN, REQUEST_FROM
|
||||||
|
from ..coresys import CoreSysAttributes
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -16,35 +17,41 @@ NO_SECURITY_CHECK = set((
|
|||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
@middleware
|
class SecurityMiddleware(CoreSysAttributes):
|
||||||
async def security_layer(request, handler):
|
"""Security middleware functions."""
|
||||||
"""Check security access of this layer."""
|
|
||||||
coresys = request.app['coresys']
|
|
||||||
hassio_token = request.headers.get(HEADER_TOKEN)
|
|
||||||
|
|
||||||
# Ignore security check
|
def __init__(self, coresys):
|
||||||
for rule in NO_SECURITY_CHECK:
|
"""Initialize security middleware."""
|
||||||
if rule.match(request.path):
|
self.coresys = coresys
|
||||||
_LOGGER.debug("Passthrough %s", request.path)
|
|
||||||
|
@middleware
|
||||||
|
async def token_validation(self, request, handler):
|
||||||
|
"""Check security access of this layer."""
|
||||||
|
hassio_token = request.headers.get(HEADER_TOKEN)
|
||||||
|
|
||||||
|
# Ignore security check
|
||||||
|
for rule in NO_SECURITY_CHECK:
|
||||||
|
if rule.match(request.path):
|
||||||
|
_LOGGER.debug("Passthrough %s", request.path)
|
||||||
|
return await handler(request)
|
||||||
|
|
||||||
|
# Need to be removed later
|
||||||
|
if not hassio_token:
|
||||||
|
_LOGGER.warning("Invalid token for access %s", request.path)
|
||||||
|
request[REQUEST_FROM] = 'UNKNOWN'
|
||||||
return await handler(request)
|
return await handler(request)
|
||||||
|
|
||||||
# Need to be removed later
|
# Home-Assistant
|
||||||
if not hassio_token:
|
if hassio_token == self._homeassistant.uuid:
|
||||||
_LOGGER.warning("Invalid token for access %s", request.path)
|
_LOGGER.debug("%s access from Home-Assistant", request.path)
|
||||||
request[REQUEST_FROM] = 'UNKNOWN'
|
request[REQUEST_FROM] = 'homeassistant'
|
||||||
return await handler(request)
|
return await handler(request)
|
||||||
|
|
||||||
# Home-Assistant
|
# Add-on
|
||||||
if hassio_token == coresys.homeassistant.uuid:
|
addon = self._addons.from_uuid(hassio_token)
|
||||||
_LOGGER.debug("%s access from Home-Assistant", request.path)
|
if addon:
|
||||||
request[REQUEST_FROM] = 'homeassistant'
|
_LOGGER.info("%s access from %s", request.path, addon.slug)
|
||||||
return await handler(request)
|
request[REQUEST_FROM] = addon.slug
|
||||||
|
return await handler(request)
|
||||||
|
|
||||||
# Add-on
|
raise HTTPUnauthorized()
|
||||||
addon = coresys.addons.from_uuid(hassio_token)
|
|
||||||
if addon:
|
|
||||||
_LOGGER.info("%s access from %s", request.path, addon.slug)
|
|
||||||
request[REQUEST_FROM] = addon.slug
|
|
||||||
return await handler(request)
|
|
||||||
|
|
||||||
raise HTTPUnauthorized()
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from ipaddress import ip_network
|
from ipaddress import ip_network
|
||||||
|
|
||||||
HASSIO_VERSION = '0.96'
|
HASSIO_VERSION = '0.97'
|
||||||
|
|
||||||
URL_HASSIO_VERSION = ('https://raw.githubusercontent.com/home-assistant/'
|
URL_HASSIO_VERSION = ('https://raw.githubusercontent.com/home-assistant/'
|
||||||
'hassio/{}/version.json')
|
'hassio/{}/version.json')
|
||||||
|
@ -108,10 +108,10 @@ class HassIO(CoreSysAttributes):
|
|||||||
# don't process scheduler anymore
|
# don't process scheduler anymore
|
||||||
self._scheduler.suspend = True
|
self._scheduler.suspend = True
|
||||||
|
|
||||||
# process stop tasks
|
|
||||||
self._websession.close()
|
|
||||||
self._websession_ssl.close()
|
|
||||||
|
|
||||||
# process async stop tasks
|
# process async stop tasks
|
||||||
await asyncio.wait(
|
await asyncio.wait([
|
||||||
[self._api.stop(), self._dns.stop()], loop=self._loop)
|
self._api.stop(),
|
||||||
|
self._dns.stop(),
|
||||||
|
self._websession.close(),
|
||||||
|
self._websession_ssl.close()
|
||||||
|
], loop=self._loop)
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 39172f8c49a5253b28eb8508940e2ffa4f0ca451
|
Subproject commit 2c79094fb48870d1c6c7f819a5fcb80744a16bb4
|
106
setup.py
106
setup.py
@ -1,53 +1,53 @@
|
|||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
from hassio.const import HASSIO_VERSION
|
from hassio.const import HASSIO_VERSION
|
||||||
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='HassIO',
|
name='HassIO',
|
||||||
version=HASSIO_VERSION,
|
version=HASSIO_VERSION,
|
||||||
license='BSD License',
|
license='BSD License',
|
||||||
author='The Home Assistant Authors',
|
author='The Home Assistant Authors',
|
||||||
author_email='hello@home-assistant.io',
|
author_email='hello@home-assistant.io',
|
||||||
url='https://home-assistant.io/',
|
url='https://home-assistant.io/',
|
||||||
description=('Open-source private cloud os for Home-Assistant'
|
description=('Open-source private cloud os for Home-Assistant'
|
||||||
' based on ResinOS'),
|
' based on ResinOS'),
|
||||||
long_description=('A maintainless private cloud operator system that'
|
long_description=('A maintainless private cloud operator system that'
|
||||||
'setup a Home-Assistant instance. Based on ResinOS'),
|
'setup a Home-Assistant instance. Based on ResinOS'),
|
||||||
classifiers=[
|
classifiers=[
|
||||||
'Intended Audience :: End Users/Desktop',
|
'Intended Audience :: End Users/Desktop',
|
||||||
'Intended Audience :: Developers',
|
'Intended Audience :: Developers',
|
||||||
'License :: OSI Approved :: Apache Software License',
|
'License :: OSI Approved :: Apache Software License',
|
||||||
'Operating System :: OS Independent',
|
'Operating System :: OS Independent',
|
||||||
'Topic :: Home Automation'
|
'Topic :: Home Automation'
|
||||||
'Topic :: Software Development :: Libraries :: Python Modules',
|
'Topic :: Software Development :: Libraries :: Python Modules',
|
||||||
'Topic :: Scientific/Engineering :: Atmospheric Science',
|
'Topic :: Scientific/Engineering :: Atmospheric Science',
|
||||||
'Development Status :: 5 - Production/Stable',
|
'Development Status :: 5 - Production/Stable',
|
||||||
'Intended Audience :: Developers',
|
'Intended Audience :: Developers',
|
||||||
'Programming Language :: Python :: 3.6',
|
'Programming Language :: Python :: 3.6',
|
||||||
],
|
],
|
||||||
keywords=['docker', 'home-assistant', 'api'],
|
keywords=['docker', 'home-assistant', 'api'],
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
platforms='any',
|
platforms='any',
|
||||||
packages=[
|
packages=[
|
||||||
'hassio',
|
'hassio',
|
||||||
'hassio.docker',
|
'hassio.docker',
|
||||||
'hassio.addons',
|
'hassio.addons',
|
||||||
'hassio.api',
|
'hassio.api',
|
||||||
'hassio.misc',
|
'hassio.misc',
|
||||||
'hassio.utils',
|
'hassio.utils',
|
||||||
'hassio.snapshots'
|
'hassio.snapshots'
|
||||||
],
|
],
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'async_timeout==2.0.0',
|
'async_timeout==2.0.0',
|
||||||
'aiohttp==2.3.10',
|
'aiohttp==3.0.7',
|
||||||
'docker==3.1.0',
|
'docker==3.1.1',
|
||||||
'colorlog==3.1.2',
|
'colorlog==3.1.2',
|
||||||
'voluptuous==0.11.1',
|
'voluptuous==0.11.1',
|
||||||
'gitpython==2.1.8',
|
'gitpython==2.1.8',
|
||||||
'pytz==2018.3',
|
'pytz==2018.3',
|
||||||
'pyudev==0.21.0',
|
'pyudev==0.21.0',
|
||||||
'pycryptodome==3.4.11'
|
'pycryptodome==3.4.11'
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"hassio": "0.96",
|
"hassio": "0.97",
|
||||||
"homeassistant": "0.65.3",
|
"homeassistant": "0.65.4",
|
||||||
"resinos": "1.3",
|
"resinos": "1.3",
|
||||||
"resinhup": "0.3",
|
"resinhup": "0.3",
|
||||||
"generic": "0.3",
|
"generic": "0.3",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user