Repository navigation
docs(golang): compare keysets, scopes and context_field for separating tenants #1934
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
base: next
Are you sure you want to change the base?
Changes from all commits
7337865
252eb0b
b1ca198
e47ef95
b230ea0
a2247ec
871a0e3
f652115
906bec6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,10 +60,13 @@ func (cph *Cipher) KeysetID(ctx context.Context) (KeysetID, error) { | |
| // Scope returns a cipher that adds a scope to the context of every field, | ||
| // in every call through it: the write, the query and the read. A scope | ||
| // narrows the data and the queries over it: a field sealed through | ||
| // cipher.Scope("tenant-42") opens and matches only through a cipher with the | ||
| // same scope. It appends to the context the tags declare and never | ||
| // replaces it. A part is a string, a byte slice or an integer (int32, | ||
| // int64, uint32, uint64; Go's int is sent as int64); a byte slice is copied. | ||
| // cipher.Scope("tenant42") opens only through a cipher with the same scope. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bound rows can open through a scope-only cipher with a different tenant scope. A row sealed through This breaks the guarantee that The engine must keep scope parts and binding parts distinct in the stored context. Otherwise, the documented guarantees must state this case as an exception. Choose the mechanism in the engine. Any change to the stored context also affects existing stored rows, so it needs a compatibility plan. The exploit requires a cipher with access to the same keyset, the parent scope value, and the row ID.
|
||
| // An equality query through another scope matches none of it, but a range | ||
| // query through another scope can still return it, with no error: see the | ||
| // README section "Queries with the wrong tenant". It appends to the context | ||
| // the tags declare and never replaces it. A part is a string, a byte slice | ||
| // or an integer (int32, int64, uint32, uint64; Go's int is sent as | ||
| // int64); a byte slice is copied. | ||
| // Several parts nest in order: Scope(a, b) is Scope(a).Scope(b). An | ||
| // unsupported part type is reported by the first call through the cipher, | ||
| // as [ErrEncoding]. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,7 +52,7 @@ | |
| // return err | ||
| // } | ||
| // defer client.Close() | ||
| // cipher := client.Keyset(encrypt.KeysetName("tenant-42")) | ||
| // cipher := client.Keyset(encrypt.KeysetName("tenant42")) | ||
| // encrypted, err := users.Encrypt(ctx, cipher, people) // []users.EncryptedUser | ||
| // opened, err := users.Decrypt(ctx, cipher, encrypted) // []users.User | ||
| // term, err := users.Fields.Email.Eq(ctx, cipher, "[email protected]") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,7 @@ func run(ctx context.Context) error { | |
|
|
||
| // One cipher for one tenant: the default keyset, and the tenant as a | ||
| // part of every field's context. Every call through it carries both. | ||
| cipher := client.DefaultKeyset().Scope("tenant-42") | ||
| cipher := client.DefaultKeyset().Scope("tenant42") | ||
|
|
||
| people := []User{ | ||
| {ID: 1, Email: "[email protected]", Age: 34}, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.