Cannot get credentials from systemd store directory when run from command line #1180
Labels
No labels
blocked
breaking
bug
data loss
design finalized
good first issue
new feature area
question / support
security
waiting for response
No milestone
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
borgmatic-collective/borgmatic#1180
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What I'm trying to do and why
I'm trying to run
borgamtic listin the command line with borgmatic configs that have systemd credentials in it. The credentials are stored in a custom directory/etc/credstore.encrypted/borgmaticbutborgmatic listreturns "Failed to read encrypted credential data: No such file or directory" errors.I've followed the instructions here for creating multiple credentials under a systemd credentials directory.
Steps to reproduce
The relevant config should be:
I am using the zfs hook. The file list in the systemd credstore:
Actual behavior
Running the config through systemd is fine and exists successfully. However, running
borgmatic listfails.Expected behavior
borgmatic listsucceeds.Other notes / implementation ideas
Seems like there are some edge cases in interpreting the credstore name in the config not considered in the code.
borgmatic version
2.0.11
borgmatic installation method
pipx
Borg version
1.4.1
Python version
No response
Database version (if applicable)
No response
Operating system and version
Ubuntu 24.04.3 LTS
Thanks for filing this! So there's a feature that falls back to using
systemd-credsto load a credential when running borgmatic outside of systemd, but it appears that the feature was never tested along with the instructions in the documentation for creating multiple credentials! And therefore the path loaded by borgmatic'ssystemd-credsinvocation is incorrect.One solution I can think of is to change the documentation to recommend storing borgmatic credentials directly in
/etc/credstore.encrypted/without theborgmatic/subdirectory ... and with theborgmatic_...prefix. That way, the credential name used in borgmatic's config file would match up with its filesystem path.A different solution would be for borgmatic to take a credential name like
borgmatic_pw1and replace the_with a/to make the credential path. That would allow you to leave everything in theborgmatic/subdirectory, but it's potentially a little less intuitive and a little more brittle.Thoughts?
I think whatever the case, there should only be only one place that stores credentials. For the documentation solution, it seems like there would be a problem if someone stores credentials in both
/etc/credstore.encrypted/borgmatic/pw1and/etc/credstore.encrypted/borgmatic_pw1where thesystemdinstance would read the credential from the former file and the cli instance would read the credential from the latter, causing problems and confusion in the future.I would prefer the second solution, but also we need to add more documentation on how the name is parsed, such as: there cannot be any underscores in the directory name. There may be a better way to store the directory info and parse it as well. I’m not sure how the folder name is being parsed now though, is it being done by borgmatic or systemd? Can you have sub folders in the credential name, e.g., borgmatic/host1/pw1?
If you point me to some relevant parts of the codebase, maybe I can take a stab at this bug as well.
Yeah, that seems problematic.
There's already a
encrypted_credentials_directoryoption under borgmatic'ssystemd:option, so in theory the user can already override that path. It does occur to me that adding the following to your configuration would almost work:Except then the credential names don't quite match up with their filenames (e.g.
pw1vsborgmatic_pw1). But that could be addressed by renaming the credentials (and then updating the documentation accordingly).Here's the relevant code: borgmatic/hooks/credential/systemd.py ... When you
borgmatic listoutside of systemd, that path is constructed entirely by borgmatic. And sub-folders won't work currently, because there's a singleencrypted_credentials_directoryused when you run borgmatic outside of systemd (and in fact when you run borgmatic inside a systemd service as well).Let me know what you decide to do!
Check out issue #1123
"Use systemd credential only when running as a systemd unit, defer to manual entry otherwise"
Just checking in... @thecodehen, did you plan to submit a PR for this? Either way, please let me know. Thanks!
Yep, I think I have a fix by checking if the name has '_' and adding that to the directory path. Is there any branch naming conventions?
Ok this is my first time submitting a PR here--let me know any feedback!
No real branch naming conventions. I generally try to go for descriptive names, but that's not always practical depending on the complexity of the issue.