Skip to content

Commit d4d6232

Browse files
lcianclaudeszokeasaurusrex
authored
feat(snapshots): Authenticate with Objectstore (#3258)
Bump `objectstore-client` to 0.1.6 and use the dedicated auth token now returned by `ObjectstoreUploadOptions`. `.token` in the newest version of Objectstore client passes it in the `X-Os-Auth` header. The Sentry auth token is still passed through the standard `Authorization` header for auth with Django. #skip-changelog Close #3159 Close CLI-292 --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Daniel Szoke <7881302+szokeasaurusrex@users.noreply.github.com>
1 parent d783793 commit d4d6232

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

Cargo.lock

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ java-properties = "2.0.0"
4444
lazy_static = "1.4.0"
4545
libc = "0.2.139"
4646
log = { version = "0.4.17", features = ["std"] }
47-
objectstore-client = { version = "0.1.4" , default-features = false, features = ["native-tls"] }
47+
objectstore-client = { version = "0.1.6" , default-features = false, features = ["native-tls"] }
4848
open = "3.2.0"
4949
parking_lot = "0.12.1"
5050
percent-encoding = "2.2.0"
@@ -79,7 +79,7 @@ zip = "2.4.2"
7979
data-encoding = "2.3.3"
8080
magic_string = "0.3.4"
8181
chrono-tz = "0.8.4"
82-
secrecy = "0.8.0"
82+
secrecy = { version = "0.8.0", features = ["serde"] }
8383
lru = "0.16.3"
8484
backon = { version = "1.5.2", features = ["std", "std-blocking-sleep"] }
8585

src/api/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use lazy_static::lazy_static;
3333
use log::{debug, info, warn};
3434
use parking_lot::Mutex;
3535
use regex::{Captures, Regex};
36-
use secrecy::ExposeSecret as _;
36+
use secrecy::{ExposeSecret as _, SecretString};
3737
use serde::de::DeserializeOwned;
3838
use serde::{Deserialize, Serialize};
3939
use sha1_smol::Digest;
@@ -2065,5 +2065,6 @@ pub struct SnapshotsUploadOptions {
20652065
pub struct ObjectstoreUploadOptions {
20662066
pub url: String,
20672067
pub scopes: Vec<(String, String)>,
2068+
pub auth_token: Option<SecretString>,
20682069
pub expiration_policy: String,
20692070
}

src/commands/build/snapshots.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -332,14 +332,26 @@ fn upload_images(
332332
let expiration = ExpirationPolicy::from_str(&options.objectstore.expiration_policy)
333333
.context("Failed to parse expiration policy from upload options")?;
334334

335-
let client = ClientBuilder::new(options.objectstore.url)
336-
.token({
337-
// TODO: replace with auth from `ObjectstoreUploadOptions` when appropriate
338-
match authenticated_api.auth() {
339-
Auth::Token(token) => token.raw().expose_secret().to_owned(),
340-
}
335+
let mut builder = ClientBuilder::new(options.objectstore.url);
336+
if let Some(token) = options.objectstore.auth_token {
337+
builder = builder.token(token.expose_secret().to_owned());
338+
}
339+
let builder = builder;
340+
341+
let sentry_token = match authenticated_api.auth() {
342+
Auth::Token(token) => token.raw().expose_secret().to_owned(),
343+
};
344+
let sentry_token = format!("Bearer {sentry_token}")
345+
.parse()
346+
// Ignore original error to avoid leaking the token (even though it's invalid)
347+
.map_err(|_| anyhow::anyhow!("Invalid auth token"))?;
348+
let client = builder
349+
.configure_reqwest(|r| {
350+
let mut headers = http::HeaderMap::new();
351+
headers.insert(http::header::AUTHORIZATION, sentry_token);
352+
r.connect_timeout(Duration::from_secs(10))
353+
.default_headers(headers)
341354
})
342-
.configure_reqwest(|r| r.connect_timeout(Duration::from_secs(10)))
343355
.build()?;
344356

345357
let scopes = options.objectstore.scopes;

0 commit comments

Comments
 (0)