rustic
rustic copied to clipboard
`key`: better key handling and additional sub commands
$ rustic --version
rustic v0.6.1
$ rustic key list
error: unrecognized subcommand 'list'
Usage: rustic key [OPTIONS] <COMMAND>
For more information, try '--help'.
$ rustic key --help
Manage keys
Usage: rustic key [OPTIONS] <COMMAND>
Commands:
add Add a new key to the repository
help Print this message or the help of the given subcommand(s)
Options:
-h, --help
Print help (see a summary with '-h')
Looks like key list command has got lost during latest refactoring...
Unless documentation is wrong: https://rustic.cli.rs/docs/commands/misc/key.html
Possibly also remove and passwd
The documentation is copied from restic, so some things need to be adapted.
For the Key management, I think this is currently a bit of a hackery and I think might need to rework it a bit, to add the other options more ergonomic way.
@kapitainsky Thanks for opening the issue - for the key there are indeed some subcommands which were never implemented.
You can use rustic list key to get a list of present key ids. Also the keys can be read manually in the repository as they are plaintext json files.
But I agree, the other subcommands for key handling need to be added. Anyone up for a PR? This should be pretty straightforward to implement...
Anyone up for a PR? This should be pretty straightforward to implement...
A PR would be nice, though I wouldn't say, that it is straight forward to implement, as there needs to be a bit more design work, I feel. Currently it's rather hacky, with creating a new fake repository to add a key:
let repo = open_repository(&config)?;
// create new "artificial" repo using the given password options
let repo_opts = RepositoryOptions {
password_file: self.new_password_file.clone(),
repository: Some(String::new()), // fake repository to make Repository::new() not bail
..Default::default()
};
let repo_newpass = Repository::new(&repo_opts)?;
let pass = repo_newpass
.password()
.map_err(|err| err.into())
.transpose()
.unwrap_or_else(|| -> Result<_> {
Ok(Password::new()
.with_prompt("enter password for new key")
.allow_empty_password(true)
.with_confirmation("confirm password", "passwords do not match")
.interact()?)
})?;
let id = repo.add_key(&pass, &self.key_opts)?;
Also, we don't have anything really about key management in rustic_core I believe? So it would be good to create something there. I could imagine a trait for managing keys and implementing it for different repository states. We should also keep in mind how that interacts with future changes to encryption algorithms and where and how it connects.