borg icon indicating copy to clipboard operation
borg copied to clipboard

What happens when a new keyfile repo is created at the same path?

Open hexagonrecursion opened this issue 3 years ago • 4 comments

@mowny https://github.com/borgbackup/borg/issues/6204#issuecomment-1028744422

What if a keyfile exists when a new repo is created?

  1. Alice creates a keyfile repo at $REPO
  2. The repo is moved or unmounted
  3. Alice creates another keyfile repo at the same location
  4. What happenes?
    1. Is the existing key reused?
    2. Is the existing key overwritten?

A new key is created:

$ borg init -e keyfile ~/collision
$ mv ~/collision ~/foo
$ borg init -e keyfile ~/collision
$ mv ~/collision ~/bar
$ borg init -e keyfile ~/collision
$ ls ~/.config/borg/keys/
home_user_collision    
home_user_collision.2 
home_user_collision.3  

It appears that we do not have a regression test to cover this edge case. I could add one. Should I also add a paragraph to faq or borg init docs?

hexagonrecursion avatar Feb 03 '22 17:02 hexagonrecursion

It seems to be handled correctly, though, and the correct key is used. (Does it test all existing keyfiles until one is found that fits?)

mowny avatar Feb 03 '22 18:02 mowny

IIRC, the repo ID is used to identify the right key. And when generating the key filename, it uses a new name, even the repo path is the same.

We could also store the repo key under REPOID.key or so, maybe that would smell less like a problem.

ThomasWaldmann avatar Feb 03 '22 21:02 ThomasWaldmann

I renamed the keyfile, and borg found it anyway, so it really seems to try all files in there.

mowny avatar Feb 03 '22 21:02 mowny

@hexagonrecursion yes, a test and docs would be nice.

ThomasWaldmann avatar Mar 20 '22 23:03 ThomasWaldmann