Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sb_fs): make s3 fs proxy capability to unsafe feature #448

Merged
merged 1 commit into from
Nov 23, 2024
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
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions crates/sb_fs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ either.workspace = true
tracing.workspace = true
rkyv = { workspace = true, features = ["validation"] }

rustls = "0.21"
hyper-proxy = { version = "0.9", default-features = false, features = ["rustls"] }
hyper-rustls = "0.24"
headers = "0.3"
rustls = { version = "0.21", optional = true }
hyper-proxy = { version = "0.9", optional = true, default-features = false, features = ["rustls"] }
hyper-rustls = { version = "0.24", optional = true }
headers = { version = "0.3", optional = true }
normalize-path = "0.2"
memmap2 = "0.9"
aws-sdk-s3 = "1.2"
Expand All @@ -63,4 +63,12 @@ serial_test.workspace = true

dotenvy = "0.15"
aws-smithy-runtime = { version = "1.7", features = ["test-util"] }
aws-smithy-runtime-api = { version = "1.7", features = ["test-util"] }
aws-smithy-runtime-api = { version = "1.7", features = ["test-util"] }

[features]
unsafe-proxy = [
"dep:rustls",
"dep:hyper-proxy",
"dep:hyper-rustls",
"dep:headers"
]
37 changes: 25 additions & 12 deletions crates/sb_fs/fs/s3_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::{
time::{Duration, SystemTime, UNIX_EPOCH},
};

use super::TryNormalizePath;
use anyhow::{anyhow, Context};
use aws_config::{retry::RetryConfig, AppName, BehaviorVersion, Region};
use aws_credential_types::{credential_fn::provide_credentials_fn, Credentials};
Expand Down Expand Up @@ -44,12 +45,9 @@ use futures::{
stream::FuturesUnordered,
AsyncWriteExt, FutureExt, StreamExt, TryFutureExt,
};
use headers::Authorization;
use hyper_proxy::{Intercept, Proxy, ProxyConnector};
use hyper_rustls::{HttpsConnector, HttpsConnectorBuilder};
use hyper_v014::{client::HttpConnector, Uri};

use memmap2::{MmapOptions, MmapRaw};
use once_cell::sync::{Lazy, OnceCell};
use once_cell::sync::OnceCell;
use serde::{Deserialize, Serialize};
use tempfile::tempfile;
use tokio::{
Expand All @@ -58,9 +56,6 @@ use tokio::{
task::JoinError,
};
use tracing::{debug, error, info_span, instrument, trace, trace_span, warn, Instrument};
use url::Url;

use super::TryNormalizePath;

const MIN_PART_SIZE: usize = 1024 * 1024 * 5;

Expand Down Expand Up @@ -240,9 +235,17 @@ impl S3FsConfig {
CLIENT.with(|it| {
it.borrow_mut()
.get_or_init(|| {
if let Some(proxy_connector) = resolve_proxy_connector() {
HyperClientBuilder::new().build(proxy_connector)
} else {
#[cfg(feature = "unsafe-proxy")]
{
if let Some(proxy_connector) = resolve_proxy_connector() {
HyperClientBuilder::new().build(proxy_connector)
} else {
HyperClientBuilder::new().build_https()
}
}

#[cfg(not(feature = "unsafe-proxy"))]
{
HyperClientBuilder::new().build_https()
}
})
Expand All @@ -251,7 +254,17 @@ impl S3FsConfig {
}
}

fn resolve_proxy_connector() -> Option<ProxyConnector<HttpsConnector<HttpConnector>>> {
#[cfg(feature = "unsafe-proxy")]
fn resolve_proxy_connector() -> Option<
hyper_proxy::ProxyConnector<hyper_rustls::HttpsConnector<hyper_v014::client::HttpConnector>>,
> {
use headers::Authorization;
use hyper_proxy::{Intercept, Proxy, ProxyConnector};
use hyper_rustls::{HttpsConnector, HttpsConnectorBuilder};
use hyper_v014::{client::HttpConnector, Uri};
use once_cell::sync::Lazy;
use url::Url;

let proxy_url: Url = std::env::var("HTTPS_PROXY").ok()?.parse().ok()?;
let proxy_uri: Uri = std::env::var("HTTPS_PROXY").ok()?.parse().ok()?;
let mut proxy = Proxy::new(Intercept::All, proxy_uri);
Expand Down