Skip to main content

rustfs_config/constants/
console.rs

1//  Copyright 2024 RustFS Team
2//
3//  Licensed under the Apache License, Version 2.0 (the "License");
4//  you may not use this file except in compliance with the License.
5//  You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14
15/// CORS allowed origins for the endpoint service
16/// Comma-separated list of origins or "*" for all origins
17pub const ENV_CORS_ALLOWED_ORIGINS: &str = "RUSTFS_CORS_ALLOWED_ORIGINS";
18
19/// Default CORS allowed origins for the endpoint service
20/// Empty means the S3 endpoint emits no generic CORS headers unless configured.
21pub const DEFAULT_CORS_ALLOWED_ORIGINS: &str = "";
22
23/// CORS allowed origins for the console service
24/// Comma-separated list of origins or "*" for all origins
25pub const ENV_CONSOLE_CORS_ALLOWED_ORIGINS: &str = "RUSTFS_CONSOLE_CORS_ALLOWED_ORIGINS";
26
27/// Default CORS allowed origins for the console service.
28///
29/// Empty string means same-origin only — no `Access-Control-Allow-Origin`
30/// header is emitted, so browsers will not allow cross-origin reads of
31/// console responses by default. Operators that need cross-origin access set
32/// `RUSTFS_CONSOLE_CORS_ALLOWED_ORIGINS` to a comma-separated allow-list, or
33/// to `*` to keep the previous permissive behavior.
34pub const DEFAULT_CONSOLE_CORS_ALLOWED_ORIGINS: &str = "";
35
36/// Enable or disable the console service
37pub const ENV_CONSOLE_ENABLE: &str = "RUSTFS_CONSOLE_ENABLE";
38
39/// Address for the console service to bind to
40pub const ENV_CONSOLE_ADDRESS: &str = "RUSTFS_CONSOLE_ADDRESS";
41
42/// RUSTFS_CONSOLE_RATE_LIMIT_ENABLE
43/// Enable or disable rate limiting for the console service
44pub const ENV_CONSOLE_RATE_LIMIT_ENABLE: &str = "RUSTFS_CONSOLE_RATE_LIMIT_ENABLE";
45
46/// Default console rate limit enable
47/// This is the default value for enabling rate limiting on the console server.
48/// Rate limiting helps protect against abuse and DoS attacks on the management interface.
49/// Default value: false
50/// Environment variable: RUSTFS_CONSOLE_RATE_LIMIT_ENABLE
51/// Command line argument: --console-rate-limit-enable
52/// Example: RUSTFS_CONSOLE_RATE_LIMIT_ENABLE=true
53/// Example: --console-rate-limit-enable true
54pub const DEFAULT_CONSOLE_RATE_LIMIT_ENABLE: bool = false;
55
56/// Set the rate limit requests per minute for the console service
57/// Limits the number of requests per minute per client IP when rate limiting is enabled
58/// Default: 100 requests per minute
59pub const ENV_CONSOLE_RATE_LIMIT_RPM: &str = "RUSTFS_CONSOLE_RATE_LIMIT_RPM";
60
61/// Default console rate limit requests per minute
62/// This is the default rate limit for console requests when rate limiting is enabled.
63/// Limits the number of requests per minute per client IP to prevent abuse.
64/// Default value: 100 requests per minute
65/// Environment variable: RUSTFS_CONSOLE_RATE_LIMIT_RPM
66/// Command line argument: --console-rate-limit-rpm
67/// Example: RUSTFS_CONSOLE_RATE_LIMIT_RPM=100
68/// Example: --console-rate-limit-rpm 100
69pub const DEFAULT_CONSOLE_RATE_LIMIT_RPM: u32 = 100;
70
71/// Set the console authentication timeout in seconds
72/// Specifies how long a console authentication session remains valid
73/// Default: 3600 seconds (1 hour)
74/// Minimum: 300 seconds (5 minutes)
75/// Maximum: 86400 seconds (24 hours)
76pub const ENV_CONSOLE_AUTH_TIMEOUT: &str = "RUSTFS_CONSOLE_AUTH_TIMEOUT";
77
78/// Default console authentication timeout in seconds
79/// This is the default timeout for console authentication sessions.
80/// After this timeout, users need to re-authenticate to access the console.
81/// Default value: 3600 seconds (1 hour)
82/// Environment variable: RUSTFS_CONSOLE_AUTH_TIMEOUT
83/// Command line argument: --console-auth-timeout
84/// Example: RUSTFS_CONSOLE_AUTH_TIMEOUT=3600
85/// Example: --console-auth-timeout 3600
86pub const DEFAULT_CONSOLE_AUTH_TIMEOUT: u64 = 3600;
87
88/// Toggle update check
89/// It controls whether to check for newer versions of rustfs
90/// Default value: true
91/// Environment variable: RUSTFS_CHECK_UPDATE
92/// Example: RUSTFS_CHECK_UPDATE=false
93pub const ENV_UPDATE_CHECK: &str = "RUSTFS_CHECK_UPDATE";
94
95/// Default value for update toggle
96pub const DEFAULT_UPDATE_CHECK: bool = true;
97
98#[cfg(test)]
99mod tests {
100    use super::*;
101
102    #[test]
103    fn endpoint_cors_default_is_restrictive() {
104        assert_eq!(ENV_CORS_ALLOWED_ORIGINS, "RUSTFS_CORS_ALLOWED_ORIGINS");
105        assert_eq!(DEFAULT_CORS_ALLOWED_ORIGINS, "");
106    }
107
108    #[test]
109    fn console_cors_default_is_same_origin_only() {
110        assert_eq!(ENV_CONSOLE_CORS_ALLOWED_ORIGINS, "RUSTFS_CONSOLE_CORS_ALLOWED_ORIGINS");
111        assert_eq!(DEFAULT_CONSOLE_CORS_ALLOWED_ORIGINS, "");
112    }
113}