-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add role records #189
Comments
Fixes #124 For details see digidem/comapeo-core#189
Overall this makes sense to me! One potential suggestion for the Capability type: any reason against a top-level specific field that holds the datatype-specific permissions? for example: type Capability = {
docId: string, // should be roleId
// Human-readable name for role
name: string,
// 👇specify a top-level field that holds information that can vary per application
dataTypes: {
[${Exclude<MapeoDoc['schemaName'] | 'role' >}]?: Array<'readOwn' | 'writeOwn' | 'readOthers' | 'writeOthers'>
},
roleAssignmentCapability: Array<string> // Array of role ids that someone with that role can assign
sync: 'allowed' | 'blocked'
} I don't really have any algorithmic reasoning for this but given that datatypes can technically vary across applications, it seems helpful to have a consistent field that will hold that dynamic information related to data types. EDIT: Maybe |
* feat: Add updated `Role` data type Fixes #124 For details see digidem/comapeo-core#189 * Update & add tests; fix things * clarify description of `fromIndex` Still not particularly clear, but hopefully a bit more so
* feat: Add updated `Role` data type Fixes #124 For details see digidem/comapeo-core#189 * Update & add tests; fix things * feat: device -> deviceInfo & new schema Fixes #126 For more info see digidem/comapeo-core#182 * add tests
Closed via #231 |
Description
We need to assign a role to each device, which is used to determine what that device can do, e.g. can invite others, can remove others from project, can edit other peoples' data etc.
In the future we might want to support users being able to configure a project to decide what each role can do.
We need to be able to validate role assignments to trace them back to the project creator, to ensure that the device that made the role assignments had a role that gave them permission to do that.
I think we can keep this simple and keep role records to:
docId
should be the core key of the auth core of the device that the role assignment applies to. I think it makes sense to use this rather than the device ID because it means that tracing a role does not require referencing thecoreOwnership
records.roleId
can be an arbitrary random ID. These roleIds should be defined in aCapability
record (see below).fromIndex
should be the index of the auth core that this role applies to (e.g. the auth core with the key matchingrole.docId
). This should normally beauthCore.length
, but there are use-cases for "back-dating" thefromIndex
to ignore role assignments by a "bad actor", see #188 (comment)For the MVP we will ignore the
fromIndex
. However this means that if a device is removed from a project then any device they have invited will also be removed. We should resolve this as soon after the MVP as possible - I don't think we should expose project removal in the UX of the MVP, since this is not a feature of current Mapeo anyway.A device without an assigned role ID should be considered not in the project and blocked from sync.
Capability
recordsThese define what each role can do in a project, and the name of the role. The
docId
for a capability record should be theroleId
.E.g. the default of two roles, coordinator and member, where only coordinators can invite others, and members can only edit their own data.
I think for the MVP the Capability records don't need to be in the database - we can hardcode them as defaults.
Validation
Validating role records will require tracing the chain of role assignments back to the project creator. This feature will be added post-MVP. For more details of the implementation plan see #188
Write capabilities (
writeOwn
andwriteOthers
)We can block this at an app-level, but we can't actually stop a device directly writing to their own database. However when indexing documents we can choose to ignore any documents that match one of these criteria (e.g. for
writeOwn
it would be the first document, or an update of a document, or forwriteOthers
it would be an update of a document created by another device).fromIndex
for other cores (other than auth core)In the future we might want to add additional fields to the Role document for
${namespace}FromIndex
, e.g. afromIndex
for each writer core of a device in each namespace. This would be valuable for ignoring data from a certain previous point in time (e.g. implementingwriteOthers=false
from a point in time) when a device had valuable data up to a point, that we want to keep, and then ignore data written past that point.This is not an MVP feature and can be added later.
Read capabilities (
readOwn
andreadOthers
)This can only initially be implemented at a runtime level - since this is a p2p system anyone with a synced copy could directly access the database and read the data. However the vast majority of users will only be interacting with the data through the apps, so app-level restrictions are enough.
In the future we can implement this via encrypted documents (e.g. document-level encryption using something like PGP, rather than the block-level encryption - with a single encryption key for the entire core - that we have right now).
readOwn=false
can be implemented with sealed box encryption.Implementation plan
Create a new
Capability
class that takesauthDataStore
andcoreOwnership
instances as constructor parameters and initially has a single method:getCapabilities(deviceId)
that should return a capability record above. Internally this class should create an instance ofDataType
withrole
.We should initially implement default capability records, with some pre-defined role IDs.
Initial idea for
getCapabilities()
Tasks
dataType.createWithDocId()
method #190getWinner
that just chooses the most recent would be ok?The text was updated successfully, but these errors were encountered: