You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+35-9
Original file line number
Diff line number
Diff line change
@@ -52,6 +52,7 @@ For optional [client side](#client-side-encryption) field level envelope encrypt
52
52
```
53
53
pip install 'abnosql[aws-kms]'
54
54
pip install 'abnosql[azure-kms]'
55
+
pip install 'abnosql[gcp-kms]'
55
56
```
56
57
57
58
By default, abnosql does not include database dependencies. This is to facilitate packaging
@@ -195,17 +196,27 @@ This works for AWS DyanmoDB & Firestore, however Azure Cosmos has a limitation w
195
196
196
197
## Audit
197
198
198
-
`put_item()` and `put_items()` take an optional `audit_user`kwarg. If supplied, absnosql will add the following to the item:
199
+
Table config attribute `audit_user` will add the following to the item being written to database:
199
200
200
201
-`createdBy` - value of `audit_user`, added if does not exist in item supplied to put_item()
201
202
-`createdDate` - UTC ISO timestamp string, added if does not exist
202
203
-`modifiedBy` - value of `audit_user` always added
203
204
-`modifiedDate` - UTC ISO timestamp string, always added
204
205
205
-
You can also specify `audit_user` as config attribute to table. If you prefer snake_case over CamelCase, you can set env var `ABNOSQL_CAMELCASE` = `FALSE`
206
+
If snake_case over CamelCase is preferred, set env var `ABNOSQL_CAMELCASE` = `FALSE`
206
207
207
208
NOTE: created* will only be added if `update` is not True in a `put_item()` operation
208
209
210
+
Table config attribute `audit_callback` with value as a function callback can be used to hook into additional audit stores.
211
+
212
+
Callback function must accept the following positional args:
213
+
214
+
-`table_name` - table name
215
+
-`dt_iso` - ISO date timestamp
216
+
-`operation` - `create`, `update`, `get` or `delete`
217
+
-`key` - key of item serialised in <key>=<value>; format
218
+
-`audit_user` - user performing the operation
219
+
209
220
## Change Feed / Stream Support
210
221
211
222
**AWS DynamoDB**[Streams](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.html) allow Lambda functions to be triggered upon create, update and delete table operations. The event sent to the lambda (see [aws docs](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.Lambda.Tutorial2.html)) contains `eventName` and `eventSourceARN`, where:
@@ -240,14 +251,15 @@ To write an Azure Function / AWS Lambda that is able to process both DynamoDB an
240
251
241
252
## Client Side Encryption
242
253
243
-
If configured in table config with `kms` attribute, abnosql will perform client side encryption using AWS KMS or Azure KeyVault
254
+
If configured in table config with `kms` attribute, abnosql will perform client side encryption using AWS KMS, Azure KeyVault or Google KMS
244
255
245
256
Each attribute value defined in the config is encrypted with a 256-bit AES-GCM data key generated for each attribute value:
246
257
247
258
-`aws` uses [AWS Encryption SDK for Python](https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/python.html)
248
-
-`azure` uses [python cryptography](https://cryptography.io/en/latest/hazmat/primitives/aead/#cryptography.hazmat.primitives.ciphers.aead.AESGCM.generate_key) to generate AES-GCM data key, encrypt the attribute value and then uses an RSA CMK in Azure Keyvault to wrap/unwrap (envelope encryption) the AES-GCM data key. The module uses the [azure-keyvaults-keys](https://learn.microsoft.com/en-us/python/api/overview/azure/keyvault-keys-readme?view=azure-python) python SDK for wrap/unrap functionality of the generated data key (Azure doesnt support generate data key as AWS does)
259
+
-`azure` uses [python cryptography](https://cryptography.io/en/latest/hazmat/primitives/aead/#cryptography.hazmat.primitives.ciphers.aead.AESGCM.generate_key) to generate AES-GCM data key, encrypt the attribute value and then uses an RSA CMK in Azure Keyvault to wrap/unwrap (envelope encryption) the AES-GCM data key. The plugin uses the [azure-keyvault-keys](https://learn.microsoft.com/en-us/python/api/overview/azure/keyvault-keys-readme?view=azure-python) python SDK for wrap/unrap functionality of the generated data key (Azure doesnt support generate data key as AWS does - see also [tink issue](https://github.com/tink-crypto/tink/issues/158#issuecomment-1382589658))
Both providers use a [256-bit AES-GCM](https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/supported-algorithms.html) generated data key with AAD/encryption context (Azure provider uses a 96-nonce). AES-GCM is an Authenticated symmetric encryption scheme used by both AWS and Azure (and [Hashicorp Vault](https://developer.hashicorp.com/vault/docs/secrets/transit#aes256-gcm96))
262
+
All providers use a [256-bit AES-GCM](https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/supported-algorithms.html) generated data key with AAD/encryption context (Azure provider uses a 96-nonce). AES-GCM is an Authenticated symmetric encryption scheme used by AWS, Azure & Google (and [Hashicorp Vault](https://developer.hashicorp.com/vault/docs/secrets/transit#aes256-gcm96))
251
263
252
264
See also [AWS Encryption Best Practices](https://docs.aws.amazon.com/prescriptive-guidance/latest/encryption-best-practices/welcome.html)
-`key_ids`: list of AWS KMS Key ARNs or Azure KeyVault identifier (URL to RSA CMK). This is picked up via `ABNOSQL_KMS_KEYS` env var as a comma separated list (*NOTE: env var recommended to avoid provider specific code*)
287
+
-`key_ids`: list of AWS KMS Key ARNs, Azure KeyVault identifier (URL to RSA CMK) or Google KMS URI. This is picked up via `ABNOSQL_KMS_KEYS` env var as a comma separated list (*NOTE: env var recommended to avoid provider specific code*)
268
288
-`key_attrs`: list of key attributes in the item from which the AAD/encryption context is set. Taken from `ABNOSQL_KEY_ATTRS` env var or table `key_attrs` if defined there
269
289
-`attrs`: list of attributes keys to encrypt
270
290
-`key_bytes`: optional for azure, use your own AESGCM key if specified, otherwise generate one
@@ -383,6 +403,7 @@ abnosql uses pluggy and registers in the `abnosql.table` namespace
383
403
The following hooks are available
384
404
385
405
-`set_config` - set config
406
+
-`get_item_pre`
386
407
-`get_item_post` - called after `get_item()`, can return modified data
387
408
-`put_item_pre`
388
409
-`put_item_post`
@@ -434,20 +455,25 @@ More examples in [tests/test_cosmos.py](./tests/test_cosmos.py)
434
455
435
456
## Google Firestore
436
457
437
-
Use [python-mock-firestore](https://github.com/mdowds/python-mock-firestore) and pass `MockFirestore()` to table config as `client` attribute
458
+
Use [python-mock-firestore](https://github.com/mdowds/python-mock-firestore) and pass `MockFirestore()` to table config as `client` attribute, or patch get_client()
438
459
439
460
Example:
440
461
441
462
```
463
+
from unittest.mock import patch
442
464
from mockfirestore import MockFirestore
465
+
from abnosql.plugins.table.firestore import Table as FirestoreTable
-[x][Google Firestore](https://cloud.google.com/python/docs/reference/firestore/latest) support, ideally in the core library (though could be added outside via use of the plugin system). Would need something like [FireSQL](https://firebaseopensource.com/projects/jsayol/firesql/) implemented for python, maybe via sqlglot
492
-
-[][Google Vault](https://cloud.google.com/python/docs/reference/cloudkms/latest/) KMS support
518
+
-[x][Google Vault](https://cloud.google.com/python/docs/reference/cloudkms/latest/) KMS support
493
519
-[ ][Hashicorp Vault](https://github.com/hashicorp/vault-examples/blob/main/examples/_quick-start/python/example.py) KMS support
494
520
-[ ] Simple caching (maybe) using globals (used for AWS Lambda / Azure Functions)
495
521
-[ ] PostgresSQL support using JSONB column (see [here](https://medium.com/geekculture/json-and-postgresql-using-json-to-mimic-nosqls-storage-benefits-1564c69f61fc) for example). Would be nice to avoid an ORM and having to define a model for each table...
0 commit comments