rustfs_config/constants/api.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/// Enable or disable per-client rate limiting for the S3 API.
16///
17/// When enabled (and `RUSTFS_API_RATE_LIMIT_RPM` > 0), requests are throttled
18/// per client IP using a token bucket; over-limit requests receive
19/// `429 Too Many Requests` with a `Retry-After` header. Internode RPC/gRPC,
20/// health probes, and the console (which has its own limiter) are exempt.
21/// Environment variable: RUSTFS_API_RATE_LIMIT_ENABLE
22/// Example: RUSTFS_API_RATE_LIMIT_ENABLE=true
23pub const ENV_API_RATE_LIMIT_ENABLE: &str = "RUSTFS_API_RATE_LIMIT_ENABLE";
24
25/// Default for `RUSTFS_API_RATE_LIMIT_ENABLE`.
26///
27/// Disabled by default: RustFS ships permissive and operators opt in to
28/// abuse-protection hardening. When disabled the request path is unchanged.
29pub const DEFAULT_API_RATE_LIMIT_ENABLE: bool = false;
30
31/// Sustained S3 API request budget per client IP, in requests per minute.
32///
33/// `0` means unlimited (rate limiting stays inert even when enabled).
34/// Environment variable: RUSTFS_API_RATE_LIMIT_RPM
35/// Example: RUSTFS_API_RATE_LIMIT_RPM=6000
36pub const ENV_API_RATE_LIMIT_RPM: &str = "RUSTFS_API_RATE_LIMIT_RPM";
37
38/// Default for `RUSTFS_API_RATE_LIMIT_RPM`.
39///
40/// `0` (unlimited) so that setting only the enable switch cannot throttle
41/// traffic by surprise; operators must choose an explicit budget.
42pub const DEFAULT_API_RATE_LIMIT_RPM: u32 = 0;
43
44/// Burst capacity per client IP (maximum tokens in the bucket).
45///
46/// Allows short spikes above the sustained rate. `0` means "same as RPM".
47/// Environment variable: RUSTFS_API_RATE_LIMIT_BURST
48/// Example: RUSTFS_API_RATE_LIMIT_BURST=200
49pub const ENV_API_RATE_LIMIT_BURST: &str = "RUSTFS_API_RATE_LIMIT_BURST";
50
51/// Default for `RUSTFS_API_RATE_LIMIT_BURST` (`0` = same as RPM).
52pub const DEFAULT_API_RATE_LIMIT_BURST: u32 = 0;
53
54/// Sustained S3 API request budget per addressed bucket, in requests per
55/// minute — a collective ceiling shared by all clients of that bucket.
56///
57/// Complements the per-client-IP dimension: it protects the server from one
58/// hot bucket regardless of how many client IPs the traffic comes from. `0`
59/// disables the bucket dimension. Requires `RUSTFS_API_RATE_LIMIT_ENABLE`.
60/// Environment variable: RUSTFS_API_RATE_LIMIT_BUCKET_RPM
61/// Example: RUSTFS_API_RATE_LIMIT_BUCKET_RPM=60000
62pub const ENV_API_RATE_LIMIT_BUCKET_RPM: &str = "RUSTFS_API_RATE_LIMIT_BUCKET_RPM";
63
64/// Default for `RUSTFS_API_RATE_LIMIT_BUCKET_RPM` (`0` = dimension disabled).
65pub const DEFAULT_API_RATE_LIMIT_BUCKET_RPM: u32 = 0;
66
67/// Burst capacity per bucket (maximum tokens in the bucket-dimension bucket).
68///
69/// `0` means "same as `RUSTFS_API_RATE_LIMIT_BUCKET_RPM`".
70/// Environment variable: RUSTFS_API_RATE_LIMIT_BUCKET_BURST
71/// Example: RUSTFS_API_RATE_LIMIT_BUCKET_BURST=2000
72pub const ENV_API_RATE_LIMIT_BUCKET_BURST: &str = "RUSTFS_API_RATE_LIMIT_BUCKET_BURST";
73
74/// Default for `RUSTFS_API_RATE_LIMIT_BUCKET_BURST` (`0` = same as bucket RPM).
75pub const DEFAULT_API_RATE_LIMIT_BUCKET_BURST: u32 = 0;
76
77/// Maximum concurrently served connections on the main API listener.
78///
79/// `0` (the default) means unlimited. When set, the accept loop stops
80/// accepting once the cap is reached and lets the kernel backlog absorb
81/// bursts, releasing capacity as connections close. This bounds file
82/// descriptor and memory usage under a connection flood.
83///
84/// The cap covers everything on the main listener — S3, admin, console,
85/// and internode gRPC — so size it well above peer-node count plus the
86/// expected client concurrency.
87/// Environment variable: RUSTFS_API_MAX_CONNECTIONS
88/// Example: RUSTFS_API_MAX_CONNECTIONS=10000
89pub const ENV_API_MAX_CONNECTIONS: &str = "RUSTFS_API_MAX_CONNECTIONS";
90
91/// Default for `RUSTFS_API_MAX_CONNECTIONS` (`0` = unlimited).
92pub const DEFAULT_API_MAX_CONNECTIONS: usize = 0;
93
94/// Maximum retained versions per object.
95///
96/// The default follows MinIO and is effectively unlimited for practical
97/// deployments. Operators can lower it to bound per-object metadata growth.
98/// Environment variable: RUSTFS_API_OBJECT_MAX_VERSIONS
99/// MinIO-compatible alias: MINIO_API_OBJECT_MAX_VERSIONS
100/// Example: RUSTFS_API_OBJECT_MAX_VERSIONS=50000
101pub const ENV_API_OBJECT_MAX_VERSIONS: &str = "RUSTFS_API_OBJECT_MAX_VERSIONS";
102
103/// Default and maximum accepted value for `RUSTFS_API_OBJECT_MAX_VERSIONS`.
104#[cfg(target_pointer_width = "64")]
105pub const DEFAULT_API_OBJECT_MAX_VERSIONS: usize = 9_223_372_036_854_775_807;
106
107/// Default and maximum accepted value for `RUSTFS_API_OBJECT_MAX_VERSIONS`.
108#[cfg(not(target_pointer_width = "64"))]
109pub const DEFAULT_API_OBJECT_MAX_VERSIONS: usize = usize::MAX;