Skip to content

Commit

Permalink
fix(derper): update config to auto generate keys (#1599)
Browse files Browse the repository at this point in the history
## Description

Deploying a derper node is a bit cumbersome right now if you don't run
with default config. You have to provide a `secret_key` but have no easy
path to generate one so either you dance to create a fresh config and
then modify it or need to use some external thing to generate keys for
you. Either way it's cumbersome.

This just adds an extra handler to inject a secret key if not present
already in the supplied config.

## Notes & open questions

<!-- Any notes, remarks or open questions you have to make about the PR.
-->

## Change checklist

- [x] Self-review.
- [ ] Documentation updates if relevant.
- [ ] Tests if relevant.
  • Loading branch information
Arqu committed Oct 9, 2023
1 parent fda9c60 commit 8fb46d4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions iroh-net/src/bin/derper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ fn load_secret_key(filename: impl AsRef<Path>) -> Result<rustls::PrivateKey> {
struct Config {
/// [`SecretKey`] for this Derper.
#[serde_as(as = "DisplayFromStr")]
#[serde(default = "SecretKey::generate")]
secret_key: SecretKey,
/// Server listen address.
///
Expand Down Expand Up @@ -284,10 +285,14 @@ impl Config {
if !path.as_ref().is_file() {
bail!("config-path must be a valid toml file");
}
let config_ser = tokio::fs::read_to_string(path)
let config_ser = tokio::fs::read_to_string(&path)
.await
.context("unable to read config")?;
let config = toml::from_str(&config_ser).context("unable to decode config")?;
let config: Self = toml::from_str(&config_ser).context("unable to decode config")?;
if !config_ser.contains("secret_key") {
info!("generating new secret key and updating config file");
config.write_to_file(path).await?;
}

Ok(config)
}
Expand Down

0 comments on commit 8fb46d4

Please sign in to comment.