Skip to content

Commit 3832337

Browse files
committed
Makes confidant ever-so-slightly easier to use
1 parent 2faab26 commit 3832337

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

streambed-confidant-cli/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ to authenticate the session. Here's an example with some dummy data:
3232

3333
```
3434
echo "1800af9b273e4b9ea71ec723426933a4" > /tmp/root-secret
35-
echo "unused-id" > /tmp/ss-secret-id
3635
```
3736

3837
We also need to create a directory for `confidant` to read and write its secrets. A security feature

streambed-confidant-cli/src/main.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{
22
error::Error,
33
fs::{self, File},
44
io::{self, BufRead, BufReader, BufWriter, Read, Write},
5-
path::PathBuf,
5+
path::{Path, PathBuf},
66
time::Duration,
77
};
88

@@ -26,8 +26,9 @@ struct ProgramArgs {
2626
/// In order to initialise the secret store, a root secret is also required. A credentials-directory path can be provided
2727
/// where a `root-secret`` file is expected. This argument corresponds conveniently with systemd's CREDENTIALS_DIRECTORY
2828
/// environment variable and is used by various services we have written.
29-
/// Also associated with this argument is the `secret_id` file` for role-based authentication with the secret store.
30-
/// This secret is expected to be found in a ss-secret-id file of the directory.
29+
/// Also associated with this argument is an optional "secret id" file` for role-based authentication with the secret store.
30+
/// This secret is expected to be found in a ss-secret-id file of the directory and, if not provided, will default to
31+
/// an "unusedid" value.
3132
#[clap(env, long, default_value = "/tmp")]
3233
pub credentials_directory: PathBuf,
3334

@@ -145,14 +146,17 @@ async fn secret_store(
145146
.ok_or(Errors::EmptyRootSecretFile)?
146147
.map_err(Errors::RootSecretFileIo)?;
147148

148-
let f = File::open(credentials_directory.join("ss-secret-id"))
149-
.map_err(Errors::SecretIdFileIo)?;
150-
let f = BufReader::new(f);
151-
let ss_secret_id = f
152-
.lines()
153-
.next()
154-
.ok_or(Errors::EmptyRootSecretFile)?
155-
.map_err(Errors::SecretIdFileIo)?;
149+
let ss_secret_id = if Path::exists(&credentials_directory.join("ss-secret-id")) {
150+
let f = File::open(credentials_directory.join("ss-secret-id"))
151+
.map_err(Errors::SecretIdFileIo)?;
152+
let f = BufReader::new(f);
153+
f.lines()
154+
.next()
155+
.ok_or(Errors::EmptyRootSecretFile)?
156+
.map_err(Errors::SecretIdFileIo)?
157+
} else {
158+
String::from("unusedid")
159+
};
156160

157161
(root_secret, ss_secret_id)
158162
};

0 commit comments

Comments
 (0)