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

[DO NOT MERGE] Demonstrate how to allow anonymous access to data. #76

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jgadling
Copy link
Contributor

This is a proposal for how Platformics can support making some data public.
It shouldn't be merged into this repo, but I'm asking for feedback about whether this is an acceptable solution for #73

Currently our codegen adds a dependency to every resolver called require_auth_principal, which essentially checks for a valid auth token and raises an exception if there isn't one available:
https://github.com/chanzuckerberg/platformics/blob/main/platformics/api/core/deps.py#L107-L112

This is OK for API's that only need to be accessible to authenticated users, but it falls over when an API also needs to be accessible to the public.

However, FastAPI provides a way to override dependencies, and main.py is controlled by application authors (that is, it isn't code-gen'd!) so we can manipulate the dependencies of our FastAPI application and override platformics default behaviors.

In this example, we're overriding require_auth_principal to return a "dummy" anonymous principal that only has read access to certain collections that we deem to be publicly accessible.

Is this a reasonable workaround to allow public access?

Copy link
Collaborator

@j-x-han j-x-han 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 pretty reasonable to me!

From my understanding, this makes everything in the specified collection publicly accessible -- would there be cases where we would only want some subset of entities in a collection to be public? (ex: all models in the collection are public, but not the datasets). Or would the recommendation be to put them in separate collections?

@jgadling
Copy link
Contributor Author

This looks pretty reasonable to me!

From my understanding, this makes everything in the specified collection publicly accessible -- would there be cases where we would only want some subset of entities in a collection to be public? (ex: all models in the collection are public, but not the datasets). Or would the recommendation be to put them in separate collections?

For the use case I have right now, making a collection entirely public is enough. But pretty soon I think that we're going to need to supply a way to override get_resource_query to handle more elaborate use cases.

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

2 participants