Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Make /secrets docker bind mount folder configurable (#2234)
Leendert de Borst67aca0b57751
diff --git a/.env.example b/.env.exampleindex a099ebc86..908b44cf2 100644--- a/.env.example+++ b/.env.example@@ -29,6 +29,16 @@ SMTP_TLS_PORT=587# Whether to force redirect all HTTP traffic (80) to HTTPS (443). Defaults to true.FORCE_HTTPS_REDIRECT=true+# ===========================================+# DOCKER BIND MOUNTS+# ===========================================++# Path inside the containers where AliasVault reads its secrets from (postgres password,+# JWT key, data protection cert password). Only change this when you run into a+# duplicate mount conflict, e.g. because of certain Docker orchestrators.+# Defaults to /secrets.+SECRETS_PATH=/secrets+# ===========================================# DATABASE CONFIGURATION# ===========================================@@ -38,7 +48,7 @@ FORCE_HTTPS_REDIRECT=true# need to change anything.## To use your own external PostgreSQL server instead (e.g. a managed instance or-# a dedicated database host), point these at your server and write its password+# a dedicated database host), point these at your server and write the password# to secrets/postgres_password. AliasVault and the install.sh db-export/db-import# commands then use whichever database is configured here.#@@ -122,10 +132,6 @@ PUBLIC_REGISTRATION_ENABLED=true# always still anonymized, e.g. "127.0.0.1" becomes "127.0.0.xxx".IP_LOGGING_ENABLED=true-# Set the support email address which is shown to users in the main web app.-# Keep this blank if you don't want to show a support email.-SUPPORT_EMAIL=-# Maximum upload size in megabytes for client-to-server requests (vault sync,# API uploads, etc.). Increase if you run into "413 Request Entity Too Large"# errors when syncing large vaults. Defaults to 100MB.diff --git a/apps/server/Databases/AliasServerDb/PostgresqlDbContextFactory.cs b/apps/server/Databases/AliasServerDb/PostgresqlDbContextFactory.csindex bd78458a9..3caf0d374 100644--- a/apps/server/Databases/AliasServerDb/PostgresqlDbContextFactory.cs+++ b/apps/server/Databases/AliasServerDb/PostgresqlDbContextFactory.cs@@ -117,7 +117,14 @@ public class PostgresqlDbContextFactory : IAliasServerDbContextFactory/// <exception cref="KeyNotFoundException">Thrown when the PostgreSQL password cannot be found.</exception>private static string GetPostgresPasswordFromSecretFile(){- const string secretsFilePath = "/secrets/postgres_password";+ // Secrets directory is configurable via SECRETS_PATH. Defaults to /secrets.+ var secretsPath = Environment.GetEnvironmentVariable("SECRETS_PATH");+ if (string.IsNullOrEmpty(secretsPath))+ {+ secretsPath = "/secrets";+ }++ var secretsFilePath = Path.Combine(secretsPath, "postgres_password");if (!File.Exists(secretsFilePath)){diff --git a/apps/server/Shared/AliasVault.Shared.Server/Utilities/SecretReader.cs b/apps/server/Shared/AliasVault.Shared.Server/Utilities/SecretReader.csindex e8490392e..b27611250 100644--- a/apps/server/Shared/AliasVault.Shared.Server/Utilities/SecretReader.cs+++ b/apps/server/Shared/AliasVault.Shared.Server/Utilities/SecretReader.cs@@ -25,6 +25,17 @@ public static class SecretReaderreturn Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER") == "true";}+ /// <summary>+ /// Gets the container secrets directory, defaults to /secrets but optionally configurable via+ /// the SECRETS_PATH environment variable.+ /// </summary>+ /// <returns>The secrets directory path.</returns>+ public static string GetSecretsPath()+ {+ var secretsPath = Environment.GetEnvironmentVariable("SECRETS_PATH");+ return string.IsNullOrEmpty(secretsPath) ? "/secrets" : secretsPath;+ }+/// <summary>/// Gets the JWT key from either the container secrets file or environment variable./// </summary>@@ -34,7 +45,7 @@ public static class SecretReader{if (IsRunningInContainer()){- return ReadSecretFromFile("/secrets/jwt_key", "JWT key");+ return ReadSecretFromFile(Path.Combine(GetSecretsPath(), "jwt_key"), "JWT key");}var jwtKey = Environment.GetEnvironmentVariable("JWT_KEY");@@ -56,7 +67,7 @@ public static class SecretReader{if (IsRunningInContainer()){- var secretsFilePath = "/secrets/admin_password_hash";+ var secretsFilePath = Path.Combine(GetSecretsPath(), "admin_password_hash");if (!File.Exists(secretsFilePath)){throw new KeyNotFoundException($"Admin password hash file not found at {secretsFilePath}. Container initialization may have failed.");@@ -106,7 +117,7 @@ public static class SecretReader{if (IsRunningInContainer()){- return ReadSecretFromFile("/secrets/data_protection_cert_pass", "Certificate password");+ return ReadSecretFromFile(Path.Combine(GetSecretsPath(), "data_protection_cert_pass"), "Certificate password");}return Environment.GetEnvironmentVariable("DATA_PROTECTION_CERT_PASS")diff --git a/docker-compose.yml b/docker-compose.ymlindex b4211804a..7fd53ec7f 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -3,14 +3,14 @@ services:image: ghcr.io/aliasvault/postgres:latestvolumes:- ./database/postgres:/var/lib/postgresql/data:rw- - ./secrets:/secrets:ro+ - ./secrets:${SECRETS_PATH:-/secrets}:roenv_file:- .envrestart: alwaysenvironment:POSTGRES_DB: aliasvaultPOSTGRES_USER: aliasvault- POSTGRES_PASSWORD_FILE: /secrets/postgres_password+ POSTGRES_PASSWORD_FILE: ${SECRETS_PATH:-/secrets}/postgres_passwordhealthcheck:test: ["CMD-SHELL", "pg_isready -U aliasvault"]interval: 5s@@ -35,7 +35,7 @@ services:volumes:- ./database:/database:rw- ./logs:/logs:rw- - ./secrets:/secrets:ro+ - ./secrets:${SECRETS_PATH:-/secrets}:rorestart: alwaysenv_file:- .env@@ -50,7 +50,7 @@ services:volumes:- ./database:/database:rw- ./logs:/logs:rw- - ./secrets:/secrets:ro+ - ./secrets:${SECRETS_PATH:-/secrets}:rorestart: alwaysenv_file:- .env@@ -84,7 +84,7 @@ services:volumes:- ./database:/database:rw- ./logs:/logs:rw- - ./secrets:/secrets:ro+ - ./secrets:${SECRETS_PATH:-/secrets}:ro- ./certificates/smtp:/certificates/smtp:rorestart: alwaysenv_file:@@ -98,7 +98,7 @@ services:volumes:- ./database:/database:rw- ./logs:/logs:rw- - ./secrets:/secrets:ro+ - ./secrets:${SECRETS_PATH:-/secrets}:rorestart: alwaysenv_file:- .envdiff --git a/dockerfiles/all-in-one/Dockerfile b/dockerfiles/all-in-one/Dockerfileindex d55f9e6fc..2a8eef983 100644--- a/dockerfiles/all-in-one/Dockerfile+++ b/dockerfiles/all-in-one/Dockerfile@@ -229,6 +229,7 @@ ENV DEPLOYMENT_MODE=${DEPLOYMENT_MODE} \POSTGRES_USER=aliasvault \POSTGRES_DATABASE=aliasvault \FORCE_HTTPS_REDIRECT=false \+ SECRETS_PATH=/secrets \S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0 \S6_VERBOSITY=0diff --git a/dockerfiles/all-in-one/s6-scripts/admin/run b/dockerfiles/all-in-one/s6-scripts/admin/runindex 3ddb68840..d9e759a14 100644--- a/dockerfiles/all-in-one/s6-scripts/admin/run+++ b/dockerfiles/all-in-one/s6-scripts/admin/run@@ -6,7 +6,7 @@ cd /app/adminVERBOSITY="${ALIASVAULT_VERBOSITY:-0}"# Read PostgreSQL password from file-POSTGRES_PASSWORD=$(cat /secrets/postgres_password)+POSTGRES_PASSWORD=$(cat "${SECRETS_PATH:-/secrets}/postgres_password")# Wait for PostgreSQL to be readyif [ "$VERBOSITY" -ge 1 ]; thendiff --git a/dockerfiles/all-in-one/s6-scripts/api/run b/dockerfiles/all-in-one/s6-scripts/api/runindex 891bf827c..5a90c99ec 100644--- a/dockerfiles/all-in-one/s6-scripts/api/run+++ b/dockerfiles/all-in-one/s6-scripts/api/run@@ -6,7 +6,7 @@ cd /app/apiVERBOSITY="${ALIASVAULT_VERBOSITY:-0}"# Read PostgreSQL password from file-POSTGRES_PASSWORD=$(cat /secrets/postgres_password)+POSTGRES_PASSWORD=$(cat "${SECRETS_PATH:-/secrets}/postgres_password")# Wait for PostgreSQL to be readyif [ "$VERBOSITY" -ge 1 ]; thendiff --git a/dockerfiles/all-in-one/s6-scripts/client/run b/dockerfiles/all-in-one/s6-scripts/client/runindex 54597fdfa..0808955d1 100644--- a/dockerfiles/all-in-one/s6-scripts/client/run+++ b/dockerfiles/all-in-one/s6-scripts/client/run@@ -4,7 +4,7 @@VERBOSITY="${ALIASVAULT_VERBOSITY:-0}"# Read PostgreSQL password from file-POSTGRES_PASSWORD=$(cat /secrets/postgres_password)+POSTGRES_PASSWORD=$(cat "${SECRETS_PATH:-/secrets}/postgres_password")# Wait for PostgreSQL to be readyif [ "$VERBOSITY" -ge 1 ]; thendiff --git a/dockerfiles/all-in-one/s6-scripts/init/script b/dockerfiles/all-in-one/s6-scripts/init/scriptindex 515610372..0b98b8e3a 100644--- a/dockerfiles/all-in-one/s6-scripts/init/script+++ b/dockerfiles/all-in-one/s6-scripts/init/script@@ -6,6 +6,9 @@# Get verbosity level (0=minimal, 1=normal, 2=verbose)VERBOSITY="${ALIASVAULT_VERBOSITY:-0}"+# Secrets directory, configurable for orchestrators (e.g. Nomad) that reserve /secrets+SECRETS_DIR="${SECRETS_PATH:-/secrets}"+# Helper function for logging based on verbositylog() {level=$1@@ -31,33 +34,33 @@ echo "[init] Starting AliasVault..."echo ""# Create required directories-if [ ! -d /database/postgres ] || [ ! -d /logs/postgres ] || [ ! -d /certificates/ssl ] || [ ! -d /certificates/smtp ] || [ ! -d /secrets ] || [ ! -d /var/run/postgresql ]; then- mkdir -p /database/postgres /logs/postgres /certificates/ssl /certificates/smtp /secrets /var/run/postgresql+if [ ! -d /database/postgres ] || [ ! -d /logs/postgres ] || [ ! -d /certificates/ssl ] || [ ! -d /certificates/smtp ] || [ ! -d "$SECRETS_DIR" ] || [ ! -d /var/run/postgresql ]; then+ mkdir -p /database/postgres /logs/postgres /certificates/ssl /certificates/smtp "$SECRETS_DIR" /var/run/postgresqllog 0 "[init] Required directories created"elselog 0 "[init] ✅ Required directories already exist"fi-if [ ! -f /secrets/postgres_password ]; then+if [ ! -f "$SECRETS_DIR/postgres_password" ]; thenlog 0 "[init] → Generating PostgreSQL password..."- openssl rand -base64 32 | tr -d "\n" > /secrets/postgres_password- chmod 600 /secrets/postgres_password+ openssl rand -base64 32 | tr -d "\n" > "$SECRETS_DIR/postgres_password"+ chmod 600 "$SECRETS_DIR/postgres_password"elselog 0 "[init] ✅ PostgreSQL password already exists "fi-if [ ! -f /secrets/data_protection_cert_pass ]; then+if [ ! -f "$SECRETS_DIR/data_protection_cert_pass" ]; thenlog 0 "[init] → Generating Data Protection Certificate password..."- openssl rand -base64 32 | tr -d "\n" > /secrets/data_protection_cert_pass- chmod 600 /secrets/data_protection_cert_pass+ openssl rand -base64 32 | tr -d "\n" > "$SECRETS_DIR/data_protection_cert_pass"+ chmod 600 "$SECRETS_DIR/data_protection_cert_pass"elselog 0 "[init] ✅ Data Protection Certificate password already exists"fi-if [ ! -f /secrets/jwt_key ]; then+if [ ! -f "$SECRETS_DIR/jwt_key" ]; thenlog 0 "[init] → Generating JWT key..."- openssl rand -base64 32 | tr -d "\n" > /secrets/jwt_key- chmod 600 /secrets/jwt_key+ openssl rand -base64 32 | tr -d "\n" > "$SECRETS_DIR/jwt_key"+ chmod 600 "$SECRETS_DIR/jwt_key"elselog 0 "[init] ✅ JWT key already exists"fi@@ -67,7 +70,7 @@ filog 0 "[init] ✅ Admin password configuration deferred to manual setup"# Read PostgreSQL password for database initialization-POSTGRES_PASSWORD=$(cat /secrets/postgres_password)+POSTGRES_PASSWORD=$(cat "$SECRETS_DIR/postgres_password")export PGDATA="/database/postgres"# Marker written only after the AliasVault role + database have been fullydiff --git a/dockerfiles/all-in-one/s6-scripts/notification/run b/dockerfiles/all-in-one/s6-scripts/notification/runindex a00c793d7..0530aa0d9 100755--- a/dockerfiles/all-in-one/s6-scripts/notification/run+++ b/dockerfiles/all-in-one/s6-scripts/notification/run@@ -1,4 +1,4 @@-#!/bin/sh+#!/command/with-contenv sh# Get verbosity level (0=minimal, 1=normal, 2=verbose)VERBOSITY="${ALIASVAULT_VERBOSITY:-0}"@@ -33,7 +33,7 @@ if [ "$VERBOSITY" -le 1 ]; thenecho ""# Check if admin password hash file exists to determine which message to show- if [ -f /secrets/admin_password_hash ]; then+ if [ -f "${SECRETS_PATH:-/secrets}/admin_password_hash" ]; then# Admin password hash exists - show the legacy warningecho "🔑 Admin Login:"echo " • Username: admin"diff --git a/dockerfiles/all-in-one/s6-scripts/smtp/run b/dockerfiles/all-in-one/s6-scripts/smtp/runindex 183267ed5..84da9a811 100644--- a/dockerfiles/all-in-one/s6-scripts/smtp/run+++ b/dockerfiles/all-in-one/s6-scripts/smtp/run@@ -6,7 +6,7 @@ cd /app/smtpVERBOSITY="${ALIASVAULT_VERBOSITY:-0}"# Read PostgreSQL password from file-POSTGRES_PASSWORD=$(cat /secrets/postgres_password)+POSTGRES_PASSWORD=$(cat "${SECRETS_PATH:-/secrets}/postgres_password")# Wait for PostgreSQL to be readyif [ "$VERBOSITY" -ge 1 ]; thendiff --git a/dockerfiles/all-in-one/s6-scripts/taskrunner/run b/dockerfiles/all-in-one/s6-scripts/taskrunner/runindex 4209d9997..e94e6fb8f 100644--- a/dockerfiles/all-in-one/s6-scripts/taskrunner/run+++ b/dockerfiles/all-in-one/s6-scripts/taskrunner/run@@ -6,7 +6,7 @@ cd /app/taskrunnerVERBOSITY="${ALIASVAULT_VERBOSITY:-0}"# Read PostgreSQL password from file-POSTGRES_PASSWORD=$(cat /secrets/postgres_password)+POSTGRES_PASSWORD=$(cat "${SECRETS_PATH:-/secrets}/postgres_password")# Wait for PostgreSQL to be readyif [ "$VERBOSITY" -ge 1 ]; thendiff --git a/dockerfiles/all-in-one/scripts/reset-admin-password.sh b/dockerfiles/all-in-one/scripts/reset-admin-password.shindex d1ce7be95..5550dbe30 100755--- a/dockerfiles/all-in-one/scripts/reset-admin-password.sh+++ b/dockerfiles/all-in-one/scripts/reset-admin-password.sh@@ -10,6 +10,9 @@ NC='\033[0m' # No ColorCONFIRM_RESET=falsePASSWORD_LENGTH=16+# Secrets directory, defaults to /secrets but optionally configurable via the SECRETS_PATH environment variable.+SECRETS_DIR="${SECRETS_PATH:-/secrets}"+# Parse command line argumentswhile [[ $# -gt 0 ]]; docase $1 in@@ -74,13 +77,13 @@ hash_password() {# Function to update the admin password hash fileupdate_hash_file() {local hash=$1- local hash_file="/secrets/admin_password_hash"+ local hash_file="$SECRETS_DIR/admin_password_hash"- # Create /secrets directory if it doesn't exist- if [ ! -d "/secrets" ]; then- mkdir -p /secrets+ # Create secrets directory if it doesn't exist+ if [ ! -d "$SECRETS_DIR" ]; then+ mkdir -p "$SECRETS_DIR"if [ $? -ne 0 ]; then- echo -e "${RED}Error: Failed to create /secrets directory${NC}" >&2+ echo -e "${RED}Error: Failed to create $SECRETS_DIR directory${NC}" >&2return 1fifi@@ -116,7 +119,7 @@ main() {# Check if running in Docker containerif [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ]; thenecho -e "${YELLOW}Warning: This script appears to be running outside of a Docker container${NC}"- echo -e "${YELLOW}The password hash file will be created at: /secrets/admin_password_hash${NC}"+ echo -e "${YELLOW}The password hash file will be created at: $SECRETS_DIR/admin_password_hash${NC}"echo ""fi@@ -171,7 +174,7 @@ main() {echo ""echo -e "${YELLOW}IMPORTANT:${NC}"echo -e "1. Save this password securely - it will not be shown again"- echo -e "2. The password hash has been saved to /secrets/admin_password_hash"+ echo -e "2. The password hash has been saved to $SECRETS_DIR/admin_password_hash"echo -e "3. Restart the Docker container for the new password to take effect"echo ""diff --git a/dockerfiles/docker-compose.all-in-one.nas.yml b/dockerfiles/docker-compose.all-in-one.nas.ymlindex 756b01dad..d3df0f20d 100644--- a/dockerfiles/docker-compose.all-in-one.nas.yml+++ b/dockerfiles/docker-compose.all-in-one.nas.yml@@ -24,13 +24,8 @@ services:- avcerts:/certificatesenvironment:- HOSTNAME: "localhost"- PUBLIC_REGISTRATION_ENABLED: "true"- IP_LOGGING_ENABLED: "true"FORCE_HTTPS_REDIRECT: "false"- SUPPORT_EMAIL: ""- PRIVATE_EMAIL_DOMAINS: ""- HIDDEN_PRIVATE_EMAIL_DOMAINS: ""+ PUBLIC_REGISTRATION_ENABLED: "true"volumes:avdata:diff --git a/dockerfiles/docker-compose.all-in-one.yml b/dockerfiles/docker-compose.all-in-one.ymlindex dfc589d8f..ef7465130 100644--- a/dockerfiles/docker-compose.all-in-one.yml+++ b/dockerfiles/docker-compose.all-in-one.yml@@ -18,14 +18,9 @@ services:volumes:- ./database:/database- ./logs:/logs- - ./secrets:/secrets+ - ./secrets:${SECRETS_PATH:-/secrets}- ./certificates:/certificatesenvironment:- HOSTNAME: "localhost"- PUBLIC_REGISTRATION_ENABLED: "true"- IP_LOGGING_ENABLED: "true"FORCE_HTTPS_REDIRECT: "false"- SUPPORT_EMAIL: ""- PRIVATE_EMAIL_DOMAINS: ""- HIDDEN_PRIVATE_EMAIL_DOMAINS: ""+ PUBLIC_REGISTRATION_ENABLED: "true"