teslamate-org / teslamate

A self-hosted data logger for your Tesla 🚘
https://docs.teslamate.org
MIT License
5.89k stars 736 forks source link

teslamate don't support http_proxy #4147

Closed papillonyi closed 4 weeks ago

papillonyi commented 2 months ago

Is there an existing issue for this?

What happened?

I'm running TeslaMate on my NAS, which requires a proxy to connect to the internet. I've set the http_proxy and https_proxy environment variables, but it's still trying to connect directly. Any advice on how to fix this?

Expected Behavior

By setting the http_proxy and https_proxy, TeslaMate can connect to the internet through my proxy server.

Steps To Reproduce

version: "3.9"
services:
  teslamate:
    container_name: teslamate
    image: teslamate/teslamate:latest
    restart: always
    environment:
      - ENCRYPTION_KEY=xxx
      - DATABASE_USER=xxx
      - DATABASE_PASS=xxx
      - DATABASE_NAME=xxx
      - DATABASE_HOST=xxx
      - MQTT_HOST=mosquitto
      - http_proxy=http://proxy
      - https_proxy=http://proxy
      - httpProxy=http://proxy
      - httpsProxy=http://proxy
      - HTTP_PROXY=http://proxy
      - HTTPS_PROXY=http://proxy
    ports:
      - 4000:4000

TeslaMate is deployed with Docker Compose and should connect via the proxy, but it’s not working. However, connecting to the internet using curl works.

Relevant log output

2024-08-20 08:36:37.250 [error] GET https://nominatim.openstreetmap.org/reverse -> error: "timeout" (5003.014 ms)
2024-08-20 08:36:37.250 [warning] Address not found: "timeout"
2024-08-20 08:36:43.756 [error] GET https://nominatim.openstreetmap.org/reverse -> error: "timeout" (5004.302 ms)
2024-08-20 08:36:43.756 [warning] Address not found: "timeout"
2024-08-20 08:36:43.756 [info] OK
2024-08-20 08:36:43.757 [info] Repairing drive #2475 ...
2024-08-20 08:36:50.261 [error] GET https://nominatim.openstreetmap.org/reverse -> error: "timeout" (5002.177 ms)
2024-08-20 08:36:50.261 [warning] Address not found: "timeout"
2024-08-20 08:36:56.765 [error] GET https://nominatim.openstreetmap.org/reverse -> error: "timeout" (5001.710 ms)
2024-08-20 08:36:56.765 [warning] Address not found: "timeout"
2024-08-20 08:36:56.765 [info] OK
2024-08-20 08:36:56.766 [info] Repairing drive #2474 ...
2024-08-20 08:37:03.270 [error] GET https://nominatim.openstreetmap.org/reverse -> error: "timeout" (5002.689 ms)
2024-08-20 08:37:03.270 [warning] Address not found: "timeout"
2024-08-20 08:37:09.775 [error] GET https://nominatim.openstreetmap.org/reverse -> error: "timeout" (5002.668 ms)
2024-08-20 08:37:09.775 [warning] Address not found: "timeout"

Screenshots

No response

Additional data

No response

Type of installation

Docker

Version

v1.30.1

brianmay commented 2 months ago

I think this is correct, we don't support the http_proxy or https_proxy env vars at present.

We use the finch library. We would need to pass the conn_opts to the pool configuration: https://hexdocs.pm/finch/Finch.html#start_link/1-pool-configuration-options

This in turn needs to have a proxy value containing an appropriate tuple: https://hexdocs.pm/mint/1.5.2/Mint.HTTP.html#connect/4

An example is in this bug report (but note this doesn't support https proxies): https://github.com/sneako/finch/issues/157

Our pool configuration is here: https://github.com/teslamate-org/teslamate/blob/master/lib/teslamate/http.ex#L2-L7

brianmay commented 2 months ago

I think our pool configuration would need to be changed to occur at run-time, not build-time.

papillonyi commented 2 months ago

Allow users to customize the API URL, enabling them to use a proxy server (e.g., http://your_proxy_address:api.github.com). This way, different servers can employ distinct proxies.

JakobLichterfeld commented 2 months ago

Thanks for reporting. From the logs you provided it looks like only OpenSteetMap is failing, thus I assume you are in an area where this is blocked by some sort of proxy, geoblocking etc.

In addition, I do see the additional effort to support http_proxy via env variables will not lead to an improved product. You can easily use TeslaMate behind a reverse proxy, which is designed to be configurable and archive what you try to build as of now.

papillonyi commented 2 months ago

Thanks for reporting. From the logs you provided it looks like only OpenSteetMap is failing, thus I assume you are in an area where this is blocked by some sort of proxy, geoblocking etc.

In addition, I do see the additional effort to support http_proxy via env variables will not lead to an improved product. You can easily use TeslaMate behind a reverse proxy, which is designed to be configurable and archive what you try to build as of now.

I'm sorry, I don't quite understand how to use a reverse proxy for egress. I thought it was only for ingress. Could you clarify?

JakobLichterfeld commented 2 months ago

I'm sorry, I don't quite understand how to use a reverse proxy for egress. I thought it was only for ingress. Could you clarify?

You are right, I mean you can use a proxy server for egress without the need for TeslaMate to support it directly

github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.