Environment variables in pgsql connect string

Eirik Rye rye at trojka.no
Wed Dec 4 14:22:37 EET 2019


Hi,

We are trying to set up a Dovecot Docker image with dynamic database 
configuration based on environment variables, however the variables do 
not appear to be expanded in the "connect=" string of the SQL config.

The documentation states that environment variables, being listed under 
global variables, work "everywhere":

 
https://doc.dovecot.org/configuration_manual/config_file/config_variables/#variables-global

However, the source code for driver-pgsql.c indicates that the connect 
string is never expanded:

 
https://github.com/dovecot/core/blob/master/src/lib-sql/driver-pgsql.c#L297

For reference, this is my configuration. dovecot.conf:

   import_environment = PASSDB_USER PASSDB_DBNAME PASSDB_PASSWORD
   passdb {
     override_fields = proxy=y
     driver = sql
     args = /etc/dovecot/dovecot-sql.conf.ext
   }

/etc/dovecot/dovecot-sql.conf.ext:

   driver = pgsql
   connect = host=mail-passdb dbname=%{env:PASSDB_DBNAME} 
user=%{env:PASSDB_USER} password=%{env:PASSDB_PASSWORD}

Does anyone have any suggestions for how to connect to a database 
without hardcoding the connection parameters in the Dovecot config, 
which does not involve patching driver-pgsql.c to make the variable 
expansion?

Best regards,
Eirik Rye


More information about the dovecot mailing list