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

feature: make rustls default in fluvio, move to reqwest from surf #3156

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
72077c4
make rustls default, move to reqwest from surf
ozgrakkurt Apr 17, 2023
fabef5f
always include async-std/tokio01 if using reqwest
ozgrakkurt Apr 17, 2023
6bf2afb
move features from workspace to individual crates
ozgrakkurt Apr 18, 2023
eba8d79
Merge branch 'master' into rustls
ozgrakkurt Apr 18, 2023
d9168ab
add async-std to fluvio dev deps
ozgrakkurt Apr 18, 2023
2c5bdfb
save
ozgrakkurt Apr 18, 2023
1293dc7
save
ozgrakkurt Apr 18, 2023
8088145
bump versions
ozgrakkurt Apr 18, 2023
b2073b9
Merge branch 'master' into rustls
ozgrakkurt Apr 18, 2023
68cee4c
update lock
ozgrakkurt Apr 18, 2023
c400386
bump fluvio-extension-common version
ozgrakkurt Apr 18, 2023
7e61700
save
ozgrakkurt Apr 18, 2023
4b4684f
save
ozgrakkurt Apr 18, 2023
91ba07c
save
ozgrakkurt Apr 18, 2023
6725c46
save
ozgrakkurt Apr 18, 2023
3436736
update lock
ozgrakkurt Apr 18, 2023
e9d9c5e
bump fluvio ver
ozgrakkurt Apr 18, 2023
fb3dcf3
remove default-features from reqwest
ozgrakkurt Apr 18, 2023
8fb6d4b
don't use fluvio-futures from workspace
ozgrakkurt Apr 18, 2023
908745b
Revert "don't use fluvio-futures from workspace"
ozgrakkurt Apr 18, 2023
810c73b
bump fluvio future
ozgrakkurt Apr 18, 2023
1828a02
Merge branch 'master' into rustls
ozgrakkurt Apr 18, 2023
0c767c9
move flv-tls-proxy to workspace deps
ozgrakkurt Apr 18, 2023
ba88787
save
ozgrakkurt Apr 18, 2023
4fbf961
save
ozgrakkurt Apr 18, 2023
c538dea
use rustls more
ozgrakkurt Apr 18, 2023
4c02bfc
save
ozgrakkurt Apr 18, 2023
4814a13
save
ozgrakkurt Apr 18, 2023
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
793 changes: 119 additions & 674 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,18 @@ tracing = "0.1.19"
url = "2.1.1"
wasmparser = "0.102.0"
which = "4.1.0"
reqwest = { version = "0.11", default-features = false }

# fluvio dep
k8-client = { version = "10.0.0" }
k8-types = { version = "0.8.0" }
k8-config = { version = "2.0.0"}
k8-metadata-client = { version = "5.1.0" }
fluvio-future = { version = "0.4.0" }
fluvio-future = { version = "0.5" }
flv-util = { version = "0.5.0" }
fluvio-helm = { version = "0.4.1"}
fluvio-command = { version = "0.2.0"}
flv-tls-proxy = { version = "0.7" }

# Used to make eyre faster on debug builds
# See https://github.com/yaahc/color-eyre#improving-perf-on-debug-builds
Expand Down
4 changes: 2 additions & 2 deletions crates/fluvio-auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ tracing = { workspace = true }
x509-parser = "0.15.0"

fluvio-controlplane-metadata = { path = "../fluvio-controlplane-metadata" }
fluvio-future = { version = "0.4.0", features = ["net", "openssl_tls"] }
fluvio-future = { workspace = true, features = ["net", "rust_tls"] }
fluvio-protocol = { path = "../fluvio-protocol" }
fluvio-socket = { path = "../fluvio-socket" }
fluvio-types = { path = "../fluvio-types" }
flv-tls-proxy = { version = "0.6.0" }
flv-tls-proxy = { workspace = true }
futures-util = { version = "0.3.5" }
2 changes: 1 addition & 1 deletion crates/fluvio-benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ anyhow = { workspace = true }

