From 1337b46e5225db3fc47700f67137c5c8a50699c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Hamb=C3=BCchen?= Date: Fri, 21 Jan 2022 21:04:29 +0100 Subject: [PATCH] Allow user to specify listen interface via LISTEN_IP. (#1190) This enables safer deployments to allow localhost-only or VPN-interface-only listening. --- CHANGELOG.md | 1 + config/runtime.exs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39d27ba80..4be2ecc5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. ## Unreleased +- Added `LISTEN_IP` configuration parameter plausible/analytics#1189 ### Added - API route `PUT /api/v1/sites/goals` with form params `site_id`, `event_name` and/or `page_path`, and `goal_type` with supported types `event` and `page` diff --git a/config/runtime.exs b/config/runtime.exs index 01337b831..7ea33f73a 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -7,6 +7,18 @@ end config_dir = System.get_env("CONFIG_DIR", "/run/secrets") +# Listen IP supports IPv4 and IPv6 addresses. +listen_ip = ( + str = get_var_from_path_or_env(config_dir, "LISTEN_IP") || "0.0.0.0" + case :inet.parse_address(String.to_charlist(str)) do + {:ok, ip_addr} -> + ip_addr + + {:error, reason} -> + raise "Invalid LISTEN_IP '#{str}' error: #{inspect(reason)}" + end +) + # System.get_env does not accept a non string default port = get_var_from_path_or_env(config_dir, "PORT") || 8000 @@ -190,7 +202,7 @@ config :plausible, :selfhost, config :plausible, PlausibleWeb.Endpoint, url: [scheme: base_url.scheme, host: base_url.host, path: base_url.path, port: base_url.port], - http: [port: port, transport_options: [max_connections: :infinity]], + http: [port: port, ip: listen_ip, transport_options: [max_connections: :infinity]], secret_key_base: secret_key_base if is_nil(db_socket_dir) do