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

feat(DCF-1446): Assign MFA policy on login #1106

Merged
merged 17 commits into from
Aug 25, 2023

Conversation

k-burt-uch
Copy link
Contributor

@k-burt-uch k-burt-uch commented Jun 28, 2023

Adds the mfa_policy on login when the configured claim and value are present in the user's id_token.

New Features

  • Enables support for identifying when users have authenticated with MFA.

Breaking Changes

Bug Fixes

Improvements

Dependency updates

Deployment changes

@@ -114,4 +114,4 @@ def post_login(self, user=None, token_result=None, id_from_idp=None):
user=user, refresh_token=refresh_token, expires=expires + issued_time
)

super(RASCallback, self).post_login(id_from_idp=id_from_idp)
super(RASCallback, self).post_login(token_result=token_result)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This says token_result but the return value from get_user_id isn't the id_token, its just a dict containing the username or email or both depending on the IdP used. I tagged the mfa property into that dict.

@@ -63,6 +66,7 @@ def __init__(
username_field="email",
email_field="email",
id_from_idp_field="sub",
app=flask.current_app,
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason for this vs from flask import current_app at the import level of the module?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I threw this on here because I found trying to emulate

with patch("fence.blueprints.data.indexd.flask.current_app", return_value=app):
with "fence.blueprints.login.base.flask.current_app" was still causing the app context error to appear.

@k-burt-uch k-burt-uch force-pushed the feat/DCF-1446-mfa-arborist-policy-assignment branch from 22e9421 to 3cd9608 Compare July 11, 2023 02:08
policy_id="mfa_policy",
)
else:
logger.info(f"Revoking mfa_policy for {username}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Open to your opinion but should we remove mfa_policy regardless of whether or not is_mfa_enabled is true. Im just thinking about a case where it was turned on and then turned off and the user still has the mfa policy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great point - done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Revisiting this: I reverted my changes here. I think its better if usersync cleans up the mfa_policy if mfa is turned off rather than during login.

@@ -42,7 +42,7 @@ def get_user_id(self, code):
claims = self.get_jwt_claims_identity(token_endpoint, jwks_endpoint, code)

if claims.get("sub"):
return {"sub": claims["sub"]}
return {"sub": claims["sub"], "mfa": self.has_mfa_claim(claims)}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also it took very little time to add this to each identity provider, however given the scope of work on DCF is limited to just RAS, I'm fine with reverting changes for the other idps. They're easy enough to insert as other IdPs are needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I say leave it, might avoid some confusion in the future

self.app.arborist.revoke_user_policy(
username=username,
policy_id="mfa_policy",
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What should we do if these arborist requests fail?

@@ -63,6 +66,7 @@ def __init__(
username_field="email",
email_field="email",
id_from_idp_field="sub",
app=flask.current_app,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I threw this on here because I found trying to emulate

with patch("fence.blueprints.data.indexd.flask.current_app", return_value=app):
with "fence.blueprints.login.base.flask.current_app" was still causing the app context error to appear.

policy_id="mfa_policy",
)
else:
logger.info(f"Revoking mfa_policy for {username}")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great point - done.

@k-burt-uch k-burt-uch force-pushed the feat/DCF-1446-mfa-arborist-policy-assignment branch 4 times, most recently from 66d2f95 to da8ba54 Compare August 2, 2023 23:28
@k-burt-uch k-burt-uch requested review from Avantol13 and BinamB August 3, 2023 14:16
@k-burt-uch k-burt-uch requested a review from Avantol13 August 3, 2023 19:41
Avantol13
Avantol13 previously approved these changes Aug 3, 2023
BinamB
BinamB previously approved these changes Aug 4, 2023
@k-burt-uch k-burt-uch deleted the feat/DCF-1446-mfa-arborist-policy-assignment branch August 25, 2023 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants