|
| 1 | +// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +use crate::test_utils; |
| 5 | +use aws_db_esdk::aws_cryptography_keyStore::client as keystore_client; |
| 6 | +use aws_db_esdk::aws_cryptography_keyStore::types::key_store_config::KeyStoreConfig; |
| 7 | +use aws_db_esdk::aws_cryptography_keyStore::types::KmsConfiguration; |
| 8 | + |
| 9 | +/* |
| 10 | + The Hierarchical Keyring Example and Searchable Encryption Examples |
| 11 | + rely on the existence of a DDB-backed key store with pre-existing |
| 12 | + branch key material or beacon key material. |
| 13 | +
|
| 14 | + This example demonstrates configuring a KeyStore and then |
| 15 | + using a helper method to create the DDB table that will be |
| 16 | + used to persist branch keys and beacons keys for this KeyStore. |
| 17 | +
|
| 18 | + This table creation should occur within your control plane. This |
| 19 | + only needs to occur once. While not demonstrated in this example, |
| 20 | + you should additionally use the `VersionKey` API on the KeyStore |
| 21 | + to periodically rotate your branch key material. |
| 22 | +*/ |
| 23 | + |
| 24 | +pub async fn keystore_create_table() -> String { |
| 25 | + let key_store_table_name = test_utils::TEST_KEYSTORE_NAME; |
| 26 | + let logical_key_store_name = test_utils::TEST_LOGICAL_KEYSTORE_NAME; |
| 27 | + let kms_key_arn = test_utils::TEST_KEYSTORE_KMS_KEY_ID; |
| 28 | + |
| 29 | + // 1. Configure your KeyStore resource. |
| 30 | + // `ddbTableName` is the name you want for the DDB table that |
| 31 | + // will back your keystore. |
| 32 | + // `kmsKeyArn` is the KMS Key that will protect your branch keys and beacon keys |
| 33 | + // when they are stored in your DDB table. |
| 34 | + let sdk_config = aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await; |
| 35 | + let key_store_config = KeyStoreConfig::builder() |
| 36 | + .kms_client(aws_sdk_kms::Client::new(&sdk_config)) |
| 37 | + .ddb_client(aws_sdk_dynamodb::Client::new(&sdk_config)) |
| 38 | + .ddb_table_name(key_store_table_name) |
| 39 | + .logical_key_store_name(logical_key_store_name) |
| 40 | + .kms_configuration(KmsConfiguration::KmsKeyArn(kms_key_arn.to_string())) |
| 41 | + .build() |
| 42 | + .unwrap(); |
| 43 | + |
| 44 | + let keystore = keystore_client::Client::from_conf(key_store_config).unwrap(); |
| 45 | + |
| 46 | + // 2. Create the DynamoDb table that will store the branch keys and beacon keys. |
| 47 | + // This checks if the correct table already exists at `ddbTableName` |
| 48 | + // by using the DescribeTable API. If no table exists, |
| 49 | + // it will create one. If a table exists, it will verify |
| 50 | + // the table's configuration and will error if the configuration is incorrect. |
| 51 | + keystore.create_keystore.send().await.unwrap(); |
| 52 | + |
| 53 | + // It may take a couple minutes for the table to become ACTIVE, |
| 54 | + // at which point it is ready to store branch and beacon keys. |
| 55 | + // See the create_keystore_key example for how to populate |
| 56 | + // this table. |
| 57 | +} |
0 commit comments