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

fix #4106: proprietary oauth #4224

Merged
merged 11 commits into from
Jun 20, 2022
Merged

fix #4106: proprietary oauth #4224

merged 11 commits into from
Jun 20, 2022

Conversation

rorour
Copy link
Contributor

@rorour rorour commented Mar 9, 2022

This branch is based on 3654-moderate-jupyterhub-user-creations. Please review and merge #4211 first.

@rorour rorour requested review from robnagler and e-carlin March 9, 2022 17:43
@rorour rorour force-pushed the 4106-proprietary-oauth branch from 87ea297 to 632cefb Compare March 9, 2022 22:45
@rorour rorour changed the base branch from master to 3654-moderate-jupyterhub-user-creations April 11, 2022 16:38
@rorour rorour force-pushed the 4106-proprietary-oauth branch from 632cefb to c0eebbb Compare April 11, 2022 17:43
@e-carlin e-carlin force-pushed the 4106-proprietary-oauth branch 5 times, most recently from 6653108 to 9ad66cf Compare April 12, 2022 14:51
@e-carlin e-carlin force-pushed the 4106-proprietary-oauth branch from 9ad66cf to 20574b9 Compare April 21, 2022 15:35
@e-carlin e-carlin changed the base branch from 3654-moderate-jupyterhub-user-creations to master April 21, 2022 15:38
@e-carlin e-carlin changed the base branch from master to 3654-moderate-jupyterhub-user-creations April 28, 2022 21:04
@e-carlin e-carlin changed the base branch from 3654-moderate-jupyterhub-user-creations to master April 28, 2022 21:04
@e-carlin e-carlin force-pushed the 4106-proprietary-oauth branch from 20574b9 to f3b2cd9 Compare April 28, 2022 21:34
@e-carlin e-carlin changed the base branch from master to 3654-moderate-jupyterhub-user-creations April 28, 2022 21:35
@e-carlin e-carlin changed the base branch from 3654-moderate-jupyterhub-user-creations to master April 28, 2022 21:36
@e-carlin e-carlin force-pushed the 4106-proprietary-oauth branch from f3b2cd9 to ebcd13a Compare April 29, 2022 20:06
@e-carlin e-carlin force-pushed the 4106-proprietary-oauth branch 3 times, most recently from e084efd to 7b63eaa Compare May 30, 2022 21:40
@e-carlin
Copy link
Member

Blocked waiting on flash center to allow our non-tls secured dev endpoint to get a response. Then need to finish https://github.com/radiasoft/sirepo/pull/4224/files#diff-6872e86bbaf9783b9521a2d7bc8efbc06219ec4d6e34d64031682626e3a13ac7R24

@e-carlin e-carlin force-pushed the 4106-proprietary-oauth branch 2 times, most recently from 135a288 to 60bd851 Compare May 31, 2022 22:32
@e-carlin
Copy link
Member

@robnagler this is working. I'd like another review because of the security impact.

One decision we made along the way was to not refresh tokens. Instead just have users log in again once expired. For flash the tokens expire after one hour so this will lead to an annoying ui (need to log in to flash center every hour). Should we implement using refresh tokens or go with just re-login?

@robnagler
Copy link
Member

Yes implement refresh tokens. It's unfortunately that they didn't set the default to something higher. First find out how many refreshes you get. Also, a refresh only works, I believe, if the user is active. Therefore, even if we implement refreshes, if they close their window and open it again, it might require a relogin

@e-carlin
Copy link
Member

e-carlin commented Jun 1, 2022

Sent an email asking for a bump to 24hour expiry. Will implement refresh if the expiry can't be increased.

@e-carlin
Copy link
Member

e-carlin commented Jun 3, 2022

Entering invalid credentials and clicking the "deny access" button on the flash login page leads to what looks like an approved authentication response (I would expect the ui to say username/password incorrect or at the very least a response with a payload saying the request was not approved). I've reached out to the flash folks and I'm waiting on a response. This blocks the release.

@e-carlin e-carlin force-pushed the 4106-proprietary-oauth branch from 60bd851 to e96f1e3 Compare June 6, 2022 15:07
@e-carlin e-carlin force-pushed the 4106-proprietary-oauth branch 5 times, most recently from aafc872 to 16129a9 Compare June 10, 2022 00:10
@e-carlin
Copy link
Member

@robnagler I think this is ready to merge. Please give it another review.

@e-carlin e-carlin force-pushed the 4106-proprietary-oauth branch from 16129a9 to 62f2668 Compare June 10, 2022 14:59
Copy link
Member

