Skip to content

Commit f8c55c9

Browse files
committed
Merge branch 'issue-2459' of github.com:ChrisBQu/defradb into issue-2459
2 parents 2c1786f + 7cd315d commit f8c55c9

File tree

19 files changed

+1818
-931
lines changed

19 files changed

+1818
-931
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</picture>
1212
</p>
1313

14-
DefraDB is a user-centric database that prioritizes data ownership, personal privacy, and information security. Its data model, powered by the convergence of [MerkleCRDTs](https://arxiv.org/pdf/2004.00107.pdf) and the content-addressability of [IPLD](https://docs.ipld.io/), enables a multi-write-master architecture. It features [DQL](https://docs.source.network/references/query-specification/query-language-overview), a query language compatible with GraphQL but providing extra convenience. By leveraging peer-to-peer networking it can be deployed nimbly in novel topologies. Access control is determined by a relationship-based DSL, supporting document or field-level policies, secured by the SourceHub network. DefraDB is a core part of the [Source technologies](https://source.network/) that enable new paradigms of decentralized data and access-control management, user-centric apps, data trustworthiness, and much more.
14+
DefraDB is a user-centric database that prioritizes data ownership, personal privacy, and information security. Its data model, powered by the convergence of [MerkleCRDTs](https://arxiv.org/pdf/2004.00107.pdf) and the content-addressability of [IPLD](https://docs.ipld.io/), enables a multi-write-master architecture. It features [DQL](https://docs.source.network/defradb/references/query-specification/query-language-overview), a query language compatible with GraphQL but providing extra convenience. By leveraging peer-to-peer networking it can be deployed nimbly in novel topologies. Access control is determined by a relationship-based DSL, supporting document or field-level policies, secured by the SourceHub network. DefraDB is a core part of the [Source technologies](https://source.network/) that enable new paradigms of decentralized data and access-control management, user-centric apps, data trustworthiness, and much more.
1515

1616
Read the documentation on [docs.source.network](https://docs.source.network/).
1717

acp/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,26 @@ Result:
631631
Error: document not found or not authorized to access
632632
```
633633

634+
Sometimes we might want to give a specific access (form a relationship) not just to one identity, but any identity.
635+
In that case we can specify "*" instead of specifying an explicit `actor`:
636+
```sh
637+
defradb client acp relationship add \
638+
--collection Users \
639+
--docID bae-ff3ceb1c-b5c0-5e86-a024-dd1b16a4261c \
640+
--relation reader \
641+
--actor "*" \
642+
--identity e3b722906ee4e56368f581cd8b18ab0f48af1ea53e635e3f7b8acd076676f6ac
643+
```
644+
645+
Result:
646+
```json
647+
{
648+
"ExistedAlready": false
649+
}
650+
```
651+
652+
**Note: specifying `*` does not overwrite any previous formed relationships, they will remain as is **
653+
634654
### Revoking Access To Private Documents
635655

636656
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
695715

696716
**Result is empty from the above command**
697717

718+
We can also revoke the previously granted implicit relationship which gave all actors access using the "*" actor.
719+
Similarly we can just specify "*" to revoke all access given to actors implicitly through this relationship:
720+
```sh
721+
defradb client acp relationship delete \
722+
--collection Users \
723+
--docID bae-ff3ceb1c-b5c0-5e86-a024-dd1b16a4261c \
724+
--relation reader \
725+
--actor "*" \
726+
--identity e3b722906ee4e56368f581cd8b18ab0f48af1ea53e635e3f7b8acd076676f6ac
727+
```
728+
729+
Result:
730+
```json
731+
{
732+
"RecordFound": true
733+
}
734+
```
735+
736+
**Note: Deleting with`*` does not remove any explicitly formed relationships, they will remain as they were **
737+
698738
## DAC Usage HTTP:
699739

700740
### Authentication

acp/acp_local.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,25 @@ func (l *ACPLocal) AddActorRelationship(
254254

255255
ctx = auth.InjectPrincipal(ctx, principal)
256256

257+
var newActorRelationship *types.Relationship
258+
if targetActor == "*" {
259+
newActorRelationship = types.NewAllActorsRelationship(
260+
resourceName,
261+
objectID,
262+
relation,
263+
)
264+
} else {
265+
newActorRelationship = types.NewActorRelationship(
266+
resourceName,
267+
objectID,
268+
relation,
269+
targetActor,
270+
)
271+
}
272+
257273
setRelationshipRequest := types.SetRelationshipRequest{
258274
PolicyId: policyID,
259-
Relationship: types.NewActorRelationship(resourceName, objectID, relation, targetActor),
275+
Relationship: newActorRelationship,
260276
CreationTime: creationTime,
261277
}
262278

@@ -285,9 +301,25 @@ func (l *ACPLocal) DeleteActorRelationship(
285301

286302
ctx = auth.InjectPrincipal(ctx, principal)
287303

304+
var newActorRelationship *types.Relationship
305+
if targetActor == "*" {
306+
newActorRelationship = types.NewAllActorsRelationship(
307+
resourceName,
308+
objectID,
309+
relation,
310+
)
311+
} else {
312+
newActorRelationship = types.NewActorRelationship(
313+
resourceName,
314+
objectID,
315+
relation,
316+
targetActor,
317+
)
318+
}
319+
288320
deleteRelationshipRequest := types.DeleteRelationshipRequest{
289321
PolicyId: policyID,
290-
Relationship: types.NewActorRelationship(resourceName, objectID, relation, targetActor),
322+
Relationship: newActorRelationship,
291323
}
292324

293325
deleteRelationshipResponse, err := l.engine.DeleteRelationship(ctx, &deleteRelationshipRequest)

acp/acp_source_hub.go

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -273,18 +273,28 @@ func (a *acpSourceHub) AddActorRelationship(
273273
creationTime *protoTypes.Timestamp,
274274
) (bool, error) {
275275
msgSet := sourcehub.MsgSet{}
276+
277+
var newActorRelationship *acptypes.Relationship
278+
if targetActor == "*" {
279+
newActorRelationship = acptypes.NewAllActorsRelationship(
280+
resourceName,
281+
objectID,
282+
relation,
283+
)
284+
} else {
285+
newActorRelationship = acptypes.NewActorRelationship(
286+
resourceName,
287+
objectID,
288+
relation,
289+
targetActor,
290+
)
291+
}
292+
276293
cmdMapper := msgSet.WithBearerPolicyCmd(&acptypes.MsgBearerPolicyCmd{
277-
Creator: a.signer.GetAccAddress(),
278-
BearerToken: requester.BearerToken,
279-
PolicyId: policyID,
280-
Cmd: acptypes.NewSetRelationshipCmd(
281-
acptypes.NewActorRelationship(
282-
resourceName,
283-
objectID,
284-
relation,
285-
targetActor,
286-
),
287-
),
294+
Creator: a.signer.GetAccAddress(),
295+
BearerToken: requester.BearerToken,
296+
PolicyId: policyID,
297+
Cmd: acptypes.NewSetRelationshipCmd(newActorRelationship),
288298
CreationTime: creationTime,
289299
})
290300
tx, err := a.txBuilder.Build(ctx, a.signer, &msgSet)
@@ -323,18 +333,28 @@ func (a *acpSourceHub) DeleteActorRelationship(
323333
creationTime *protoTypes.Timestamp,
324334
) (bool, error) {
325335
msgSet := sourcehub.MsgSet{}
336+
337+
var newActorRelationship *acptypes.Relationship
338+
if targetActor == "*" {
339+
newActorRelationship = acptypes.NewAllActorsRelationship(
340+
resourceName,
341+
objectID,
342+
relation,
343+
)
344+
} else {
345+
newActorRelationship = acptypes.NewActorRelationship(
346+
resourceName,
347+
objectID,
348+
relation,
349+
targetActor,
350+
)
351+
}
352+
326353
cmdMapper := msgSet.WithBearerPolicyCmd(&acptypes.MsgBearerPolicyCmd{
327-
Creator: a.signer.GetAccAddress(),
328-
BearerToken: requester.BearerToken,
329-
PolicyId: policyID,
330-
Cmd: acptypes.NewDeleteRelationshipCmd(
331-
acptypes.NewActorRelationship(
332-
resourceName,
333-
objectID,
334-
relation,
335-
targetActor,
336-
),
337-
),
354+
Creator: a.signer.GetAccAddress(),
355+
BearerToken: requester.BearerToken,
356+
PolicyId: policyID,
357+
Cmd: acptypes.NewDeleteRelationshipCmd(newActorRelationship),
338358
CreationTime: creationTime,
339359
})
340360

cli/acp_relationship_add.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ Example: Let another actor (4d092126012ebaf56161716018a71630d99443d9d5217e9d8502
6464
--actor did:key:z7r8os2G88XXBNBTLj3kFR5rzUJ4VAesbX7PgsA68ak9B5RYcXF5EZEmjRzzinZndPSSwujXb4XKHG6vmKEFG6ZfsfcQn \
6565
--identity e3b722906ee4e56368f581cd8b18ab0f48af1ea53e635e3f7b8acd076676f6ac
6666
67+
Example: Let all actors read a private document:
68+
defradb client acp relationship add \
69+
--collection Users \
70+
--docID bae-ff3ceb1c-b5c0-5e86-a024-dd1b16a4261c \
71+
--relation reader \
72+
--actor "*" \
73+
--identity e3b722906ee4e56368f581cd8b18ab0f48af1ea53e635e3f7b8acd076676f6ac
74+
6775
Example: Creating a dummy relationship does nothing (from database perspective):
6876
defradb client acp relationship add \
6977
-c Users \

client/db.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ type DB interface {
113113
// If failure occurs, the result will return an error. Upon success the boolean value will
114114
// be true if the relationship already existed (no-op), and false if a new relationship was made.
115115
//
116-
// Note: The request actor must either be the owner or manager of the document.
116+
// Note:
117+
// - The request actor must either be the owner or manager of the document.
118+
// - If the target actor arg is "*", then the relationship applies to all actors implicitly.
117119
AddDocActorRelationship(
118120
ctx context.Context,
119121
collectionName string,
@@ -128,7 +130,10 @@ type DB interface {
128130
// be true if the relationship record was found and deleted. Upon success the boolean value
129131
// will be false if the relationship record was not found (no-op).
130132
//
131-
// Note: The request actor must either be the owner or manager of the document.
133+
// Note:
134+
// - The request actor must either be the owner or manager of the document.
135+
// - If the target actor arg is "*", then the implicitly added relationship with all actors is
136+
// removed, however this does not revoke access from actors that had explicit relationships.
132137
DeleteDocActorRelationship(
133138
ctx context.Context,
134139
collectionName string,

docs/website/references/cli/defradb_client_acp_relationship_add.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ Example: Let another actor (4d092126012ebaf56161716018a71630d99443d9d5217e9d8502
3030
--actor did:key:z7r8os2G88XXBNBTLj3kFR5rzUJ4VAesbX7PgsA68ak9B5RYcXF5EZEmjRzzinZndPSSwujXb4XKHG6vmKEFG6ZfsfcQn \
3131
--identity e3b722906ee4e56368f581cd8b18ab0f48af1ea53e635e3f7b8acd076676f6ac
3232

33+
Example: Let all actors read a private document:
34+
defradb client acp relationship add \
35+
--collection Users \
36+
--docID bae-ff3ceb1c-b5c0-5e86-a024-dd1b16a4261c \
37+
--relation reader \
38+
--actor "*" \
39+
--identity e3b722906ee4e56368f581cd8b18ab0f48af1ea53e635e3f7b8acd076676f6ac
40+
3341
Example: Creating a dummy relationship does nothing (from database perspective):
3442
defradb client acp relationship add \
3543
-c Users \

go.mod

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ require (
1919
github.com/go-errors/errors v1.5.1
2020
github.com/gofrs/uuid/v5 v5.3.0
2121
github.com/iancoleman/strcase v0.3.0
22-
github.com/ipfs/boxo v0.24.2
22+
github.com/ipfs/boxo v0.24.3
2323
github.com/ipfs/go-block-format v0.2.0
2424
github.com/ipfs/go-cid v0.4.1
2525
github.com/ipfs/go-datastore v0.6.0
@@ -34,7 +34,7 @@ require (
3434
github.com/lestrrat-go/jwx/v2 v2.1.2
3535
github.com/libp2p/go-libp2p v0.37.0
3636
github.com/libp2p/go-libp2p-gostream v0.6.0
37-
github.com/libp2p/go-libp2p-kad-dht v0.27.0
37+
github.com/libp2p/go-libp2p-kad-dht v0.28.1
3838
github.com/libp2p/go-libp2p-pubsub v0.12.0
3939
github.com/libp2p/go-libp2p-record v0.2.0
4040
github.com/mr-tron/base58 v1.2.0
@@ -62,7 +62,7 @@ require (
6262
go.opentelemetry.io/otel/metric v1.32.0
6363
go.opentelemetry.io/otel/sdk/metric v1.32.0
6464
go.uber.org/zap v1.27.0
65-
golang.org/x/crypto v0.28.0
65+
golang.org/x/crypto v0.29.0
6666
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c
6767
google.golang.org/grpc v1.67.1
6868
)
@@ -80,7 +80,7 @@ require (
8080
cosmossdk.io/depinject v1.0.0 // indirect
8181
cosmossdk.io/errors v1.0.1 // indirect
8282
cosmossdk.io/log v1.4.1 // indirect
83-
cosmossdk.io/math v1.3.0 // indirect
83+
cosmossdk.io/math v1.4.0 // indirect
8484
cosmossdk.io/store v1.1.1 // indirect
8585
cosmossdk.io/x/circuit v0.1.0 // indirect
8686
cosmossdk.io/x/evidence v0.1.0 // indirect
@@ -151,7 +151,7 @@ require (
151151
github.com/flynn/noise v1.1.0 // indirect
152152
github.com/francoispqt/gojay v1.2.13 // indirect
153153
github.com/fsnotify/fsnotify v1.7.0 // indirect
154-
github.com/gabriel-vasile/mimetype v1.4.4 // indirect
154+
github.com/gabriel-vasile/mimetype v1.4.6 // indirect
155155
github.com/getsentry/sentry-go v0.27.0 // indirect
156156
github.com/go-jose/go-jose/v3 v3.0.1-0.20221117193127-916db76e8214 // indirect
157157
github.com/go-kit/kit v0.12.0 // indirect
@@ -190,7 +190,7 @@ require (
190190
github.com/gorilla/websocket v1.5.3 // indirect
191191
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
192192
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
193-
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
193+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
194194
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
195195
github.com/hashicorp/errwrap v1.1.0 // indirect
196196
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
@@ -351,7 +351,7 @@ require (
351351
go.etcd.io/bbolt v1.3.10 // indirect
352352
go.opencensus.io v0.24.0 // indirect
353353
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
354-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 // indirect
354+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect
355355
go.opentelemetry.io/otel v1.32.0 // indirect
356356
go.opentelemetry.io/otel/sdk v1.32.0 // indirect
357357
go.opentelemetry.io/otel/trace v1.32.0 // indirect
@@ -362,17 +362,17 @@ require (
362362
golang.org/x/mod v0.21.0 // indirect
363363
golang.org/x/net v0.30.0 // indirect
364364
golang.org/x/oauth2 v0.23.0 // indirect
365-
golang.org/x/sync v0.8.0 // indirect
365+
golang.org/x/sync v0.9.0 // indirect
366366
golang.org/x/sys v0.27.0 // indirect
367-
golang.org/x/term v0.25.0 // indirect
368-
golang.org/x/text v0.19.0 // indirect
367+
golang.org/x/term v0.26.0 // indirect
368+
golang.org/x/text v0.20.0 // indirect
369369
golang.org/x/time v0.5.0 // indirect
370370
golang.org/x/tools v0.26.0 // indirect
371371
gonum.org/v1/gonum v0.15.0 // indirect
372372
google.golang.org/api v0.171.0 // indirect
373373
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
374-
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect
375-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
374+
google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9 // indirect
375+
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect
376376
google.golang.org/protobuf v1.35.1 // indirect
377377
gopkg.in/ini.v1 v1.67.0 // indirect
378378
gopkg.in/yaml.v2 v2.4.0 // indirect

0 commit comments

Comments
 (0)