Skip to content

chore: Cdk plus basic ci test#1

Merged
kessplas merged 36 commits into
stagingfrom
cdk-plus-basic-ci-test
Aug 12, 2025
Merged

chore: Cdk plus basic ci test#1
kessplas merged 36 commits into
stagingfrom
cdk-plus-basic-ci-test

Conversation

@kessplas

@kessplas kessplas commented Aug 6, 2025

Copy link
Copy Markdown
Contributor

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@kessplas kessplas changed the base branch from main to staging August 6, 2025 23:58

@lucasmcdonald3 lucasmcdonald3 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial skim, I'd also recommend adding linters sooner rather than later. I think the "cool" linters these days are a combination of ruff and black: https://github.com/aws/aws-database-encryption-sdk-dynamodb/blob/python-poc/DynamoDbEncryption/runtimes/python/pyproject.toml#L59-L61

Comment thread pyproject.toml Outdated
Comment on lines +13 to +14
# There is a newer version, but MPL wants this one.
cryptography = "^43.0.1"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# There is a newer version, but MPL wants this one.
cryptography = "^43.0.1"

This is included transitively via MPL

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok -- given that you don't need the MPL let me also save you from a mistake I made and set this as a range

Suggested change
# There is a newer version, but MPL wants this one.
cryptography = "^43.0.1"
# There is a newer version, but MPL wants this one.
cryptography = ">=45.0.1, <46"

the "^43.0.1" syntax resolves to >=43.0.1, <44 which restricts customers.

When launching MPL-Python, we decided the best thing to do was to drop support for as many older versions as possible of cryptography, so ideally we're launching with the newest support possible. It's easy to decrease the minimum version later on but hard to increase it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to specify an upper bound on future major versions? I feel like it's reasonable to trust the future MVs will be backwards compatible (unless there's a serious security issue in which case we'd need to do some work to upgrade). Any reason we shouldn't just go with cryptography = ">=45.0.6"?

Comment thread pyproject.toml Outdated
boto3 = "^1.37.2"
# There is a newer version, but MPL wants this one.
cryptography = "^43.0.1"
aws-cryptographic-material-providers = "^1.7.4"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
aws-cryptographic-material-providers = "^1.7.4"
aws-cryptographic-material-providers = "^1.11.1"

Bump to latest when you get a chance, there are traps in earlier versions

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait -- does this need the MPL?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't, not sure how/why it ended up there. Will remove.

Comment thread pyproject.toml Outdated
cryptography = "^43.0.1"
aws-cryptographic-material-providers = "^1.7.4"
attrs = "^25.1.0"
pytest = "^8.4.1"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread pyproject.toml Outdated
@@ -0,0 +1,22 @@
[tool.poetry]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might consider using uv instead of poetry. All the cool projects are using uv these days: https://github.com/astral-sh/uv

poetry is not a great package management system, but it solved some needs specific to Dafny-Python issues. Since you're not generating any Dafny code, you can probably branch out.

Comment thread src/s3_encryption/__init__.py Outdated
Comment on lines +29 to +31
# TODO: I don't know exactly how boto3 works,
# we maybe instead prefer only using kwargs?
# Do we need to provide specific arg overloads?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo, ideally any clients we write should be able to act as drop-in replacements for the boto3 equivalents, which means just using kwargs.

from typing import List, Dict, Any, Union

# API Stub for CMM
class AbstractCryptoMaterialsManager():

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, now I know my abc's

from attrs import define
from .keyring import AbstractKeyring
from .materials import EncryptionMaterials, DecryptionMaterials
from typing import List, Dict, Any, Union

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the built-int dict and list types now (3.9+)

@lucasmcdonald3 lucasmcdonald3 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few more notes


# API Stub for CMM
class AbstractCryptoMaterialsManager:
def getEncryptionMaterials(self, encMatsRequest):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style nit that I'm sure a linter will pick up -- snakecase methods and field names

Suggested change
def getEncryptionMaterials(self, encMatsRequest):
def get_encryption_materials(self, enc_mats_request):

