Configuring Postgres 'Keycloak' Credentials

The Postgres keycloak credentials have to be changed with an SQL query directly done in the PostgreSQL instance connected with postgres-r00t-us3rn4m3 admin account

To Configure Postgres 'Keycloak' Credentials

  1. With the tools of your choice, connect to the database with the postgres user at the JDBC URL: jdbc:postgresql://localhost:5432/postgres.

  2. Run the following SQL query:

    ALTER ROLE keycloak WITH PASSWORD 'NEW_PASSWORD';
  3. Only on the target machine, i.e. the machine that hosts the deployments script and the Docker file, open the script deployment/docker/infra/postgres/start/10-create_user.sh and edit the password in the CREATE USER query.

    ...
    echo "Creating database role: keycloak"
    ${POSTGRES} <<-EOSQL
    CREATE USER keycloak WITH CREATEDB PASSWORD 'NEW_PASSWORD';
    EOSQL

    This ensures the change survives to volume removing.

    Note:

    Note that the script files must be executable. Run chmod +x if needed.

  4. Change the password configuration in the microservices that need to connect to Postgres through this user (in this particular case it is keycloak).

    1. Edit deployment/docker/infra/docker-compose.yml and add the DB_PASSWORD environment variable.

      keycloak:
          ...
          environment:
          - DB_PASSWORD # Not specifying a value allow to transmit environment variable to the container.
    2. Edit the .env file located in docker-compose.yml parent folder and add an environment variable DB_PASSWORD with the password you have chosen. Note that you can also add the environment variable to the host machine.