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

Token scoping #314

Open
dchoi27 opened this issue Aug 5, 2021 · 14 comments
Open

Token scoping #314

dchoi27 opened this issue Aug 5, 2021 · 14 comments
Labels
Epic kind/enhancement A net-new feature or improvement to an existing feature need/approach P1 High: Likely tackled by core team if no one steps up pi/upload-v2 stack/api-protocols

Comments

@dchoi27
Copy link
Contributor

dchoi27 commented Aug 5, 2021

Issues related to how tokens are scoped (permissions, how users interact with multiple tokens, etc.).

@dchoi27 dchoi27 added the Epic label Aug 5, 2021
@dchoi27
Copy link
Contributor Author

dchoi27 commented Aug 5, 2021

@alanshaw know you had some thoughts related to token permissions, feel free to make a new issue and add to this epic!

@alanshaw
Copy link
Member

alanshaw commented Aug 13, 2021

Problem

At the moment, developers building web applications are likely to bundle a Web3.Storage token together with the app. This allows users to interact directly with the Web3.Storage service from their browser. However it has some issues:

  • Token is openly available in the application source code. Anyone can take the token and use it to upload their own content.
  • The token when used to list uploads does so on an account level so you see uploads that were created using other tokens.

The alternatives to bundling a token currently are:

  1. Applications ask users to sign up at web3.storage and obtain a token for use. This is terrible UX.
  2. Application developers create their own API and proxy uploads from their users. This is a lot of work and means that content is funneled through a centralized point that is maybe not as well prepared for the amount of traffic it may receive.

Proposal: Token Scoping and Token Management API

Developers simply have to implement an API in their app that creates "user" scoped tokens. It uses an "admin" scoped token to do this. The "user" token may be stored in local storage for use by the web app. It is a centralized component of the user's app, but avoids token bundling, asking the user for a token and allows uploads listings that are filtered to the token that performed the upload.

This feature has been requested by users in: #371

Scopes

Public permissions are implied.

  1. Admin
    • Create user token
    • Delete user token
    • List user tokens
    • Upload
    • List all uploads
    • Delete any upload
  2. User
  3. Legacy (existing tokens already created)
    • Upload
    • List all uploads
    • Delete owned upload

Work Involved

  • The list uploads endpoint should fetch uploads belonging to a token if it has the "user" scope, else everything for the account
  • The delete endpoint should allow deletion of any content from a token with "admin" scope
  • The create token endpoint should...
    • Accept a scope param that allows magic.link tokens to create "admin" or "user" scoped tokens
    • Allow a token with "admin" scope to create a "user" scoped token
  • The delete token endpoint should allow a token with "admin" scope to delete (revoke) a "user" scoped token
  • The list tokens endpoint should allow a token with "admin" scope to list all "user" scoped tokens
  • UI work for selecting scope of token to create from the website and showing scopes in token list

Alternative

Leverage magic.link's blockchain auth and allow authentication using metamask, allowing an account and token to be created on Web3.Storage entirely from the browser.

This flow requires users to install the metamask plugin which is a hurdle and may not be preferable to all dapp developers.

We should do this alternative also though!

@atopal
Copy link
Contributor

atopal commented Aug 13, 2021

My hunch is that the issue is having to run a back-end service at all. Browser only apps would still have to ship with the admin token or ask users to create a web3.storage account. That said, I'd say let's go for it, because the current practice is indeed problematic, even for those who want to run their own back-end as a service, and this proposals solves a problem for them.

@dchoi27
Copy link
Contributor Author

dchoi27 commented Aug 13, 2021

How problematic is it for the developer to run a back-end service in-and-of-itself? Ideally they don't have to, but is most the value captured by allowing the user to directly send data to web3.storage rather than the back-end service touching the data? We should test this.

@mikeal
Copy link

mikeal commented Aug 13, 2021

Another alternative to consider is to allow our users to give us their magic link application token to use instead of ours so that we authenticate their users in out backend. Then they wouldn’t need a backend at all, and we can add the user data from the token to each upload.

This only works if they are a magic link user, which would be a good recommendation at hackathons but won’t help with a lot of our partners.

This might be a great step forward in making nft.storage a “client” of web3.storage.

@dchoi27 dchoi27 added kind/enhancement A net-new feature or improvement to an existing feature P1 High: Likely tackled by core team if no one steps up labels Aug 20, 2021
@ryanwolhuter
Copy link

Hey everyone 👋 is anyone working on this currently? I would love to get involved with building the solution here.

@farahats9
Copy link

I have been wondering about this too, it would be awesome if I could make a token that allows adding files and not delete existing files.

@olizilla
Copy link
Contributor

olizilla commented Sep 8, 2021

@farahats9 the good news is: that's how it works currently. We're not going to allow deleting via an API token until users are able to create scoped tokens, and tokens created before we supported scoping will never be able to delete. Tokens you create with web3.storage today can upload files and list all the uploads for an account.

@olizilla
Copy link
Contributor

olizilla commented Sep 9, 2021

@ryanwolhuter great! no one is working on this right now, as we are in the middle of an epic refactor to switch out our db, see: #388 which is blocking other things that would need to save state to the db. Are you keen to work on the token scoping issue specifically or are you interested in hacking on web3.storage more generally?

@farahats9
Copy link

@olizilla thank you for the explanation, if the token cannot delete then its good enough for my use case. It would've been better if we can also control the "list" permission but for now its ok, I will encrypt the uploaded data anyways.

@ryanwolhuter
Copy link

@olizilla I am keen on hacking in the most general sense! My project Ferry is using web3.storage right now to great success (finalists in HackFS) and we're super invested in growth here. I have permission to dedicate some of my work hours to helping out on building Web3.Storage, if you'll have me. I'd love to chat you about how I can be most helpful.

@codewithpom
Copy link

Any updated on it ?

@dchoi27
Copy link
Contributor Author

dchoi27 commented Feb 7, 2022

Hey, we are kicking off work on implementing UCAN-based auth in Web3.Storage in the coming weeks. (#261 (comment)) This should handle the whole uploads side of token scopes out of the box, and then things like delete tokens can follow after.

@orvn
Copy link
Contributor

orvn commented Jun 20, 2022

For the scoping of tokens (here and #300), note that the Pinning Services API table retrieves using a single user-generated token. So if tokens become scoped and the user has multiple tokens, not all pins will be visible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Epic kind/enhancement A net-new feature or improvement to an existing feature need/approach P1 High: Likely tackled by core team if no one steps up pi/upload-v2 stack/api-protocols
Projects
None yet
Development

No branches or pull requests

9 participants