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

Support docker secrets #14

Closed
schklom opened this issue Feb 9, 2022 · 8 comments · Fixed by #1254
Closed

Support docker secrets #14

schklom opened this issue Feb 9, 2022 · 8 comments · Fixed by #1254
Assignees
Labels
enhancement New feature or request

Comments

@schklom
Copy link
Contributor

schklom commented Feb 9, 2022

Hi!

Would you please implement extra Docker environment variables called *_FILE or something in that fashion, and feed them /run/secrets/immich_*, at least for the database password and the jwt secret?
Doing otherwise can be unsafe. Ideally, the database name and username can also be read as secrets.

The docker-compose.yml would look like (only included the relevant parts)

services:
  server:
    environment:
      # STAGE
      NODE_ENV: development

      # Database
      DB_USERNAME_FILE: /run/secrets/immich_db_user
      DB_PASSWORD_FILE: /run/secrets/immich_db_password
      DB_DATABASE_NAME_FILE: /run/secrets/immich_db_db

      # Upload File Config
      UPLOAD_LOCATION: ./upload

      # JWT SECRET
      JWT_SECRET_FILE: /run/secrets/immich_jwt
    secrets:
      - immich_db_db
      - immich_db_user
      - immich_db_password
      - immich_jwt

  database:
    environment:
      TZ: ${TZ}
      POSTGRES_DB_FILE: /run/secrets/immich_db_db
      POSTGRES_USER: /run/secrets/immich_db_user
      POSTGRES_PASSWORD_FILE: /run/secrets/immich_db_password
    secrets:
      - immich_db_db
      - immich_db_user
      - immich_db_password

secrets:
  immich_db_db:
    file: /secrets_path/immich_db_db
  immich_db_user:
    file: /secrets_path/immich_db_user
  immich_db_password:
    file: /secrets_path/immich_db_password
  immich_jwt:
    file: /secrets_path/immich_jwt

I don't know Dart and TypeScript, but some possible code to read them in bash and store the contents in variables is:

[[ -z "${JWT_SECRET_FILE}" ]] && [[ -f "${JWT_SECRET_FILE}" ]] && JWT_SECRET='$(head -n 1 "${JWT_SECRET_FILE}")'

Hopefully this helps

@alextran1502
Copy link
Contributor

Thank you for the suggestion, I will take a look at this.

@alextran1502 alextran1502 self-assigned this Feb 9, 2022
@alextran1502 alextran1502 added the enhancement New feature or request label Feb 9, 2022
@kaysond
Copy link
Contributor

kaysond commented Mar 28, 2022

LSIO does this for all their containers and its great

@alextran1502
Copy link
Contributor

@kaysond Can you help me find one that I can refer to?

@kaysond
Copy link
Contributor

kaysond commented Mar 29, 2022

They've set it up in a very generic way in all of their base images. You can see an example of their bash script here and here is an example of the usage.

@kaysond
Copy link
Contributor

kaysond commented Mar 29, 2022

Oh and MariaDB's official image also does the same thing (though they use a suffix instead of prefix)

@EnochPrime
Copy link
Contributor

They've set it up in a very generic way in all of their base images. You can see an example of their bash script here and here is an example of the usage.

LSIO's method requires s6-overlay. The code is here.

Oh and MariaDB's official image also does the same thing (though they use a suffix instead of prefix)

This method is less dynamic, but done purely with bash script. Unfortunately the variable expansion method used is not supported by sh and the immich containers don't have bash currently.

# usage: file_env VAR [DEFAULT]
#    ie: file_env 'XYZ_DB_PASSWORD' 'example'
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
#  "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() {
	local var="$1"
	local fileVar="${var}_FILE"
	local def="${2:-}"
	if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
		mysql_error "Both $var and $fileVar are set (but are exclusive)"
	fi
	local val="$def"
	if [ "${!var:-}" ]; then
		val="${!var}"
	elif [ "${!fileVar:-}" ]; then
		val="$(< "${!fileVar}")"
	fi
	export "$var"="$val"
	unset "$fileVar"
}

@EnochPrime
Copy link
Contributor

EnochPrime commented Jan 4, 2023

Also, definitely not an expert, but I think we can't use the MariaDB method verbatim anyway since they are under GPL2 license and this project is under MIT.

Edit: And the LSIO is under GPL3 too.

@EnochPrime
Copy link
Contributor

Actually I just found the identical code over in the postgres docker which is MIT license. So I believe it is fair to copy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants