Refactor postgres password to use docker secrets

This commit is contained in:
2024-09-11 15:21:58 +02:00
parent 69b6f50b4b
commit d44fcefe13
3 changed files with 38 additions and 5 deletions

View File

@ -7,6 +7,8 @@ DOMAIN=bigbluebutton.example.com
LETS_ENCRYPT_ENV=production LETS_ENCRYPT_ENV=production
SECRET_POSTGRES_PASSWORD_VERSION=v1
# ==================================== # ====================================
# ADDITIONS to BigBlueButton # ADDITIONS to BigBlueButton
# ==================================== # ====================================

View File

@ -359,7 +359,8 @@ services:
- postgres - postgres
- redis - redis
environment: environment:
DATABASE_URL: postgres://postgres:${POSTGRESQL_SECRET:-password}@postgres:5432/greenlight-v3 # how to add docker secret here? # DATABASE_URL: postgres://postgres:${POSTGRESQL_SECRET:-password}@postgres:5432/greenlight-v3
# DATABASE_URL is being set by entrypoint-greenlight.sh
REDIS_URL: redis://redis:6379 REDIS_URL: redis://redis:6379
BIGBLUEBUTTON_ENDPOINT: https://${DOMAIN}/bigbluebutton/api BIGBLUEBUTTON_ENDPOINT: https://${DOMAIN}/bigbluebutton/api
BIGBLUEBUTTON_SECRET: /run/secret/shared_secret # can this use docker secrets? BIGBLUEBUTTON_SECRET: /run/secret/shared_secret # can this use docker secrets?
@ -367,6 +368,13 @@ services:
RELATIVE_URL_ROOT: / RELATIVE_URL_ROOT: /
volumes: volumes:
- greenlight_data:/usr/src/app/storage - greenlight_data:/usr/src/app/storage
configs:
- source: abra_entrypoint_greenlight
target: /entrypoint-greenlight.sh
mode: 0555
secrets:
- postgres_password
entrypoint: /entrypoint-greenlight.sh
networks: networks:
bbb-net: bbb-net:
ipv4_address: 10.7.7.21 ipv4_address: 10.7.7.21
@ -385,7 +393,7 @@ services:
environment: environment:
POSTGRES_DB: greenlight-v3 POSTGRES_DB: greenlight-v3
POSTGRES_USER: postgres POSTGRES_USER: postgres
POSTGRES_PASSWORD_FILE: /run/secret/postgresql_secret POSTGRES_PASSWORD_FILE: /run/secret/postgres_password
#healthcheck: #healthcheck:
#test: ["CMD-SHELL", "pg_isready -U postgres"] #test: ["CMD-SHELL", "pg_isready -U postgres"]
#interval: 10s #interval: 10s
@ -393,6 +401,8 @@ services:
#retries: 5 #retries: 5
volumes: volumes:
- "postgres_data:/var/lib/postgresql/data" - "postgres_data:/var/lib/postgresql/data"
secrets:
- postgres_password
networks: networks:
bbb-net: bbb-net:
ipv4_address: 10.7.7.22 ipv4_address: 10.7.7.22
@ -412,7 +422,9 @@ volumes:
configs: configs:
turnserver_conf: turnserver_conf:
name: ${STACK_NAME}_turnserver_conf_${TURNSERVER_CONF_VERSION} name: ${STACK_NAME}_turnserver_conf_${TURNSERVER_CONF_VERSION}
abra_entrypoint_greenlight:
name: ${STACK_NAME}_entrypoint_greenlight_${ENTRYPOINT_GREENLIGHT_VERSION}
file: ./entrypoint-greenlight.sh
secrets: secrets:
shared_secret: shared_secret:
@ -424,9 +436,9 @@ secrets:
rails_secret: rails_secret:
external: true external: true
name: ${STACK_NAME}_rails_secret_${RAILS_SECRET_VERSION} name: ${STACK_NAME}_rails_secret_${RAILS_SECRET_VERSION}
postgresql_secret: postgres_password:
external: true external: true
name: ${STACK_NAME}_postgresql_secret_${POSTGRESQL_SECRET_VERSION} name: ${STACK_NAME}_postgres_password_${SECRET_POSTGRES_PASSWORD_VERSION}
fsesl_password: fsesl_password:
external: true external: true
name: ${STACK_NAME}_fsesl_password_${FSESL_PASSWORD_VERSION} name: ${STACK_NAME}_fsesl_password_${FSESL_PASSWORD_VERSION}

19
entrypoint-greenlight.sh Normal file
View File

@ -0,0 +1,19 @@
#!/bin/sh
set -e
if test -f "/run/secrets/postgres_password"; then
pwd=`cat /run/secrets/postgres_password`
if [ -z $pwd ]; then
echo >&2 "error: /run/secrets/postgres_password is empty"
exit 1
fi
echo "entrypoint-greenlight.sh setting DATABASE_URL"
export "DATABASE_URL"="postgres://postgres:${pwd}@postgres:5432/greenlight-v3"
unset "pwd"
else
echo >&2 "error: /run/secrets/postgres_password does not exist"
exit 1
fi
# https://github.com/bigbluebutton/greenlight/blob/master/dockerfiles/v3/alpine
./bin/start