Opened 4 years ago

Last modified 4 years ago

#32456 closed New feature

Pass dbshell passwords as option files — at Version 1

Reported by: Dominik George Owned by: nobody
Component: Database layer (models, ORM) Version: 4.0
Severity: Normal Keywords:
Cc: Florian Apolloner, Daniel Bowring, Simon Charette Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Dominik George)

The dbshell management commands all carry the risk of leaking passwords through process information (as noted in a comment in db.backends.mysql.client). As of Django 3.2, there is the settings_to_cmd_args_env class method, which provides an API to generate the environment needed to call the utility.

Using the environment is somewhat more secure, but the environment of processes can potentially still be read. Both MySQL and PostgreSQL advise against using the respective environment variables.

I want to propose a way to solve this. I already did this in django-dbbackup, which also happened to construct a command line before:

https://github.com/django-dbbackup/django-dbbackup/pull/385/commits/222152afe9032e98249cada6d7e200a3eb751e63

The mechanism is that in addition to the environment and args, a temporary file is generated. For PostgreSQL, this is a file in .pgpass format; for MySQL, it could be an options file. I wrapped that handling in a neat context manager.

For Django itself, I did a quick shot at PostgreSQL as well, as attached in the patch. The patch is not complete, and is only intended as a base for discussion. If we find consensus about the mechanism, I will happily complete it and extend to the other backends.

Change History (2)

by Dominik George, 4 years ago

comment:1 by Dominik George, 4 years ago

Description: modified (diff)
Summary: Pass runshell passwords as option filesPass dbshell passwords as option files
Note: See TracTickets for help on using tickets.
Back to Top