Skip to content
Open
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
33 changes: 6 additions & 27 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ java-properties = "2.0.0"
lazy_static = "1.4.0"
libc = "0.2.139"
log = { version = "0.4.17", features = ["std"] }
objectstore-client = { version = "0.1.2" , default-features = false, features = ["native-tls"] }
objectstore-client = { version = "0.1.6" , default-features = false, features = ["native-tls"] }
open = "3.2.0"
parking_lot = "0.12.1"
percent-encoding = "2.2.0"
Expand Down Expand Up @@ -79,7 +79,7 @@ zip = "2.4.2"
data-encoding = "2.3.3"
magic_string = "0.3.4"
chrono-tz = "0.8.4"
secrecy = "0.8.0"
secrecy = { version = "0.8.0", features = ["serde"] }
lru = "0.16.3"
backon = { version = "1.5.2", features = ["std", "std-blocking-sleep"] }

Expand Down
3 changes: 2 additions & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use lazy_static::lazy_static;
use log::{debug, info, warn};
use parking_lot::Mutex;
use regex::{Captures, Regex};
use secrecy::ExposeSecret as _;
use secrecy::{ExposeSecret as _, SecretString};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use sha1_smol::Digest;
Expand Down Expand Up @@ -2065,5 +2065,6 @@ pub struct SnapshotsUploadOptions {
pub struct ObjectstoreUploadOptions {
pub url: String,
pub scopes: Vec<(String, String)>,
pub auth_token: Option<SecretString>,
pub expiration_policy: String,
}
29 changes: 20 additions & 9 deletions src/commands/build/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,26 @@ fn upload_images(
let expiration = ExpirationPolicy::from_str(&options.objectstore.expiration_policy)
.context("Failed to parse expiration policy from upload options")?;

let client = ClientBuilder::new(options.objectstore.url)
.token({
// TODO: replace with auth from `ObjectstoreUploadOptions` when appropriate
let auth = match authenticated_api.auth() {
Auth::Token(token) => token.raw().expose_secret().to_owned(),
};
auth
let mut builder = ClientBuilder::new(options.objectstore.url);
if let Some(token) = options.objectstore.auth_token {
builder = builder.token(token.expose_secret().to_owned());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: Why not implement From<Secret<String>> for TokenProvider?

I think that probably reduces the scope where the secret string could accidentally get leaked in a panic.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed previously, internally the TokenProvider stores a newtype with a Debug implementation which redacts the key, so practically the effect is the same.
I'm not opposed to implementing From<Secret<String>> for TokenProvider though, it just adds a single dep more to objectstore-client, I'll do it sometime soon.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could place the From implementation behind a feature flag, that would make the secrecy crate an optional dependency

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but this comment is nonblocking in any case

}
let builder = builder;

let sentry_token = match authenticated_api.auth() {
Auth::Token(token) => token.raw().expose_secret().to_owned(),
};
let sentry_token = format!("Bearer {sentry_token}")
.parse()
// Ignore original error to avoid leaking the token (even though it's invalid)
.map_err(|_| anyhow::anyhow!("Invalid auth token"))?;
let client = builder
.configure_reqwest(|r| {
let mut headers = http::HeaderMap::new();
headers.insert(http::header::AUTHORIZATION, sentry_token);
r.connect_timeout(Duration::from_secs(10))
.default_headers(headers)
})
.configure_reqwest(|r| r.connect_timeout(Duration::from_secs(10)))
.build()?;

let mut scope = Usecase::new("preprod").scope();
Expand Down Expand Up @@ -400,7 +411,7 @@ fn upload_images(
warn!("Some images share identical file names. Only the first occurrence of each is included:{details}");
}

let result = runtime.block_on(async { many_builder.send().error_for_failures().await });
let result = runtime.block_on(async { many_builder.send().await.error_for_failures().await });

let uploaded_count = manifest_entries.len();

Expand Down
Loading