Skip to content

Commit 268be90

Browse files
committed
chore(python): feedback
1 parent 003c0e8 commit 268be90

File tree

11 files changed

+130
-50
lines changed

11 files changed

+130
-50
lines changed
Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,51 @@
11
# Plaintext to AWS Database Encryption SDK for DynamoDB Migration
22

3-
This project demonstrates the three steps necessary to migrate to the AWS Database Encryption SDK for DynamoDB
4-
if you are currently using plaintext data in your DynamoDB tables.
3+
This project demonstrates the steps necessary
4+
to migrate to the AWS Database Encryption SDK for DynamoDb
5+
from a plaintext database.
56

67
[Step 0](./plaintext/README.md) demonstrates the starting state for your system.
78

89
## Step 1
910

1011
In Step 1, you update your system to do the following:
1112

12-
- continue to read items in plaintext format
13-
- continue to write items in plaintext format
14-
- prepare to read items in the encrypted format
13+
- continue to read plaintext items
14+
- continue to write plaintext items
15+
- prepare to read encrypted items
1516

16-
When you deploy changes in Step 1, you should not expect any behavior change in your system,
17-
and your dataset still consists of data written in plaintext format.
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.
1820

19-
You must ensure that the changes in Step 1 make it to all your reads before you proceed to step 2.
21+
You must ensure that the changes in Step 1 make it to all your readers before you proceed to Step 2.
2022

2123
## Step 2
2224

2325
In Step 2, you update your system to do the following:
2426

25-
- continue to read items in plaintext format
26-
- start writing items in the encrypted format
27-
- continue to read items in the encrypted format
27+
- continue to read plaintext items
28+
- start writing encrypted items
29+
- continue to read encrypted items
2830

29-
When you deploy changes in Step 2, you are introducing an encrypted format to your system,
31+
When you deploy changes in Step 2,
32+
you are introducing encrypted items to your system,
3033
and must make sure that all your readers are updated with the changes from Step 1.
3134

32-
Before you move onto the next step, you will need to re-encrypt all plaintext items in your dataset
33-
to use the newest format. How you will want to do this, and how long you may want to remain in this Step,
34-
depends on your system and your desired security properties for old and new items.
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.
3541

3642
## Step 3
3743

38-
Once all plaintext items are re-encrypted to use the encrypted format,
39-
you may update your system to do the following:
44+
Once all plaintext items are encrypted,
45+
update your system to do the following:
4046

41-
- continue to write items in the encrypted format
42-
- continue to read items in the encrypted format
43-
- do not accept reading items in plaintext format
47+
- continue to write encrypted items
48+
- continue to read encrypted items
49+
- do not accept reading plaintext items
4450

4551
Once you have deployed these changes to your system, you have completed migration.

Examples/runtimes/python/Migration/plaintext_to_awsdbe/src/awsdbe/client/common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
)
2020

2121

22-
def setup_pure_awsdbe_client(kms_key_id: str, ddb_table_name: str):
22+
def setup_awsdbe_client_without_plaintext_override(kms_key_id: str, ddb_table_name: str):
2323
"""
2424
Set up a pure AWS Database Encryption SDK EncryptedClient without plaintext override.
2525
@@ -183,6 +183,7 @@ def setup_awsdbe_client_with_plaintext_override(kms_key_id: str, ddb_table_name:
183183
sort_key_name="sort_key",
184184
attribute_actions_on_encrypt=attribute_actions_on_encrypt,
185185
keyring=kms_mrk_multi_keyring,
186+
# Provide plaintext_override policy to the config here
186187
plaintext_override=policy,
187188
allowed_unsigned_attribute_prefix=unsignAttrPrefix,
188189
# Specifying an algorithm suite is not required,

Examples/runtimes/python/Migration/plaintext_to_awsdbe/src/awsdbe/client/migration_step_3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
- Sort key is named "sort_key" with type (S)
2121
"""
2222

23-
from .common import setup_pure_awsdbe_client
23+
from .common import setup_awsdbe_client_without_plaintext_override
2424

2525