fluvio = { path = "../fluvio" }
fluvio-cli-common = { path = "../fluvio-cli-common"}
fluvio-future = { version = "0.4.3", features = [
fluvio-future = { workspace = true, features = [
'task',
'future',
'sync',
Expand Down
2 changes: 1 addition & 1 deletion crates/fluvio-channel-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ anyhow = { workspace = true }

fluvio-cli-common = { path = "../fluvio-cli-common" }
fluvio-channel = { path = "../fluvio-channel" }
fluvio-future = { version = "0.4.0", features = ["task", "subscriber", "native2_tls"], optional = true }
fluvio-future = { workspace = true, features = ["task", "subscriber", "rust_tls"], optional = true }
fluvio-types = { path = "../fluvio-types", default-features = false, optional = true }
fluvio-package-index = { path = "../fluvio-package-index" }

Expand Down
2 changes: 1 addition & 1 deletion crates/fluvio-cli-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ fluvio = { path = "../fluvio", default-features = false, optional = true }
fluvio-protocol = { path = "../fluvio-protocol", optional = true }

[dev-dependencies]
fluvio-future = { version = "0.4.0", features = ["fs", "io", "subscriber", "native2_tls", "fixture"] }
fluvio-future = { workspace = true, features = ["fs", "io", "subscriber", "rust_tls", "fixture"] }
7 changes: 5 additions & 2 deletions crates/fluvio-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ tokio = { version = "1.3.0", features = ["macros"] }
async-net = "1.7.0"
anyhow = { workspace = true }
current_platform = "0.2"
reqwest = { workspace = true, default-features = false, features = ["json", "gzip", "rustls-tls"] }
# added to make sure reqwest works
async-std = { version = "1.6.4", default-features = false, features = ["tokio1"] }

# Fluvio dependencies
k8-config = { workspace = true, optional = true }
Expand All @@ -96,10 +99,10 @@ fluvio-controlplane-metadata = { path = "../fluvio-controlplane-metadata", featu

# Optional Fluvio dependencies
fluvio-types = { path = "../fluvio-types", optional = true }
fluvio-future = { version = "0.4.0", features = ["fs", "io", "subscriber", "native2_tls"], optional = true }
fluvio-future = { workspace = true, features = ["fs", "io", "subscriber", "rust_tls"], optional = true }
fluvio-sc-schema = { path = "../fluvio-sc-schema", features = ["use_serde"], optional = true }
fluvio-spu-schema = { path = "../fluvio-spu-schema", optional = true }


[dev-dependencies]
fluvio-future = { version = "0.4.0", features = ["fixture"] }
fluvio-future = { workspace = true, features = ["fixture"] }
14 changes: 10 additions & 4 deletions crates/fluvio-cli/src/client/hub/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,26 @@ pub(crate) async fn get_pkg_list(
endpoint: &str,
remote: &Option<String>,
) -> Result<PackageListMeta> {
use hubutil::http;
use reqwest::{Client as HttpClient, header};

let access = get_hub_access(remote)?;

let action_token = access.get_list_token().await.map_err(|_| {
CliError::HubError("rejected access credentials, try 'fluvio cloud login'".into())
})?;
let url = format!("{}/{endpoint}", &access.remote);
let mut res = http::get(&url)
.header("Authorization", &action_token)

let client = HttpClient::default();

let res = client
.get(&url)
.header(header::AUTHORIZATION, &action_token)
.send()
.await
.map_err(|e| CliError::HubError(format!("list api access error {e}")))?;

let pl: PackageListMeta = res
.body_json()
.json()
.await
.map_err(|e| CliError::HubError(format!("list api data parse error {e}")))?;
Ok(pl)
Expand Down
2 changes: 1 addition & 1 deletion crates/fluvio-cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub enum CliError {
PackageError(String),

#[error(transparent)]
TlsError(#[from] fluvio_future::openssl::TlsError),
TlsError(#[from] fluvio_future::tls::TlsError),

#[error("Invalid argument: {0}")]
InvalidArg(String),
Expand Down
20 changes: 12 additions & 8 deletions crates/fluvio-cli/src/install/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use clap::Parser;
use tracing::debug;
use anyhow::Result;
use current_platform::CURRENT_PLATFORM;
use reqwest::{Client as HttpClient, header, StatusCode};

use fluvio_cli_common::error::{HttpError, PackageNotFound};
use fluvio_cli_common::install::{
Expand All @@ -12,8 +13,7 @@ use fluvio_cli_common::install::{
use fluvio_index::{PackageId, HttpAgent, MaybeVersion};
use fluvio_channel::{LATEST_CHANNEL_NAME, FLUVIO_RELEASE_CHANNEL};
use fluvio_hub_util as hubutil;
use hubutil::{http, HubAccess, INFINYON_HUB_REMOTE, FLUVIO_HUB_PROFILE_ENV};
use hubutil::http::StatusCode;
use hubutil::{HubAccess, INFINYON_HUB_REMOTE, FLUVIO_HUB_PROFILE_ENV};

use crate::error::CliError;
use crate::install::update::{
Expand Down Expand Up @@ -256,26 +256,30 @@ impl InstallOpt {
systuple = self.get_target(),
);
debug!("Downloading binary from hub: {binurl}");
let mut resp = http::get(binurl)
.header("Authorization", actiontoken)

let client = HttpClient::default();
let resp = client
.get(binurl)
.header(header::AUTHORIZATION, &actiontoken)
.send()
.await
.map_err(|_| HttpError::InvalidInput("authorization error".into()))?;

match resp.status() {
StatusCode::Ok => {}
StatusCode::OK => {}
code => {
let body_err_message = resp
.body_string()
.text()
.await
.unwrap_or_else(|_err| "couldn't fetch error message".to_string());
let msg = format!("Status({code}) {body_err_message}");
return Err(crate::CliError::HubError(msg).into());
}
}
let data = resp
.body_bytes()
.bytes()
.await
.map_err(|_| crate::CliError::HubError("Data unpack failure".into()))?;
Ok(data)
Ok(data.into())
}
}
2 changes: 1 addition & 1 deletion crates/fluvio-controlplane-metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ fluvio-protocol = { path = "../fluvio-protocol", version = "0.9", features = [

[dev-dependencies]
serde_yaml = { workspace = true }
fluvio-future = { version = "0.4.0", features = ["fixture"] }
fluvio-future = { workspace = true, features = ["fixture"] }
16 changes: 4 additions & 12 deletions crates/fluvio-hub-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,13 @@ toml = { workspace = true }
tracing = { workspace = true }
thiserror = { workspace = true }
wasmparser = { workspace = true }
reqwest = { workspace = true, default-features = false, features = ["json", "gzip", "rustls-tls"] }
# added to make sure reqwest works
async-std = { version = "1.6.4", default-features = false, features = ["tokio1"] }

fluvio-future = { workspace = true, features = ["task"]}
fluvio-future = { workspace = true, features = ["task"] }
fluvio-hub-protocol = { path = "../fluvio-hub-protocol" }
fluvio-types = { path = "../fluvio-types" }

# feature control
[dependencies.surf]
version = "2.3.2"
features = ["h1-client-rustls", "encoding"]
default-features = false

[dependencies.http-client]
version = "6.5.3"
features = ["h1_client", "rustls"]
default-features = false

[dev-dependencies]
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
58 changes: 29 additions & 29 deletions crates/fluvio-hub-util/src/hubaccess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use std::path::{Path, PathBuf};

use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha512};
use surf::http::mime;
use surf::StatusCode;
use tracing::{debug, info};
use reqwest::{Client as HttpClient, StatusCode, header};

use fluvio_future::task::run_block_on;
use fluvio_hub_protocol::{Result, HubError};
Expand Down Expand Up @@ -60,30 +59,30 @@ impl HubAccess {
hubid: hubid.to_string(),
pubkey: self.pubkey.clone(),
};
let msg_json = serde_json::to_string(&msg)?;
let host = &self.remote;
let api_url = format!("{host}/{HUB_API_HUBID}");
debug!("Sending Action token {action_token}");
let req = surf::put(api_url)
.content_type(mime::JSON)
.body_bytes(msg_json)
.header("Authorization", &action_token);
let res = req
let client = HttpClient::default();
let res = client
.put(&api_url)
.header(header::AUTHORIZATION, &action_token)
.json(&msg)
.send()
.await
.map_err(|e| HubError::HubAccess(format!("Failed to connect {e}")))?;
let status = res.status();
match status {
StatusCode::Created => {
StatusCode::CREATED => {
println!("hub: hubid {hubid} created");
}
StatusCode::Ok => {
StatusCode::OK => {
println!("hub: hubid {hubid} is set");
}
StatusCode::Forbidden => {
StatusCode::FORBIDDEN => {
let msg = format!("hub: hubid {hubid} already taken");
return Err(HubError::HubAccess(msg));
}
StatusCode::Unauthorized => {
StatusCode::UNAUTHORIZED => {
let msg = "hub: authorization error, try 'fluvio cloud login'".to_string();
return Err(HubError::HubAccess(msg));
}
Expand Down Expand Up @@ -127,35 +126,36 @@ impl HubAccess {
self.make_action_token(action, read_infinyon_token()?).await
}

async fn make_action_token(&self, action: &str, authn_token: String) -> Result<String> {
async fn make_action_token(&self, action: &str, auth_token: String) -> Result<String> {
let host = &self.remote;
let api_url = format!("{host}/{HUB_API_ACT}");
let mat = MsgActionToken {
act: String::from(action),
};
let msg_action_token = serde_json::to_string(&mat)
.map_err(|_e| HubError::HubAccess("Failed access setup".to_string()))?;
let req = surf::get(api_url)
.content_type(mime::JSON)
.body_bytes(msg_action_token)
.header("Authorization", &authn_token);
let mut res = req
let client = HttpClient::default();

let res = client
.get(&api_url)
.header(header::AUTHORIZATION, &auth_token)
.json(&mat)
.send()
.await
.map_err(|e| HubError::HubAccess(format!("Failed to connect {e}")))?;
let status_code = res.status();
match status_code {
StatusCode::Ok => {
let action_token = res.body_string().await.map_err(|e| {
debug!("err {e} {res:?}");
StatusCode::OK => {
let action_token = res.text().await.map_err(|_| {
let msg = format!("Status({status_code}). couldn't fetch error message");
debug!("{msg}");
HubError::HubAccess("Failed to parse reply".to_string())
})?;
Ok(action_token)
}
StatusCode::Unauthorized => Err(HubError::HubAccess(
StatusCode::UNAUTHORIZED => Err(HubError::HubAccess(
"Unauthorized, please log in with 'fluvio cloud login'".into(),
)),
_ => {
let msg = format!("Unknown error: {}", res.status());
let msg = format!("Unknown error: {}", status_code);
Err(HubError::HubAccess(msg))
}
}
Expand Down Expand Up @@ -307,10 +307,10 @@ fn get_hubref() -> Option<String> {
return None; // use default
}
let hubref_url = format!("{fcremote}/api/v1/hubref");
let reply: std::result::Result<String, surf::Error> = run_block_on(async {
let req = surf::get(hubref_url);
let mut res = req.await?;
let reply: ReplyHubref = res.body_json().await?;
let reply: std::result::Result<String, reqwest::Error> = run_block_on(async {
let req = reqwest::get(hubref_url);
let res = req.await?;
let reply: ReplyHubref = res.json().await?;
// fluvio profile switch does not switch the cloud login
// so hub remote can be pointed to the cloud login different that the profile
// this will only be printed when using a nonstd hub
Expand Down
1 change: 0 additions & 1 deletion crates/fluvio-hub-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub use hubaccess::*;
pub use package::*;
pub use package_meta_ext::*;
pub use utils::*;
pub use surf as http;

pub use fluvio_hub_protocol::*;
pub use fluvio_hub_protocol::constants::*;
Expand Down
Loading