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

ATO-1248: Add AuthSession To UserContext #5590

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

ghost
Copy link

@ghost ghost commented Nov 27, 2024

What

Added AuthSession to UserContext. The old Session lives on the UserContext so this will help us switch over to the AuthSession with less refactoring.

How to review

Code Review

Notes

The auth session has been added as an optional field for the time being. This is related to how the auth session is currently initialised/updated in the start handler where the user context is used to construct one of the inputs. With a bit of refactoring we should be able to make it non-optional once the start handler is no longer dependant on the session.

@ghost ghost force-pushed the ATO-1248/Add-AuthSession-To-UserContext branch 9 times, most recently from e3e522c to df51ed0 Compare November 28, 2024 11:40
@ghost ghost marked this pull request as ready for review November 28, 2024 12:07
@ghost ghost requested review from a team as code owners November 28, 2024 12:07
Copy link
Contributor

@Ryan-Andrews99 Ryan-Andrews99 left a comment

Choose a reason for hiding this comment

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

Have looked through the first few of the handlers and most of them don't have the read permissions for the auth session table. All the handlers which inherit from the BaseFrontendHandler will need this as it is querying the table to check if there is an auth session.

Also would it be possible to maybe break this PR up into several commits which apply the changes to each lambda. Just makes this PR less scary to review 😄

@ghost ghost force-pushed the ATO-1248/Add-AuthSession-To-UserContext branch 6 times, most recently from 74e34f9 to 566d2c1 Compare November 28, 2024 17:44
Ryan-Andrews99
Ryan-Andrews99 previously approved these changes Dec 9, 2024
Copy link
Contributor

@Ryan-Andrews99 Ryan-Andrews99 left a comment

Choose a reason for hiding this comment

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

Approved awaiting auth review

@@ -45,6 +49,10 @@ public Session getSession() {
return session;
}

public AuthSessionItem getAuthSession() {
return authSession.orElseThrow(() -> new RuntimeException("Auth session not set."));
Copy link
Contributor

Choose a reason for hiding this comment

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

In what circumstance would this happen? We're trying no to throw exceptions but rather return http error responses, because exceptions cause cold starts.

Copy link
Author

@ghost ghost Dec 9, 2024

Choose a reason for hiding this comment

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

This is a good question. I actually made a mistake and was calling buildUserContext with a null auth session from StartHandler instead of optional.empty (fixed now). From the other handlers, it will always be present as the base frontend handler returns a http error if the auth session isn't present. The reason for making it optional is really just a stopgap, as if you look in the main handle method in StartHandler, the auth session is constructed with upliftRequired as a parameter, but upliftRequired is computed off of the user context, which otherwise requires an auth session. The construction loop only effects this handler and having discussed it with Bill we thought it's something to be considered in a future refactor. So in summary, this should never be thrown in practise.

@ghost ghost force-pushed the ATO-1248/Add-AuthSession-To-UserContext branch from 566d2c1 to 5bba2f4 Compare December 9, 2024 10:06
Copy link

sonarqubecloud bot commented Dec 9, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
4 New Code Smells (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@@ -13,6 +13,7 @@ module "frontend_api_account_interventions_role" {
aws_iam_policy.dynamo_client_registry_read_access_policy.arn,
aws_iam_policy.redis_parameter_policy.arn,
module.oidc_txma_audit.access_policy_arn,
aws_iam_policy.dynamo_auth_session_read_policy.arn,
Copy link
Contributor

Choose a reason for hiding this comment

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

This (and all new policies) needs to be added at the end of the list of policies in auth's roles. If the order is changed, the role is rewritten while live (not ideal infrastructure), meaning we'd have brief downtime on this lambda while it's permissions were updated. Concat can take multiple arguments, so it's best to have this added after the ticf_cri_lambda_invocation_policy just below.

Copy link
Author

Choose a reason for hiding this comment

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

done

@ghost ghost force-pushed the ATO-1248/Add-AuthSession-To-UserContext branch from 5bba2f4 to 70799fb Compare December 9, 2024 17:28
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