encrypted_data_key (bytes): The encrypted data key
"""

key_provider_info: str = field()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the field()s are redundant on a class annotated with define? Not terribly familiar with this though, and you may have plans to expand the behavior in the field calls here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's correct, since none of these has a default, we can remove them

Comment thread pyproject.toml Outdated
Comment on lines +13 to +14
# There is a newer version, but MPL wants this one.
cryptography = "^43.0.1"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok -- given that you don't need the MPL let me also save you from a mistake I made and set this as a range

Suggested change
# There is a newer version, but MPL wants this one.
cryptography = "^43.0.1"
# There is a newer version, but MPL wants this one.
cryptography = ">=45.0.1, <46"

the "^43.0.1" syntax resolves to >=43.0.1, <44 which restricts customers.

When launching MPL-Python, we decided the best thing to do was to drop support for as many older versions as possible of cryptography, so ideally we're launching with the newest support possible. It's easy to decrease the minimum version later on but hard to increase it.

Comment thread src/s3_encryption/__init__.py Outdated
config: S3EncryptionClientConfig = field()

# TODO: rename Data-> Body to match boto
def put_object(self, Bucket, Key, Data, EncryptionContext=None, **kwargs):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opening a debate here: I'd suggest just this instead:

Suggested change
def put_object(self, Bucket, Key, Data, EncryptionContext=None, **kwargs):
def put_object(self, **kwargs):

imo, our clients' API arguments should align with the boto3 API arguments.
Note that I might expect customers to provide EncryptionContext just in kwargs.
I could be wrong here -- what you have seems totally fine but I think it's worth discussing.


@define
class KmsKeyring(S3Keyring):
kms_client = field()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note that I've used botocore.client.BaseClient for the boto3 client typehint before

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally it'd be a KmsClient specifically,
but i suppose BaseClient is better than nothing.

@kessplas kessplas Aug 11, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's actually some default arg shenanigans from line 58 in those logs:

self = KmsKeyring(kms_key_id=<botocore.client.KMS object at 0x7f38961ff5d0>, enable_legacy_wrapping_algorithms='arn:aws:kms:us-west-2:370957321024:alias/S3EC-Python-Github-KMS-Key')

Comment thread test/test_decryption_materials.py Outdated
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

import unittest

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might suggest pytest instead of unittest:

  1. more robust feature support
  2. we have pretty extensive examples of tests using pytest in ESDK and DBESDK doing some complicated things (ex parametrization/matrices, fixtures) so if you ever want more complicated behavior in tests you can just refer to those

Comment thread poetry.lock Outdated
@@ -0,0 +1,656 @@
# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should gitignore this (and other files)

Comment thread src/s3_encryption/__init__.py Outdated
# Extract required parameters from kwargs
bucket = kwargs.pop("Bucket")
key = kwargs.pop("Key")
body = kwargs.pop("Body")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implies Body is a required parameter, but boto3 docs imply it is optional: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3/client/put_object.html

Is this intentional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, as senseless as it seems, omitting the Body produces a 0 byte object. This is technically fine to do with AES-GCM encryption, so we should support it.

"""Get encryption materials from the keyring.

Args:
enc_mats_request (Dict[str, Any]): Request containing encryption parameters

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
enc_mats_request (Dict[str, Any]): Request containing encryption parameters
enc_mats_request (Dict[str, Any] or EncryptionMaterials): Request containing encryption parameters

I think this type syntax is still a little off, but you might need to play around with pydocs to find the right syntax


@define
class KmsKeyring(S3Keyring):
kms_client = field()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's actually some default arg shenanigans from line 58 in those logs:

self = KmsKeyring(kms_key_id=<botocore.client.KMS object at 0x7f38961ff5d0>, enable_legacy_wrapping_algorithms='arn:aws:kms:us-west-2:370957321024:alias/S3EC-Python-Github-KMS-Key')

encryption_context_from_request=materials_dict.get(
"encryption_context_from_request", {}
),
plaintext_data_key=materials_dict.get("PDK"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why "PDK"? Why not plaintext_data_key? That's more idiomatic

@kessplas kessplas merged commit 7a3b929 into staging Aug 12, 2025
2 checks passed
@kessplas kessplas deleted the cdk-plus-basic-ci-test branch August 12, 2025 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants