Add passcommand for database dumps #795

Closed
opened 2023-11-24 20:16:08 +00:00 by Martin · 7 comments

What I'd like to do and why

A passcommand in addition to password for database dumps would be nice for those who cannot login without password nor like to have the password in config.yaml.

Other notes / implementation ideas

No response

### What I'd like to do and why A `passcommand` in addition to `password` for database dumps would be nice for those who cannot login without password nor like to have the password in `config.yaml`. ### Other notes / implementation ideas _No response_
witten added the
good first issue
label 2023-11-24 21:17:27 +00:00
Owner

Thanks for taking the time to file this! Maybe there could be a new option in each database configuration that allows the user to specify the passcommand for that database instead of a password. And if specified, borgmatic would call out to that command, consuming its stdout (stripped of newlines) to get the password to use.

In the meantime though, these docs may be helpful: https://torsion.org/borgmatic/docs/how-to/provide-your-passwords/

Thanks for taking the time to file this! Maybe there could be a new option in each database configuration that allows the user to specify the passcommand for that database instead of a password. And if specified, borgmatic would call out to that command, consuming its stdout (stripped of newlines) to get the password to use. In the meantime though, these docs may be helpful: https://torsion.org/borgmatic/docs/how-to/provide-your-passwords/
Contributor

But borgmatic can already do that right? Afaik it should support reading things from the env so why add a feature to do that manually for one field? Is there any limitation to running your password script before calling borgmatic, saving the output in the env and calling borgmatic after that?

But borgmatic can already do that right? Afaik it should support reading things from the env so why add a feature to do that manually for one field? Is there any limitation to running your password script before calling borgmatic, saving the output in the env and calling borgmatic after that?
Owner

If there's one common theme in borgmatic feature requests, it's that users want to do more and more directly from the configuration file rather than having to rely on external shell scripting. Having said that, the work-around you describe is a totally viable option for certain users.

If there's one common theme in borgmatic feature requests, it's that users want to do more and more directly from the configuration file rather than having to rely on external shell scripting. Having said that, the work-around you describe is a totally viable option for certain users.
Owner

@Martin borgmatic is getting several new credential loading hooks in the next release. None of them directly solve this ask, but it would be pretty easy now to add a new credential hook that allows calling arbitrary commands from password fields within borgmatic's configuration file. Made-up example:

postgresql_databases:
    - name: invoices
      username: postgres
      password: "{credential command some-command-to-run}"

However, one question first so I can understand the use case: What command do you want to run to get your password? It might be useful to support running arbitrary commands, but it might also be neat to add a more targeted credential hook as well (or instead). For instance, I just added a credential hook that allows loading credentials from KeePassXC, a password manager. Example:

postgresql_databases:
    - name: invoices
      username: postgres
      password: "{credential keepassxc keys.kdbx borgmatic}"

So where is your database password actually coming from?

@Martin borgmatic is getting several new credential loading hooks in the next release. None of them directly solve this ask, but it would be pretty easy now to add a new credential hook that allows calling arbitrary commands from password fields within borgmatic's configuration file. Made-up example: ```yaml postgresql_databases: - name: invoices username: postgres password: "{credential command some-command-to-run}" ``` However, one question first so I can understand the use case: What command do you want to run to get your password? It might be useful to support running arbitrary commands, but it might also be neat to add a more targeted credential hook as well (or instead). For instance, I just added a credential hook that allows loading credentials from KeePassXC, a password manager. Example: ```yaml postgresql_databases: - name: invoices username: postgres password: "{credential keepassxc keys.kdbx borgmatic}" ``` So where is your database password actually coming from?
Author

So where is your database password actually coming from?

In my case, it is probably sth. simple as cat <filename>, while the file contains only the password.
I.e. special handling that might make sense.

> So where is your database password actually coming from? In my case, it is probably sth. simple as `cat <filename>`, while the file contains only the password. I.e. special handling that might make sense.
Owner

Oh, good news then! This is already implemented in main and will be part of the next release! Example usage:

postgresql_databases:
    - name: invoices
      username: postgres
      password: "{credential file /path/to/my/credential.txt}"

What that does is read the contents of the /path/to/my/credential.txt file and insert it into the password field.

So I'll call this done for now even though it doesn't (yet) support running arbitrary commands. But that could potentially be added later on if there's a need.

Oh, good news then! This is already implemented in main and will be part of the next release! Example usage: ``` postgresql_databases: - name: invoices username: postgres password: "{credential file /path/to/my/credential.txt}" ``` What that does is read the contents of the `/path/to/my/credential.txt` file and insert it into the password field. So I'll call this done for now even though it doesn't (yet) support running arbitrary commands. But that could potentially be added later on if there's a need.
Owner

Released in borgmatic 1.9.11!

Released in borgmatic 1.9.11!
Sign in to join this conversation.
3 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: borgmatic-collective/borgmatic#795
No description provided.