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

refactor(auth, gateway): use user_id over account_name #1674

Merged
merged 27 commits into from
Mar 15, 2024
Merged

Conversation

jonaro00
Copy link
Member

@jonaro00 jonaro00 commented Mar 8, 2024

Description of change

  • Rename AccountName -> UserId but use a type alias instead of a newtype with no parsing logic (IMO user_id should not be stricly parsed to allow more flexibility)
  • Still set the old XShuttleAccountName header manually (for old deployers), but with the new user id value ✔️
  • Use the claim to set user_id field in deployer, like the other backends do ✔️
  • Posting a user still uses account name, returns struct with a user id
  • Keeping get user by account name for console
  • Admin call to gw still includes account_name
  • Admin command logic not updated
  • Auth's create user CLI command inserts user with blank name and the provided string as user_id ✔️
  • New projects in gw get a blank account_name ✔️

How has this been tested? (if applicable)

✔️ = tested

Copy link
Contributor

@chesedo chesedo left a comment

Choose a reason for hiding this comment

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

Seems good. The metrics notes can be ignored - I just want to make sure we update them all

auth/migrations/0004_user_ids_part2.sql Show resolved Hide resolved
auth/src/api/builder.rs Outdated Show resolved Hide resolved
delete(delete_subscription),
)
.route_layer(from_extractor::<Metrics>())
.layer(
TraceLayer::new(|request| {
request_span!(
request,
request.params.account_name = field::Empty,
request.params.user_id = field::Empty,
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: this will affect metrics

auth/src/api/handlers.rs Outdated Show resolved Hide resolved
auth/src/api/handlers.rs Show resolved Hide resolved
@@ -33,15 +33,15 @@ impl Header for XShuttleAdminSecret {
}
}

pub static X_SHUTTLE_ACCOUNT_NAME: HeaderName = HeaderName::from_static("x-shuttle-account-name");
pub static X_SHUTTLE_USER_ID: HeaderName = HeaderName::from_static("x-shuttle-user-id");
Copy link
Contributor

Choose a reason for hiding this comment

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

Changing the header name will break old deployers iirc. So we can't do that

Copy link
Member Author

@jonaro00 jonaro00 Mar 8, 2024

Choose a reason for hiding this comment

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

This one is only used between auth and gateway, so we can. Nevermind, it is being used for setting the account.name trace field in deployer. However, if we're changing the value that is going to be recorded there (user_xyz instead of github-123), then it makes sense to change the name of the field (like I have in https://github.com/shuttle-hq/shuttle/pull/1674/files#diff-223aa4e48caca5d2fae2a4a306bcd0c99b8480713749f509eb60e858b9f73c04R166). Old deployers don't fail if it goes missing. It is possible to set both the old and new names+values of this header for backwards compat (it becomes pretty ugly tho... we can instead set both fields to the new user id, which is much simpler. Edit: did it).

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in 1edf407

let posthog_client = state.posthog_client.clone();
tokio::spawn(async move {
let event = async_posthog::Event::new("shuttle_api_start_deployment", &account_name);
let event = async_posthog::Event::new("shuttle_api_start_deployment", &user_id);
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: will affect metrics

@@ -869,9 +869,9 @@ impl ApiBuilder {
TraceLayer::new(|request| {
request_span!(
request,
account.name = field::Empty,
account.user_id = field::Empty,
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: will affect metrics

gateway/src/project.rs Outdated Show resolved Hide resolved
gateway/src/project.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@oddgrd oddgrd left a comment

Choose a reason for hiding this comment

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

The code changes LGTM, but we should figure out exactly how our metrics will be affected by these changes, and what we will need to do after the release.

auth/migrations/0004_user_ids_part2.sql Outdated Show resolved Hide resolved
deployer/src/handlers/mod.rs Show resolved Hide resolved
common/src/models/user.rs Show resolved Hide resolved
Copy link
Contributor

@chesedo chesedo left a comment

Choose a reason for hiding this comment

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

Quick extra question

auth/src/lib.rs Show resolved Hide resolved
only: main
# filters:
# branches:
# only: main
Copy link
Member Author

Choose a reason for hiding this comment

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

reminder

@jonaro00 jonaro00 merged commit 4937f4b into main Mar 15, 2024
29 of 32 checks passed
@jonaro00 jonaro00 deleted the token-user-id branch March 15, 2024 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants