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

Signed URLs for tiles endpoint and ipyleaflet tile viewer #603

Merged
merged 13 commits into from
Nov 30, 2021

Conversation

banesullivan
Copy link
Contributor

These changes enable support for embedding the authentication token as a query parameter. This is for use cases where we want to "pre-sign" a URL for handing off to 3rd party software. Specifically, this is for the use case of generating a pre-signed tile URL for an image so that we can visualize it interactively with ipyleafelt.

@mvandenburgh and @AlmightyYakob, would you please review the changes to the authentication and python client?


Here is an example with a new helper method in the rgd_imagery_client:

from ipyleaflet import Map, projections, ScaleControl, FullScreenControl
from rgd_client import create_rgd_client

client = create_rgd_client(username='email@kitware.com', api_url='http://localhost:8000/api')

t = client.imagery.get_leaflet_tile_source(18, band=1, palette='matplotlib.Viridis_20', vmin=50, vmax=200)

m = Map(
        center=(37.7249511580583, -122.27230466902257), 
        zoom=9, crs=projections.EPSG3857, 
       )

m.add_layer(t)
m

Screen Shot 2021-11-20 at 11 34 08 AM

@jjnesbitt jjnesbitt changed the title Auth token param and ipyleaflet tile veiwer Auth token param and ipyleaflet tile viewer Nov 22, 2021
@jjnesbitt
Copy link
Member

@banesullivan and I discussed this offline, and we decided to change this approach to utilize presigned URLs, as including the entire auth token in the URL presents big security vulnerabilities. We came across this package, which seems to implement exactly what we're looking for. If nothing else it's a good starting point.

@banesullivan banesullivan self-assigned this Nov 22, 2021
@banesullivan
Copy link
Contributor Author

banesullivan commented Nov 22, 2021

To mitigate these concerns, I added a new SignatureView to create expiry signatures per user and a new SignedURLRestViewMixin that can be added to downstream views which can use this SignedURLAuthentication that can be manually added to downstream view's authentication_classes.

At present, I only enable this functionality for the tiles endpoint and I think it should remain an opt-in feature. That way if someone gets ahold of a signature with malicious intent, they cannot use it to access any POST endpoints.

@mcovalt, would you please review?

@banesullivan banesullivan changed the title Auth token param and ipyleaflet tile viewer Signed URLs for tiles endpoint and ipyleaflet tile viewer Nov 22, 2021
Copy link
Contributor

@mcovalt mcovalt 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 good!

signer = UserSigner()
signature = signer.sign(user=self.request.user)
param = getattr(settings, 'RGD_SIGNED_URL_QUERY_PARAM', 'signature')
return response.Response({param: signature})
Copy link
Member

Choose a reason for hiding this comment

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

I think it'd be good to include an expires_at param here, indicating the unix timestamp this signature expires as. I'll open an issue so it can be addressed separately.

Copy link
Member

Choose a reason for hiding this comment

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

@banesullivan banesullivan merged commit a3195a9 into main Nov 30, 2021
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.

None yet

4 participants