powerhouse-inc / powerhouse

0 stars 0 forks source link

Agree on auth, roles and permissions #358

Open valiafetisov opened 1 year ago

valiafetisov commented 1 year ago

Goal

Agree on the overall functionality related to auth

Context

Since the initial version of the authentication was already implemented in powerhouse-inc/switchboard#16 and powerhouse-inc/switchboard#28, it's time to make it production-ready and close all open questions.

Tasks

valiafetisov commented 1 year ago
  1. Who is able to fetch data?
    • Proposal: In order to make requests, one have to register and send authorization token with every request
      • Reason: in order to prevent potential distributed denial-of-service attacks, we need to identify each request, this will also help us identify who is using the API
  2. Who is able to register?
    • Proposal: registration is open for everyone, once account is created, the user can immediately make get requests
      • Reason: we anyway plan to make database dump publicly available, and make operations transparent
  3. What external service will be used to validate registration (email, captcha, etc)? (we need that in order to protect from ddos attacks and potentially provide "password reset" functionality)
    • Proposal: users should be able to register using their email
      • Reason: Email is a decentralized protocol, although still commonly used and is suitable for non-technical users (ie analysts). later on we can also support Sign-In with Ethereum functionality interchangeably
  4. Do we need to set origin restrictions for tokens?
    • Proposal: yes
      • Reason: since we expect that many requests will be coming from other frontends that publicly expose our tokens, this is essential to prevent token stealing
  5. Do we need to distinguish between read and write tokens?
    • Proposal: Maybe in the long-term
      • Reason: The user who creates the token will give the token the same rights as the user itself (as in many other services)
  6. How will the rights be distributed and by whom?
    • a) There will be a special role to edit all user roles
    • b) There will be a user document model with special operations to add or remove roles, different roles will allow editing of particular user roles and managing of particular roles
  7. How will other frontends get authorised to do write operations? Will they implement their own login forms (and trust other websites to put their passwords in)? Or will we need to provide SSO-like functionality?
    • SSO-functionality is safer for the user, but maybe harder to integrate on other websites
valiafetisov commented 1 year ago

Reaction to Permissioned_Document_Processes.pdf:

For each state (External, Draft, and Final), there is a TO_{STATE} permission that can be assigned.

Based on the above, I would propose to:

Based on the proposal, we need to agree on:

valiafetisov commented 1 year ago

Reaction to Authentication_and_Message_Signing.pdf

Summary

Questions/Reactions

Typically, a delegated identity is tied to an application instance or an application session that needs to act (sign messages) on the user’s behalf

Literally signing all requests using deligated identity is possible, but will make API interactions much more complicated. Current tooling such as for example graphql playground does not support this type of authentication. In my opinion it's important to keep JWT tokens as a means of authentication to streamline adoption of the API.

I also see more harm than value in "rolling your own authentication" for the web. There is a standard for authenticating with wallets described in EIP-4361. It does work for the "primary identity", but it's not directly suitable for the "delegated identity" (one example reason: then, every request will need to be turned into two to include challange (nonce) to prevent replay attacks, which is a lot of overhead for someone wanting to implement API requests)

The Delegate Identity is then approved by the user by signing a transaction with their Primary Identity (this typically happens on Renown), and by submitting this transaction to the blockchain

I'm not sure why we need to do something on chain if it was suggested above in the document to use off-chain message singing to avoid transaction fees. Keeping signed message in our database (for the potential auditability) is effectively the same thing (for this particular use case) as submitting it on-chain.

Burn Message

Same here: this can be done via off-chain message that is then (stored in our database as a proof). Please elaborate on the need of the on-chain transaction here and how does it play together.

Timestamp Attestations

To validate that the message was indeed signed not earlier than x point of time, we can also include hash of the latest block. If the exact timestamp is required, then it's better to do on-chain transaction by the user or our service independentry from the user. I don't think using Twitter as attestation service is suitable for decentralised application.