@robnagler robnagler left a comment

Choose a reason for hiding this comment

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

It was easier to edit. I think the code is right. I removed some proprietary information.

t = sirepo.template.assert_sim_type(sim_type)
if t not in sirepo.feature_config.auth_controlled_sim_types():
return
#QUESTION(robnagler) I think this is sufficient, that is, the tests can be reversed
Copy link
Member

Choose a reason for hiding this comment

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

This is the only thing I'm concerned about. LMK what you think.

Copy link
Member

Choose a reason for hiding this comment

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

That doesn't workin in the api_checkAuthJupyterhub case. That API is allow_visitor which means that this check is always True and we return when we should really be prompting to moderate.

Thoughts ccaa8f6 ? I don't love adding another api_perm and I struggled to find a name for it...

@@ -12,7 +12,7 @@
description='accelerator code gui',
install_requires=[
'Flask==2.0.3',
'SQLAlchemy',
'SQLAlchemy>=1.4',
Copy link
Member

Choose a reason for hiding this comment

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

Should we put a test in for why we have to pin versions? Someday we'll want to upgrade and it would be helpful to know why we pinned it in the first place

t = sirepo.template.assert_sim_type(sim_type)
if t not in sirepo.feature_config.auth_controlled_sim_types():
return
#QUESTION(robnagler) I think this is sufficient, that is, the tests can be reversed
Copy link
Member

Choose a reason for hiding this comment

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

That doesn't workin in the api_checkAuthJupyterhub case. That API is allow_visitor which means that this check is always True and we return when we should really be prompting to moderate.

Thoughts ccaa8f6 ? I don't love adding another api_perm and I struggled to find a name for it...

@e-carlin e-carlin requested a review from robnagler June 13, 2022 17:50
@@ -33,15 +34,15 @@


class API(sirepo.api.Base):
@sirepo.api_perm.allow_visitor
@sirepo.api_perm.manual_permission_check
Copy link
Member

Choose a reason for hiding this comment

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

What I think is going on is that this function is doing too much. It should be @sirepo.api_perm.require_user which will throw an exception, and then the code in sirepo.jupyterhub would do the parsing of the response. It's all inside the sirepo repo. Then you wouldn't have to catch anything in this module. All the exceptions would cause a Response to go back to the sirepo.jupyterhub.authenticate. The fall through case (creating the juptyerhub user) would also do the right thing.

Copy link
Member

Choose a reason for hiding this comment

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

How will sirepo.jupyterhub build the urls? We have access to self.sirepo_uri but all the methods like uri_for_api and local_route access the flask object directly which we can't do because we are outside the flask context.

Copy link
Member

Choose a reason for hiding this comment

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

The schema is available, but not quite. It's what's necessary to map URIs from APIs. For now, these mappings could be hardwired in sirepo.jupyterhub, since we need to get this PR out.

I don't like adding the new API permission. Another approach is to use self.call_api and have a "hidden" api that api_checkAuthJupyterhub calls and wraps in a proper response. One things we could do to fix the SRException mess is to include a header in the response (X-Sirepo-SRException) that contains a serialized version of the exception so the HTML doesn't need to be parsed (which isn't terrible, and could be better encapsulated).

Anyway, I prefer the first approach and to get to work pulling apart the request dependent (external) from the static stuff (schema and args).

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Thoughts on adding sirepo_uri? Then we can re-use the code without adding another place where we handle creation of uris

@e-carlin e-carlin requested a review from robnagler June 14, 2022 21:37
Copy link
Member

@robnagler robnagler left a comment

Choose a reason for hiding this comment

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

See question about sirepo_uri.


def _maybe_html_redirect(response):
m = re.search(r'window.location = "(.*)"', pkcompat.from_bytes(response.content))
m and self._redirect(handler, f'{self.sirepo_uri}{m.group(1)}')
Copy link
Member

Choose a reason for hiding this comment

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

Does there need to be a sirepo_uri? Doesn't the redirect just work on / without http://....?

Copy link
Member

Choose a reason for hiding this comment

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

You're right, it isn't needed. I removed it from everywhere and made the uri building code external=False and to just use '/' in that case (not call into flask) 579a421

@e-carlin e-carlin requested a review from robnagler June 15, 2022 15:19
@robnagler
Copy link
Member

@e-carlin I'll let you merge

@e-carlin e-carlin merged commit d0b2235 into master Jun 20, 2022
@e-carlin e-carlin deleted the 4106-proprietary-oauth branch June 20, 2022 15:48
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