mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
feat: add Docker _FILE secret convention for sensitive env vars (#205)
Support reading secrets from mounted files instead of plain-text environment variables, following the standard Docker/Kubernetes convention used by MariaDB, Postgres, and Stirling-PDF. Supported vars: DEFAULT_PASSWORD, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, OIDC_CLIENT_SECRET, COOKIE_SECRET, SNAPOTTER_LICENSE_KEY.
This commit is contained in:
@@ -51,6 +51,15 @@ services:
|
||||
# - OIDC_USERNAME_CLAIM=preferred_username
|
||||
# - OIDC_CLOCK_TOLERANCE=30
|
||||
# - COOKIE_SECRET=
|
||||
#
|
||||
# Docker secrets (_FILE convention): mount secrets as files instead of
|
||||
# passing them as plain-text env vars. Supported for sensitive vars only.
|
||||
# - DEFAULT_PASSWORD_FILE=/run/secrets/snapotter_password
|
||||
# - S3_ACCESS_KEY_ID_FILE=/run/secrets/s3_access_key
|
||||
# - S3_SECRET_ACCESS_KEY_FILE=/run/secrets/s3_secret_key
|
||||
# - OIDC_CLIENT_SECRET_FILE=/run/secrets/oidc_secret
|
||||
# - COOKIE_SECRET_FILE=/run/secrets/cookie_secret
|
||||
# - SNAPOTTER_LICENSE_KEY_FILE=/run/secrets/license_key
|
||||
restart: unless-stopped
|
||||
# --- Security hardening ---
|
||||
mem_limit: 8g
|
||||
@@ -91,6 +100,13 @@ services:
|
||||
max-size: "50m"
|
||||
max-file: "5"
|
||||
|
||||
# Uncomment to use Docker secrets (requires Docker Swarm or compose v2.23+):
|
||||
# secrets:
|
||||
# snapotter_password:
|
||||
# file: ./secrets/snapotter_password.txt
|
||||
# oidc_secret:
|
||||
# file: ./secrets/oidc_secret.txt
|
||||
|
||||
volumes:
|
||||
SnapOtter-data:
|
||||
SnapOtter-workspace:
|
||||
|
||||
@@ -50,6 +50,15 @@ services:
|
||||
# - OIDC_USERNAME_CLAIM=preferred_username
|
||||
# - OIDC_CLOCK_TOLERANCE=30
|
||||
# - COOKIE_SECRET=
|
||||
#
|
||||
# Docker secrets (_FILE convention): mount secrets as files instead of
|
||||
# passing them as plain-text env vars. Supported for sensitive vars only.
|
||||
# - DEFAULT_PASSWORD_FILE=/run/secrets/snapotter_password
|
||||
# - S3_ACCESS_KEY_ID_FILE=/run/secrets/s3_access_key
|
||||
# - S3_SECRET_ACCESS_KEY_FILE=/run/secrets/s3_secret_key
|
||||
# - OIDC_CLIENT_SECRET_FILE=/run/secrets/oidc_secret
|
||||
# - COOKIE_SECRET_FILE=/run/secrets/cookie_secret
|
||||
# - SNAPOTTER_LICENSE_KEY_FILE=/run/secrets/license_key
|
||||
restart: unless-stopped
|
||||
# --- Security hardening ---
|
||||
mem_limit: 6g
|
||||
@@ -83,6 +92,13 @@ services:
|
||||
max-size: "50m"
|
||||
max-file: "5"
|
||||
|
||||
# Uncomment to use Docker secrets (requires Docker Swarm or compose v2.23+):
|
||||
# secrets:
|
||||
# snapotter_password:
|
||||
# file: ./secrets/snapotter_password.txt
|
||||
# oidc_secret:
|
||||
# file: ./secrets/oidc_secret.txt
|
||||
|
||||
volumes:
|
||||
SnapOtter-data:
|
||||
SnapOtter-workspace:
|
||||
|
||||
@@ -1,6 +1,44 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# --- Docker secret file convention (_FILE suffix) ---
|
||||
# For each supported var, if VAR_FILE is set, read the secret from that file
|
||||
# path into VAR. This lets users mount Docker/Kubernetes secrets instead of
|
||||
# passing credentials as plain-text environment variables.
|
||||
#
|
||||
# Supported: DEFAULT_PASSWORD, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY,
|
||||
# OIDC_CLIENT_SECRET, COOKIE_SECRET, SNAPOTTER_LICENSE_KEY
|
||||
resolve_file_env() {
|
||||
var="$1"
|
||||
file_var="${var}_FILE"
|
||||
eval current_val="\"\${${var}:-}\""
|
||||
eval file_path="\"\${${file_var}:-}\""
|
||||
|
||||
if [ -z "$file_path" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
if [ -n "$current_val" ]; then
|
||||
echo "WARNING: Both $var and $file_var are set. $file_var takes precedence." >&2
|
||||
fi
|
||||
|
||||
if [ ! -f "$file_path" ] || [ ! -r "$file_path" ]; then
|
||||
echo "ERROR: $file_var points to '$file_path' but the file does not exist or is not readable." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Command substitution strips trailing newlines (standard for secret files)
|
||||
export "$var"="$(cat "$file_path")"
|
||||
unset "$file_var"
|
||||
}
|
||||
|
||||
resolve_file_env DEFAULT_PASSWORD
|
||||
resolve_file_env S3_ACCESS_KEY_ID
|
||||
resolve_file_env S3_SECRET_ACCESS_KEY
|
||||
resolve_file_env OIDC_CLIENT_SECRET
|
||||
resolve_file_env COOKIE_SECRET
|
||||
resolve_file_env SNAPOTTER_LICENSE_KEY
|
||||
|
||||
# Apply auth defaults at runtime so they are never baked into image layers.
|
||||
# Users can override any of these via -e flags at docker run time.
|
||||
export AUTH_ENABLED="${AUTH_ENABLED:-true}"
|
||||
|
||||
Reference in New Issue
Block a user