|
| 1 | +# DynamoDB Encryption Client for Go |
| 2 | + |
| 3 | +This is a Go library that provides an encrypted client for interacting with Amazon DynamoDB. It allows you to perform common DynamoDB operations such as PutItem, GetItem, Query, Scan, BatchGetItem, BatchWriteItem, and DeleteItem while automatically encrypting and decrypting sensitive data. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Encrypt and decrypt DynamoDB items transparently |
| 8 | +- Support for standard and deterministic encryption |
| 9 | +- Integration with AWS Key Management Service (KMS) for key management |
| 10 | +- Customizable encryption actions for individual attributes |
| 11 | +- Secure storage and retrieval of cryptographic materials |
| 12 | +- High-level interface for working with encrypted DynamoDB tables |
| 13 | +- Pagination support for Query and Scan operations |
| 14 | + |
| 15 | +## Installation |
| 16 | + |
| 17 | +To use this library in your Go project, you can install it using go get: |
| 18 | + |
| 19 | +```shell |
| 20 | +go get github.com/cloudopsy/dynamodb-encryption-go |
| 21 | +``` |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +Here's a basic example of how to use the EncryptedClient to perform encrypted DynamoDB operations: |
| 26 | + |
| 27 | +```go |
| 28 | +import ( |
| 29 | + "context" |
| 30 | + "github.com/aws/aws-sdk-go-v2/service/dynamodb" |
| 31 | + "github.com/cloudopsy/dynamodb-encryption-go/pkg/encrypted" |
| 32 | + "github.com/cloudopsy/dynamodb-encryption-go/pkg/provider" |
| 33 | +) |
| 34 | + |
| 35 | +func main() { |
| 36 | + // Create a regular DynamoDB client |
| 37 | + dynamodbClient := dynamodb.NewFromConfig(cfg) |
| 38 | + |
| 39 | + // Create a key material store |
| 40 | + materialStore, err := store.NewMetaStore(dynamodbClient, "metastore-table") |
| 41 | + if err != nil { |
| 42 | + log.Fatalf("Failed to create key material store: %v", err) |
| 43 | + } |
| 44 | + if err := materialStore.CreateTableIfNotExists(context.Background()); err != nil { |
| 45 | + log.Fatalf("Failed to ensure metastore table exists: %v", err) |
| 46 | + } |
| 47 | + |
| 48 | + // Create a cryptographic materials provider |
| 49 | + keyURI := "aws-kms://arn:aws:kms:eu-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab" |
| 50 | + cmp, err := provider.NewAwsKmsCryptographicMaterialsProvider(keyURI, nil, materialStore) |
| 51 | + if err != nil { |
| 52 | + log.Fatalf("Failed to create cryptographic materials provider: %v", err) |
| 53 | + } |
| 54 | + |
| 55 | + // Create an encrypted DynamoDB client |
| 56 | + attributeActions := encrypted.NewAttributeActions(encrypted.AttributeActionDoNothing) |
| 57 | + attributeActions.SetAttributeAction("SensitiveData", encrypted.AttributeActionEncrypt) |
| 58 | + encryptedClient := encrypted.NewEncryptedClient(dynamodbClient, cmp, attributeActions) |
| 59 | + |
| 60 | + // Perform encrypted DynamoDB operations |
| 61 | + putItemInput := &dynamodb.PutItemInput{ |
| 62 | + TableName: aws.String("my-table"), |
| 63 | + Item: map[string]types.AttributeValue{ |
| 64 | + "PK": &types.AttributeValueMemberS{Value: "123"}, |
| 65 | + "SK": &types.AttributeValueMemberS{Value: "456"}, |
| 66 | + "SensitiveData": &types.AttributeValueMemberS{Value: "my secret data"}, |
| 67 | + }, |
| 68 | + } |
| 69 | + _, err = encryptedClient.PutItem(context.Background(), putItemInput) |
| 70 | + if err != nil { |
| 71 | + log.Fatalf("Failed to put encrypted item: %v", err) |
| 72 | + } |
| 73 | + |
| 74 | + // ... perform other operations ... |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +In this example, we create a regular `dynamodb.Client`, a key material store, and a cryptographic materials provider. Then, we create an `EncryptedClient` instance with custom attribute actions to specify which attributes should be encrypted. Finally, we use the `EncryptedClient` to perform operations like PutItem, and the library automatically handles the encryption and decryption of sensitive data. |
| 79 | + |
| 80 | +For more detailed examples and usage instructions, please refer to the documentation and the examples directory in the repository. |
| 81 | + |
| 82 | +## Contributing |
| 83 | + |
| 84 | +Contributions to this library are welcome! If you find a bug, have a feature request, or want to contribute code improvements, please open an issue or submit a pull request on the GitHub repository. |
| 85 | + |
| 86 | +## License |
| 87 | + |
| 88 | +This library is licensed under the MIT License. |
0 commit comments