Skip to content

trusted_proxies are not working once internal_url and external_url are set #58326

Description

@runningman84

The problem

I cannot access home assistant anymore due to this error:

│ home-assistant 2021-10-24 11:34:01 ERROR (MainThread) [homeassistant.components.http.forwarded] Received X-Forwarded-For header from an untrusted proxy 10.0.20.82                                             │
│ home-assistant 2021-10-24 11:34:02 ERROR (MainThread) [homeassistant.components.http.forwarded] Received X-Forwarded-For header from an untrusted proxy 10.0.20.82                                             │
│ home-assistant 2021-10-24 11:34:04 ERROR (MainThread) [homeassistant.components.http.forwarded] Received X-Forwarded-For header from an untrusted proxy 10.0.20.82                                             │
│ home-assistant 2021-10-24 11:34:04 ERROR (MainThread) [homeassistant.components.http.forwarded] Received X-Forwarded-For header from an untrusted proxy 10.0.20.82                                             │
│ home-assistant 2021-10-24 11:34:04 ERROR (MainThread) [homeassistant.components.http.forwarded] Received X-Forwarded-For header from an untrusted proxy 10.0.20.82                                             │
│ home-assistant 2021-10-24 11:34:06 ERROR (MainThread) [homeassistant.components.http.forwarded] Received X-Forwarded-For header from an untrusted proxy 10.0.20.82 

My config looks like this:

http:
  internal_url: https://hass.k8s-prod.home.example.com
  external_url: https://hass.home.example.com
  server_port: 8123
  cors_allowed_origins:
    - https://hass.home.example.com
    - http://hass.home.example.com
    - https://hass.k8s-prod.home.example.com
    - http://hass.k8s-prod.home.example.com
  use_x_forwarded_for: True
  trusted_proxies:
    - 127.0.0.1
    - ::1
    - 10.0.20.0/24
    - 10.10.0.0/16
    - 10.43.0.0/16
    - 10.42.0.0/16
    - 10.0.20.81
    - 10.0.20.82
    - 10.0.20.83
    - 10.42.1.14
    - 10.42.0.42
  ip_ban_enabled: False
  login_attempts_threshold: 5

Neither network wide nor single ips seem to work.

The system used to work just fine. The problem appeared after I configured the internal and external_url setting.

I can fix this issue by commenting out the internal and external_url setting.

What version of Home Assistant Core has the issue?

homeassistant/home-assistant:2021.10.6

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

http

Link to integration documentation on our website

https://www.home-assistant.io/integrations/http

Example YAML snippet

http:
  internal_url: https://hass.k8s-prod.home.example.com
  external_url: https://hass.home.example.com
  server_port: 8123
  cors_allowed_origins:
    - https://hass.home.example.com
    - http://hass.home.example.com
    - https://hass.k8s-prod.home.example.com
    - http://hass.k8s-prod.home.example.com
  use_x_forwarded_for: True
  trusted_proxies:
    - 127.0.0.1
    - ::1
    - 10.0.20.0/24
    - 10.10.0.0/16
    - 10.43.0.0/16
    - 10.42.0.0/16
    - 10.0.20.81
    - 10.0.20.82
    - 10.0.20.83
    - 10.42.1.14
    - 10.42.0.42
  ip_ban_enabled: False
  login_attempts_threshold: 5

Anything in the logs that might be useful for us?

│ home-assistant 2021-10-24 11:34:01 ERROR (MainThread) [homeassistant.components.http.forwarded] Received X-Forwarded-For header from an untrusted proxy 10.0.20.82                                             │
│ home-assistant 2021-10-24 11:34:02 ERROR (MainThread) [homeassistant.components.http.forwarded] Received X-Forwarded-For header from an untrusted proxy 10.0.20.82                                             │
│ home-assistant 2021-10-24 11:34:04 ERROR (MainThread) [homeassistant.components.http.forwarded] Received X-Forwarded-For header from an untrusted proxy 10.0.20.82                                             │
│ home-assistant 2021-10-24 11:34:04 ERROR (MainThread) [homeassistant.components.http.forwarded] Received X-Forwarded-For header from an untrusted proxy 10.0.20.82                                             │
│ home-assistant 2021-10-24 11:34:04 ERROR (MainThread) [homeassistant.components.http.forwarded] Received X-Forwarded-For header from an untrusted proxy 10.0.20.82                                             │
│ home-assistant 2021-10-24 11:34:06 ERROR (MainThread) [homeassistant.components.http.forwarded] Received X-Forwarded-For header from an untrusted proxy 10.0.20.82

Additional information

I am runnig home assistant in a k8s cluster. I use traefik as a central reverse proxy for the whole system.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions