Skip to content

Commit 742a943

Browse files
committed
Add option to generate new JWT secret
Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
1 parent 2d54962 commit 742a943

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/main.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: LGPL-2.1-or-later
2-
// Copyright (C) 2024 Collabora, Ltd.
2+
// Copyright (C) 2024-2025 Collabora, Ltd.
33
// Author: Denys Fedoryshchenko <denys.f@collabora.com>
44
/*
55
KernelCI Storage Server
@@ -53,6 +53,13 @@ struct Args {
5353
help = "Config file, relative to files_directory"
5454
)]
5555
config_file: String,
56+
57+
#[clap(
58+
short,
59+
long,
60+
help = "Generate JWT secret"
61+
)]
62+
generate_jwt_secret: bool,
5663
}
5764

5865
struct ReceivedFile {
@@ -87,6 +94,11 @@ async fn initial_setup() -> Option<RustlsConfig> {
8794
let download_dir = "download";
8895
let args = Args::parse();
8996

97+
if args.generate_jwt_secret {
98+
storjwt::generate_jwt_secret();
99+
std::process::exit(0);
100+
}
101+
90102
if let Err(e) = std::env::set_current_dir(&args.files_directory) {
91103
eprintln!("Error changing directory: {}", e);
92104
std::process::exit(1);

src/storjwt.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,15 @@ pub fn verify_jwt_token(token_str: &str) -> Result<BTreeMap<String, String>, jwt
3636
}
3737
Ok(claims.clone())
3838
}
39+
40+
pub fn generate_jwt_secret() {
41+
// generate a random 32 bytes alphanumeric string
42+
use rand::{distributions::Alphanumeric, Rng};
43+
44+
let secret: String = rand::thread_rng()
45+
.sample_iter(&Alphanumeric)
46+
.take(32)
47+
.map(char::from)
48+
.collect();
49+
println!("jwt_secret=\"{}\"", secret);
50+
}

0 commit comments

Comments
 (0)