Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Ability to inject secrets into XML config file at startup using Environment variables #287

Open
ashleysommer opened this issue Apr 27, 2022 · 1 comment

Comments

@ashleysommer
Copy link

ashleysommer commented Apr 27, 2022

When configuring username and password for postgres db, it would be great to not have to hardcode the values into the config file.

When using containerisation runtimes like docker-compose or kubernetes, it is common to have and required secrets made available as environment variables supplied into the container at runtime.

In short, instead of this:

<dimension type="postgresql" name="time" default="d1" time="true">
  <connection>
    host=my.postgres.host.org user=mapcache password=xxchangemexx dbname=index port=5433
  </connection>
  <list_query>SELECT ts FROM timedim</list_query>
  <validate_query>
       SELECT to_char(ts,'YYYY-MM-DD"T"HH24:MI:SS"Z"') FROM timedim
        WHERE ts &gt;= to_timestamp(:start_timestamp)
          AND ts &lt;= to_timestamp(:end_timestamp)
     ORDER BY ts DESC
  </validate_query>
</dimension>

I want to do this:

<dimension type="postgresql" name="time" default="d1" time="true">
  <connection>
    host=my.postgres.host.org user=${DB_USERNAME} password=${DB_PASSWORD} dbname=index port=5433
  </connection>
  <list_query>SELECT ts FROM timedim</list_query>
  <validate_query>
       SELECT to_char(ts,'YYYY-MM-DD"T"HH24:MI:SS"Z"') FROM timedim
        WHERE ts &gt;= to_timestamp(:start_timestamp)
          AND ts &lt;= to_timestamp(:end_timestamp)
     ORDER BY ts DESC
  </validate_query>
</dimension>

Similar question on stackoverflow:
https://gis.stackexchange.com/questions/418360/referencing-environment-variables-in-mapcache-xml

Kind of related to #273

@lubojr
Copy link

lubojr commented Aug 4, 2022

As this functionality is not yet in Mapcache, we are solving following situation with replacing the template values with env values via a configure script, which runs before mapcache is run. Of course the generated mapcache.xml will still have the credentials shown in plain text at runtime.

cat mapcache-template.xml \
    | sed -e "s/{{DB_USER}}/$(echo ${DB_USER} | sed -e 's/[]\/$*.^[]/\\&/g')/g" \
    | sed -e "s/{{DB_PW}}/$(echo ${DB_PW} | sed -e 's/[]\/$*.^[]/\\&/g')/g" \
    | sed -e "s/{{DB_HOST}}/$(echo ${DB_HOST} | sed -e 's/[]\/$*.^[]/\\&/g')/g" \
    | sed -e "s/{{DB_PORT}}/$(echo ${DB_PORT} | sed -e 's/[]\/$*.^[]/\\&/g')/g" \
    | sed -e "s/{{DB_NAME}}/$(echo ${DB_NAME} | sed -e 's/[]\/$*.^[]/\\&/g')/g" > mapcache.xml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants