Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/scripts/build-cuobject-client.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# Build and link the combined client against NVIDIA's x86_64 SDK without a GPU.
set -euo pipefail
: "${NIXL_PREFIX:?NIXL SDK prefix is required}"
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
packages="${RUNNER_TEMP:-$work}/cuobject-packages"
mkdir -p "$packages"
repo=https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64
while read -r digest package; do
archive="$packages/$package"
if ! echo "$digest $archive" | sha256sum --check --status 2>/dev/null; then
curl --fail --silent --show-error --location --retry 3 --retry-all-errors \
--connect-timeout 20 --max-time 300 "$repo/$package" -o "$archive"
echo "$digest $archive" | sha256sum --check
fi
dpkg-deb -x "$archive" "$work/sdk"
done <<'PACKAGES'
e06a0f89898ec9a7df3124e4d6ad3a1ebf92a0b3ea42c3f81c6fff5ef92a5126 libcuobjclient-13-5_1.4.0.107-1_amd64.deb
ce6188558d94a15593c4ae82cb578828ce7686ea09e2658a201962f56e66fe7c libcuobjclient-dev-13-5_1.4.0.107-1_amd64.deb
d02925a4ab1706b6ba578ff6d7db953c5bcae3291d3abdbd7e4311de8d3d4c11 libcufile-13-5_1.20.0.107-1_amd64.deb
b8e2c20dc796ca09b3ec55ce5fd72f2bdc4c6efea857b907a9cec5b356256072 libcufile-dev-13-5_1.20.0.107-1_amd64.deb
e079c64a1ab86d69a43a7dd8029ddcacb7de8c1953a4c095e485429bd90e8636 cuda-cudart-dev-13-5_13.5.37-1_amd64.deb
PACKAGES
export CUDA_HOME="$work/sdk/usr/local/cuda-13.5"
export CUOBJCLIENT_ROOT="$CUDA_HOME/targets/x86_64-linux"
export LD_LIBRARY_PATH="$CUOBJCLIENT_ROOT/lib:$NIXL_PREFIX/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
export LIBRARY_PATH="$CUOBJCLIENT_ROOT/lib${LIBRARY_PATH:+:$LIBRARY_PATH}"
export NIXL_PLUGIN_DIR="$NIXL_PREFIX/lib/plugins"
./scripts/build-rdma.sh --features cuobject
cargo test --locked --manifest-path nixl/Cargo.toml --features cuobject
7 changes: 6 additions & 1 deletion .github/workflows/nixl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'Cargo.lock'
- 'scripts/build-rdma.sh'
- '.github/scripts/build-nixl-runtime.sh'
- '.github/scripts/build-cuobject-client.sh'
- '.github/workflows/nixl.yml'

permissions:
Expand All @@ -31,11 +32,13 @@ jobs:
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
with:
workspaces: nixl
- name: Check the cuObject crates without the NVIDIA SDK
run: cargo check --locked --manifest-path nixl/Cargo.toml -p rustfs-cuobject-client -p rustfs-cuobject-client-sys
- name: Install native build tools
run: |
echo "NIXL_PREFIX=$RUNNER_TEMP/nixl" >> "$GITHUB_ENV"
sudo apt-get update
sudo apt-get install -y --no-install-recommends libclang-dev ninja-build python3-dev python3-venv
sudo apt-get install -y --no-install-recommends libibverbs-dev librdmacm1t64 libclang-dev ninja-build python3-dev python3-venv
python3 -m venv "$RUNNER_TEMP/native-tools"
"$RUNNER_TEMP/native-tools/bin/pip" install meson==1.12.1 pybind11==3.1.0
echo "$RUNNER_TEMP/native-tools/bin" >> "$GITHUB_PATH"
Expand All @@ -54,3 +57,5 @@ jobs:
export NIXL_PLUGIN_DIR="$NIXL_PREFIX/lib/plugins"
./scripts/build-rdma.sh
cargo test --locked --manifest-path nixl/Cargo.toml
- name: Build and test the NVIDIA cuObject client with the real SDK
run: .github/scripts/build-cuobject-client.sh
7 changes: 4 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ Modifying protected files requires:
- Must use `?` or `expect("reason")`
- Violation: may cause panic

3. **Using `unsafe` code**
- No exceptions
- Violation: security risk
3. **Using `unsafe` outside the private NVIDIA SDK bridge**
- Only the private bridge in `nixl/cuobject-client-sys/src/sdk.rs`, enabled by the native executable’s `cuobject` feature, may declare the C++ interface and the thread ownership of its opaque window. Keep handwritten Rust operations outside this exception.
- Native host slices require an exclusive window. Once a token is exposed, retain it with its registration until confirmed completion or proof that DMA never started. Quarantine an uncertain exchange or failed token release for the life of the process.
- Keep the lint exception on the bridge. The native executable and the `rustfs-cuobject-client` library must retain `forbid(unsafe_code)`.

4. **Printing credentials in logs/errors**
- Includes: access_key, secret_key, Authorization headers
Expand Down
60 changes: 58 additions & 2 deletions crates/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use std::io::{IsTerminal, stderr, stdout};
use clap::{Parser, Subcommand, ValueEnum};
use rc_core::config::Defaults;
use rc_core::{
ConfigManager, DataTransportMode, RequestHeader, set_global_data_transport_mode,
set_global_request_headers,
ConfigManager, DataTransportMode, RdmaBackend, RequestHeader, set_global_data_transport_mode,
set_global_rdma_backend, set_global_request_headers,
};

use crate::exit_code::ExitCode;
Expand Down Expand Up @@ -98,6 +98,10 @@ pub struct Cli {
#[arg(long, global = true, env = "RC_DATA_TRANSPORT", default_value = "http")]
pub data_transport: DataTransportMode,

/// RDMA backend for auto or rdma mode: nixl or cuobject
#[arg(long, global = true, env = "RC_RDMA_BACKEND", default_value = "nixl")]
pub rdma_backend: RdmaBackend,

/// Maximum multipart parts per object for the destination backend
#[arg(long, global = true, env = "RC_MAX_PARTS", default_value_t = 10_000,
value_parser = clap::value_parser!(u32).range(1..=10_000))]
Expand Down Expand Up @@ -371,6 +375,7 @@ pub enum Commands {
/// Execute the CLI command and return an exit code
pub async fn execute(cli: Cli) -> ExitCode {
set_global_data_transport_mode(cli.data_transport);
set_global_rdma_backend(cli.rdma_backend);
set_global_request_headers(cli.request_headers.clone());
let cli_output_options = GlobalOutputOptions::from_cli(&cli);
if let Err(error) = rc_core::set_global_multipart_max_parts(cli.max_parts as usize) {
Expand Down Expand Up @@ -592,6 +597,57 @@ mod tests {
assert_eq!(cli.data_transport, DataTransportMode::Rdma);
assert!(Cli::try_parse_from(["rc", "--data-transport", "udp", "alias", "list"]).is_err());
}
#[test]
fn external_transport_headers_cannot_be_supplied_by_the_caller() {
for name in [
"X-AmZ-RdMa-ToKeN",
"x-amz-rdma-reply",
"x-amz-rdma-bytes-transferred",
"x-rustfs-nixl-agent",
"x-rustfs-nixl-metadata",
"x-rustfs-nixl-buffer",
] {
for mode in ["http", "auto", "rdma"] {
assert!(
Cli::try_parse_from([
"rc",
"--data-transport",
mode,
"-H",
&format!("{name}:opaque"),
"alias",
"list"
])
.is_err(),
"{name} in {mode}"
);
}
}
assert!(
Cli::try_parse_from(["rc", "-H", "x-amz-meta-format:onnx", "alias", "list"]).is_ok()
);
}

#[test]
fn rdma_backend_is_independent_of_fallback_policy() {
for policy in ["rdma", "auto"] {
let args = [
"rc",
"--data-transport",
policy,
"--rdma-backend",
"cuobject",
"alias",
"list",
];
let cli = Cli::try_parse_from(args).expect("select NVIDIA cuObject");
assert_eq!(cli.rdma_backend, RdmaBackend::CuObject);
assert_eq!(cli.data_transport, policy.parse().unwrap());
}
let default = Cli::try_parse_from(["rc", "alias", "list"]).unwrap();
assert_eq!(default.rdma_backend, RdmaBackend::Nixl);
assert!(Cli::try_parse_from(["rc", "--rdma-backend", "unknown", "alias", "list"]).is_err());
}
use clap::Parser;

#[test]
Expand Down
17 changes: 15 additions & 2 deletions crates/core/src/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,23 @@ impl RequestHeader {
return Err(Error::Config(format!("Invalid value for header '{name}'")));
}

Ok(Self {
let header = Self {
name,
value: header_value,
})
};
header.validate_transport_name()?;
Ok(header)
}

/// Transport control headers must come from the owner of the registered memory.
pub fn validate_transport_name(&self) -> Result<()> {
let name = self.name.to_ascii_lowercase();
if name.starts_with("x-amz-rdma-") || name.starts_with("x-rustfs-nixl-") {
return Err(Error::Config(
"RDMA headers are reserved for the selected transport".into(),
));
}
Ok(())
}
}

Expand Down
34 changes: 34 additions & 0 deletions crates/core/src/data_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,40 @@ impl FromStr for DataTransportMode {
}
}

/// The wire protocol for external object transfers, independent of HTTP fallback.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
#[repr(u8)]
pub enum RdmaBackend {
#[default]
Nixl,
CuObject,
}

impl FromStr for RdmaBackend {
type Err = String;

fn from_str(value: &str) -> Result<Self, Self::Err> {
match value {
"nixl" => Ok(Self::Nixl),
"cuobject" => Ok(Self::CuObject),
_ => Err("RDMA backend must be nixl or cuobject".into()),
}
}
}

