Skip to content

Commit c615157

Browse files
authored
Merge branch 'main' into ajewell/buckets
2 parents c0da3ad + 95168a2 commit c615157

File tree

19 files changed

+1008
-30
lines changed

19 files changed

+1008
-30
lines changed

.github/actions/install_smithy_dafny_codegen_dependencies/action.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ runs:
3030
python -m pip install --upgrade black
3131
python -m pip install --upgrade docformatter
3232
33+
- name: Install Go
34+
uses: actions/setup-go@v2
35+
with:
36+
go-version: "1.23"
37+
38+
- name: Install Go imports
39+
shell: bash
40+
run: |
41+
go install golang.org/x/tools/cmd/goimports@latest
42+
3343
# Without this the if-dafny-at-least command includes "Downloading ..." output
3444
- name: Arbitrary makefile target to force downloading Gradle
3545
shell: bash

.github/workflows/ci_codegen.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ jobs:
5656
with:
5757
go-version: ${{ matrix.go-version }}
5858

59-
- name: Install Go imports
60-
run: |
61-
go install golang.org/x/tools/cmd/goimports@latest
62-
6359
- name: Create temporary global.json
6460
run: echo '{"sdk":{"rollForward":"latestFeature","version":"6.0.0"}}' > ./global.json
6561

.github/workflows/ci_test_go.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@ jobs:
9595
with:
9696
go-version: ${{ matrix.go-version }}
9797

98-
- name: Install Go imports
99-
run: |
100-
go install golang.org/x/tools/cmd/goimports@latest
101-
10298
- uses: actions/checkout@v3
10399
- name: Init Submodules
104100
shell: bash
@@ -109,11 +105,6 @@ jobs:
109105
- name: Install Smithy-Dafny codegen dependencies
110106
uses: ./.github/actions/install_smithy_dafny_codegen_dependencies
111107

112-
- name: Install Go imports
113-
shell: bash
114-
run: |
115-
go install golang.org/x/tools/cmd/goimports@latest
116-
117108
- name: Build ${{ matrix.library }} implementation
118109
shell: bash
119110
working-directory: ./${{ matrix.library }}

.github/workflows/go-release.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,6 @@ jobs:
5252
with:
5353
dafny-version: ${{ needs.get-dafny-version.outputs.version }}
5454

55-
- name: Install Go
56-
uses: actions/setup-go@v5
57-
with:
58-
go-version: "1.23"
59-
60-
- name: Install Go imports
61-
run: |
62-
go install golang.org/x/tools/cmd/goimports@latest
63-
6455
- name: Install Smithy-Dafny codegen dependencies
6556
uses: ./.github/actions/install_smithy_dafny_codegen_dependencies
6657

.github/workflows/library_rust_tests.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
- name: Setup Dafny
7171
uses: ./submodules/MaterialProviders/.github/actions/setup_dafny/
7272
with:
73-
dafny-version: nightly-2025-01-30-7db1e5f
73+
dafny-version: 4.10.0
7474

7575
- name: Update MPL submodule if using MPL HEAD
7676
if: ${{ inputs.mpl-head == true }}
@@ -91,12 +91,6 @@ jobs:
9191
if: matrix.os == 'windows-latest'
9292
uses: ilammy/setup-nasm@v1
9393

94-
# Go is needed for aws-lc-FIPS
95-
- name: Install Go
96-
uses: actions/setup-go@v5
97-
with:
98-
go-version: ">=1.18"
99-
10094
- name: Install Smithy-Dafny codegen dependencies
10195
uses: ./.github/actions/install_smithy_dafny_codegen_dependencies
10296

@@ -146,3 +140,4 @@ jobs:
146140
shell: bash
147141
run: |
148142
cargo run --release --example main
143+
cargo test --release --example main

DynamoDbEncryption/runtimes/rust/examples/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub mod keyring;
1414
pub mod multi_get_put_example;
1515
pub mod searchableencryption;
1616
pub mod test_utils;
17+
pub mod migration;
1718

