Skip to content

Conversation

@peterdudfield
Copy link
Collaborator

@peterdudfield peterdudfield commented Apr 20, 2022

Pull Request

Description

  • Add Auth0 authentication to all routes
  • add pv route back in

Screenshot 2022-04-20 at 14 39 37

Screenshot 2022-04-20 at 14 39 42

TODO need to update nowcasting APP to get bearer token

Fixes #2 and #130

How Has This Been Tested?

  • unittests

  • tested locally

  • Yes

If your changes affect data processing, have you plotted any changes? i.e. have you done a quick sanity check?

  • Yes

Checklist:

  • My code follows OCF's coding style guidelines
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked my code and corrected any misspellings

@peterdudfield peterdudfield self-assigned this Apr 20, 2022
@codecov-commenter
Copy link

codecov-commenter commented Apr 20, 2022

Codecov Report

Merging #83 (e95b6de) into main (96cca6c) will decrease coverage by 0.30%.
The diff coverage is 96.96%.

@@            Coverage Diff             @@
##             main      #83      +/-   ##
==========================================
- Coverage   95.66%   95.36%   -0.31%     
==========================================
  Files          17       18       +1     
  Lines         508      539      +31     
==========================================
+ Hits          486      514      +28     
- Misses         22       25       +3     
Impacted Files Coverage Δ
src/auth_utils.py 85.71% <85.71%> (ø)
src/gsp.py 100.00% <100.00%> (ø)
src/main.py 84.48% <100.00%> (ø)
src/national.py 100.00% <100.00%> (ø)
src/system.py 100.00% <100.00%> (ø)
src/tests/conftest.py 100.00% <100.00%> (ø)
src/tests/test_gsp.py 100.00% <100.00%> (ø)
src/tests/test_main.py 100.00% <100.00%> (ø)
src/tests/test_merged_routes.py 100.00% <100.00%> (ø)
src/tests/test_national.py 100.00% <100.00%> (ø)
... and 1 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@flowirtz flowirtz changed the title Issue/2 auth0 Add Auth0 authentication to all routes Apr 20, 2022
@flowirtz flowirtz self-requested a review April 20, 2022 14:41
requirements.txt Outdated
geopandas
aiofiles
pytest-cov
fastapi-auth0
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, I'm not a big fan of introducing this dependency: fastapi-auth0.

  • maintained by someone not affiliated with Auth0
  • last release in 12/'21 (>4 months ago)
  • current stable version is 0.3.0 which seems very early
  • 96 stars on GitHub is very low

Seeing as authentication is critical, paired with the points above, I'd be keen not to introduce this dependency into our production app.

I'd suggest that instead we follow the official Auth0 guide here. What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok- I can give that ago, perhaps Ill do on a different branch incase its too hard

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The guide there only does Bearing token ID, and doesnt do 0Auth with google login. I find the Google log in partiruclar useful.

it was acknowledged by Auth0 though - https://community.auth0.com/t/using-auth0-with-fastapi/58764

i'm happy to pin the version to 0.3.0, so there are not security leaks in the future.
I can also copy out the code from that repo - its only 200 lines. This seems the wrong way to do it though

src/gsp.py Outdated
@router.get(
"/forecast/one_gsp/{gsp_id}",
response_model=Forecast,
dependencies=[Depends(get_auth_implicit_scheme())],
Copy link
Contributor

Choose a reason for hiding this comment

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

By explicitly requiring auth on every endpoint it's very easy for us to create an endpoint where we forget about this requirement. If possible, I'd prefer to implement the auth as a middleware. We need to require auth on every single endpoint anyways, so if we implement it as a middleware that would be satisfied.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I take your point, we may miss one.

Ill have a go at putting as middleware,
if we wanted to leave some things public, thenI dont think we should do this. But I think its fine putting everything private

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Althought actually we might want to have one end point not authenticed, so we can easily do a quick check to see if they api is up and running

src/gsp.py Outdated
"""

logger.info(f"Get truth values for gsp id {gsp_id} and regime {regime}")
logger.info(f"Get truth values for gsp id {gsp_id} and regime {regime} for {user}")
Copy link
Contributor

Choose a reason for hiding this comment

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

What is user here?
We don't want to be logging PII (Personally Identifiable Information), so maybe, if this user includes a full name and/or email, we could be logging the user id instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure, perhaps once reworked, ill have a look.
I was thinking it would print out the 'full name'/ 'component name', so we have a little bit of an idea who is calling the api in the logs

src/gsp.py Outdated
"""

logger.info("Getting all GSP boundaries")
logger.info(f"Getting all GSP boundaries for {user}")
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above and more below

src/main.py Outdated

app.include_router(gsp_router, prefix=f"{v0_route}/gsp")
# app.include_router(pv_router, prefix=f"{v0_route}/pv")
app.include_router(pv_router, prefix=f"{v0_route}/pv")
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed with @JackKelly on Slack previously: We should never be exposing this data, no matter if it's behind authentication or not. We're not the data owners and neither do we have the right to publish it, according to our license agreement.

While the authentication is nice, as it won't make the data publicly available, we are not allowed to redistribute this raw data to our customers in any way.

src/pv.py Outdated
@@ -1,42 +1,50 @@
""" Expose PV data """
Copy link
Contributor

Choose a reason for hiding this comment

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

see comment above, this should be deleted

peterdudfield and others added 10 commits April 20, 2022 16:12
Co-authored-by: Flo <6052785+flowirtz@users.noreply.github.com>
Co-authored-by: Flo <6052785+flowirtz@users.noreply.github.com>
…auth0

# Conflicts:
#	src/gsp.py
#	src/main.py
#	src/tests/test_gsp.py
@braddf braddf merged commit bfd4727 into main Nov 7, 2022
@peterdudfield peterdudfield deleted the issue/2-auth0 branch March 11, 2024 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

Design and Add Access Control Restrictions to Nowcasting API

5 participants