rustfs_config/constants/tls.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/// TLS related environment variable names and default values
16/// Environment variable to enable TLS key logging
17/// When set to "1", RustFS will log TLS keys to the specified file for debugging purposes.
18/// By default, this is disabled.
19/// To enable, set the environment variable RUSTFS_TLS_KEYLOG=1
20pub const ENV_TLS_KEYLOG: &str = "RUSTFS_TLS_KEYLOG";
21
22/// Default value for TLS key logging
23/// By default, RustFS does not log TLS keys.
24/// To change this behavior, set the environment variable RUSTFS_TLS_KEYLOG=1
25pub const DEFAULT_TLS_KEYLOG: bool = false;
26
27/// Environment variable to trust system CA certificates
28/// When set to "1", RustFS will trust system CA certificates in addition to any
29/// custom CA certificates provided in the configuration.
30/// By default, this is disabled.
31/// To enable, set the environment variable RUSTFS_TRUST_SYSTEM_CA=1
32pub const ENV_TRUST_SYSTEM_CA: &str = "RUSTFS_TRUST_SYSTEM_CA";
33
34/// Default value for trusting system CA certificates
35/// By default, RustFS does not trust system CA certificates.
36/// To change this behavior, set the environment variable RUSTFS_TRUST_SYSTEM_CA=1
37pub const DEFAULT_TRUST_SYSTEM_CA: bool = false;
38
39/// Environment variable for an extra outbound root CA certificate bundle.
40/// Use this to trust an internal CA for outbound HTTPS clients without replacing
41/// the default operating-system/web PKI roots via SSL_CERT_FILE.
42pub const ENV_RUSTFS_EXTRA_CA_CERT: &str = "RUSTFS_EXTRA_CA_CERT";
43
44/// Environment variable to trust leaf certificates as CA
45/// When set to "1", RustFS will treat leaf certificates as CA certificates for trust validation.
46/// By default, this is disabled.
47/// To enable, set the environment variable RUSTFS_TRUST_LEAF_CERT_AS_CA=1
48pub const ENV_TRUST_LEAF_CERT_AS_CA: &str = "RUSTFS_TRUST_LEAF_CERT_AS_CA";
49
50/// Default value for trusting leaf certificates as CA
51/// By default, RustFS does not trust leaf certificates as CA.
52/// To change this behavior, set the environment variable RUSTFS_TRUST_LEAF_CERT_AS_CA=1
53pub const DEFAULT_TRUST_LEAF_CERT_AS_CA: bool = false;
54
55/// Default filename for client CA certificate
56/// client_ca.crt (CA bundle for verifying client certificates in server mTLS)
57pub const RUSTFS_CLIENT_CA_CERT_FILENAME: &str = "client_ca.crt";
58
59/// Environment variable for client certificate file path
60/// RUSTFS_MTLS_CLIENT_CERT
61/// Specifies the file path to the client certificate used for mTLS authentication.
62/// If not set, RustFS will look for the default filename "client_cert.pem" in the current directory.
63/// To set, use the environment variable RUSTFS_MTLS_CLIENT_CERT=/path/to/client_cert.pem
64pub const ENV_MTLS_CLIENT_CERT: &str = "RUSTFS_MTLS_CLIENT_CERT";
65
66/// Default filename for client certificate
67/// client_cert.pem
68pub const RUSTFS_CLIENT_CERT_FILENAME: &str = "client_cert.pem";
69
70/// Environment variable for client private key file path
71/// RUSTFS_MTLS_CLIENT_KEY
72/// Specifies the file path to the client private key used for mTLS authentication.
73/// If not set, RustFS will look for the default filename "client_key.pem" in the current directory.
74/// To set, use the environment variable RUSTFS_MTLS_CLIENT_KEY=/path/to/client_key.pem
75pub const ENV_MTLS_CLIENT_KEY: &str = "RUSTFS_MTLS_CLIENT_KEY";
76
77/// Default filename for client private key
78/// client_key.pem
79pub const RUSTFS_CLIENT_KEY_FILENAME: &str = "client_key.pem";
80
81/// RUSTFS_SERVER_MTLS_ENABLE
82/// Environment variable to enable server mTLS
83/// When set to "1", RustFS server will require client certificates for authentication.
84/// By default, this is disabled.
85/// To enable, set the environment variable RUSTFS_SERVER_MTLS_ENABLE=1
86pub const ENV_SERVER_MTLS_ENABLE: &str = "RUSTFS_SERVER_MTLS_ENABLE";
87
88/// Default value for enabling server mTLS
89/// By default, RustFS server mTLS is disabled.
90/// To change this behavior, set the environment variable RUSTFS_SERVER_MTLS_ENABLE=1
91pub const DEFAULT_SERVER_MTLS_ENABLE: bool = false;
92
93// ── HTTP Transport Tuning Parameters ──
94
95/// Environment variable for HTTP/2 initial stream window size (bytes)
96/// Default: 4194304 (4 MB)
97pub const ENV_H2_INITIAL_STREAM_WINDOW_SIZE: &str = "RUSTFS_H2_INITIAL_STREAM_WINDOW_SIZE";
98pub const DEFAULT_H2_INITIAL_STREAM_WINDOW_SIZE: u32 = 4 * 1024 * 1024; // 4 MB
99
100/// Environment variable for HTTP/2 initial connection window size (bytes)
101/// Default: 8388608 (8 MB)
102pub const ENV_H2_INITIAL_CONN_WINDOW_SIZE: &str = "RUSTFS_H2_INITIAL_CONN_WINDOW_SIZE";
103pub const DEFAULT_H2_INITIAL_CONN_WINDOW_SIZE: u32 = 8 * 1024 * 1024; // 8 MB
104
105/// Environment variable for HTTP/2 max frame size (bytes)
106/// Range: 16384 (16 KB) to 16777216 (16 MB) per RFC 7540
107/// Default: 524288 (512 KB)
108pub const ENV_H2_MAX_FRAME_SIZE: &str = "RUSTFS_H2_MAX_FRAME_SIZE";
109pub const DEFAULT_H2_MAX_FRAME_SIZE: u32 = 512 * 1024; // 512 KB
110
111/// Environment variable for HTTP/2 max header list size (bytes)
112/// Default: 65536 (64 KB)
113pub const ENV_H2_MAX_HEADER_LIST_SIZE: &str = "RUSTFS_H2_MAX_HEADER_LIST_SIZE";
114pub const DEFAULT_H2_MAX_HEADER_LIST_SIZE: u32 = 64 * 1024; // 64 KB
115
116/// Environment variable for HTTP/2 max concurrent streams
117/// Default: 2048
118pub const ENV_H2_MAX_CONCURRENT_STREAMS: &str = "RUSTFS_H2_MAX_CONCURRENT_STREAMS";
119pub const DEFAULT_H2_MAX_CONCURRENT_STREAMS: u32 = 2048;
120
121/// Environment variable for HTTP/2 keep-alive interval (seconds)
122/// Default: 20
123pub const ENV_H2_KEEP_ALIVE_INTERVAL: &str = "RUSTFS_H2_KEEP_ALIVE_INTERVAL";
124pub const DEFAULT_H2_KEEP_ALIVE_INTERVAL: u64 = 20;
125
126/// Environment variable for HTTP/2 keep-alive timeout (seconds)
127/// Default: 10
128pub const ENV_H2_KEEP_ALIVE_TIMEOUT: &str = "RUSTFS_H2_KEEP_ALIVE_TIMEOUT";
129pub const DEFAULT_H2_KEEP_ALIVE_TIMEOUT: u64 = 10;
130
131/// Environment variable for HTTP/1.1 header read timeout (seconds)
132/// Default: 75
133///
134/// In hyper's HTTP/1.1 stack this timeout is armed as soon as the connection is
135/// ready to read the *next* request head, so on a keep-alive connection it also
136/// bounds how long an idle upstream connection is allowed to sit before RustFS
137/// closes it. Reverse proxies (Caddy, Nginx) pool upstream connections and keep
138/// them idle far longer than a few seconds (Caddy ≈ 2 min, Nginx = 60 s by
139/// default). A short value here makes RustFS FIN pooled connections while the
140/// proxy still believes they are alive; the proxy then reuses a dead socket and
141/// the client sees `socket hang up` / connection reset — most visibly on
142/// non-idempotent `PUT` uploads, which proxies will not transparently retry
143/// (see issue #3076).
144///
145/// The default is therefore set above common proxy idle-keepalive windows.
146/// Operators fronting RustFS with a proxy should keep this larger than the
147/// proxy's upstream idle-keepalive, or lower the proxy's keepalive below this
148/// value. Environments that expose RustFS directly to untrusted slow clients and
149/// want tighter slowloris protection can lower it via the env var below.
150///
151/// The same budget bounds the TLS handshake on the listener, so an unauthenticated
152/// peer cannot park an accept task and its socket indefinitely by opening a
153/// connection and then stalling the handshake.
154pub const ENV_HTTP1_HEADER_READ_TIMEOUT: &str = "RUSTFS_HTTP1_HEADER_READ_TIMEOUT";
155pub const DEFAULT_HTTP1_HEADER_READ_TIMEOUT: u64 = 75;
156
157/// Environment variable for HTTP/1.1 max buffer size (bytes)
158/// Default: 65536 (64 KB)
159pub const ENV_HTTP1_MAX_BUF_SIZE: &str = "RUSTFS_HTTP1_MAX_BUF_SIZE";
160pub const DEFAULT_HTTP1_MAX_BUF_SIZE: usize = 64 * 1024; // 64 KB
161
162/// Environment variable for a fixed kernel receive buffer (`SO_RCVBUF`, bytes)
163/// on the API listener. Default: 0, which leaves the buffer to kernel
164/// autotuning.
165///
166/// A fixed `SO_RCVBUF` is inherited by every accepted socket and disables
167/// receive-buffer autotuning. Queued multipart bodies can accumulate in kernel
168/// memory with either policy: a reused autotuned connection may already have
169/// a large buffer. Socket capacity is not the same as queued payload or actual
170/// memory allocation. Set this only on kernels without receive-buffer autotuning
171/// (illumos/Solaris) or on very high-bandwidth-delay links where the kernel's
172/// autotuning ceiling (`net.ipv4.tcp_rmem` on Linux) is too low and cannot be
173/// raised.
174pub const ENV_HTTP_SOCKET_RECV_BUFFER_BYTES: &str = "RUSTFS_HTTP_SOCKET_RECV_BUFFER_BYTES";
175pub const DEFAULT_HTTP_SOCKET_RECV_BUFFER_BYTES: usize = 0;
176
177/// Environment variable for the S3 request-body inter-chunk read timeout
178/// (seconds). Default: 300. Set to 0 to disable.
179///
180/// This bounds how long a `PutObject`/upload may wait for the *next* body chunk
181/// while more bytes are still expected. It resets on every chunk, so it does not
182/// penalize slow-but-progressing uploads — it only fires when a peer sends a
183/// partial body and then goes silent *without* closing the connection (no EOF).
184/// A reverse proxy or CDN that forwards a truncated body this way would
185/// otherwise make RustFS wait forever for bytes that never arrive; with this
186/// timeout the stalled read is aborted and logged with the received/expected
187/// byte counts, turning a silent hang into an actionable diagnostic (issue
188/// #3076). A short-body that arrives with a proper EOF is already rejected
189/// promptly and is unaffected by this setting.
190pub const ENV_HTTP_REQUEST_BODY_READ_TIMEOUT: &str = "RUSTFS_HTTP_REQUEST_BODY_READ_TIMEOUT";
191pub const DEFAULT_HTTP_REQUEST_BODY_READ_TIMEOUT: u64 = 300;
192
193// ── TLS Hot Reload Parameters ──
194
195/// Environment variable to enable TLS certificate hot reload
196/// Default: false
197/// To enable, set the environment variable RUSTFS_TLS_RELOAD_ENABLE=1
198pub const ENV_TLS_RELOAD_ENABLE: &str = "RUSTFS_TLS_RELOAD_ENABLE";
199
200/// Default value for TLS certificate hot reload
201/// By default, RustFS does not reload TLS certificates automatically.
202pub const DEFAULT_TLS_RELOAD_ENABLE: bool = false;
203
204/// Environment variable for TLS certificate reload interval (seconds)
205/// Default: 30 seconds. Minimum: 5 seconds.
206pub const ENV_TLS_RELOAD_INTERVAL: &str = "RUSTFS_TLS_RELOAD_INTERVAL";
207
208/// Default interval for TLS certificate reload check
209pub const DEFAULT_TLS_RELOAD_INTERVAL: u64 = 30;