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

[WIP] Add extra check for dashboards behind auth #229

Merged
merged 18 commits into from
May 16, 2022

Conversation

viniciusdc
Copy link
Contributor

@viniciusdc viniciusdc commented Apr 29, 2022

closes #225

This does not solve #190 completely but presents a second validation step using only a single fetch which enables the request to be performed in the same browser session.

There are some points here that I would like to point out:

  • I am adding an extra condition here to check for gateway in the URL, but that's not ideal. I would like to have another opinion on which mechanic should be used here. I originally thought of passing an extra setting to the lab extension config to enable/disable this optional validation...
  • My knowledge of TS/JS is very premature, so I just added this simple branch here. But I think the best approach should have been something like an Interceptor to verify the response and then move accordingly to that...

Well, this issue is fixed in our case with these changes, but I would love to know what I can do to improve this contribution and have such a feature added to main 😄

Copy link
Collaborator

@ian-r-rose ian-r-rose left a comment

Choose a reason for hiding this comment

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

Thanks for this @viniciusdc, and sorry for the slow review! The logic looks sound to me (though I haven't been able to test this on a QHub-like deployment). My main request is that we expose this as a setting rather than a "gateway" URL check.

But I think the best approach should have been something like an Interceptor

I'm not familiar with this, can you elaborate?

src/dashboard.tsx Outdated Show resolved Hide resolved
src/dashboard.tsx Outdated Show resolved Hide resolved
@viniciusdc
Copy link
Contributor Author

viniciusdc commented May 9, 2022

Hi @ian-r-rose thanks for the comments above, I tried to add what you suggested, but I am not sure how to incorporate the changes made to DaskDashboardLauncher.IOptions into the testDaskDashboard new parameter.

@viniciusdc viniciusdc requested a review from ian-r-rose May 10, 2022 20:40
Copy link
Collaborator

@ian-r-rose ian-r-rose left a comment

Choose a reason for hiding this comment

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

Thanks @viniciusdc! Left a few style comments, but I think those could mostly be fixed by getting the pre-commit hooks working.

Regarding passing the option down to the dashboard check: perhaps my earlier suggestion of using an additional option in an IOption object was overkill, we could also just have a setter on the URLInput class (since that is the class that actually checks the URL). It's still an unfortunate number of steps, but one fewer than what I suggested before :). So it would look something like

  1. in onSettingsChanged read the new setting value
  2. Update that value using a new setter on URLInput
  3. The URLInput object then passes the setting value into the dashboard check utility function.

schema/plugin.json Outdated Show resolved Hide resolved
schema/plugin.json Outdated Show resolved Hide resolved
src/dashboard.tsx Outdated Show resolved Hide resolved
schema/plugin.json Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
@viniciusdc
Copy link
Contributor Author

Thanks @viniciusdc! Left a few style comments, but I think those could mostly be fixed by getting the pre-commit hooks working.

Regarding passing the option down to the dashboard check: perhaps my earlier suggestion of using an additional option in an IOption object was overkill, we could also just have a setter on the URLInput class (since that is the class that actually checks the URL). It's still an unfortunate number of steps, but one fewer than what I suggested before :). So it would look something like

  1. in onSettingsChanged read the new setting value
  2. Update that value using a new setter on URLInput
  3. The URLInput object then passes the setting value into the dashboard check utility function.

Hi @ian-r-rose, many thanks for the explanation. I tried to implement these changes (I think I understand a little bit more how this works 🙂 ). Let me know your thoughts about this. Thanks in advance

@viniciusdc viniciusdc requested a review from ian-r-rose May 11, 2022 19:18
Copy link
Collaborator

@ian-r-rose ian-r-rose left a comment

Choose a reason for hiding this comment

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

This is looking pretty good @viniciusdc, I just have one request to add get accessor, and I think this will be good to go!

src/dashboard.tsx Show resolved Hide resolved
src/dashboard.tsx Outdated Show resolved Hide resolved
@@ -301,9 +301,11 @@ export class URLInput extends Widget {
/**
* The in browser dashboard check for authenticated dashboards.
*/
get browserDashboardCheck(): boolean {
return this.browserDashboardCheck;
Copy link
Collaborator

Choose a reason for hiding this comment

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

These should be underscored attributes to not shadow the method names

Copy link
Contributor Author

@viniciusdc viniciusdc May 16, 2022

Choose a reason for hiding this comment

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

uhm I see, I was not sure about how to use _ in there. Thanks @ian-r-rose. So, just to be sure, I only need to change the methods inside the setter/getter, do I also need to change inside the class as well?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry to be terse! Typically what we do is add a private attribute (see the bottom of this class) which is prefixed with an underscore. It's a bit Java-ey, but hopefully not too bad.

So this line would become

return this._browserDashboardCheck;

and further down with the other private attributes you would have

private _browserDashboardCheck = false;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, just added that. Let me know if its correct 🙂

Copy link
Collaborator

@ian-r-rose ian-r-rose left a comment

Choose a reason for hiding this comment

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

This looks great, thanks for all your work on this @viniciusdc! Looks like pre-commit is unhappy, but for a reason unrelated to this PR, so I'll go ahead and fix that myself.

@viniciusdc, can I ask you to confirm that the PR in this state still works for your use-case, since I'm not set up to test it myself?

Also, cc @jsignell, who has requested a similar option in the past.

@viniciusdc
Copy link
Contributor Author

viniciusdc commented May 16, 2022

This looks great, thanks for all your work on this @viniciusdc! Looks like pre-commit is unhappy, but for a reason unrelated to this PR, so I'll go ahead and fix that myself.

@viniciusdc, can I ask you to confirm that the PR in this state still works for your use-case, since I'm not set up to test it myself?

Also, cc @jsignell, who has requested a similar option in the past.

Thanks @ian-r-rose for the review, I am currently testing it now will let you know once I finish. Just I question, where should I modify in the config the new attribute to propagate it?

@ian-r-rose
Copy link
Collaborator

where should I modify in the config the new attribute to propagate it?

As a user, you should be able to go to the JupyterLab settings editor (Settings -> Advanced Settings Editor) and find the "Dask" tab. That will open a JSON editor in which you can change the settings. These settings are stored in JSON files on disk (you can find the path to those files if you want to manually edit them by running jupyter lab paths. That's probably enough for our purposes here.

As a system admin, you'll want to distribute a settings file to your users that have the appropriate values for these settings. That way they won't need to change the settings themselves. This functionality is documented here.

@ian-r-rose
Copy link
Collaborator

Whoops, found one more place where we need to pass this._browserDashboardCheck to testDaskDashboard, mind if I push here @viniciusdc?

@viniciusdc
Copy link
Contributor Author

Hi @ian-r-rose, so I was able to toggle the options and I can see the table
image
the only problem is that it loses connection right after that

The connection to dask dashboard https://qhubstages2.qhub.dev/gateway/clusters/dev.6f863607b3684dd1b8191cf207877cd2/ has been lost

@ian-r-rose
Copy link
Collaborator

Okay, this looks good to me if you are happy with it @viniciusdc

@viniciusdc
Copy link
Contributor Author

I will check again with this addition, thanks for updating it 🙂

@ian-r-rose
Copy link
Collaborator

the only problem is that it loses connection right after that

Hmm, weird. Do you see anything in the Network tab in your browser dev tools?

@viniciusdc
Copy link
Contributor Author

viniciusdc commented May 16, 2022

the only problem is that it loses connection right after that

Hmm, weird. Do you see anything in the Network tab in your browser dev tools?

I can see two responses, one from individual-plots.json which contains the json:

Request URL: https://qhubstages2.qhub.dev/gateway/clusters/dev.6f863607b3684dd1b8191cf207877cd2/individual-plots.json
Request Method: GET
Status Code: 304 
Remote Address: 35.225.180.207:443
Referrer Policy: strict-origin-when-cross-origin

the second one though

https://qhubstages2.qhub.dev/user/test-user/dask/dashboard-check/https%3A%2F%2Fqhubstages2.qhub.dev%2Fgateway%2Fclusters%2Fdev.6f863607b3684dd1b8191cf207877cd2%2F?1652726806120
Request Method: GET
Status Code: 200 
Remote Address: 35.225.180.207:443
Referrer Policy: strict-origin-when-cross-origin

with the following body

isActive: false
plots: {}
url: "https://qhubstages2.qhub.dev/gateway/clusters/dev.6f863607b3684dd1b8191cf207877cd2/"

@ian-r-rose
Copy link
Collaborator

Getting two different responses suggests to me that the issue is with having two different checks to testDaskDashboard, one with true, one with false. Maybe you need to rebuild the extension with my last commit?

@viniciusdc
Copy link
Contributor Author

Getting two different responses suggests to me that the issue is with having two different checks to testDaskDashboard, one with true, one with false. Maybe you need to rebuild the extension with my last commit?

Sure, I think that might be the case as well, rebuilding now.

@viniciusdc
Copy link
Contributor Author

Hi @ian-r-rose, that did the trick. Thank you, its working flawlessly 😄

@ian-r-rose
Copy link
Collaborator

Hi @ian-r-rose, that did the trick. Thank you, its working flawlessly smile

Great, in it goes, thanks @viniciusdc!

@ian-r-rose ian-r-rose merged commit fc8de03 into dask:main May 16, 2022
@viniciusdc
Copy link
Contributor Author

Thanks for all the help with this @ian-r-rose!! Hope to contribute more in the future with you all!

@ian-r-rose
Copy link
Collaborator

Thanks again for this @viniciusdc! I've just published version 5.3.0 of dask-labextension which includes this feature. Please let me know if any follow-up work is needed!

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.

Dask Lab-extension not connecting with dask-gateway dashboards
2 participants