-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Passing secrets as environment variables #1105
Comments
I don't see this as a big concern since Plausible is designed for Docker. I understand that environment variables get passed along to child processes which makes them risky. However, since we run everything inside Docker, I don't see a way the environment variables leaking outside of the container. The container does not run any child processes on the host machine, it is self-contained. In our self-hosting setup and also in our cloud version we don't actually pass environment variables. We provide a file like this which is read by docker. |
aren't containerized processes visible in the host's /proc ? |
Ah yes I was completely wrong. Indeed, the way secrets are managed is currently leaky. In terms of finding a solution, I think we can come up with something that's also aligned with Docker secrets and Kubernetes secrets. They both seem to have an option to store secrets in files in a certain directory. Maybe this could work similarly as the |
I like the SECRETS_DIR idea. How about doing away with the capitalization since it was coming from ENV_VARS.
then the file name could just be the same name as the elixir variable, or option name (that it will passed to). For docker, it looks like the docker compose file still has to define every single secret. Just to be sure we would be talking about the following environment variables right? |
Yes, and also What do you think about allowing any variable to be supplied as either a file or env var with one (probably file) having precedence? That would be way more extensible in the future if we decide to add or remove secret variables. I also think it would be easier to document and communicate as opposed to having a list of special variables that can/must be supplied differently from all the rest. |
What about something like the following
You can keep compatibility with existing env var and say that the old format will be deprecated in the release after the next? |
Yeah I think that would work. The only thing I don't like about this is having to manually manage the mapping between Alternatively, we could apply |
Oh I see, so that there is only one name. It makes sense. Then we are talking about
|
Right, exactly! Happy to merge a PR for this. Maybe just one final adjustment would be to rename |
I agree that you could, but do you want to though? |
Single file? I thought we're talking about a directory where each config option is it's own file I still prefer I also think we can alleviate any potential confusion in our docs. The only officially supported use-case is running Plausible in Docker Compose so people don't even need to know anything about the |
What I meant was that everything in the CONFIG_DIR needs to be in a separate file. |
Yes |
Opened a PR #1117 Would you be open to adding a shell.nix file in the base of the repo? The idea would be that all the dependencies would be defined in that file so that anybody with nix could just run the application without needing to define anything. |
We use If there's a way to auto-generate a |
Sure. Thanks for the explanation. |
Just to outline clearly the argument for shell.nix
Against
I perfectly understand the need to keep a single source of truth. |
Thanks @happysalada. I don't know anything about Nix but tbh it sounds great. I love reproducible builds on Docker but I find it too heavyweight and slow to integrate it into my development flow. So I'm still developing on a normal OS and then shipping things with Docker. Nix sounds great, it seems to get best of both worlds - everyone gets a consistent virtual environment without having to wait for a heavyweight virtual machine to boot up. I'm not ready to make the switch immediately but you've definitely peaked my interest in Nix and I'm much more likely to give it a go sometime soon. Like you said the community around Docker is bigger so I think we'll always promote our Docker setup as the official route for self-hosting. |
Another downside of nix that I didn't mention is that the doc is less than optimal. |
Fixed in #1129 |
I'm having some difficulty getting this to work with docker secrets & docker swarm. The following shows that plausible is not able to read the contents of a secrets file. I just don't know what I'm doing wrong here. Reading through the code, it should be reading the ~ $ ls -l /run/secrets/
total 20
-rw-rwxr-- 1 root root 19 Sep 8 08:52 ADMIN_USER_EMAIL
-rw-rwxr-- 1 root root 7 Sep 8 08:52 ADMIN_USER_NAME
-rw-rwxr-- 1 root root 12 Sep 8 08:52 ADMIN_USER_PWD
-rw-rwxr-- 1 root root 47 Sep 8 08:52 BASE_URL
-rw-rwxr-- 1 root root 89 Sep 8 08:52 SECRET_KEY_BASE
~ $ cat /run/secrets/BASE_URL
https://plausible.docker-box.richardwillis.info~ $
~ $ echo $CONFIG_DIR
/run/secrets
~ $ /entrypoint.sh run
ERROR! Config provider Config.Reader failed with:
{"init terminating in do_boot",{#{'__exception__'=>true,'__struct__'=>'Elixir.RuntimeError',message=><<"BASE_URL configuration option is required. See https://plausible.io/docs/self-hosting-configuration#server">>},[{erl_eval,do_apply,6,[{file,"erl_eval.erl"},{line,680}]},{elixir,recur_eval,3,[{file,"src/elixir.erl"},{line,280}]},{elixir,eval_forms,3,[{file,"src/elixir.erl"},{line,265}]},{'Elixir.Code',eval_string_with_error_handling,3,[{file,"lib/code.ex"},{line,341}]},{'Elixir.Config','__eval__!',3,[{file,"lib/config.ex"},{line,255}]},{'Elixir.Config.Reader','read!',2,[{file,"lib/config/reader.ex"},{line,86}]},{'Elixir.Config.Reader',load,2,[{file,"lib/config/reader.ex"},{line,52}]},{'Elixir.Config.Provider','-run_providers/2-fun-0-',2,[{file,"lib/config/provider.ex"},{line,347}]}]}}
init terminating in do_boot ({,[{erl_eval,do_apply,6,[{_},{_}]},{elixir,recur_eval,3,[{_},{_}]},{elixir,eval_forms,3,[{_},{_}]},{Elixir.Code,eval_string_with_error_handling,3,[{_},{_}]},{Elixir.Config
Crash dump is being written to: erl_crash.dump...done
~ $ Here's my plausible service definition: plausible:
image: plausible/analytics:latest
command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh db init-admin && /entrypoint.sh run"
networks:
- plausible
deploy:
mode: replicated
replicas: 1
environment:
- CONFIG_DIR=/run/secrets
secrets:
- source: richardwillis-plausible-admin-user-email
target: /run/secrets/ADMIN_USER_EMAIL
- source: richardwillis-plausible-admin-user-name
target: /run/secrets/ADMIN_USER_NAME
- source: richardwillis-plausible-admin-user-password
target: /run/secrets/ADMIN_USER_PWD
- source: richardwillis-plausible-base-url
target: /run/secrets/BASE_URL
- source: richardwillis-plausible-secret-key-base
target: /run/secrets/SECRET_KEY_BASE |
Which version are you using ? those features are only available on master and not with the last release (1.3) |
@happysalada thanks for the pointer! i'm now using Unfortunately I'm now getting a different error: #1311 |
I believe the error I'm experiencing (#1311) is due to
I believe that should rather be |
That makes sense, good catch! |
There is another discussion that I'm not sure where it's the best place to take.
This discussion is around secret environment variables. It seems the consensus is that you cannot have secrets inside environment variables because they can be read by others.
Ideally secrets should be put in files, that will be read by the application.
I'm linking to that discussion in systemd systemd/systemd#19604
I'm not sure how you feel about this. I can open a new issue if you want to discuss more.
Basically the change would look like (multiplied by every secret env var)
I'm not sure if you are open to such a change or how you feel about the issue.
Let me know if you need/want more information, and I'll be happy to provide.
The text was updated successfully, but these errors were encountered: