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

Add support for Docker Secrets by reading secrets files #3989

Open
dabikuru opened this issue Mar 2, 2020 · 19 comments
Open

Add support for Docker Secrets by reading secrets files #3989

dabikuru opened this issue Mar 2, 2020 · 19 comments
Assignees
Labels
a/security c/server Related to server help wanted Good candidate for contribution. Community help wanted! k/enhancement New feature or improve an existing feature

Comments

@dabikuru
Copy link

dabikuru commented Mar 2, 2020

Currently, the only way to pass secrets (DB credentials, Hasura admin secret) to Hasura is only by environment variables. For users of Docker Compose or Docker Swarm, this means these secrets have to be stored in plaintext, which presents security risks.

It would be great to build support for Docker Secrets (or even Vault), by adding the following environment variables, as recommended by Docker:

  • HASURA_GRAPHQL_ACCESS_KEY_FILE
  • HASURA_GRAPHQL_DATABASE_URL_FILE

If these variables are present, the access key and DB URL should be read from the corresponding files.

Docs: https://docs.docker.com/engine/swarm/secrets/#build-support-for-docker-secrets-into-your-images

@tirumaraiselvan
Copy link
Contributor

@dcultrera Do you mean document this way of adding the secret in docker-compose? (I don't think Hasura needs to provide any support for this, this is a pure docker thing?)

@dabikuru
Copy link
Author

dabikuru commented Mar 2, 2020

Hi @tirumaraiselvan, thanks for your reply!

I don't think is purely a Docker thing: when Hasura starts up, it expects to receive those credentials as environment variables. The proposed change is to enable Hasura to read them from the specified files.

Docker Compose/Swarm is not the only orchestrator that suggests passing credentials this way. For example, Hashicorp's Nomad does the same with Vault secrets: they are made available to a container as files, without the host system being aware of the secrets themselves.

@tirumaraiselvan
Copy link
Contributor

@dcultrera Gotcha! This makes sense.

@tirumaraiselvan tirumaraiselvan added the k/enhancement New feature or improve an existing feature label Mar 2, 2020
@dabikuru
Copy link
Author

dabikuru commented Mar 2, 2020

@tirumaraiselvan thanks! I'd be happy to try and make a PR for this myself :) could I have some pointers as to where to get started?

@marionschleifer marionschleifer added the c/server Related to server label Mar 2, 2020
@tirumaraiselvan
Copy link
Contributor

@dcultrera That'd be awesome.

You will need to add a server flag/environment variable. You can see this file where all server start options are specified: https://github.com/hasura/graphql-engine/blob/master/server/src-lib/Hasura/Server/Init.hs .

Then you need to resolve this new flag/variable in here: https://github.com/hasura/graphql-engine/blob/master/server/src-lib/Hasura/Server/Init.hs#L325

@dabikuru
Copy link
Author

dabikuru commented Mar 5, 2020

@tirumaraiselvan thank you for your help! I will have a go at it soon :)

@rhyslbw
Copy link

rhyslbw commented Apr 6, 2020

@dcultrera Did you have a chance to look at implementing this?

@D3CK3R
Copy link

D3CK3R commented May 5, 2020

@dcultrera Any updates on this ticket?

@dabikuru
Copy link
Author

dabikuru commented May 6, 2020

Hi @rhyslbw and @D3CK3R, I haven't been able to spend time on this, so if anyone would like to have a go, I'd appreciate it!

@rhyslbw
Copy link

rhyslbw commented May 22, 2020

Thanks for the update @dcultrera

@D3CK3R I'm handling this in a custom Docker image (required for a different migration strategy), so won't be in a position to contribute either sorry.

@apjoseph
Copy link

Is there any workaround for this issue until fixed? It really seems like a bad idea in 2020 to just paste a superuser postgres password in plaintext.

@korylprince
Copy link

Here's a workaround to use docker secrets:

  graphql-engine:
    image: hasura/graphql-engine:v1.3.0
    command: sh -c 'graphql-engine --database-url "postgres://postgres:$$(cat /run/secrets/postgres_pass)@db:5432/postgres" serve --admin-secret "$$(cat /run/secrets/admin_secret)"'
    secrets:
      - postgres_pass
      - admin_secret

Obviously, you'll need to fill in the rest of the config like networks, ports, etc. You can still pass environment variables like HASURA_GRAPHQL_ENABLE_CONSOLE if needed.

@Miyou
Copy link

Miyou commented Nov 8, 2020

Can we get an update on this issue from the Hasura team? I was using the workaround above by @korylprince, but it doesn't work with the cli-migrations-v2 image.
It really seems silly that Hasura expects us to store our confidential info in plaintext in production? I hope that's not what they're doing themselves...

@tirumaraiselvan tirumaraiselvan added the help wanted Good candidate for contribution. Community help wanted! label Dec 17, 2020
@dionjwa
Copy link

dionjwa commented Apr 21, 2022

You can also store the secrets in a .env file that will be consumed by docker-compose, and you can git-exclude that file

@adepto-io
Copy link

You can also store the secrets in a .env file that will be consumed by docker-compose, and you can git-exclude that file

Environment variables can be unintentionally leaked between containers. This is why this issue deserves a higher priority if you ask me.

@tintin10q
Copy link

Its been two years.
If I look into this, will it also be added to Hasura version 2?

@tintin10q
Copy link

Actually the HASURA_GRAPHQL_DYNAMIC_SECRETS_ALLOWED_PATH_PREFIX does what we need.

Like every variable could follow the dynamic-from-file:///var/path behavior instead of only database connection strings.

@tintin10q
Copy link

I looked around and is it correct that changes need to be made to just this file:

https://github.com/hasura/graphql-engine/blob/master/server/src-lib/Hasura/Server/Init/Env.hs

@tintin10q
Copy link

You could add it to the considerEnv function. If the value of the env starts with from-file: then load from that file instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a/security c/server Related to server help wanted Good candidate for contribution. Community help wanted! k/enhancement New feature or improve an existing feature
Projects
None yet
Development

No branches or pull requests