From 366b75fc231d4ca7ac4eeb7dcd82c8ab4b6831e2 Mon Sep 17 00:00:00 2001 From: Jean-Benoit PAUX <9682558+jbpaux@users.noreply.github.com> Date: Mon, 11 Apr 2022 15:05:51 +0200 Subject: [PATCH 1/6] GUACAMOLE-1572: match PostgreSQL environment variables with guacamole.properties variables --- guacamole-docker/README.md | 30 +++++------ guacamole-docker/bin/start.sh | 94 +++++++++++++++++------------------ 2 files changed, 62 insertions(+), 62 deletions(-) diff --git a/guacamole-docker/README.md b/guacamole-docker/README.md index 0f6200f89..e800345eb 100644 --- a/guacamole-docker/README.md +++ b/guacamole-docker/README.md @@ -55,31 +55,31 @@ Deploying Guacamole with PostgreSQL authentication -------------------------------------------------- docker run --name some-guacamole --link some-guacd:guacd \ - --link some-postgres:postgres \ - -e POSTGRES_DATABASE=guacamole_db \ - -e POSTGRES_USER=guacamole_user \ - -e POSTGRES_PASSWORD=some_password \ - -e POSTGRES_DATABASE_FILE=/run/secrets/ \ - -e POSTGRES_USER_FILE=/run/secrets/ \ - -e POSTGRES_PASSWORD_FILE=/run/secrets/ \ + --link some-postgresql:postgresql \ + -e POSTGRESQL_DATABASE=guacamole_db \ + -e POSTGRESQL_USER=guacamole_user \ + -e POSTGRESQL_PASSWORD=some_password \ + -e POSTGRESQL_DATABASE_FILE=/run/secrets/ \ + -e POSTGRESQL_USER_FILE=/run/secrets/ \ + -e POSTGRESQL_PASSWORD_FILE=/run/secrets/ \ -d -p 8080:8080 guacamole/guacamole Linking Guacamole to PostgreSQL requires three environment variables. If any of these environment variables are omitted, you will receive an error message, and the image will stop: -1. `POSTGRES_DATABASE` - The name of the database to use for Guacamole +1. `POSTGRESQL_DATABASE` - The name of the database to use for Guacamole authentication. -2. `POSTGRES_USER` - The user that Guacamole will use to connect to PostgreSQL. -3. `POSTGRES_PASSWORD` - The password that Guacamole will provide when - connecting to PostgreSQL as `POSTGRES_USER`. -4. `POSTGRES_DATABASE_FILE` - The path of the docker secret containing the name +2. `POSTGRESQL_USER` - The user that Guacamole will use to connect to PostgreSQL. +3. `POSTGRESQL_PASSWORD` - The password that Guacamole will provide when + connecting to PostgreSQL as `POSTGRESQL_USER`. +4. `POSTGRESQL_DATABASE_FILE` - The path of the docker secret containing the name of database to use for Guacamole authentication. -5. `POSTGRES_USER_FILE` - The path of the docker secret containing the name of +5. `POSTGRESQL_USER_FILE` - The path of the docker secret containing the name of the user that Guacamole will use to connect to PostgreSQL. -6. `POSTGRES_PASSWORD_FILE` - The path of the docker secret containing the +6. `POSTGRESQL_PASSWORD_FILE` - The path of the docker secret containing the password that Guacamole will provide when connecting to PostgreSQL as - `POSTGRES_USER. + `POSTGRESQL_USER. ### Initializing the PostgreSQL database diff --git a/guacamole-docker/bin/start.sh b/guacamole-docker/bin/start.sh index f466d4ed6..c3da02687 100755 --- a/guacamole-docker/bin/start.sh +++ b/guacamole-docker/bin/start.sh @@ -242,7 +242,7 @@ END } # Print error message regarding missing required variables for PostgreSQL authentication -postgres_missing_vars() { +postgresql_missing_vars() { cat < Date: Mon, 11 Apr 2022 15:06:59 +0200 Subject: [PATCH 2/6] GUACAMOLE-1572: Update init script to match postgresql too --- guacamole-docker/README.md | 2 +- guacamole-docker/bin/initdb.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/guacamole-docker/README.md b/guacamole-docker/README.md index e800345eb..78631e852 100644 --- a/guacamole-docker/README.md +++ b/guacamole-docker/README.md @@ -91,7 +91,7 @@ To generate a SQL script which can be used to initialize a fresh PostgreSQL database [as documented in the Guacamole manual](http://guacamole.apache.org/doc/gug/jdbc-auth.html#jdbc-auth-postgresql): - docker run --rm guacamole/guacamole /opt/guacamole/bin/initdb.sh --postgres > initdb.sql + docker run --rm guacamole/guacamole /opt/guacamole/bin/initdb.sh --postgresql > initdb.sql Alternatively, you can use the SQL scripts included with the guacamole-auth-jdbc extension from diff --git a/guacamole-docker/bin/initdb.sh b/guacamole-docker/bin/initdb.sh index 6031189c9..aa92b66bb 100755 --- a/guacamole-docker/bin/initdb.sh +++ b/guacamole-docker/bin/initdb.sh @@ -26,7 +26,7 @@ ## ## @param DATABASE ## The database to generate the SQL script for. This may be either -## "--postgres", for PostgreSQL, "--mysql" for MySQL, or "--sqlserver" for Microsoft SQL Server. +## "--postgresql", for PostgreSQL, "--mysql" for MySQL, or "--sqlserver" for Microsoft SQL Server. ## DATABASE="$1" @@ -37,7 +37,7 @@ DATABASE="$1" ## incorrect_usage() { cat < Date: Wed, 27 Apr 2022 15:13:41 +0200 Subject: [PATCH 3/6] GUACAMOLE-1572: Revert postgres link name change --- guacamole-docker/README.md | 2 +- guacamole-docker/bin/start.sh | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/guacamole-docker/README.md b/guacamole-docker/README.md index 78631e852..a6e7e1670 100644 --- a/guacamole-docker/README.md +++ b/guacamole-docker/README.md @@ -55,7 +55,7 @@ Deploying Guacamole with PostgreSQL authentication -------------------------------------------------- docker run --name some-guacamole --link some-guacd:guacd \ - --link some-postgresql:postgresql \ + --link some-postgres:postgres \ -e POSTGRESQL_DATABASE=guacamole_db \ -e POSTGRESQL_USER=guacamole_user \ -e POSTGRESQL_PASSWORD=some_password \ diff --git a/guacamole-docker/bin/start.sh b/guacamole-docker/bin/start.sh index c3da02687..e696c379b 100755 --- a/guacamole-docker/bin/start.sh +++ b/guacamole-docker/bin/start.sh @@ -273,9 +273,9 @@ END associate_postgresql() { # Use linked container if specified - if [ -n "$POSTGRESQL_NAME" ]; then - POSTGRESQL_HOSTNAME="$POSTGRESQL_PORT_5432_TCP_ADDR" - POSTGRESQL_PORT="$POSTGRESQL_PORT_5432_TCP_PORT" + if [ -n "$POSTGRES_NAME" ]; then + POSTGRESQL_HOSTNAME="$POSTGRES_PORT_5432_TCP_ADDR" + POSTGRESQL_PORT="$POSTGRES_PORT_5432_TCP_PORT" fi # Use default port if none specified @@ -284,11 +284,11 @@ associate_postgresql() { # Verify required connection information is present if [ -z "$POSTGRESQL_HOSTNAME" -o -z "$POSTGRESQL_PORT" ]; then cat < Date: Wed, 27 Apr 2022 15:52:50 +0200 Subject: [PATCH 4/6] GUACAMOLE-1572: Add compatibility mechanism for POSTGRES variables --- guacamole-docker/bin/start.sh | 71 +++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 7 deletions(-) diff --git a/guacamole-docker/bin/start.sh b/guacamole-docker/bin/start.sh index e696c379b..ef2d26978 100755 --- a/guacamole-docker/bin/start.sh +++ b/guacamole-docker/bin/start.sh @@ -263,6 +263,63 @@ END exit 1; } +## Provide backward compatibility on POSTGRES_* environment variables +## In case of new deployment, please use POSTGRESQL_* equivalent variables. +if [ -n "$POSTGRES_HOSTNAME" ]; then + POSTGRESQL_HOSTNAME=$POSTGRES_HOSTNAME; +fi +if [ -n "$POSTGRES_PORT" ]; then + POSTGRESQL_PORT=$POSTGRES_PORT; +fi +if [ -n "$POSTGRES_DATABASE" ]; then + POSTGRESQL_DATABASE=$POSTGRES_DATABASE; +fi +if [ -n "$POSTGRES_DATABASE_FILE" ]; then + POSTGRESQL_DATABASE=$POSTGRES_DATABASE_FILE; +fi +if [ -n "$POSTGRES_USER_FILE" ]; then + POSTGRESQL_USER_FILE=$POSTGRES_USER_FILE; +fi +if [ -n "$POSTGRES_USER" ]; then + POSTGRESQL_USER=$POSTGRES_USER; +fi +if [ -n "$POSTGRES_PASSWORD_FILE" ]; then + POSTGRESQL_PASSWORD_FILE=$POSTGRES_PASSWORD_FILE; +fi +if [ -n "$POSTGRES_PASSWORD" ]; then + POSTGRESQL_PASSWORD=$POSTGRES_PASSWORD; +fi +if [ -n "$POSTGRES_ABSOLUTE_MAX_CONNECTIONS" ]; then + POSTGRESQL_ABSOLUTE_MAX_CONNECTIONS=$POSTGRES_ABSOLUTE_MAX_CONNECTIONS; +fi +if [ -n "$POSTGRES_DEFAULT_MAX_CONNECTIONS" ]; then + POSTGRESQL_DEFAULT_MAX_CONNECTIONS=$POSTGRES_DEFAULT_MAX_CONNECTIONS; +fi +if [ -n "$POSTGRES_DEFAULT_MAX_GROUP_CONNECTIONS" ]; then + POSTGRESQL_DEFAULT_MAX_GROUP_CONNECTIONS=$POSTGRES_DEFAULT_MAX_GROUP_CONNECTIONS; +fi +if [ -n "$POSTGRES_DEFAULT_MAX_CONNECTIONS_PER_USER" ]; then + POSTGRESQL_DEFAULT_MAX_CONNECTIONS_PER_USER=$POSTGRES_DEFAULT_MAX_CONNECTIONS_PER_USER; +fi +if [ -n "$POSTGRES_DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER" ]; then + POSTGRESQL_DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER=$POSTGRES_DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER; +fi +if [ -n "$POSTGRES_DEFAULT_STATEMENT_TIMEOUT" ]; then + POSTGRESQL_DEFAULT_STATEMENT_TIMEOUT=$POSTGRES_DEFAULT_STATEMENT_TIMEOUT; +fi +if [ -n "$POSTGRES_USER_REQUIRED" ]; then + POSTGRESQL_USER_REQUIRED=$POSTGRES_USER_REQUIRED; +fi +if [ -n "$POSTGRES_SOCKET_TIMEOUT" ]; then + POSTGRESQL_SOCKET_TIMEOUT=$POSTGRES_SOCKET_TIMEOUT; +fi +if [ -n "$POSTGRES_SSL_KEY_PASSWORD_FILE" ]; then + POSTGRESQL_SSL_KEY_PASSWORD_FILE=$POSTGRES_SSL_KEY_PASSWORD_FILE; +fi +if [ -n "$POSTGRES_SSL_KEY_PASSWORD" ]; then + POSTGRESQL_SSL_KEY_PASSWORD=$POSTGRES_SSL_KEY_PASSWORD; +fi + ## ## Adds properties to guacamole.properties which select the PostgreSQL ## authentication provider, and configure it to connect to the linked @@ -294,14 +351,14 @@ If using a PostgreSQL database, you must either: connection to your database using the following environment variables: POSTGRESQL_HOSTNAME The hostname or IP address of the PostgreSQL server. If - not using a PostgreSQL Docker container and - corresponding link, this environment variable is - *REQUIRED*. + not using a PostgreSQL Docker container and + corresponding link, this environment variable is + *REQUIRED*. POSTGRESQL_PORT The port on which the PostgreSQL server is listening for - TCP connections. This environment variable is option. If - omitted, the standard PostgreSQL port of 5432 will be - used. + TCP connections. This environment variable is option. If + omitted, the standard PostgreSQL port of 5432 will be + used. END exit 1; fi @@ -430,7 +487,7 @@ set the path of the corresponding secrets in the following three variables: the user that Guacamole will use to connect to SQLServer. SQLSERVER_PASSWORD_FILE The path of the docker secret containing the - password that Guacamole will provide when connecting to + password that Guacamole will provide when connecting to SQLServer as SQLSERVER_USER. END From c081fd3ff2bb5f52350c73eb213b3bc615457c76 Mon Sep 17 00:00:00 2001 From: jbpaux <9682558+jbpaux@users.noreply.github.com> Date: Tue, 9 Aug 2022 15:27:10 +0200 Subject: [PATCH 5/6] GUACAMOLE-1572: Make POSTGRESQL env variable backward comp dynamic --- guacamole-docker/bin/start.sh | 76 ++++++++++------------------------- 1 file changed, 21 insertions(+), 55 deletions(-) diff --git a/guacamole-docker/bin/start.sh b/guacamole-docker/bin/start.sh index ef2d26978..eafb422d3 100755 --- a/guacamole-docker/bin/start.sh +++ b/guacamole-docker/bin/start.sh @@ -1,4 +1,4 @@ -#!/bin/sh -e +#!/bin/bash -e # # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file @@ -265,60 +265,26 @@ END ## Provide backward compatibility on POSTGRES_* environment variables ## In case of new deployment, please use POSTGRESQL_* equivalent variables. -if [ -n "$POSTGRES_HOSTNAME" ]; then - POSTGRESQL_HOSTNAME=$POSTGRES_HOSTNAME; -fi -if [ -n "$POSTGRES_PORT" ]; then - POSTGRESQL_PORT=$POSTGRES_PORT; -fi -if [ -n "$POSTGRES_DATABASE" ]; then - POSTGRESQL_DATABASE=$POSTGRES_DATABASE; -fi -if [ -n "$POSTGRES_DATABASE_FILE" ]; then - POSTGRESQL_DATABASE=$POSTGRES_DATABASE_FILE; -fi -if [ -n "$POSTGRES_USER_FILE" ]; then - POSTGRESQL_USER_FILE=$POSTGRES_USER_FILE; -fi -if [ -n "$POSTGRES_USER" ]; then - POSTGRESQL_USER=$POSTGRES_USER; -fi -if [ -n "$POSTGRES_PASSWORD_FILE" ]; then - POSTGRESQL_PASSWORD_FILE=$POSTGRES_PASSWORD_FILE; -fi -if [ -n "$POSTGRES_PASSWORD" ]; then - POSTGRESQL_PASSWORD=$POSTGRES_PASSWORD; -fi -if [ -n "$POSTGRES_ABSOLUTE_MAX_CONNECTIONS" ]; then - POSTGRESQL_ABSOLUTE_MAX_CONNECTIONS=$POSTGRES_ABSOLUTE_MAX_CONNECTIONS; -fi -if [ -n "$POSTGRES_DEFAULT_MAX_CONNECTIONS" ]; then - POSTGRESQL_DEFAULT_MAX_CONNECTIONS=$POSTGRES_DEFAULT_MAX_CONNECTIONS; -fi -if [ -n "$POSTGRES_DEFAULT_MAX_GROUP_CONNECTIONS" ]; then - POSTGRESQL_DEFAULT_MAX_GROUP_CONNECTIONS=$POSTGRES_DEFAULT_MAX_GROUP_CONNECTIONS; -fi -if [ -n "$POSTGRES_DEFAULT_MAX_CONNECTIONS_PER_USER" ]; then - POSTGRESQL_DEFAULT_MAX_CONNECTIONS_PER_USER=$POSTGRES_DEFAULT_MAX_CONNECTIONS_PER_USER; -fi -if [ -n "$POSTGRES_DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER" ]; then - POSTGRESQL_DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER=$POSTGRES_DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER; -fi -if [ -n "$POSTGRES_DEFAULT_STATEMENT_TIMEOUT" ]; then - POSTGRESQL_DEFAULT_STATEMENT_TIMEOUT=$POSTGRES_DEFAULT_STATEMENT_TIMEOUT; -fi -if [ -n "$POSTGRES_USER_REQUIRED" ]; then - POSTGRESQL_USER_REQUIRED=$POSTGRES_USER_REQUIRED; -fi -if [ -n "$POSTGRES_SOCKET_TIMEOUT" ]; then - POSTGRESQL_SOCKET_TIMEOUT=$POSTGRES_SOCKET_TIMEOUT; -fi -if [ -n "$POSTGRES_SSL_KEY_PASSWORD_FILE" ]; then - POSTGRESQL_SSL_KEY_PASSWORD_FILE=$POSTGRES_SSL_KEY_PASSWORD_FILE; -fi -if [ -n "$POSTGRES_SSL_KEY_PASSWORD" ]; then - POSTGRESQL_SSL_KEY_PASSWORD=$POSTGRES_SSL_KEY_PASSWORD; -fi +for VAR_BASE in \ + HOSTNAME PORT \ + DATABASE USER PASSWORD \ + DATABASE_FILE USER_FILE PASSWORD_FILE \ + ABSOLUTE_MAX_CONNECTIONS DEFAULT_MAX_CONNECTIONS \ + DEFAULT_MAX_GROUP_CONNECTIONS DEFAULT_MAX_CONNECTIONS_PER_USER \ + DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER \ + DEFAULT_STATEMENT_TIMEOUT SOCKET_TIMEOUT \ + USER_REQUIRED \ + SSL_KEY_PASSWORD_FILE SSL_KEY_PASSWORD; do + + OLD_VAR="POSTGRES_$VAR_BASE" + NEW_VAR="POSTGRESQL_$VAR_BASE" + + if [ -n "${!OLD_VAR}" ]; then + printf -v "$NEW_VAR" "%s" "${!OLD_VAR}" + echo "WARNING: ${OLD_VAR} detected, please use ${NEW_VAR} for further deployments." + fi + +done ## ## Adds properties to guacamole.properties which select the PostgreSQL From 6d0d3badabb90afdbda31ff83797222d7d33a031 Mon Sep 17 00:00:00 2001 From: jbpaux <9682558+jbpaux@users.noreply.github.com> Date: Tue, 9 Aug 2022 19:03:41 +0200 Subject: [PATCH 6/6] GUACAMOLE-1572: Add space indentation on error message --- guacamole-docker/bin/start.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/guacamole-docker/bin/start.sh b/guacamole-docker/bin/start.sh index eafb422d3..5289305b6 100755 --- a/guacamole-docker/bin/start.sh +++ b/guacamole-docker/bin/start.sh @@ -252,13 +252,13 @@ to the environment variable, and setting the value to the path of the corresponding secret: POSTGRESQL_USER The user to authenticate as when connecting to - PostgreSQL. + PostgreSQL. POSTGRESQL_PASSWORD The password to use when authenticating with PostgreSQL - as POSTGRESQL_USER. + as POSTGRESQL_USER. POSTGRESQL_DATABASE The name of the PostgreSQL database to use for Guacamole - authentication. + authentication. END exit 1; }