encryption_passcommand in one config file A wrongly used for repo in config file B #555

Closed
opened 2022-06-30 09:25:32 +00:00 by real-or-random · 4 comments

What I'm trying to do and why

I have multiple config files, say A.yaml and B.yaml (sanitized). I want to run borg check on a repo in B.yaml, specifying the repo using --repository.

Steps to reproduce (if a bug)

Relevant snippets of the config files:

A.yaml:

location:
    repositories:
        - /repo/A        
storage:
    encryption_passcommand: secret-tool lookup  ... 

B.yaml:

location:
    repositories:
        - /repo/B
storage:
    #encryption_passcommand unset 
    #encryption_passphrase unset

No merging/YAML magic in the config files.

Actual behavior (if a bug)

borgmatic --repository /repo/B borg check ... aborts with "passphrase supplied in BORG_PASSPHRASE, by BORG_PASSCOMMAND or via BORG_PASSPHRASE_FD is incorrect.".
strace shows that borg runs the encryption_passcommand from A.yaml before aborting.

borgmatic --config /etc/borgmatic.d/B.yaml --repository /repo/B borg check ...

Expected behavior (if a bug)

borgmatic --repository /repo/B borg check ... ignores everything in A.yaml and asks for a passphrase

Other notes / implementation ideas

Not sure if this is specific to arbitritrary borg commands / borg check. I vaguely remember that I saw this problem with normal operations in the past but I never really bothered reporting it. I can't try right now because the borg check is in progress now... ;) I can try later if this is relevant.

Environment

borgmatic version: 1.6.4

borgmatic installation method: Arch Linux package

Borg version: 1.1.17

Python version: 3.10.5

operating system and version: Arch Linux

#### What I'm trying to do and why I have multiple config files, say A.yaml and B.yaml (sanitized). I want to run borg check on a repo in B.yaml, specifying the repo using `--repository`. #### Steps to reproduce (if a bug) Relevant snippets of the config files: A.yaml: ``` location: repositories: - /repo/A storage: encryption_passcommand: secret-tool lookup ... ``` B.yaml: ``` location: repositories: - /repo/B storage: #encryption_passcommand unset #encryption_passphrase unset ``` No merging/YAML magic in the config files. #### Actual behavior (if a bug) `borgmatic --repository /repo/B borg check ...` aborts with "passphrase supplied in BORG_PASSPHRASE, by BORG_PASSCOMMAND or via BORG_PASSPHRASE_FD is incorrect.". `strace` shows that borg runs the `encryption_passcommand` from A.yaml before aborting. `borgmatic --config /etc/borgmatic.d/B.yaml --repository /repo/B borg check ...` #### Expected behavior (if a bug) `borgmatic --repository /repo/B borg check ...` ignores everything in A.yaml and asks for a passphrase #### Other notes / implementation ideas Not sure if this is specific to arbitritrary borg commands / borg check. I vaguely remember that I saw this problem with normal operations in the past but I never really bothered reporting it. I can't try right now because the borg check is in progress now... ;) I can try later if this is relevant. #### Environment **borgmatic version:** 1.6.4 **borgmatic installation method:** Arch Linux package **Borg version:** 1.1.17 **Python version:** 3.10.5 **operating system and version:** Arch Linux
witten added the
bug
label 2022-06-30 17:11:32 +00:00
Owner

Thank you for bothering to report this! 😄 I have a hunch about what's going on here. Things like Borg passcommands are communicated from borgmatic to Borg via environment variable. So borgmatic is probably setting the passcommand environment variable for repository A and then it's still around when it gets to repository B, causing the behavior you're seeing.

The fix is probably to avoid altering the global environment and instead pass in a local environment specific to each Borg command that it runs. (More specifically, execute_command(extra_environment=....) The trick will be plumbing that through everywhere that needs it set.

Thank you for bothering to report this! 😄 I have a hunch about what's going on here. Things like Borg passcommands are communicated from borgmatic to Borg via environment variable. So borgmatic is probably setting the passcommand environment variable for repository A and then it's still around when it gets to repository B, causing the behavior you're seeing. The fix is probably to avoid altering the global environment and instead pass in a local environment specific to each Borg command that it runs. (More specifically, `execute_command(extra_environment=...`.) The trick will be plumbing that through everywhere that needs it set.
Owner

Okay, it took some doing, but this should be fixed. Environment variables are no longer set globally, so they should be scoped to particular configuration files now. Release forthcoming. Thanks again for reporting this!

Okay, it took some doing, but this should be fixed. Environment variables are no longer set globally, so they should be scoped to particular configuration files now. Release forthcoming. Thanks again for reporting this!
Owner

Fix released in borgmatic 1.6.5!

Fix released in borgmatic 1.6.5!
Author

Thanks for the quick fix!

Thanks for the quick fix!
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

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