diff --git a/acp/README.md b/acp/README.md index 4e8d5b7f5b..3fedb5a274 100644 --- a/acp/README.md +++ b/acp/README.md @@ -631,6 +631,26 @@ Result: Error: document not found or not authorized to access ``` +Sometimes we might want to give a specific access (form a relationship) not just to one identity, but any identity. +In that case we can specify "*" instead of specifying an explicit `actor`: +```sh +defradb client acp relationship add \ +--collection Users \ +--docID bae-ff3ceb1c-b5c0-5e86-a024-dd1b16a4261c \ +--relation reader \ +--actor "*" \ +--identity e3b722906ee4e56368f581cd8b18ab0f48af1ea53e635e3f7b8acd076676f6ac +``` + +Result: +```json +{ + "ExistedAlready": false +} +``` + +**Note: specifying `*` does not overwrite any previous formed relationships, they will remain as is ** + ### Revoking Access To Private Documents To revoke access to a document for an actor, we must delete the relationship between the @@ -695,6 +715,26 @@ defradb client collection docIDs --identity 4d092126012ebaf56161716018a71630d994 **Result is empty from the above command** +We can also revoke the previously granted implicit relationship which gave all actors access using the "*" actor. +Similarly we can just specify "*" to revoke all access given to actors implicitly through this relationship: +```sh +defradb client acp relationship delete \ +--collection Users \ +--docID bae-ff3ceb1c-b5c0-5e86-a024-dd1b16a4261c \ +--relation reader \ +--actor "*" \ +--identity e3b722906ee4e56368f581cd8b18ab0f48af1ea53e635e3f7b8acd076676f6ac +``` + +Result: +```json +{ + "RecordFound": true +} +``` + +**Note: Deleting with`*` does not remove any explicitly formed relationships, they will remain as they were ** + ## DAC Usage HTTP: ### Authentication diff --git a/cli/acp_relationship_add.go b/cli/acp_relationship_add.go index c0838a2ce2..0026e992f5 100644 --- a/cli/acp_relationship_add.go +++ b/cli/acp_relationship_add.go @@ -64,6 +64,14 @@ Example: Let another actor (4d092126012ebaf56161716018a71630d99443d9d5217e9d8502 --actor did:key:z7r8os2G88XXBNBTLj3kFR5rzUJ4VAesbX7PgsA68ak9B5RYcXF5EZEmjRzzinZndPSSwujXb4XKHG6vmKEFG6ZfsfcQn \ --identity e3b722906ee4e56368f581cd8b18ab0f48af1ea53e635e3f7b8acd076676f6ac +Example: Let all actors read a private document: + defradb client acp relationship add \ + --collection Users \ + --docID bae-ff3ceb1c-b5c0-5e86-a024-dd1b16a4261c \ + --relation reader \ + --actor "*" \ + --identity e3b722906ee4e56368f581cd8b18ab0f48af1ea53e635e3f7b8acd076676f6ac + Example: Creating a dummy relationship does nothing (from database perspective): defradb client acp relationship add \ -c Users \ diff --git a/client/db.go b/client/db.go index e8942e8501..bfafb76942 100644 --- a/client/db.go +++ b/client/db.go @@ -113,7 +113,9 @@ type DB interface { // If failure occurs, the result will return an error. Upon success the boolean value will // be true if the relationship already existed (no-op), and false if a new relationship was made. // - // Note: The request actor must either be the owner or manager of the document. + // Note: + // - The request actor must either be the owner or manager of the document. + // - If the target actor arg is "*", then the relationship applies to all actors implicitly. AddDocActorRelationship( ctx context.Context, collectionName string, @@ -128,7 +130,10 @@ type DB interface { // be true if the relationship record was found and deleted. Upon success the boolean value // will be false if the relationship record was not found (no-op). // - // Note: The request actor must either be the owner or manager of the document. + // Note: + // - The request actor must either be the owner or manager of the document. + // - If the target actor arg is "*", then the implicitly added relationship with all actors is + // removed, however this does not revoke access from actors that had explicit relationships. DeleteDocActorRelationship( ctx context.Context, collectionName string, diff --git a/docs/website/references/cli/defradb_client_acp_relationship_add.md b/docs/website/references/cli/defradb_client_acp_relationship_add.md index 1251ffb74e..f3313b45d4 100644 --- a/docs/website/references/cli/defradb_client_acp_relationship_add.md +++ b/docs/website/references/cli/defradb_client_acp_relationship_add.md @@ -30,6 +30,14 @@ Example: Let another actor (4d092126012ebaf56161716018a71630d99443d9d5217e9d8502 --actor did:key:z7r8os2G88XXBNBTLj3kFR5rzUJ4VAesbX7PgsA68ak9B5RYcXF5EZEmjRzzinZndPSSwujXb4XKHG6vmKEFG6ZfsfcQn \ --identity e3b722906ee4e56368f581cd8b18ab0f48af1ea53e635e3f7b8acd076676f6ac +Example: Let all actors read a private document: + defradb client acp relationship add \ + --collection Users \ + --docID bae-ff3ceb1c-b5c0-5e86-a024-dd1b16a4261c \ + --relation reader \ + --actor "*" \ + --identity e3b722906ee4e56368f581cd8b18ab0f48af1ea53e635e3f7b8acd076676f6ac + Example: Creating a dummy relationship does nothing (from database perspective): defradb client acp relationship add \ -c Users \