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

[24.0] Fix authentication error for anonymous users querying jobs #18333

Conversation

davelopez
Copy link
Contributor

Fixes #18331

I added the check at the API level (to fail fast) and at the manager level in case it gets called from somewhere else.

How to test the changes?

  • I've included appropriate automated tests.
  • This is a refactoring of components with existing test coverage.
  • Instructions for manual testing are as follows:
    1. [add testing steps and prerequisites here if you didn't write automated tests covering all your changes]

License

  • I agree to license these and all my past contributions to the core galaxy codebase under the MIT license.

@galaxyproject-sentryintegration

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: lib/galaxy/managers/jobs.py

Function Unhandled Issue
index_query AttributeError: 'NoneType' object has no attribute 'id' /a...
Event Count: 7
📄 File: lib/galaxy/webapps/galaxy/services/jobs.py (Click to Expand)
Function Unhandled Issue
index AttributeError: 'NoneType' object has no attribute 'id' /a...
Event Count: 7
---

Did you find this useful? React with a 👍 or 👎

@@ -111,6 +112,8 @@ def index_query(self, trans, payload: JobIndexQueryPayload) -> sqlalchemy.engine
Otherwise this will only return the user's jobs or all jobs if the requesting
user is acting as an admin.
"""
if trans.user is None:
Copy link
Member

Choose a reason for hiding this comment

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

Can we instead query the jobs using the session id or current session history ? I think there's no reason anon user can't see their jobs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! I forgot there was a way to differentiate jobs from other anonymous users. I'll give it a try 👍

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 tried to write an API or selenium test but I couldn't figure out how to use the session. I manually tested and seems to work though.

@davelopez davelopez marked this pull request as draft June 6, 2024 08:31
@davelopez davelopez force-pushed the 24.0_fix_500_for_anonymous_job_listing branch from 3370b23 to 2e91272 Compare June 6, 2024 12:59
Co-authored-by: Nicola Soranzo <nicola.soranzo@earlham.ac.uk>
@davelopez davelopez marked this pull request as ready for review June 6, 2024 14:49
@mvdbeek mvdbeek merged commit f38461b into galaxyproject:release_24.0 Jun 7, 2024
50 checks passed
if trans.galaxy_session and trans.galaxy_session.current_history_id:
history_id = trans.galaxy_session.current_history_id
else:
return None
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if we should raise an AuthenticationRequired exception here instead, so the error is not hidden from the user.

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 not an error, if a session doesn't have a history it also doesn't have any jobs.

Copy link
Member

Choose a reason for hiding this comment

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

But None is returned also is trans.galaxy_session is None.

Copy link
Member

Choose a reason for hiding this comment

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

Which is fine and not a error ?

Copy link
Member

Choose a reason for hiding this comment

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

You could as well query some public thing, like jobs belonging to a history, raising an exception here feels very unpredictable.

Copy link
Member

Choose a reason for hiding this comment

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

Then I don't understand the changes in lines 131-133 above: if we want a session-less user to be able to view public history jobs, we should overwrite history_id only when it's None .

Copy link
Member

Choose a reason for hiding this comment

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

That is a good point, we might want to instead filter on the job itself using the session id.

Copy link
Member

Choose a reason for hiding this comment

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

If history_id is passed in the API payload, the job's history accessibility is checked on the jobs returned by this method at

if check_security_of_jobs and not security_check(trans, job.history, check_accessible=True):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the catch! I'll follow up with the proposed change 👍

@davelopez davelopez deleted the 24.0_fix_500_for_anonymous_job_listing branch June 10, 2024 09:53
@jdavcs jdavcs added this to the 24.1 milestone Jun 19, 2024
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.

None yet

4 participants