Skip to content

Commit bccb646

Browse files
authored
Create issue to warn against using http.server_host in supervised installs (#155837)
1 parent 4a5dc8c commit bccb646

File tree

4 files changed

+76
-4
lines changed

4 files changed

+76
-4
lines changed

homeassistant/components/http/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from homeassistant.core import Event, HomeAssistant, callback
3939
from homeassistant.exceptions import HomeAssistantError
4040
from homeassistant.helpers import config_validation as cv, issue_registry as ir, storage
41+
from homeassistant.helpers.hassio import is_hassio
4142
from homeassistant.helpers.http import (
4243
KEY_ALLOW_CONFIGURED_CORS,
4344
KEY_AUTHENTICATED, # noqa: F401
@@ -109,7 +110,7 @@
109110
cv.deprecated(CONF_BASE_URL),
110111
vol.Schema(
111112
{
112-
vol.Optional(CONF_SERVER_HOST, default=_DEFAULT_BIND): vol.All(
113+
vol.Optional(CONF_SERVER_HOST): vol.All(
113114
cv.ensure_list, vol.Length(min=1), [cv.string]
114115
),
115116
vol.Optional(CONF_SERVER_PORT, default=SERVER_PORT): cv.port,
@@ -207,7 +208,17 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
207208
if conf is None:
208209
conf = cast(ConfData, HTTP_SCHEMA({}))
209210

210-
server_host = conf[CONF_SERVER_HOST]
211+
if CONF_SERVER_HOST in conf and is_hassio(hass):
212+
ir.async_create_issue(
213+
hass,
214+
DOMAIN,
215+
"server_host_may_break_hassio",
216+
is_fixable=False,
217+
severity=ir.IssueSeverity.ERROR,
218+
translation_key="server_host_may_break_hassio",
219+
)
220+
221+
server_host = conf.get(CONF_SERVER_HOST, _DEFAULT_BIND)
211222
server_port = conf[CONF_SERVER_PORT]
212223
ssl_certificate = conf.get(CONF_SSL_CERTIFICATE)
213224
ssl_peer_certificate = conf.get(CONF_SSL_PEER_CERTIFICATE)

homeassistant/components/http/strings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"issues": {
3+
"server_host_may_break_hassio": {
4+
"description": "The `server_host` configuration option in the HTTP integration is prone to break the communication between Home Assistant Core and Supervisor, and will be removed in a future release.\n\nIf you are using this option to bind Home Assistant to specific network interfaces, please remove it from your configuration. Home Assistant will automatically bind to all available interfaces by default.\n\nIf you have specific networking requirements, consider using firewall rules or other network configuration to control access to Home Assistant.",
5+
"title": "The `server_host` HTTP configuration may break Home Assistant Core - Supervisor communication"
6+
},
37
"ssl_configured_without_configured_urls": {
48
"description": "Home Assistant detected that SSL has been set up on your instance, however, no custom external internet URL has been set.\n\nThis may result in unexpected behavior. Text-to-speech may fail, and integrations may not be able to connect back to your instance correctly.\n\nTo address this issue, go to Settings > System > Network; under the \"Home Assistant URL\" section, configure your new \"Internet\" and \"Local network\" addresses that match your new SSL configuration.",
59
"title": "SSL is configured without an external URL or internal URL"

tests/components/http/test_init.py

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ipaddress import ip_network
88
import logging
99
from pathlib import Path
10-
from unittest.mock import Mock, patch
10+
from unittest.mock import ANY, Mock, patch
1111

1212
import pytest
1313

@@ -667,3 +667,61 @@ async def test_ssl_issue_urls_configured(
667667
"http",
668668
"ssl_configured_without_configured_urls",
669669
) not in issue_registry.issues
670+
671+
672+
@pytest.mark.parametrize(
673+
(
674+
"hassio",
675+
"http_config",
676+
"expected_serverhost",
677+
"expected_issues",
678+
),
679+
[
680+
(False, {}, ["0.0.0.0", "::"], set()),
681+
(False, {"server_host": "0.0.0.0"}, ["0.0.0.0"], set()),
682+
(True, {}, ["0.0.0.0", "::"], set()),
683+
(
684+
True,
685+
{"server_host": "0.0.0.0"},
686+
[
687+
"0.0.0.0",
688+
],
689+
{("http", "server_host_may_break_hassio")},
690+
),
691+
],
692+
)
693+
async def test_server_host(
694+
hass: HomeAssistant,
695+
hassio: bool,
696+
issue_registry: ir.IssueRegistry,
697+
http_config: dict,
698+
expected_serverhost: list,
699+
expected_issues: set[tuple[str, str]],
700+
) -> None:
701+
"""Test server_host behavior."""
702+
mock_server = Mock()
703+
with (
704+
patch("homeassistant.components.http.is_hassio", return_value=hassio),
705+
patch(
706+
"asyncio.BaseEventLoop.create_server", return_value=mock_server
707+
) as mock_create_server,
708+
):
709+
assert await async_setup_component(
710+
hass,
711+
"http",
712+
{"http": http_config},
713+
)
714+
await hass.async_start()
715+
await hass.async_block_till_done()
716+
717+
mock_create_server.assert_called_once_with(
718+
ANY,
719+
expected_serverhost,
720+
8123,
721+
ssl=None,
722+
backlog=128,
723+
reuse_address=None,
724+
reuse_port=None,
725+
)
726+
727+
assert set(issue_registry.issues) == expected_issues

tests/scripts/test_check_config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ def test_secrets() -> None:
137137
"server_port": 8123,
138138
"ssl_profile": "modern",
139139
"use_x_frame_options": True,
140-
"server_host": ["0.0.0.0", "::"],
141140
}
142141
assert res["secret_cache"] == {
143142
get_test_config_dir("secrets.yaml"): {"http_pw": "http://google.com"}

0 commit comments

Comments
 (0)