2

I want to provide a config ini file with my python package that will hold sensitive database credentials. How do I provide default config file that will be installed let's say under /etc/config folder? what is the best practice in terms of deploying such config files with packages, installed with pip? I do not like to keep this config file with the rest of the package files.

Thanks!

mishkin
  • 5,932
  • 8
  • 45
  • 64
  • What is relevant about the fact that the credentials are *sensitive*? – Stephen Rauch Jan 15 '18 at 02:56
  • 1
    I've seen projects use SQLite as a default, copy a config file to the home directory, and then let the user configure higher databases. Otherwise maybe use a CLI with user input? – Sebastian Jan 15 '18 at 04:19
  • i guess if data in config file is not sensitive, it is okay to leave it in the user home directory. the best practice though is to keep it somewhere safe like under /etc/ so users with normal privileges cannot see/change it – mishkin Jan 15 '18 at 13:16

1 Answers1

3

I just checked how it is done with popular python projects.

django creates a config file that allows pointing to another config file with database connection details, stored in a different place: https://docs.djangoproject.com/en/2.0/ref/databases/#connecting-to-the-database

flask and airflow create default configs under user home folder but then allow to use an environment variable to overwrite location of a config file. Config file stores sensitive data such as database connections or secret keys: http://flask.pocoo.org/docs/0.12/config/#configuring-from-files https://airflow.apache.org/configuration.html

Both methods allow to: 1) distribute default config file and deploy easily with the package install 2) allow storing sensitive config values in a secured folder

airflow also allows encrypting database connection string using a secret key.

Also refer to this post below and some ideas on how to deploy/store your config file: https://stackoverflow.com/a/22554594/473725

mishkin
  • 5,932
  • 8
  • 45
  • 64