Skip to main content

rustfs_config/constants/
app.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
15use const_str::concat;
16
17/// Application name
18/// Default value: RustFS
19/// Environment variable: RUSTFS_APP_NAME
20pub const APP_NAME: &str = "RustFS";
21/// Application version
22/// Default value: 1.0.0
23/// Environment variable: RUSTFS_VERSION
24pub const VERSION: &str = "1.0.0";
25
26/// Default configuration logger level
27/// Default value: error
28/// Environment variable: RUSTFS_OBS_LOGGER_LEVEL
29pub const DEFAULT_LOG_LEVEL: &str = "error";
30
31/// Default configuration use stdout
32/// Default value: false
33pub const USE_STDOUT: bool = false;
34
35/// Default configuration sample ratio
36/// Default value: 1.0
37pub const SAMPLE_RATIO: f64 = 1.0;
38/// Default configuration meter interval
39/// Default value: 30
40pub const METER_INTERVAL: u64 = 30;
41
42/// Default configuration service version
43/// Default value: 1.0.0
44/// Environment variable: RUSTFS_OBS_SERVICE_VERSION
45/// Uses the same value as VERSION constant
46pub const SERVICE_VERSION: &str = "1.0.0";
47
48/// Default configuration environment
49/// Default value: production
50pub const ENVIRONMENT: &str = "production";
51
52/// Default console enable
53/// This is the default value for the console server.
54/// It is used to enable or disable the console server.
55/// Default value: true
56/// Environment variable: RUSTFS_CONSOLE_ENABLE
57/// Command line argument: --console-enable
58/// Example: RUSTFS_CONSOLE_ENABLE=true
59/// Example: --console-enable true
60pub const DEFAULT_CONSOLE_ENABLE: bool = true;
61
62/// Default OBS configuration endpoint
63/// Environment variable: DEFAULT_OBS_ENDPOINT
64/// Command line argument: --obs-endpoint
65/// Example: DEFAULT_OBS_ENDPOINT="http://localost:4318"
66/// Example: --obs-endpoint http://localost:4318
67pub const DEFAULT_OBS_ENDPOINT: &str = "";
68
69/// Default TLS key for rustfs
70/// This is the default key for TLS.
71pub const RUSTFS_TLS_KEY: &str = "rustfs_key.pem";
72
73/// Default TLS cert for rustfs
74/// This is the default cert for TLS.
75pub const RUSTFS_TLS_CERT: &str = "rustfs_cert.pem";
76
77/// Default public certificate filename for rustfs
78/// This is the default public certificate filename for rustfs.
79/// It is used to store the public certificate of the application.
80/// Default value: public.crt
81pub const RUSTFS_PUBLIC_CERT: &str = "public.crt";
82
83/// Default CA certificate filename for rustfs
84/// This is the default CA certificate filename for rustfs.
85/// It is used to store the CA certificate of the application.
86/// Default value: ca.crt
87pub const RUSTFS_CA_CERT: &str = "ca.crt";
88
89/// Default HTTP prefix for rustfs
90/// This is the default HTTP prefix for rustfs.
91/// It is used to identify HTTP URLs.
92/// Default value: http://
93pub const RUSTFS_HTTP_PREFIX: &str = "http://";
94
95/// Default HTTPS prefix for rustfs
96/// This is the default HTTPS prefix for rustfs.
97/// It is used to identify HTTPS URLs.
98/// Default value: https://
99pub const RUSTFS_HTTPS_PREFIX: &str = "https://";
100
101/// Default documentation URL for rustfs
102/// This is the default documentation URL for rustfs.
103/// It is used to provide the documentation of the application.
104/// Default value: https://docs.rustfs.com
105pub const RUSTFS_DOCS_URL: &str = "https://docs.rustfs.com";
106
107/// Default GitHub URL for rustfs
108/// This is the default GitHub URL for rustfs.
109/// It is used to provide the source code of the application.
110/// Default value: https://github.com/rustfs/rustfs
111pub const RUSTFS_GITHUB_URL: &str = "https://github.com/rustfs/rustfs";
112
113/// Default license for rustfs
114/// This is the default license for rustfs.
115/// It is used to provide the license of the application.
116/// Default value: Apache-2.0
117pub const RUSTFS_LICENSE: &str = "Apache-2.0";
118
119/// Default license URL for rustfs
120/// This is the default license URL for rustfs.
121/// It is used to provide the license URL of the application.
122/// Default value: https://www.apache.org/licenses/LICENSE-2.0
123pub const RUSTFS_LICENSE_URL: &str = "https://www.apache.org/licenses/LICENSE-2.0";
124
125/// Environment variable for rustfs address
126/// This is the environment variable for rustfs address.
127/// It is used to bind the server to a specific address.
128/// Example: RUSTFS_ADDRESS=":9000"
129pub const ENV_RUSTFS_ADDRESS: &str = "RUSTFS_ADDRESS";
130
131/// Environment variable for server volumes.
132pub const ENV_RUSTFS_VOLUMES: &str = "RUSTFS_VOLUMES";
133
134/// Environment variable identifying this server's host in distributed endpoint
135/// lists without relying on DNS locality discovery.
136pub const ENV_LOCAL_ENDPOINT_HOST: &str = "RUSTFS_LOCAL_ENDPOINT_HOST";
137
138/// Environment variable to explicitly bypass local physical disk independence checks.
139pub const ENV_UNSAFE_BYPASS_DISK_CHECK: &str = "RUSTFS_UNSAFE_BYPASS_DISK_CHECK";
140
141/// Compatibility alias used by legacy MinIO CI pipelines.
142///
143/// RustFS keeps this alias for backward compatibility only. Prefer
144/// `ENV_UNSAFE_BYPASS_DISK_CHECK` for explicit bypass control.
145pub const ENV_MINIO_CI: &str = "MINIO_CI";
146
147/// Default flag value for bypassing local physical disk independence checks.
148pub const DEFAULT_UNSAFE_BYPASS_DISK_CHECK: bool = false;
149
150/// Environment variable selecting how startup waits for DNS/topology
151/// convergence in multi-node setups. One of `auto` (default), `orchestrated`,
152/// `bounded`, or `fail-fast`.
153///
154/// - `orchestrated`: wait effectively indefinitely for recoverable DNS/topology
155///   errors so the process stays Running (readiness stays false) instead of
156///   exiting and triggering a Kubernetes pod restart loop.
157/// - `bounded`: wait for a finite window (see
158///   `ENV_STARTUP_TOPOLOGY_WAIT_TIMEOUT`) then fail with an actionable error.
159/// - `fail-fast`: fail on the first non-transient resolution error (CI/local).
160/// - `auto`: distributed URL endpoints use orchestrated on Kubernetes and
161///   bounded otherwise; local path endpoints use fail-fast (no DNS to await).
162pub const ENV_STARTUP_TOPOLOGY_WAIT_MODE: &str = "RUSTFS_STARTUP_TOPOLOGY_WAIT_MODE";
163
164/// Environment variable bounding how long startup waits for topology/DNS
165/// convergence before failing in `bounded` mode. Accepts durations such as
166/// `3m`, `90s`, `500ms`, or a bare number of seconds.
167pub const ENV_STARTUP_TOPOLOGY_WAIT_TIMEOUT: &str = "RUSTFS_STARTUP_TOPOLOGY_WAIT_TIMEOUT";
168
169/// Environment variable capping the per-attempt backoff delay while retrying
170/// startup topology/DNS convergence. Accepts durations such as `8s`.
171pub const ENV_STARTUP_TOPOLOGY_RETRY_MAX_DELAY: &str = "RUSTFS_STARTUP_TOPOLOGY_RETRY_MAX_DELAY";
172
173/// Environment variable injected into every Kubernetes pod; its presence marks
174/// an orchestrated deployment for startup topology auto-detection.
175pub const ENV_KUBERNETES_SERVICE_HOST: &str = "KUBERNETES_SERVICE_HOST";
176
177/// Default bounded-mode wait window (seconds) for non-Kubernetes distributed
178/// deployments before startup topology convergence is declared failed.
179pub const DEFAULT_STARTUP_TOPOLOGY_WAIT_TIMEOUT_SECS: u64 = 180;
180
181/// Default per-attempt backoff cap (seconds) while retrying startup
182/// topology/DNS convergence.
183pub const DEFAULT_STARTUP_TOPOLOGY_RETRY_MAX_DELAY_SECS: u64 = 8;
184
185/// Environment variable for server access key.
186pub const ENV_RUSTFS_ACCESS_KEY: &str = "RUSTFS_ACCESS_KEY";
187
188/// Environment variable for server access key file.
189pub const ENV_RUSTFS_ACCESS_KEY_FILE: &str = "RUSTFS_ACCESS_KEY_FILE";
190
191/// Environment variable for server secret key.
192pub const ENV_RUSTFS_SECRET_KEY: &str = "RUSTFS_SECRET_KEY";
193
194/// Environment variable for server secret key file.
195pub const ENV_RUSTFS_SECRET_KEY_FILE: &str = "RUSTFS_SECRET_KEY_FILE";
196
197/// Environment variable controlling startup behavior when unsupported filesystem types are detected.
198///
199/// Accepted values:
200/// - "warn" (default): log a warning and continue startup
201/// - "fail": abort startup with an error
202pub const ENV_RUSTFS_UNSUPPORTED_FS_POLICY: &str = "RUSTFS_UNSUPPORTED_FS_POLICY";
203pub const RUSTFS_UNSUPPORTED_FS_POLICY_WARN: &str = "warn";
204pub const RUSTFS_UNSUPPORTED_FS_POLICY_FAIL: &str = "fail";
205pub const DEFAULT_RUSTFS_UNSUPPORTED_FS_POLICY: &str = RUSTFS_UNSUPPORTED_FS_POLICY_WARN;
206
207/// Environment variable for server OBS endpoint.
208pub const ENV_RUSTFS_OBS_ENDPOINT: &str = "RUSTFS_OBS_ENDPOINT";
209
210/// Environment variable for console server enable.
211pub const ENV_RUSTFS_CONSOLE_ENABLE: &str = "RUSTFS_CONSOLE_ENABLE";
212
213/// Environment variable for console server address.
214pub const ENV_RUSTFS_CONSOLE_ADDRESS: &str = "RUSTFS_CONSOLE_ADDRESS";
215
216/// URL path prefix for the embedded console, read once at server startup.
217pub const ENV_RUSTFS_CONSOLE_PREFIX: &str = "RUSTFS_CONSOLE_PREFIX";
218/// Default embedded console URL path prefix.
219pub const DEFAULT_CONSOLE_PREFIX: &str = "/rustfs/console";
220
221/// Public browser entrypoint used to build OIDC callback and console redirects.
222///
223/// This should be the externally reachable scheme and authority, without a path.
224/// Example: `RUSTFS_BROWSER_REDIRECT_URL=https://console.example.com`.
225pub const ENV_RUSTFS_BROWSER_REDIRECT_URL: &str = "RUSTFS_BROWSER_REDIRECT_URL";
226
227/// Environment variable for server tls path.
228pub const ENV_RUSTFS_TLS_PATH: &str = "RUSTFS_TLS_PATH";
229
230/// Environment variable for server KMS enable.
231pub const ENV_RUSTFS_KMS_ENABLE: &str = "RUSTFS_KMS_ENABLE";
232
233/// Default KMS enable for server-side encryption
234/// This is the default value for enabling KMS encryption for server-side encryption.
235/// Default value: false
236pub const DEFAULT_KMS_ENABLE: bool = false;
237
238/// Environment variable enabling per-key KMS authorization on the SSE-KMS data path.
239///
240/// When enabled, an SSE-KMS write additionally requires `kms:GenerateDataKey` and an
241/// SSE-KMS read additionally requires `kms:Decrypt` on the resolved key, evaluated as
242/// the requesting identity. SSE-S3 and SSE-C are unaffected.
243pub const ENV_RUSTFS_KMS_ENFORCE_SSE_KEY_POLICY: &str = "RUSTFS_KMS_ENFORCE_SSE_KEY_POLICY";
244
245/// Default per-key KMS authorization mode for the SSE-KMS data path.
246///
247/// Off for now so deployments whose identity policies only grant s3 actions keep
248/// working; the default flips to on in a later release.
249pub const DEFAULT_KMS_ENFORCE_SSE_KEY_POLICY: bool = false;
250
251/// Environment variable for server KMS backend.
252pub const ENV_RUSTFS_KMS_BACKEND: &str = "RUSTFS_KMS_BACKEND";
253
254/// Environment variable for Vault Transit mount path.
255pub const ENV_RUSTFS_KMS_VAULT_MOUNT_PATH: &str = "RUSTFS_KMS_VAULT_MOUNT_PATH";
256
257/// Default KMS backend for server-side encryption
258/// This is the default KMS backend for server-side encryption.
259/// Default value: local
260pub const DEFAULT_KMS_BACKEND: &str = "local";
261
262/// Environment variable for selecting the buffer profile used for adaptive buffer sizing.
263pub const ENV_RUSTFS_BUFFER_PROFILE: &str = "RUSTFS_BUFFER_PROFILE";
264
265/// Default buffer profile for adaptive buffer sizing
266/// This is the default buffer profile for adaptive buffer sizing.
267/// It is used to identify the workload profile for adaptive buffer sizing.
268/// Default value: GeneralPurpose
269pub const DEFAULT_BUFFER_PROFILE: &str = "GeneralPurpose";
270
271/// Default value for the server TLS path if `ENV_RUSTFS_TLS_PATH` is not set.
272pub const DEFAULT_RUSTFS_TLS_PATH: &str = "";
273
274/// Default port for rustfs
275/// This is the default port for rustfs.
276/// This is used to bind the server to a specific port.
277pub const DEFAULT_PORT: u16 = 9000;
278
279/// Default address for rustfs
280/// This is the default address for rustfs.
281pub const DEFAULT_ADDRESS: &str = concat!(":", DEFAULT_PORT);
282
283/// Default port for rustfs console
284/// This is the default port for rustfs console.
285pub const DEFAULT_CONSOLE_PORT: u16 = 9001;
286
287/// Default address for rustfs console
288/// This is the default address for rustfs console.
289/// This is used to bind the console server to a specific address.
290/// Default value: :9001
291pub const DEFAULT_CONSOLE_ADDRESS: &str = concat!(":", DEFAULT_CONSOLE_PORT);
292
293/// Default region for rustfs
294/// This is the default region for rustfs.
295/// It is used to identify the region of the application.
296/// Default value: us-east-1
297pub const RUSTFS_REGION: &str = "us-east-1";
298
299/// Environment variable for server region.
300pub const ENV_RUSTFS_REGION: &str = "RUSTFS_REGION";
301
302/// Environment variable for server license.
303pub const ENV_RUSTFS_LICENSE: &str = "RUSTFS_LICENSE";
304
305/// Environment variable for the RSA public key used to verify server licenses.
306pub const ENV_RUSTFS_LICENSE_PUBLIC_KEY: &str = "RUSTFS_LICENSE_PUBLIC_KEY";
307
308/// Default log filename for rustfs
309/// This is the default log filename for rustfs.
310/// It is used to store the logs of the application.
311/// Default value: rustfs.log
312/// Environment variable: RUSTFS_OBS_LOG_FILENAME
313pub const DEFAULT_LOG_FILENAME: &str = "rustfs";
314
315/// Default OBS log filename for rustfs
316/// This is the default log filename for OBS.
317/// It is used to store the logs of the application.
318/// Default value: rustfs.log
319pub const DEFAULT_OBS_LOG_FILENAME: &str = concat!(DEFAULT_LOG_FILENAME, ".log");
320
321/// Default log directory for rustfs
322/// This is the default log directory for rustfs.
323/// It is used to store the logs of the application.
324/// Default value: logs
325/// Environment variable: RUSTFS_LOG_DIRECTORY
326pub const DEFAULT_LOG_DIR: &str = "logs";
327
328/// Default log rotation size mb for rustfs
329/// This is the default log rotation size for rustfs.
330/// It is used to rotate the logs of the application.
331/// Default value: 100 MB
332/// Environment variable: RUSTFS_OBS_LOG_ROTATION_SIZE_MB
333pub const DEFAULT_LOG_ROTATION_SIZE_MB: u64 = 100;
334
335/// Default log rotation time for rustfs
336/// This is the default log rotation time for rustfs.
337/// It is used to rotate the logs of the application.
338/// Default value: hour, eg: daily,hourly,minutely
339/// Environment variable: RUSTFS_OBS_LOG_ROTATION_TIME
340pub const DEFAULT_LOG_ROTATION_TIME: &str = "hourly";
341
342/// Default log keep files for rustfs
343/// This is the default log keep files for rustfs.
344/// It is used to keep the logs of the application.
345/// Default value: 30
346/// Environment variable: RUSTFS_OBS_LOG_KEEP_FILES
347pub const DEFAULT_LOG_KEEP_FILES: usize = 30;
348
349/// Default trace export enabled
350/// It is used to enable or disable exporting traces
351/// Default value: true
352/// Environment variable: RUSTFS_OBS_TRACES_EXPORT_ENABLED
353pub const DEFAULT_OBS_TRACES_EXPORT_ENABLED: bool = true;
354
355/// Default metrics export enabled
356/// It is used to enable or disable exporting metrics
357/// Default value: true
358/// Environment variable: RUSTFS_OBS_METRICS_EXPORT_ENABLED
359pub const DEFAULT_OBS_METRICS_EXPORT_ENABLED: bool = true;
360
361/// Default detailed PUT stage metrics enabled
362/// Default value: false
363/// Environment variable: RUSTFS_OBS_PUT_STAGE_METRICS_ENABLED
364pub const DEFAULT_OBS_PUT_STAGE_METRICS_ENABLED: bool = false;
365
366/// Default logs export enabled
367/// It is used to enable or disable exporting logs
368/// Default value: true
369/// Environment variable: RUSTFS_OBS_LOGS_EXPORT_ENABLED
370pub const DEFAULT_OBS_LOGS_EXPORT_ENABLED: bool = true;
371
372/// Default profiling export enabled
373/// It is used to enable or disable exporting profiles
374/// Default value: true
375/// Environment variable: RUSTFS_OBS_PROFILING_EXPORT_ENABLED
376pub const DEFAULT_OBS_PROFILING_EXPORT_ENABLED: bool = true;
377
378/// Default log local logging enabled for rustfs
379/// This is the default log local logging enabled for rustfs.
380/// It is used to enable or disable local logging of the application.
381/// Default value: false
382/// Environment variable: RUSTFS_OBS_LOG_STDOUT_ENABLED
383pub const DEFAULT_OBS_LOG_STDOUT_ENABLED: bool = false;
384
385/// Constant representing 1 Kibibyte (1024 bytes)
386/// Default value: 1024
387pub const KI_B: usize = 1024;
388/// Constant representing 1 Mebibyte (1024 * 1024 bytes)
389/// Default value: 1048576
390pub const MI_B: usize = 1024 * KI_B;
391
392#[cfg(test)]
393mod tests {
394    use super::*;
395
396    #[test]
397    fn test_const_str_concat_functionality() {
398        // Test const_str::concat macro functionality
399        let expected_address = format!(":{DEFAULT_PORT}");
400        assert_eq!(DEFAULT_ADDRESS, expected_address);
401
402        let expected_console_address = format!(":{DEFAULT_CONSOLE_PORT}");
403        assert_eq!(DEFAULT_CONSOLE_ADDRESS, expected_console_address);
404    }
405
406    #[test]
407    fn test_string_constants_validity() {
408        // Test validity of string constants
409        let string_constants = [
410            APP_NAME,
411            VERSION,
412            DEFAULT_LOG_LEVEL,
413            SERVICE_VERSION,
414            ENVIRONMENT,
415            RUSTFS_TLS_KEY,
416            RUSTFS_TLS_CERT,
417            DEFAULT_ADDRESS,
418            DEFAULT_CONSOLE_ADDRESS,
419            ENV_RUSTFS_BROWSER_REDIRECT_URL,
420        ];
421
422        for constant in &string_constants {
423            assert!(!constant.is_empty(), "String constant should not be empty: {constant}");
424            assert!(!constant.starts_with(' '), "String constant should not start with space: {constant}");
425            assert!(!constant.ends_with(' '), "String constant should not end with space: {constant}");
426        }
427    }
428
429    #[test]
430    fn test_numeric_constants_validity() {
431        // Test validity of numeric constants
432        assert!(SAMPLE_RATIO.is_finite(), "Sample ratio should be finite");
433        assert!(!SAMPLE_RATIO.is_nan(), "Sample ratio should not be NaN");
434
435        // All these are const values, so range checks are redundant
436        // assert!(METER_INTERVAL < u64::MAX, "Meter interval should be reasonable");
437        // assert!(MAX_CONNECTIONS < usize::MAX, "Max connections should be reasonable");
438        // assert!(DEFAULT_TIMEOUT_MS < u64::MAX, "Timeout should be reasonable");
439
440        // These are const non-zero values, so zero checks are redundant
441        assert_ne!(DEFAULT_PORT, 0, "Default port should not be zero");
442        assert_ne!(DEFAULT_CONSOLE_PORT, 0, "Console port should not be zero");
443    }
444
445    #[test]
446    fn test_configuration_consistency() {
447        // Test configuration consistency
448
449        // Version consistency
450        assert_eq!(VERSION, SERVICE_VERSION, "Application version should match service version");
451
452        // Port conflict check
453        let ports = [DEFAULT_PORT, DEFAULT_CONSOLE_PORT];
454        let mut unique_ports = std::collections::HashSet::new();
455        for port in &ports {
456            assert!(unique_ports.insert(port), "Port {port} is duplicated");
457        }
458
459        // Address format consistency
460        assert_eq!(DEFAULT_ADDRESS, format!(":{DEFAULT_PORT}"));
461        assert_eq!(DEFAULT_CONSOLE_ADDRESS, format!(":{DEFAULT_CONSOLE_PORT}"));
462    }
463}