static GLOBAL_BACKEND: AtomicU8 = AtomicU8::new(RdmaBackend::Nixl as u8);

pub fn set_global_rdma_backend(backend: RdmaBackend) {
GLOBAL_BACKEND.store(backend as u8, Ordering::Relaxed);
}

pub fn global_rdma_backend() -> RdmaBackend {
match GLOBAL_BACKEND.load(Ordering::Relaxed) {
i if i == RdmaBackend::CuObject as u8 => RdmaBackend::CuObject,
_ => RdmaBackend::Nixl,
}
}

/// Business outcome classification. Transport timeouts never imply rejection.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DataTransferState {
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ pub use alias::{
pub use config::{Config, ConfigManager};
pub use cors::{CorsConfiguration, CorsRule};
pub use data_transport::{
DataTransferState, DataTransportMode, global_data_transport_mode,
set_global_data_transport_mode,
DataTransferState, DataTransportMode, RdmaBackend, global_data_transport_mode,
global_rdma_backend, set_global_data_transport_mode, set_global_rdma_backend,
};
pub use encryption::{BucketEncryption, ObjectEncryptionRequest};
pub use error::{Error, MultipartAbortStatus, Result};
Expand Down
54 changes: 45 additions & 9 deletions crates/s3/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1806,6 +1806,10 @@ impl Intercept for CustomHeaderInterceptor {
impl S3Client {
/// Create a new S3 client from an alias configuration
pub async fn new(alias: Alias) -> Result<Self> {
let request_headers = global_request_headers();
for header in &request_headers {
header.validate_transport_name()?;
}
let endpoint = alias.endpoint.clone();
let region = alias.region.clone();
let access_key = alias.access_key.clone();
Expand Down Expand Up @@ -1865,7 +1869,6 @@ impl S3Client {
let config = config_loader.load().await;

// Build S3 client with path-style addressing for compatibility
let request_headers = global_request_headers();
let mut s3_config_builder = aws_sdk_s3::config::Builder::from(&config)
.force_path_style(force_path_style_for_alias(&alias))
// Improve compatibility with S3-compatible backends by only sending request
Expand Down Expand Up @@ -1926,7 +1929,8 @@ impl S3Client {
(_, Some(transport)) => Ok(Some(transport)),
(DataTransportMode::Rdma, None) => Err(Error::DataTransfer {
state: rc_core::DataTransferState::NotAccepted,
message: "This executable has no external object data provider".to_string(),
message: "This executable has no provider for the selected RDMA backend"
.to_string(),
source: None,
}),
}
Expand Down Expand Up @@ -7697,10 +7701,8 @@ impl ObjectStore for S3Client {
}
}

/// External control exchanges retain the host client's TLS and signing policy.
#[async_trait]
impl ControlExecutor for S3Client {
async fn execute_headers(&self, request: ControlRequest) -> Result<ControlResponse> {
impl S3Client {
async fn send_external_control(&self, request: ControlRequest) -> Result<reqwest::Response> {
if self.alias.anonymous {
return Err(Error::RequestRejected(
"External object control requires an authenticated S3 principal".to_string(),
Expand Down Expand Up @@ -7762,8 +7764,7 @@ impl ControlExecutor for S3Client {
// Only response headers travel over HTTPS. Bound the complete wait,
// including connection setup, using the same alias policy as S3.
let timeout = self.alias.timeout_config();
let mut response = self
.xml_http_client
self.xml_http_client
.request(request.method, url)
.headers(signed)
.timeout(Duration::from_millis(
Expand All @@ -7778,7 +7779,42 @@ impl ControlExecutor for S3Client {
"External control exchange failed"
};
Error::Network(message.to_owned())
})?;
})
}
}

/// External control exchanges retain the host client's TLS and signing policy.
#[async_trait]
impl ControlExecutor for S3Client {
fn endpoint(&self) -> Option<&str> {
Some(&self.alias.endpoint)
}

async fn execute_registered(
&self,
request: ControlRequest,
) -> Result<data_transport::RegisteredControlResponse> {
let method = request.method.clone();
let conditional = request.headers.contains_key("if-match");
let mut response = self.send_external_control(request).await?;
let status = response.status();
let headers = std::mem::take(response.headers_mut());
if object_error::dma_precondition_response(&method, conditional, status, &headers)
&& object_error::has_precondition_error_body(response).await
{
return Ok(
data_transport::RegisteredControlResponse::RejectedBeforeDma(Error::Conflict(
"The S3 endpoint rejected the conditional GET before transferring data".into(),
)),
);
}
Ok(data_transport::RegisteredControlResponse::Response(
ControlResponse { status, headers },
))
}

async fn execute_headers(&self, request: ControlRequest) -> Result<ControlResponse> {
let mut response = self.send_external_control(request).await?;
Ok(ControlResponse {
status: response.status(),
headers: std::mem::take(response.headers_mut()),
Expand Down
Loading