Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to specify listen interface via LISTEN_IP #1190

Merged
merged 1 commit into from
Jan 21, 2022

Conversation

nh2
Copy link
Contributor

@nh2 nh2 commented Jul 15, 2021

This enables safer deployments to allow localhost-only or VPN-interface-only listening.

Changes

Tests

  • Automated tests have been added
  • This PR does not require tests

Changelog

  • Entry has been added to changelog

Documentation

nh2 added a commit to nh2/docs that referenced this pull request Jul 15, 2021
Also explain how to fully lock down the services that Plausible requires
(`beam` inter-node communication and `epmd`).
nh2 added a commit to nh2/docs that referenced this pull request Jul 15, 2021
Also explain how to fully lock down the services that Plausible requires
(`beam` inter-node communication and `epmd`).
@nh2
Copy link
Contributor Author

nh2 commented Jul 15, 2021

For some extra motivation on why restricting listen addresses to localhost is a good default practice, see MongoDB's history, or e.g. NixOS/nixpkgs#130244 for Erlang.

This PR only adds the option, it does not change the default away from 0.0.0.0.

@nh2
Copy link
Contributor Author

nh2 commented Jul 15, 2021

CC @Ma27 @happysalada

@@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally would be happy if the default was 127.0.0.1, like most software does it, as a safe default.

However, I didn't want to change it here without asking the project first if they want to change the default.

@happysalada
Copy link
Contributor

An alternative solution to this would be to set RELEASE_DISTRIBUTION to none on our side.

I'm not commited to any particular solution, just mentioning an alternative.

https://hexdocs.pm/mix/Mix.Tasks.Release.html#module-environment-variables

nh2 added a commit to nh2/docs that referenced this pull request Jul 16, 2021
Also explain how to fully lock down the services that Plausible requires
(`beam` inter-node communication and `epmd`).
@nh2
Copy link
Contributor Author

nh2 commented Jul 16, 2021

An alternative solution to this would be to set RELEASE_DISTRIBUTION to none

@happysalada RELEASE_DISTRIBUTION does not affect the port that the Plausible HTTP web server is listening on. (This PR is about the HTTP web server, not the Erlang inter-node communication and epmd ports.)

However, I've added your recommendation to the docs PR at plausible/docs#112, which talks about both topics.

@happysalada
Copy link
Contributor

Reading more about the docs, I see this PR is just to configure the IP the server is listening on and has nothing to do with a security issue, understood, thanks!

This enables safer deployments to allow localhost-only
or VPN-interface-only listening.
@nh2
Copy link
Contributor Author

nh2 commented Jan 13, 2022

@ukutaht I have rebased the PR to fix the conflict, could you have a look at it?

It's a trivial change, the main question is if you also want to switch to the safer default that is 127.0.0.1, like many other web projects do in their default configuration.

@bundlemon
Copy link

bundlemon bot commented Jan 13, 2022

BundleMon

Unchanged files (7)
Status Path Size Limits
static/css/app.css
514.8KB -
static/js/dashboard.js
283.79KB -
static/js/app.js
12.13KB -
static/js/embed.host.js
5.58KB -
static/js/embed.content.js
5.06KB -
tracker/js/plausible.js
750B -
static/js/applyTheme.js
314B -

No change in files bundle size

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@ukutaht
Copy link
Contributor

ukutaht commented Jan 21, 2022

Thanks @nh2 for this.

I like having more safe and secure defaults. I believe in order to run Plausible in a docker container, it needs to bind to 0.0.0.0. But we can achieve that by adding ENV LISTEN_IP=0.0.0.0 to the Dockerfile, thus allowing the elixir release to default to 127.0.0.1. Nix is the only use-case I know of anyone running Plausible in production but without Docker.

While erlang is really eager to connect nodes and form a cluster, we don't use any of those features within the Plausible codebase. In fact, Plausible is currently limited to running in a single node because the service itself is stateful with no synchronization between nodes.

We will move to a multi-node setup at some point but I think the synchronization will happen at the level of the database, not the app server. App servers will be stateless and independent. Therefore we can add extra safety and set RELEASE_DISTRIBUTION=none by default in all Plausible instances. If we end up needing it in the future, we'll enable it then. Better to be safe in the meanwhile.

I will merge this for now and test it out with some docker containers.

@ukutaht ukutaht merged commit 1337b46 into plausible:master Jan 21, 2022
@ukutaht
Copy link
Contributor

ukutaht commented Jan 21, 2022

This seems like a good default to me: 69576aa

nh2 added a commit to nh2/nixpkgs that referenced this pull request Nov 10, 2023
This is a safer default configuration, changing:

* the plausible HTTP web server

to be listening on localhost only.

This makes Plausible have a safe default configuration, like all other
networked services in NixOS

For background discussion, see: NixOS#130244

As per my upstream Plausible contribution
(plausible/analytics#1190)
Plausible >= 1.5 also defaults to listening to localhost only;
nevertheless a NixOS user must be able to configure the
`listenAddress`, as there are valid use cases for that.

Also, disable

* the Erlang Beam VM inter-node RPC port
* the Erlang EPMD port

because Plausible does not use them (see added comment).
This is done by setting `RELEASE_DISTRIBUTION=none`.

Thus, this commit also removes the NixOS setting `releaseCookiePath`,
because it now has no effect.
nh2 added a commit to nh2/nixpkgs that referenced this pull request Nov 14, 2023
This changes

* the plausible HTTP web server

to be listening on localhost only, explicitly.

This makes Plausible have an explicit safe default configuration,
like all other networked services in NixOS.

For background discussion, see: NixOS#130244

As per my upstream Plausible contribution
(plausible/analytics#1190)
Plausible >= 1.5 also defaults to listening to localhost only;
nevertheless, this default should be stated explicitly in nixpkgs
for easier review and independence from upstream changes, and
a NixOS user must be able to configure the
`listenAddress`, as there are valid use cases for that.

Also, disable

* the Erlang Beam VM inter-node RPC port
* the Erlang EPMD port

because Plausible does not use them (see added comment).
This is done by setting `RELEASE_DISTRIBUTION=none`.

Thus, this commit also removes the NixOS setting `releaseCookiePath`,
because it now has no effect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants