Skip to content

Commit f36256d

Browse files
committed
Gate NoopAuthorizer behind the noop_authorizer cfg flag
`NoopAuthorizer` is now only accessible via `RUSTFLAGS="--cfg noop_authorizer" cargo run --no-default-features`. We want to discourage our users from ever using `NoopAuthorizer`.
1 parent d8b1295 commit f36256d

File tree

6 files changed

+29
-9
lines changed

6 files changed

+29
-9
lines changed

.github/workflows/build-and-deploy-rust.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,16 @@ jobs:
3333
- name: Build and Deploy VSS Server
3434
run: |
3535
cd rust
36-
cargo build
37-
cargo run server/vss-server-config.toml&
36+
RUSTFLAGS="--cfg noop_authorizer" cargo run --no-default-features server/vss-server-config.toml&
3837
3938
- name: Hit endpoint to verify service is up
4039
run: |
41-
sleep 5
40+
sleep 60
4241
4342
# Put request with store='storeId' and key=k1
4443
hex=0A0773746F726549641A150A026B3110FFFFFFFFFFFFFFFFFF011A046B317631
45-
curl --data-binary "$(echo "$hex" | xxd -r -p)" http://localhost:8080/vss/putObjects
44+
curl -f --data-binary "$(echo "$hex" | xxd -r -p)" http://localhost:8080/vss/putObjects
4645
4746
# Get request with store='storeId' and key=k1
4847
hex=0A0773746F7265496412026B31
49-
curl --data-binary "$(echo "$hex" | xxd -r -p)" http://localhost:8080/vss/getObject
48+
curl -f --data-binary "$(echo "$hex" | xxd -r -p)" http://localhost:8080/vss/getObject

.github/workflows/ldk-node-integration.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ jobs:
3939
- name: Build and Deploy VSS Server
4040
run: |
4141
cd vss-server/rust
42-
cargo build
43-
cargo run --no-default-features server/vss-server-config.toml&
42+
RUSTFLAGS="--cfg noop_authorizer" cargo run --no-default-features server/vss-server-config.toml&
4443
- name: Run LDK Node Integration tests
4544
run: |
4645
cd ldk-node

rust/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ lto = true
1010

1111
[profile.dev]
1212
panic = "abort"
13+
14+
[workspace.lints.rust.unexpected_cfgs]
15+
level = "forbid"
16+
check-cfg = ['cfg(noop_authorizer)']

rust/api/src/auth.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::error::VssError;
22
use async_trait::async_trait;
33
use std::collections::HashMap;
4-
use std::string::ToString;
54

65
/// Response returned for [`Authorizer`] request if user is authenticated and authorized.
76
#[derive(Debug, Clone)]
@@ -21,10 +20,13 @@ pub trait Authorizer: Send + Sync {
2120
}
2221

2322
/// A no-operation authorizer, which lets any user-request go through.
23+
#[cfg(feature = "_test_utils")]
2424
pub struct NoopAuthorizer {}
2525

26+
#[cfg(feature = "_test_utils")]
2627
const UNAUTHENTICATED_USER: &str = "unauth-user";
2728

29+
#[cfg(feature = "_test_utils")]
2830
#[async_trait]
2931
impl Authorizer for NoopAuthorizer {
3032
async fn verify(

rust/server/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,9 @@ toml = { version = "0.8.9", default-features = false, features = ["parse"] }
2424
log = { version = "0.4.29", default-features = false, features = ["std"] }
2525
chrono = { version = "0.4", default-features = false, features = ["clock"] }
2626
rand = { version = "0.9.2", default-features = false }
27+
28+
[target.'cfg(noop_authorizer)'.dependencies]
29+
api = { path = "../api", features = ["_test_utils"] }
30+
31+
[lints]
32+
workspace = true

rust/server/src/main.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ use hyper_util::rt::TokioIo;
1919

2020
use log::{error, info, warn};
2121

22-
use api::auth::{Authorizer, NoopAuthorizer};
22+
use api::auth::Authorizer;
23+
#[cfg(noop_authorizer)]
24+
use api::auth::NoopAuthorizer;
2325
use api::kv_store::KvStore;
2426
#[cfg(feature = "jwt")]
2527
use auth_impls::jwt::JWTAuthorizer;
@@ -98,13 +100,21 @@ fn main() {
98100
authorizer = Some(Arc::new(SignatureValidatingAuthorizer));
99101
}
100102
}
103+
104+
#[cfg(noop_authorizer)]
101105
let authorizer = if let Some(auth) = authorizer {
102106
auth
103107
} else {
104108
warn!("No authentication method configured, all storage with the same store id will be commingled.");
105109
Arc::new(NoopAuthorizer {})
106110
};
107111

112+
#[cfg(not(noop_authorizer))]
113+
let authorizer = authorizer.unwrap_or_else(|| {
114+
error!("No authentication method configured, please configure either `JWTAuthorizer` or `SignatureValidatingAuthorizer`");
115+
std::process::exit(-1);
116+
});
117+
108118
let store: Arc<dyn KvStore> = if let Some(crt_pem) = config.tls_config {
109119
let postgres_tls_backend = PostgresTlsBackend::new(
110120
&config.postgresql_prefix,

0 commit comments

Comments
 (0)