fix(security): document unsafe and TLS overrides (#2835)

This commit is contained in:
安正超
2026-05-06 23:09:02 +08:00
committed by GitHub
parent 70be0804ee
commit 4728abcff1
18 changed files with 89 additions and 17 deletions
+4
View File
@@ -651,6 +651,10 @@ fn build_object_lambda_http_client(config: &ObjectLambdaWebhookConfig) -> S3Resu
}
if config.skip_tls_verify {
warn!(
"Object Lambda webhook target '{}' is configured to skip TLS certificate verification. This permits MITM attacks and should not be used in production.",
config.endpoint
);
builder = builder.danger_accept_invalid_certs(true);
} else if !config.client_ca.is_empty() {
let ca_pem = std::fs::read(&config.client_ca)
+1 -2
View File
@@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#![allow(unsafe_code)]
use metrics::{counter, gauge, histogram};
use std::time::Duration;
use tokio_util::sync::CancellationToken;
@@ -91,6 +89,7 @@ fn reclaimable_work_snapshot() -> ReclaimableWorkSnapshot {
not(target_os = "windows"),
not(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64"))
))]
#[allow(unsafe_code)]
fn collect_allocator_memory(force: bool) -> Result<(), String> {
// SAFETY: `mi_collect` is provided by the active global allocator backend
// on this target family. It is explicitly intended to reclaim retained
+2 -4
View File
@@ -28,6 +28,8 @@ mod tests {
/// # Safety
/// This function uses unsafe env::set_var and env::remove_var.
/// Tests using this helper must be marked with #[serial] to avoid race conditions.
// SAFETY: This helper mutates process environment only inside serial tests
// and restores the variable before returning or resuming a panic.
#[allow(unsafe_code)]
fn with_env_var<F>(key: &str, value: &str, test_fn: F)
where
@@ -366,7 +368,6 @@ mod tests {
/// Uses #[serial] to avoid concurrent env var modifications.
#[test]
#[serial]
#[allow(unsafe_code)]
fn test_rustfs_volumes_env_variable() {
// Test case 1: Single volume via environment variable
with_env_var("RUSTFS_VOLUMES", "/data/vol1", || {
@@ -511,7 +512,6 @@ mod tests {
/// which means paths with spaces are NOT supported.
#[test]
#[serial]
#[allow(unsafe_code)]
fn test_volumes_boundary_cases() {
// Test case 1: Paths with spaces are not properly supported (known limitation)
// This test documents the current behavior - space-separated paths will be split
@@ -670,7 +670,6 @@ mod tests {
#[test]
#[serial]
#[allow(unsafe_code)]
fn test_access_key_arguments_mutually_exclusive_env_var() {
// Test that env var args configuration fails on conflict
with_env_var("RUSTFS_VOLUMES", "/data/my disk/vol1", || {
@@ -710,7 +709,6 @@ mod tests {
#[test]
#[serial]
#[allow(unsafe_code)]
fn test_secret_key_arguments_mutually_exclusive_env_var() {
// Test that env var args configuration fails on conflict
with_env_var("RUSTFS_VOLUMES", "/data/my disk/vol1", || {
+9 -2
View File
@@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#![allow(unsafe_code)]
use backtrace::Backtrace;
use pprof::protos::Message;
use rand::RngExt;
@@ -343,6 +341,11 @@ fn handle_dealloc_sampling(ptr: *mut u8) {
}
}
// SAFETY: This allocator wrapper preserves the `GlobalAlloc` contract by
// delegating all allocation operations to `inner` with the exact caller-provided
// layouts and pointers. Sampling records metadata only and does not take
// ownership of allocation memory.
#[allow(unsafe_code)]
unsafe impl<A: GlobalAlloc> GlobalAlloc for TracingAllocator<A> {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
// SAFETY: Delegating to inner allocator.
@@ -376,6 +379,10 @@ unsafe impl<A: GlobalAlloc> GlobalAlloc for TracingAllocator<A> {
}
#[cfg(test)]
// SAFETY: Tests call the unsafe `GlobalAlloc` methods with layouts created by
// `Layout::from_size_align` and deallocate each returned pointer with the same
// layout.
#[allow(unsafe_code)]
mod tests {
use super::*;
use serial_test::serial;
+5
View File
@@ -1021,6 +1021,9 @@ fn get_listen_backlog() -> i32 {
// For macOS and BSD variants use the syscall way of getting the connection queue length.
// NetBSD has no somaxconn-like kernel state.
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "openbsd"))]
// SAFETY: The only unsafe operation in this function is `libc::sysctl`, called
// with kernel MIB arrays selected by target OS, a valid output buffer, and no
// input buffer.
#[allow(unsafe_code)]
fn get_listen_backlog() -> i32 {
const DEFAULT_BACKLOG: i32 = 1024;
@@ -1032,6 +1035,8 @@ fn get_listen_backlog() -> i32 {
let mut buf = [0; 1];
let mut buf_len = size_of_val(&buf);
// SAFETY: `name` points to the target OS MIB, `buf` is a valid writable
// output buffer, `buf_len` points to its size, and no input buffer is used.
if unsafe {
libc::sysctl(
name.as_mut_ptr(),