Skip to content

chore(duvet): annotate Keyring, S3Keyring, and KmsKeyring classes#143

Merged
kessplas merged 9 commits into
stagingfrom
kessplas/backfil-duvet
Mar 3, 2026
Merged

chore(duvet): annotate Keyring, S3Keyring, and KmsKeyring classes#143
kessplas merged 9 commits into
stagingfrom
kessplas/backfil-duvet

Conversation

@kessplas

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 marked this pull request as ready for review February 24, 2026 17:35

@texastony texastony 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.

I have a few nits, but in general, LGTM.

Comment on lines +81 to +85
##= specification/s3-encryption/materials/s3-kms-keyring.md#encryptdatakey
##= type=exception
##% The KmsKeyring MUST implement the EncryptDataKey method.
##% The keyring MUST call [AWS KMS Encrypt](https://docs.aws.amazon.com/kms/latest/
##% APIReference/API_Encrypt.html) using the configured AWS KMS client.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this duplicated from the exceptions file?

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 catch

Comment thread test/test_kms_keyring.py
##% When decrypting using Kms+Context mode, the KmsKeyring MUST validate the provided (request) encryption context with the stored (materials) encryption context.
##= specification/s3-encryption/materials/s3-kms-keyring.md#decryptdatakey
##= type=test
##% If the Key Provider Info of the Encrypted Data Key is "kms+context", the KmsKeyring MUST attempt to decrypt using Kms+Context mode.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: this is not really asserted directly by this test.

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 point, i'll move it to the below test

Comment thread test/test_kms_keyring.py
Comment on lines +268 to +271
encryption_context_stored={
"aws:x-amz-cek-alg": "AES/GCM/NoPadding",
"custom-key": "stored-value",
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The spec says two reserved keys. But I only count 1.

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.

Aside: the spec should include a line to specify that the presence of a reserved key MUST throw an exception.

Also, yes, this is a bug in the existing Python code. I've cut an issue to track this: #146

Comment thread test/test_kms_keyring.py Outdated
Comment on lines +435 to +436
with pytest.raises(Exception):
keyring.on_decrypt(dec_materials)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we ensure that this the exception defined on line 420?

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 shout, this test was fine but test_on_decrypt_fails_when_kms_v1_fails was throwing a different exception.

@kessplas kessplas merged commit 4d8a1a6 into staging Mar 3, 2026
5 checks passed
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.

2 participants