-
-
Notifications
You must be signed in to change notification settings - Fork 246
fix(auth): Route org token requests to region_url #3342
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -19,6 +19,23 @@ pub struct AuthTokenPayload { | |||
| // URL may be missing from some old auth tokens, see getsentry/sentry#57123 | ||||
| #[serde(deserialize_with = "url_deserializer")] | ||||
| pub url: String, | ||||
|
|
||||
| // Region URL is the host that actually serves this org's API requests. It is | ||||
| // absent from older tokens, in which case requests fall back to `url`. | ||||
| #[serde(default, deserialize_with = "url_deserializer")] | ||||
| pub region_url: String, | ||||
| } | ||||
|
|
||||
| impl AuthTokenPayload { | ||||
| /// Returns the base URL that API requests for this org should target, | ||||
| /// preferring the region URL and falling back to `url` when it is absent. | ||||
| pub fn base_url(&self) -> &str { | ||||
| if self.region_url.is_empty() { | ||||
| &self.url | ||||
| } else { | ||||
| &self.region_url | ||||
| } | ||||
|
Comment on lines
+33
to
+37
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part makes sense to me as most CLI operations (and org auth tokens in general) work on regional resources. This would make it so that org-auth-tokens can't be used on anything that involves control though.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 on this: Broadly switching all operations to prefer the region URL could be risky; we should validate that all endpoints supported by org auth tokens also are available on the region. Less risky could be to expose a way to get the region URL while still maintaining a way to get the base URL, although that is likely a bit complex. That would allow us to use the region URL where needed and for commands where we have validated that it works, while continuing to use the base URL elsewhere.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that an old version of CLI had this utility Line 1191 in de5cda2
Maybe relevant for the discussion here?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, we had used this for the pre-chunked-uploading uploads that were removed in Sentry CLI 3.x. We no longer needed it for chunked uploads, as the chunked upload endpoint already returns the region-specific URL as the upload URL, which is why this was removed. If we go with a fix in the CLI, though, we might want something like this utility so that we only migrate the API calls that need to go to the region-specific endpoints over to the region specific URLs; that lowers the risk of this change by keeping most things on control silo. |
||||
| } | ||||
| } | ||||
|
|
||||
| /// Deserializes a URL from a string, returning an empty string if the URL is missing or null. | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| A region-scoped org token where url (control silo) differs from region_url (the org's | ||
| region host). The region_url governs routing: it is preferred over the token's url and | ||
| overrides --url. Payload: {"url":"http://control.example","region_url":"http://region.example","org":"sentry"} | ||
| ``` | ||
| $ sentry-cli --auth-token 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 --url http://example.com info | ||
| ? failed | ||
| [..]WARN[..] Using http://region.example (embedded in token) rather than manually-configured URL http://example.com. To use http://example.com, please provide an auth token for this URL. | ||
| ... | ||
|
|
||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| This auth token has an empty URL. We expect the --url argument to take precedence here | ||
| This token has an empty url but a non-empty region_url. The region_url now governs | ||
| routing, so it overrides the --url argument (the warning references the region_url). | ||
| ``` | ||
| $ 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 this URL. | ||
| ... | ||
|
|
||
| ``` |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be the proper type, instead of using an empty string as a sentinel value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I guess the reason the clanker used String is that we're gonna need a new
opt_url_deserializerto do it that way