2626
def migration_step_3_with_client(kms_key_id: str, ddb_table_name: str, sort_read_value: int = 3):
@@ -33,7 +33,7 @@ def migration_step_3_with_client(kms_key_id: str, ddb_table_name: str, sort_read
3333
"""
3434
# 1. Create the EncryptedClient.
3535
# Do not configure any plaintext override.
36-
encrypted_client = setup_pure_awsdbe_client(kms_key_id, ddb_table_name)
36+
encrypted_client = setup_awsdbe_client_without_plaintext_override(kms_key_id, ddb_table_name)
3737

3838
# 2. Put an item into your table using the Encrypted Client.
3939
# This item will be encrypted using the DB Encryption SDK, using the

Examples/runtimes/python/Migration/plaintext_to_awsdbe/src/awsdbe/paginator/migration_step_3.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
- Sort key is named "sort_key" with type (N)
2020
"""
2121

22-
from ..client.common import setup_pure_awsdbe_client
22+
from ..client.common import setup_awsdbe_client_without_plaintext_override
2323

2424

2525
def migration_step_3_with_paginator(kms_key_id: str, ddb_table_name: str, sort_read_value: int = 3):
@@ -33,7 +33,9 @@ def migration_step_3_with_paginator(kms_key_id: str, ddb_table_name: str, sort_r
3333
# 1. Create an EncryptedClient without plaintext override.
3434
# Without a plaintext override, both reads and writes will use the AWS Database Encryption SDK,
3535
# meaning that we can only read items that have been encrypted and we will always encrypt items on write.
36-
encrypted_client = setup_pure_awsdbe_client(kms_key_id=kms_key_id, ddb_table_name=ddb_table_name)
36+
encrypted_client = setup_awsdbe_client_without_plaintext_override(
37+
kms_key_id=kms_key_id, ddb_table_name=ddb_table_name
38+
)
3739

3840
# 2. Put an example item into our DynamoDb table using the Encrypted Client.
3941
# This item will be encrypted using the DB Encryption SDK, using the

Examples/runtimes/python/Migration/plaintext_to_awsdbe/src/awsdbe/resource/common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
)
2020

2121

22-
def setup_pure_awsdbe_resource(kms_key_id: str, ddb_table_name: str):
22+
def setup_awsdbe_resource_without_plaintext_override(kms_key_id: str, ddb_table_name: str):
2323
"""
2424
Set up a pure AWS Database Encryption SDK EncryptedResource without plaintext override.
2525
@@ -187,6 +187,7 @@ def setup_awsdbe_resource_with_plaintext_override(kms_key_id: str, ddb_table_nam
187187
sort_key_name="sort_key",
188188
attribute_actions_on_encrypt=attribute_actions_on_encrypt,
189189
keyring=kms_mrk_multi_keyring,
190+
# Provide plaintext_override policy to the config here
190191
plaintext_override=policy,
191192
allowed_unsigned_attribute_prefix=unsignAttrPrefix,
192193
# Specifying an algorithm suite is not required,

Examples/runtimes/python/Migration/plaintext_to_awsdbe/src/awsdbe/resource/migration_step_3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
- Sort key is named "sort_key" with type (N)
2121
"""
2222

23-
from .common import setup_pure_awsdbe_resource
23+
from .common import setup_awsdbe_resource_without_plaintext_override
2424

2525

2626
def migration_step_3_with_resource(kms_key_id: str, ddb_table_name: str, sort_read_value: int = 3):
@@ -33,7 +33,7 @@ def migration_step_3_with_resource(kms_key_id: str, ddb_table_name: str, sort_re
3333
"""
3434
# 1. Create the EncryptedResource.
3535
# Do not configure any plaintext override.
36-
encrypted_resource = setup_pure_awsdbe_resource(kms_key_id, ddb_table_name)
36+
encrypted_resource = setup_awsdbe_resource_without_plaintext_override(kms_key_id, ddb_table_name)
3737

3838
# 2. Write a batch of items to the table using the Encrypted Resource.
3939
# These items will be encrypted using the DB Encryption SDK, using the

Examples/runtimes/python/Migration/plaintext_to_awsdbe/src/awsdbe/table/common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
)
2020

2121

22-
def setup_pure_awsdbe_table(kms_key_id: str, ddb_table_name: str):
22+
def setup_awsdbe_table_without_plaintext_override(kms_key_id: str, ddb_table_name: str):
2323
"""
2424
Set up a pure AWS Database Encryption SDK EncryptedTable without plaintext override.
2525
@@ -188,6 +188,7 @@ def setup_awsdbe_table_with_plaintext_override(kms_key_id: str, ddb_table_name:
188188
sort_key_name="sort_key",
189189
attribute_actions_on_encrypt=attribute_actions_on_encrypt,
190190
keyring=kms_mrk_multi_keyring,
191+
# Provide plaintext_override policy to the config here
191192
plaintext_override=policy,
192193
allowed_unsigned_attribute_prefix=unsignAttrPrefix,
193194
# Specifying an algorithm suite is not required,

Examples/runtimes/python/Migration/plaintext_to_awsdbe/src/awsdbe/table/migration_step_3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
- Sort key is named "sort_key" with type (N)
2121
"""
2222

23-
from .common import setup_pure_awsdbe_table
23+
from .common import setup_awsdbe_table_without_plaintext_override
2424

2525

2626
def migration_step_3_with_table(kms_key_id: str, ddb_table_name: str, sort_read_value: int = 3):
@@ -33,7 +33,7 @@ def migration_step_3_with_table(kms_key_id: str, ddb_table_name: str, sort_read_
3333
"""
3434
# 1. Create the EncryptedTable.
3535
# Do not configure any plaintext override.
36-
encrypted_table = setup_pure_awsdbe_table(kms_key_id, ddb_table_name)
36+
encrypted_table = setup_awsdbe_table_without_plaintext_override(kms_key_id, ddb_table_name)
3737

3838
# 2. Put an item into your table using the Encrypted Table.
3939
# This item will be encrypted using the DB Encryption SDK, using the

Examples/runtimes/python/Migration/plaintext_to_awsdbe/test/awsdbe/paginator/test_migration_step_3.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77
Step 3 can only read encrypted items and will fail with plaintext items.
88
"""
99
import pytest
10+
from aws_dbesdk_dynamodb.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb_transforms.errors import (
11+
DynamoDbItemEncryptor,
12+
)
1013

1114
from ....src.awsdbe.paginator import (
15+
migration_step_1,
1216
migration_step_2,
1317
migration_step_3,
1418
)
19+
from ....src.plaintext.paginator import migration_step_0
1520
from ...test_utils import TEST_DDB_TABLE_NAME, TEST_KMS_KEY_ID
1621

1722
pytestmark = [pytest.mark.examples]
@@ -20,14 +25,36 @@
2025
def test_migration_step_3_with_paginator():
2126
"""Test migration step 3 compatibility with encrypted data formats only."""
2227
# Successfully executes Step 3
23-
migration_step_3.migration_step_3_with_paginator(kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME)
28+
migration_step_3.migration_step_3_with_paginator(
29+
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=3
30+
)
2431

25-
# Given: Step 2 has succeeded (writing encrypted data)
26-
migration_step_2.migration_step_2_with_paginator(kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME)
27-
# When: Execute Step 3
28-
# Then: Success (i.e. can read values in encrypted format)
29-
migration_step_3.migration_step_3_with_paginator(kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME)
32+
# Given: Step 0 has succeeded
33+
migration_step_0.migration_step_0_with_paginator(ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=0)
34+
# When: Execute Step 3 with sort_read_value=0
35+
# Then: throws DynamoDbItemEncryptor Exception (i.e. cannot read values in plaintext format)
36+
with pytest.raises(DynamoDbItemEncryptor):
37+
migration_step_3.migration_step_3_with_paginator(
38+
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=0
39+
)
3040

31-
# Note: Step 3 cannot read plaintext items (those written by Step 0 or Step 1)
32-
# If attempted, it would throw an error because those items don't have the
33-
# necessary encryption material
41+
# Given: Step 1 has succeeded
42+
migration_step_1.migration_step_1_with_paginator(
43+
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=1
44+
)
45+
# When: Execute Step 3 with sort_read_value=1
46+
# Then: throws DynamoDbItemEncryptor Exception (i.e. cannot read values in plaintext format)
47+
with pytest.raises(DynamoDbItemEncryptor):
48+
migration_step_3.migration_step_3_with_paginator(
49+
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=1
50+
)
51+
52+
# Given: Step 2 has succeeded
53+
migration_step_2.migration_step_2_with_paginator(
54+
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=2
55+
)
56+
# When: Execute Step 3 with sort_read_value=2
57+
# Then: Success (i.e. can read values in encrypted format)
58+
migration_step_3.migration_step_3_with_paginator(
59+
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=2
60+
)

Examples/runtimes/python/Migration/plaintext_to_awsdbe/test/awsdbe/resource/test_migration_step_3.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77
Step 3 can only read encrypted items and will fail with plaintext items.
88
"""
99
import pytest
10+
from aws_dbesdk_dynamodb.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb_transforms.errors import (
11+
DynamoDbItemEncryptor,
12+
)
1013

1114
from ....src.awsdbe.resource import (
15+
migration_step_1,
1216
migration_step_2,
1317
migration_step_3,
1418
)
19+
from ....src.plaintext.resource import migration_step_0
1520
from ...test_utils import TEST_DDB_TABLE_NAME, TEST_KMS_KEY_ID
1621

1722
pytestmark = [pytest.mark.examples]
@@ -24,7 +29,27 @@ def test_migration_step_3_with_resource():
2429
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=3
2530
)
2631

27-
# Given: Step 2 has succeeded (writing encrypted data)
32+
# Given: Step 0 has succeeded
33+
migration_step_0.migration_step_0_with_resource(ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=0)
34+
# When: Execute Step 3 with sort_read_value=0
35+
# Then: throws DynamoDbItemEncryptor Exception (i.e. cannot read values in plaintext format)
36+
with pytest.raises(DynamoDbItemEncryptor):
37+
migration_step_3.migration_step_3_with_resource(
38+
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=0
39+
)
40+
41+
# Given: Step 1 has succeeded
42+
migration_step_1.migration_step_1_with_resource(
43+
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=1
44+
)
45+
# When: Execute Step 3 with sort_read_value=1
46+
# Then: throws DynamoDbItemEncryptor Exception (i.e. cannot read values in plaintext format)
47+
with pytest.raises(DynamoDbItemEncryptor):
48+
migration_step_3.migration_step_3_with_resource(
49+
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=1
50+
)
51+
52+
# Given: Step 2 has succeeded
2853
migration_step_2.migration_step_2_with_resource(
2954
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=2
3055
)
@@ -33,7 +58,3 @@ def test_migration_step_3_with_resource():
3358
migration_step_3.migration_step_3_with_resource(
3459
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=2
3560
)
36-
37-
# Note: Step 3 cannot read plaintext items (those written by Step 0 or Step 1)
38-
# If attempted, it would throw an error because those items don't have the
39-
# necessary encryption material

0 commit comments

Comments
 (0)