Skip to content

Commit 9c442a2

Browse files
committed
fixup: Take the rsa public key as a string, not as a file
1 parent 748532c commit 9c442a2

3 files changed

Lines changed: 29 additions & 13 deletions

File tree

rust/server/src/main.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn main() {
3636
std::process::exit(1);
3737
}
3838

39-
let Config { server_config: ServerConfig { host, port, rsa_pub_file_path }, postgresql_config } =
39+
let Config { server_config: ServerConfig { host, port }, jwt_auth_config, postgresql_config } =
4040
match util::config::load_config(&args[1]) {
4141
Ok(cfg) => cfg,
4242
Err(e) => {
@@ -69,23 +69,20 @@ fn main() {
6969
},
7070
};
7171

72-
let authorizer: Arc<dyn Authorizer> = if let Some(file_path) = rsa_pub_file_path {
73-
let rsa_pub_file = match std::fs::read(file_path) {
74-
Ok(pem) => pem,
75-
Err(e) => {
76-
println!("Failed to read RSA public key file: {}", e);
77-
std::process::exit(-1);
78-
},
79-
};
80-
let rsa_public_key = match DecodingKey::from_rsa_pem(&rsa_pub_file) {
81-
Ok(pem) => pem,
72+
let rsa_pem =
73+
std::env::var("VSS_JWT_RSA_PEM").ok().or(jwt_auth_config.map(|config| config.rsa_pem));
74+
let authorizer: Arc<dyn Authorizer> = if let Some(pem) = rsa_pem {
75+
let rsa_public_key = match DecodingKey::from_rsa_pem(pem.as_bytes()) {
76+
Ok(p) => p,
8277
Err(e) => {
8378
println!("Failed to parse RSA public key file: {}", e);
8479
std::process::exit(-1);
8580
},
8681
};
82+
println!("Configured JWT authorizer with RSA public key");
8783
Arc::new(JWTAuthorizer::new(rsa_public_key).await)
8884
} else {
85+
println!("No JWT authentication method configured");
8986
Arc::new(NoopAuthorizer {})
9087
};
9188

rust/server/src/util/config.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@ use serde::Deserialize;
33
#[derive(Deserialize)]
44
pub(crate) struct Config {
55
pub(crate) server_config: ServerConfig,
6+
pub(crate) jwt_auth_config: Option<JwtAuthConfig>,
67
pub(crate) postgresql_config: Option<PostgreSQLConfig>,
78
}
89

910
#[derive(Deserialize)]
1011
pub(crate) struct ServerConfig {
1112
pub(crate) host: String,
1213
pub(crate) port: u16,
13-
pub(crate) rsa_pub_file_path: Option<String>,
14+
}
15+
16+
#[derive(Deserialize)]
17+
pub(crate) struct JwtAuthConfig {
18+
pub(crate) rsa_pem: String,
1419
}
1520

1621
#[derive(Deserialize)]

rust/server/vss-server-config.toml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
[server_config]
22
host = "127.0.0.1"
33
port = 8080
4-
# rsa_pub_file_path = "rsa_public_key.pem" # Uncomment to verify JWT tokens in the HTTP Authorization header
4+
5+
# Uncomment the table below to verify JWT tokens in the HTTP Authorization header against the given RSA public key,
6+
# can be overridden by env var `VSS_JWT_RSA_PEM`
7+
# [jwt_auth_config]
8+
# rsa_pem = """
9+
# -----BEGIN PUBLIC KEY-----
10+
# MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAstPJs4ut+tFAI0qrOyGt
11+
# /3FN5jWc5gLv/j9Rc6lgr4hm7lyR05PU/G+4rfxdXGNyGTlQ6dRqcVy78CjxWz9f
12+
# 8l08EKLERPh8JhE5el6vr+ehWD5iQxSP3ejpx0Mr977fKMNKg6jlFiL+y50hOEp2
13+
# 6iN9QzZQjLxotDT3aQvbCA/DZpI+fV6WKDKWGS+pZGDVgOz5x/RcStJQXxkX3ACK
14+
# WhVdrtN3h6mHlhIt7ZIqVvQmY4NL03QPyljt13sYHoiFaoxINF/funBMCjrfSLcB
15+
# ko1rWE2BWdOrFqi27RtBs5AHOSAWXuz/2SUGpFuTQuJi7U68QUfjKeQO46JpQf+v
16+
# kQIDAQAB
17+
# -----END PUBLIC KEY-----
18+
# """
519

620
[postgresql_config]
721
username = "postgres" # Optional in TOML, can be overridden by env var `VSS_POSTGRESQL_USERNAME`

0 commit comments

Comments
 (0)