1819
use std::convert::From;
1920

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
pub mod plaintext_to_awsdbe;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Plaintext DynamoDB Table to AWS Database Encryption SDK Encrypted Table Migration
2+
3+
This projects demonstrates the steps necessary
4+
to migrate to the AWS Database Encryption SDK for DynamoDb
5+
from a plaintext database.
6+
7+
[Step 0](plaintext/step0.go) demonstrates the starting state for your system.
8+
9+
## Step 1
10+
11+
In Step 1, you update your system to do the following:
12+
13+
- continue to read plaintext items
14+
- continue to write plaintext items
15+
- prepare to read encrypted items
16+
17+
When you deploy changes in Step 1,
18+
you should not expect any behavior change in your system,
19+
and your dataset still consists of plaintext data.
20+
21+
You must ensure that the changes in Step 1 make it to all your readers before you proceed to Step 2.
22+
23+
## Step 2
24+
25+
In Step 2, you update your system to do the following:
26+
27+
- continue to read plaintext items
28+
- start writing encrypted items
29+
- continue to read encrypted items
30+
31+
When you deploy changes in Step 2,
32+
you are introducing encrypted items to your system,
33+
and must make sure that all your readers are updated with the changes from Step 1.
34+
35+
Before you move onto the next step, you will need to encrypt all plaintext items in your dataset.
36+
Once you have completed this step,
37+
while new items are being encrypted using the new format and will be authenticated on read,
38+
your system will still accept reading plaintext, unauthenticated items.
39+
In order to complete migration to a system where you always authenticate your items,
40+
you should prioritize moving on to Step 3.
41+
42+
## Step 3
43+
44+
Once all old items are encrypted,
45+
update your system to do the following:
46+
47+
- continue to write encrypted items
48+
- continue to read encrypted items
49+
- do not accept reading plaintext items
50+
51+
Once you have deployed these changes to your system, you have completed migration.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
use aws_db_esdk::material_providers::client;
5+
use aws_db_esdk::material_providers::types::material_providers_config::MaterialProvidersConfig;
6+
use aws_db_esdk::CryptoAction;
7+
use aws_db_esdk::dynamodb::types::DynamoDbTableEncryptionConfig;
8+
use aws_db_esdk::types::dynamo_db_tables_encryption_config::DynamoDbTablesEncryptionConfig;
9+
use aws_db_esdk::dynamodb::types::PlaintextOverride;
10+
use std::collections::HashMap;
11+
12+
pub async fn create_table_configs(
13+
kms_key_id: &str,
14+
ddb_table_name: &str,
15+
plaintext_override: PlaintextOverride,
16+
) -> Result<DynamoDbTablesEncryptionConfig, Box<dyn std::error::Error>> {
17+
// Create a Keyring. This Keyring will be responsible for protecting the data keys that protect your data.
18+
// For this example, we will create a AWS KMS Keyring with the AWS KMS Key we want to use.
19+
// We will use the `CreateMrkMultiKeyring` method to create this keyring,
20+
// as it will correctly handle both single region and Multi-Region KMS Keys.
21+
let provider_config = MaterialProvidersConfig::builder().build()?;
22+
let mat_prov = client::Client::from_conf(provider_config)?;
23+
let kms_keyring = mat_prov
24+
.create_aws_kms_mrk_multi_keyring()
25+
.generator(kms_key_id)
26+
.send()
27+
.await?;
28+
29+
// Configure which attributes are encrypted and/or signed when writing new items.
30+
// For each attribute that may exist on the items we plan to write to our DynamoDbTable,
31+
// we must explicitly configure how they should be treated during item encryption:
32+
// - ENCRYPT_AND_SIGN: The attribute is encrypted and included in the signature
33+
// - SIGN_ONLY: The attribute not encrypted, but is still included in the signature
34+
// - DO_NOTHING: The attribute is not encrypted and not included in the signature
35+
let partition_key_name = "partition_key";
36+
let sort_key_name = "sort_key";
37+
let attribute_actions_on_encrypt = HashMap::from([
38+
(partition_key_name.to_string(), CryptoAction::SignOnly),
39+
(sort_key_name.to_string(), CryptoAction::SignOnly),
40+
("attribute1".to_string(), CryptoAction::EncryptAndSign),
41+
("attribute2".to_string(), CryptoAction::SignOnly),
42+
("attribute3".to_string(), CryptoAction::DoNothing),
43+
]);
44+
45+
// Configure which attributes we expect to be excluded in the signature
46+
// when reading items. There are two options for configuring this:
47+
//
48+
// - (Recommended) Configure `allowedUnsignedAttributesPrefix`:
49+
// When defining your DynamoDb schema and deciding on attribute names,
50+
// choose a distinguishing prefix (such as ":") for all attributes that
51+
// you do not want to include in the signature.
52+
// This has two main benefits:
53+
// - It is easier to reason about the security and authenticity of data within your item
54+
// when all unauthenticated data is easily distinguishable by their attribute name.
55+
// - If you need to add new unauthenticated attributes in the future,
56+
// you can easily make the corresponding update to your `attributeActionsOnEncrypt`
57+
// and immediately start writing to that new attribute, without
58+
// any other configuration update needed.
59+
// Once you configure this field, it is not safe to update it.
60+
//
61+
// - Configure `allowedUnsignedAttributes`: You may also explicitly list
62+
// a set of attributes that should be considered unauthenticated when encountered
63+
// on read. Be careful if you use this configuration. Do not remove an attribute
64+
// name from this configuration, even if you are no longer writing with that attribute,
65+
// as old items may still include this attribute, and our configuration needs to know
66+
// to continue to exclude this attribute from the signature scope.
67+
// If you add new attribute names to this field, you must first deploy the update to this
68+
// field to all readers in your host fleet before deploying the update to start writing
69+
// with that new attribute.
70+
//
71+
// For this example, we will explicitly list the attributes that are not signed.
72+
let unsigned_attributes = vec!["attribute3".to_string()];
73+
74+
// Create the DynamoDb Encryption configuration for the table we will be writing to.
75+
let table_config = DynamoDbTableEncryptionConfig::builder()
76+
.logical_table_name(ddb_table_name)
77+
.partition_key_name(partition_key_name)
78+
.sort_key_name(sort_key_name)
79+
.attribute_actions_on_encrypt(attribute_actions_on_encrypt)
80+
.keyring(kms_keyring)
81+
.allowed_unsigned_attributes(unsigned_attributes)
82+
.plaintext_override(plaintext_override)
83+
.build()?;
84+
85+
let table_configs = DynamoDbTablesEncryptionConfig::builder()
86+
.table_encryption_configs(HashMap::from([(ddb_table_name.to_string(), table_config)]))
87+
.build()?;
88+
89+
Ok(table_configs)
90+
}

0 commit comments

Comments
 (0)