Skip to content

Docker entrypoint, read environment variables from files.#10918

Closed
epuronta wants to merge 0 commit intokeycloak:mainfrom
epuronta:main
Closed

Docker entrypoint, read environment variables from files.#10918
epuronta wants to merge 0 commit intokeycloak:mainfrom
epuronta:main

Conversation

@epuronta
Copy link
Copy Markdown
Contributor

Adds a special entrypoint script for the Docker image.

The script supports using (mounted) files for configuring sensitive variables (like passwords). It is an alternative to passing the sensitive value directly as an environment variable (KC_DB_PASSWORD=MyPassword).

Basic process:

  • The information is mounted as a file to the container (e.g. /tmp/kc-db-password)
  • File path is passed as an environment variable (KC_DB_PASSWORD_FILE=/tmp/kc-db-password)
  • The entrypoint detects KC_DB_PASSWORD_FILE, reads the file content and exports it as KC_DB_PASSWORD

Closes #10816.

@epuronta
Copy link
Copy Markdown
Contributor Author

I had no idea if and how the included test script should be run automatically. Might be appropriate.

Copy link
Copy Markdown
Contributor

@stianst stianst left a comment

Choose a reason for hiding this comment

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

We should consider how reading secrets for things like DB aligns with reading secrets for things like LDAP server within a realm.

I can see that we should support something along the line of DB_USERNAME_FILE, but in that case it's something we would add to the Quarkus distribution to support somehow, and not as a wrapper in the container image.

@stianst stianst requested review from andreaTP and pedroigor March 30, 2022 15:34
@ahus1 ahus1 added area/dist/quarkus kind/feature Categorizes a PR related to a new feature labels Apr 4, 2022
@epuronta
Copy link
Copy Markdown
Contributor Author

Agreed @stianst, it would be better to have this directly where Quarkus loads the configuration instead of a wrapper script. I don't have the expertise to create a PR though, so someone else would need to step in for that.

Also, sorry for the late response - I totally missed the reply notification here.

@artpdr
Copy link
Copy Markdown

artpdr commented Nov 16, 2022

Adds a special entrypoint script for the Docker image.

The script supports using (mounted) files for configuring sensitive variables (like passwords). It is an alternative to passing the sensitive value directly as an environment variable (KC_DB_PASSWORD=MyPassword).

Basic process:

  • The information is mounted as a file to the container (e.g. /tmp/kc-db-password)
  • File path is passed as an environment variable (KC_DB_PASSWORD_FILE=/tmp/kc-db-password)
  • The entrypoint detects KC_DB_PASSWORD_FILE, reads the file content and exports it as KC_DB_PASSWORD

Closes #10816.

Sorry if I'm missing something, but if you do an export foo=content_from_secret_file you will end up with secrets in the environment variables, which has associated security risks.

@epuronta
Copy link
Copy Markdown
Contributor Author

@artpdr as far as I understand, the primary security risk with having secrets in environment variables is related to how Docker displays the environment variables supplied to the container with docker inspect as this exposes the secrets to anyone with access to the docker socket.

The approach in this issue, however, exports the variables inside the container, so they are not exposed to docker (or at least not shown with docker inspect, I don't know how exactly it works internally).

For a simple example, fire up a container with one supplied secret and export another one from the inside

> docker run -it --rm  -e SECRET1=secret1 --name secret-test alpine
/ # export SECRET2=secret2
/ # printenv
HOSTNAME=941be17a9ac1
SECRET1=secret1
SECRET2=secret2

Inspecting the container only exposes the first secret

docker inspect secret-test -f "{{ .Config.Env }}"
[SECRET1=secret1]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/dist/quarkus kind/feature Categorizes a PR related to a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Read secrets from files

4 participants