Skip to content
Closed
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: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

- (auth) Use an org auth token's embedded `region_url` as the API base URL so uploads from orgs with non-default (e.g. EU) data residency reach the correct region instead of failing with `Invalid org token`. Previously only the token's `url` (always the primary US URL) was honored, and `SENTRY_URL`/`--url` overrides were ignored ([#3377](https://github.com/getsentry/sentry-cli/pull/3377))

## 3.6.2

### Fixes
Expand Down
8 changes: 5 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl Config {
};
let token_url = token_data
.as_ref()
.map(|data| data.url.as_str())
.map(|data| data.base_url())
.unwrap_or_default();
let base_url = if token_url.is_empty() {
auth_and_url.url.unwrap_or_else(|| DEFAULT_URL.to_owned())
Expand Down Expand Up @@ -282,7 +282,7 @@ impl Config {
Some(Auth::Token(ref val)) => {
self.cached_token_data = val.payload().cloned();

if let Some(token_url) = self.cached_token_data.as_ref().map(|td| td.url.as_str()) {
if let Some(token_url) = self.cached_token_data.as_ref().map(|td| td.base_url()) {
self.cached_base_url = token_url.to_owned();
}

Expand Down Expand Up @@ -719,7 +719,9 @@ impl AuthAndUrl {

/// Returns whether a token is self-contained because it has a nonempty embedded URL.
fn token_has_embedded_url(token: &AuthToken) -> bool {
token.payload().is_some_and(|data| !data.url.is_empty())
token
.payload()
.is_some_and(|data| !data.base_url().is_empty())
}

/// Determines which inherited value must be removed before applying another source.
Expand Down
13 changes: 13 additions & 0 deletions src/utils/auth_token/org_auth_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ pub struct AuthTokenPayload {
// URL may be missing from some old auth tokens, see getsentry/sentry#57123
#[serde(deserialize_with = "url_deserializer")]
pub url: String,

#[serde(default, deserialize_with = "url_deserializer")]
pub region_url: String,
}

impl AuthTokenPayload {
pub fn base_url(&self) -> &str {
if self.region_url.is_empty() {
&self.url
} else {
&self.region_url
}
}
}

/// Deserializes a URL from a string, returning an empty string if the URL is missing or null.
Expand Down
4 changes: 4 additions & 0 deletions src/utils/auth_token/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ fn test_valid_org_auth_token() {
let payload = token.payload().unwrap();
assert_eq!(payload.org, "sentry");
assert_eq!(payload.url, "http://localhost:8000");
assert_eq!(payload.region_url, "http://localhost:8000");
assert_eq!(payload.base_url(), "http://localhost:8000");

assert_eq!(good_token, token.raw().expose_secret().clone());

Expand All @@ -43,6 +45,8 @@ fn test_valid_org_auth_token_missing_url() {
let payload = token.payload().unwrap();
assert_eq!(payload.org, "sentry");
assert!(payload.url.is_empty());
assert_eq!(payload.region_url, "http://localhost:8000");
assert_eq!(payload.base_url(), "http://localhost:8000");

assert_eq!(good_token, token.raw().expose_secret().clone());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
This auth token has an empty URL. We expect the --url argument to take precedence here
This auth token has an empty URL but a set region URL. The region URL is used as the base URL and takes precedence over the --url argument.
```
$ sentry-cli --auth-token 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 --url https://sentry.example.com info
? failed
Sentry Server: https://sentry.example.com
[..]WARN[..] Using http://localhost:8000 (embedded in token) rather than manually-configured URL https://sentry.example.com. To use https://sentry.example.com, please provide an auth token for https://sentry.example.com.
...

```
Loading