Skip to content

Commit 564f34a

Browse files
committed
fixup! fixup! feat: add request body size configuration
- exit process instead of return - make maximum request body size (mrbs) config optional - remove heap allocation of mrbs - improve error message if mrbs exceeds maximum
1 parent 40c91c0 commit 564f34a

4 files changed

Lines changed: 13 additions & 10 deletions

File tree

rust/server/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ fn main() {
3939
});
4040
let vss_service_config = match &config.maximum_request_body_size {
4141
Some(size) => match VssServiceConfig::new(*size) {
42-
Ok(config) => Arc::new(config),
42+
Ok(config) => config,
4343
Err(e) => {
4444
eprintln!("Configuration validation error: {}", e);
45-
return;
45+
std::process::exit(-1);
4646
},
4747
},
48-
None => Arc::new(VssServiceConfig::default()),
48+
None => VssServiceConfig::default(),
4949
};
5050

5151
let runtime = match tokio::runtime::Builder::new_multi_thread().enable_all().build() {
@@ -142,7 +142,7 @@ fn main() {
142142
match res {
143143
Ok((stream, _)) => {
144144
let io_stream = TokioIo::new(stream);
145-
let vss_service = VssService::new(Arc::clone(&store), Arc::clone(&authorizer), Arc::clone(&vss_service_config));
145+
let vss_service = VssService::new(Arc::clone(&store), Arc::clone(&authorizer), vss_service_config.clone());
146146
runtime.spawn(async move {
147147
if let Err(err) = http1::Builder::new().serve_connection(io_stream, vss_service).await {
148148
eprintln!("Failed to serve connection: {}", err);

rust/server/src/util/config.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ pub(crate) fn load_configuration(config_file_path: Option<&str>) -> Result<Confi
119119
max_request_body_size_config,
120120
"VSS server maximum request body size",
121121
MAX_REQUEST_BODY_SIZE,
122-
)?;
122+
)
123+
.ok();
123124

124125
let rsa_pem_env = read_env(JWT_RSA_PEM_VAR)?;
125126
let rsa_pem = rsa_pem_env.or(jwt_auth_config.and_then(|config| config.rsa_pem));
@@ -179,7 +180,7 @@ pub(crate) fn load_configuration(config_file_path: Option<&str>) -> Result<Confi
179180

180181
Ok(Configuration {
181182
bind_address,
182-
maximum_request_body_size: Some(maximum_request_body_size),
183+
maximum_request_body_size,
183184
rsa_pem,
184185
postgresql_prefix,
185186
default_db,

rust/server/src/vss_service.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl VssServiceConfig {
2929
pub fn new(maximum_request_body_size: usize) -> Result<Self, String> {
3030
if maximum_request_body_size > MAXIMUM_REQUEST_BODY_SIZE {
3131
return Err(format!(
32-
"Request body size {} exceeds maximum {}",
32+
"Maximum request body size {} exceeds maximum {}",
3333
maximum_request_body_size, MAXIMUM_REQUEST_BODY_SIZE
3434
));
3535
}
@@ -48,12 +48,12 @@ impl Default for VssServiceConfig {
4848
pub struct VssService {
4949
store: Arc<dyn KvStore>,
5050
authorizer: Arc<dyn Authorizer>,
51-
config: Arc<VssServiceConfig>,
51+
config: VssServiceConfig,
5252
}
5353

5454
impl VssService {
5555
pub(crate) fn new(
56-
store: Arc<dyn KvStore>, authorizer: Arc<dyn Authorizer>, config: Arc<VssServiceConfig>,
56+
store: Arc<dyn KvStore>, authorizer: Arc<dyn Authorizer>, config: VssServiceConfig,
5757
) -> Self {
5858
Self { store, authorizer, config }
5959
}

rust/server/vss-server-config.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[server_config]
22
bind_address = "127.0.0.1:8080" # Optional in TOML, can be overridden by env var `VSS_BIND_ADDRESS`
3-
maximum_request_body_size = 1073741824 # Optional in TOML: maximum request body size in bytes capped at 1 GB, can be overriden by env var 'VSS_MAX_REQUEST_BODY_SIZE'
3+
# Maximum request body size in bytes. Can be set here or be overridden by env var 'VSS_MAX_REQUEST_BODY_SIZE'
4+
# Defaults to 1 GB if unset.
5+
# maximum_request_body_size = 1073741824
46

57
# Uncomment the table below to verify JWT tokens in the HTTP Authorization header against the given RSA public key,
68
# can be overridden by env var `VSS_JWT_RSA_PEM`

0 commit comments

Comments
 (0)