yral-dapp / hot-or-not-auth

Other
1 stars 0 forks source link

Endpoints for user canister & username storage #63

Closed rupansh-sekar-yral closed 9 months ago

rupansh-sekar-yral commented 9 months ago

Proposal Details

Each user owns an individual canister. Previously this lookup was done using a global user index canister which had a mapping for user's principal to their individual canister's principal

The single user index has been changed to a sharded index instead in our new multi subnet model. We currently don't have a quick way to do this lookup.

This proposal defines a rough sketch for allowing this lookup via the auth service

Requirements

Endpoints

Security

We should use signatures for ensuring that the correct user is making the request. Signatures from delegated identity can be verified in rust outside canisters as well. An example is available here: https://github.com/go-bazzinga/ic-verify-example

Another alternative is to use the Delegated Identity: https://docs.rs/ic-agent/latest/ic_agent/identity/struct.DelegatedIdentity.html Which the frontend can provide. Note that to ensure that a Delegated Identity is valid, we need to ensure that the delegation chain points to the current public key: https://docs.rs/ic-agent/latest/ic_agent/trait.Identity.html#method.delegation_chain

I don't have an example to verify this identity unfortunately

For the sake of a quick implementation, we can add the verification later as well but please make sure to track this as its a severe security flaw that could lead to DoS. (An attacker could store an arbitrary canister id for anyone and cause failures in frontend for the user(s))

Entities

A User Principal -> User Canister mapping A Username -> User Canister mapping (Optional) Store user canister in user's metadata as well & make this part of the session: The reason why i think this is optional is that frontend can afford to make another call for getting the user's canister (it previously had to call user index anyways) as cloudflare kv is super optimized for reads

rupansh-sekar-yral commented 9 months ago

Converting DelegationIdentity from auth service to DelegatedIdentity for ic-agent: https://github.com/go-bazzinga/hot-or-not-web-leptos-ssr/blob/main/src/state/auth.rs#L67