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

DIG-1887, DIG-1890, DIG-1892, DIG-1897: refactoring authz, adding preapproved list #151

Merged
merged 14 commits into from
Jan 27, 2025

Conversation

daisieh
Copy link
Member

@daisieh daisieh commented Jan 24, 2025

  • Moved a lot of the auth methods to the candigv2-authx library for consistency
  • Added preapproved users methods
  • Refactored and renamed a bunch of the dac-related ingest methods

Tested in CanDIG/CanDIGv2#938

Copy link
Contributor

@OrdiNeu OrdiNeu left a comment

Choose a reason for hiding this comment

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

Unsure if this is because of this PR but when I try to POST to /ingest/user/pending, it leads to a 307 redirect to the internal URL of ingest.

(candig) 16:04 fnguyen@fnguyen-worktop:~/Documents/CanDIGv2$ curl -v candig.docker.internal:5080/ingest/user/pending/ -H "Authorization: Bearer $TOKEN"
* Host candig.docker.internal:5080 was resolved.
* IPv6: ::1
* IPv4: (none)
*   Trying [::1]:5080...
* Connected to candig.docker.internal (::1) port 5080
> GET /ingest/user/pending/ HTTP/1.1
> Host: candig.docker.internal:5080
> User-Agent: curl/8.5.0
> Accept: */*
> Authorization: Bearer ...
> 
< HTTP/1.1 307 Temporary Redirect
< Content-Length: 0
< Date: Fri, 24 Jan 2025 21:04:12 GMT
< Location: http://candig-ingest:1235/user/pending
< Server: uvicorn
< X-Ratelimit-Limit: 10000
< X-Ratelimit-Remaining: 9999
< X-Ratelimit-Reset: 1737756253
< 
* Connection #0 to host candig.docker.internal left intact

response = list(response["programs"].values())
print(response)
return {"results": response}, status_code
user_id = authx.auth.get_user_id(request)
Copy link
Contributor

Choose a reason for hiding this comment

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

NameError: name 'request' is not defined

ingest_operations.py Outdated Show resolved Hide resolved
user_result["site_roles"].append(role_type)

user_result["program_authorizations"] = {}
opa_permissions, status_code = authx.auth.get_opa_permissions(bearer_token=token, user_token=user_result["userinfo"]["sample_jwt"])
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit confused now; the return value of ingest/user/me is 200 if the user exists, 404 if the user doesn't exist, and then... how do I tell if I'm a pending user?

Copy link
Member Author

Choose a reason for hiding this comment

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

You would try to request pending access again, /ingest/pending/request...if you get a 200, you're already pending.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we get a non-destructive way of checking pending status? When the user enters the site we want to show them a different screen depending on whether or not they're already pending.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't understand how it's destructive: if you repeatedly hit the pending/request endpoint, you just get repeated 200 OKs...nothing changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

image
When the user first visits the page, they should be given the screen on the left. When they click the button to POST to /ingest/pending/request, they should be given the screen on the right. From then onwards, whenever they check the page, they should immediately be given the screen on the right.

The problem I'd run into is that it's impossible to determine which screen the user should be given when they load up the page without inadvertently signing them up to be on the pending list, or via using some sort of cookie/local storage check (which would fail if they checked it in a different browser or on a different computer).

Copy link
Contributor

Choose a reason for hiding this comment

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

When we last discussed this I had thought there was some GET endpoint with a different status code depending on the user's authorization state -- was it only the POST endpoint that was planned?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I see. I'll try to add another endpoint then.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added GET to /user/pending/{user_id}. "me" works to get the status of yourself. (had to add a bit in Opa; please pull the opa commit in CanDIG/CanDIGv2#938 and recompose opa.

@daisieh
Copy link
Member Author

daisieh commented Jan 24, 2025

Unsure if this is because of this PR but when I try to POST to /ingest/user/pending, it leads to a 307 redirect to the internal URL of ingest.

(candig) 16:04 fnguyen@fnguyen-worktop:~/Documents/CanDIGv2$ curl -v candig.docker.internal:5080/ingest/user/pending/ -H "Authorization: Bearer $TOKEN"
* Host candig.docker.internal:5080 was resolved.
* IPv6: ::1
* IPv4: (none)
*   Trying [::1]:5080...
* Connected to candig.docker.internal (::1) port 5080
> GET /ingest/user/pending/ HTTP/1.1
> Host: candig.docker.internal:5080
> User-Agent: curl/8.5.0
> Accept: */*
> Authorization: Bearer ...
> 
< HTTP/1.1 307 Temporary Redirect
< Content-Length: 0
< Date: Fri, 24 Jan 2025 21:04:12 GMT
< Location: http://candig-ingest:1235/user/pending
< Server: uvicorn
< X-Ratelimit-Limit: 10000
< X-Ratelimit-Remaining: 9999
< X-Ratelimit-Reset: 1737756253
< 
* Connection #0 to host candig.docker.internal left intact

In this situation, are you trying to request pending access? what are you POSTing?

Copy link
Contributor

@OrdiNeu OrdiNeu left a comment

Choose a reason for hiding this comment

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

LGTM ✔️

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.

2 participants