Repository navigation
Conversation
JuanLeee
force-pushed
the
feat/kms-stack-5-integration-tests
branch
from
November 18, 2026 09:43
5b47c72 to
28b3bf3
Compare
JuanLeee
force-pushed
the
feat/kms-stack-5-integration-tests
branch
2 times, most recently
from
November 19, 2026 10:24
ae97e03 to
42c9aa2
Compare
JuanLeee
force-pushed
the
feat/kms-stack-5-integration-tests
branch
from
November 27, 2026 08:46
42c9aa2 to
3cf4b92
Compare
Add container tests for the KMS Encryption plugin on PostgreSQL and MySQL, including SQLAlchemy and Django, against LocalStack's KMS, a real KMS key and Aurora. The harness gets the RUN_KMS_ENCRYPTION_TESTS_ONLY, KMS_LOCALSTACK and KMS_MANUAL_TESTS features, three Gradle tasks, a LocalStack container pinned by digest, PostgreSQL statement logging and a JUnit XML report. No product code changes. Without KMS_KEY_ARN, the harness finds the marked test key behind a KMS alias (KMS_KEY_ALIAS, or alias/aws-advanced-python-wrapper/integration-tests) and reuses it. It makes the key and the alias only when KMS_ALLOW_KEY_CREATION is set, and for the Docker task it makes a decrypt-only role for the run and deletes it at the end. It never deletes or reuses a key or role that it didn't make or mark. Two harness changes apply to every Aurora and RDS task: a run refuses an RDS_DB_NAME that names an existing cluster, and it revokes only the IP rule that it added itself. Add a compose lane, tests/integration/kms_local/run.sh, that runs the LocalStack modules without Gradle. It replaces tests/integration/test_kms_encryption_live.py. A new workflow runs the LocalStack job on pull requests and pushes to main, and the real-key and Aurora jobs on dispatch and on pushes to main once their repository variables are set. Each job fails when no KMS test ran. Two strict xfails track product defects on mysql-connector's C extension: fetchmany() without a size returns no rows, and with use_unicode=False a read or write on an encrypted table raises a bare KeyError. The real-key and Aurora jobs need one-time administrator setup: a symmetric key, an OIDC role trusted only for main and limited to that key, a Decrypt-only role, and the KMS_KEY_ARN, KMS_REGION, KMS_IT_ROLE_ARN and KMS_DECRYPT_ONLY_ROLE_ARN repository variables.
JuanLeee
force-pushed
the
feat/kms-stack-5-integration-tests
branch
from
December 1, 2026 13:03
3cf4b92 to
b7bda0c
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The KMS Encryption Plugin (#1331) has unit tests, but nothing runs it against real servers, drivers, KMS or Aurora in the integration harness or in CI. The only end-to-end checks were
tests/integration/test_kms_encryption_live.py, a module run by hand against local servers, which CI never ran. Testing against a real key also needs a key and a decrypt-only role, which the harness had no way to find, make or remove.This PR adds the plugin's integration tests on three environments (LocalStack's KMS, a real KMS key and Aurora), the Gradle tasks and workflow that run them, and harness code that finds or makes the real test key. It changes no product code. Its base is #1331's branch, so the diff holds none of #1331's code, and it should merge with #1331, which builds on #1330, #1300 and #1317.
KeyManagementUtility, KMS refusals and the allow-list. Others check that the server's statement log holds no written plaintext or plaintext data key, and run SQLAlchemy and Django round trips. On MySQL the tests run on both the C extension and the pure build, except 15 that skip the pure build.tests/integration/kms_local/runs the LocalStack modules without Gradle, with every port on127.0.0.1, and replaces the deletedtest_kms_encryption_live.py.RUN_KMS_ENCRYPTION_TESTS_ONLY,KMS_LOCALSTACKandKMS_MANUAL_TESTSfeatures and three Gradle tasks:test-kms-encryption-docker(LocalStack, no AWS account),test-kms-encryption-docker-kms(a real key) andtest-kms-encryption-aurora(two-instance clusters), all on Python 3.12 without async drivers. LocalStack (3.8.1, per the harness comment) is pinned by digest alone, because Testcontainers rejects a tag with a digest, and it publishes no port. In KMS environments the PostgreSQL container logs every statement, so tests can prove the server never saw a written plaintext or a plaintext data key. Inside a KMS task every non-KMS test skips, and outside one the KMS classes skip.KMS_MANUAL_TESTS=1adds the 3 manual real-key tests (akms:ViaServicecondition, CloudTrail records, expired credentials), which CI never runs.KmsTestUtility, new in the harness, gives a real-key run its key whenKMS_KEY_ARNis unset. It uses the key behindKMS_KEY_ALIASoralias/aws-advanced-python-wrapper/integration-testsonly when that key is enabled and symmetric, its description starts with "aws-advanced-python-wrapper test KMS key" and it has the tagaws-advanced-python-wrapper=integration-tests. It makes the key and the alias only whenKMS_ALLOW_KEY_CREATIONis1,trueoryes, as the Ruby wrapper reads that variable, and keeps them for later runs. The Docker task makes a per-run role that may only callkms:Decrypton the key and deletes it at the end, so that task needs the opt-in even to reuse the key; the Aurora task makes no role and reuses the key without it.KMS_KEY_ARNlooks up and makes nothing; before any environment starts, it checks that the value is a key ARN (not an alias or key ID) inKMS_REGIONand, for the Docker task, thatKMS_DECRYPT_ONLY_ROLE_ARNis set, so an Aurora run never creates a cluster without a key.test-*Gradle task now writestests/integration/container/reports/<environment>.xmlbeside the HTML report, which the workflow counts. Apytest_runtest_makereportwrapper in the container conftest replaces the database password, the application users' passwords and a real key's account ID and key ID with***in both reports, because the harness runs pytest with--tb=long, which prints each frame's arguments. The live console output isn't redacted; CI makes a random database password for each job and masks it with::add-mask::.kms_encryption_integration_tests.ymlruns each job on PostgreSQL and MySQL.kms-localstackneeds no secrets and runs on pull requests to any base and pushes tomainthat touch the wrapper, the integration tests,pyproject.toml,poetry.lockor the workflow.kms-real-keyandkms-aurorarun on dispatch, and on pushes tomainonce their repository variables are set, somainstays green until then; after that, each such push makes one two-instance Aurora cluster per engine. Each job fails when no KMS test ran, because pytest exits 0 when every test skips. The Aurora job ends by deleting the cluster namedRDS_DB_NAME, because the harness doesn't delete it when a run is cancelled.Behaviour changes
Other fixes
RDS_DB_NAMEnamed an existing cluster tried to create a cluster under that name, and the failed create'scatchthen deleted the existing cluster (from reading the code; not reproduced). The run now fails first with "Cluster already exists: set REUSE_RDS_DB=true to use it, or set RDS_DB_NAME to a new name." Live sinceb525ea9b(upgrade integration test suite (host part) #430, 2024-03-12); a Multi-AZ instance run keeps the old path.defaultsecurity group even when the rule existed before the run, becauseec2AuthorizeIPskipped an existing rule silently.ec2AuthorizeIPnow reports whether it added the rule, and teardown revokes only then. Live sinceb525ea9b(upgrade integration test suite (host part) #430, 2024-03-12).pytest_runtest_setupraisedTypeErrorfor a test without parameters, since it addedNoneto a string.TestEnvironment.get_proxy_infosraisedAttributeErrorwhen no proxies were set up, as in the compose lane; it now returns[].Not in scope
AwsWrapperCursor.fetchmany()defaultssizeto 0 and passes it on, so the C extension returns no rows; the same code is onmain, and the async cursor defaults toNone. Withuse_unicode=False,DriverDialect.fetch_rows, new in feat: kms encryption plugin #1331, keys rows by column names that the C extension returns as bytes, so the plugin raises a bareKeyErrorinstead ofInvalidAlgorithmError(seen through the xfail; the C extension's source wasn't read).MetadataError, which doesn't startfailover_v2, as the guide says. The failover test accepts that on PostgreSQL by opening a new connection, while MySQL must write through.kms_encryption.mysql_connectorDjango backend.Administrator setup, once
subequal torepo:aws/aws-advanced-python-wrapper:ref:refs/heads/main(StringEquals) andaudequal tosts.amazonaws.com, allowedkms:GenerateDataKey,kms:Decryptandkms:DescribeKeyon the key andsts:AssumeRoleon the Decrypt-only role, with an explicit deny on key and alias changes.kms:Decrypton the key.main.KMS_KEY_ARN(a key ARN, not an alias),KMS_REGION,KMS_IT_ROLE_ARNandKMS_DECRYPT_ONLY_ROLE_ARN. The Aurora job uses the existingAWS_DEPLOY_ROLEsecret, whose role also needs the test container's KMS actions on the key.Tests
./gradlew test-kms-encryption-dockeron this tree passed PostgreSQL 97 and MySQL 190 cases, with the 2 strict xfails and nothing failed, and this PR'skms-localstackjobs reported "KMS tests run: 97" and "KMS tests run: 190". That lane collected every container test (475 on PostgreSQL, 585 on MySQL), so the new conftest import works at collection; no non-KMS Gradle task was run on this tree../gradlew test-kms-encryption-docker-kmsin a test account passed MySQL 8 and PostgreSQL 5 cases three times: when the harness made the key and the alias, when it reused them and made no new key or alias and with an explicitKMS_KEY_ARN. Without an alias or the opt-in, and with an alias naming an unmarked key, the run failed before it made anything. The two runs withoutKMS_KEY_ARNeach deleted the decrypt-only role they made, and the key and alias stayed for later runs. The 6 new unit tests (9 cases) cover the async wrapper refusingkms_encryption, a read refused when its key row names an unlisted master key (lenient mode too), the guide's DDL matching the tests' schema and MySQL routines reading no session variables.pytest tests/unit -Werrorpasses 4713 tests on Python 3.12 and 3.10, with flake8, isort and mypy clean. The Aurora task, the manual tests and the compose lane weren't run on this tree, and the workflow's real-key and Aurora jobs skip on pull requests. On an earlier commit, the Aurora task's auth and TLS test and trigger test passed on Aurora PostgreSQL 17.9 and MySQL 3.10.3, and its failover test passed on MySQL.IntegrationTests.mdgains "Running the KMS encryption tests" and "Existing clusters and leftovers", and the plugin guide gains three lines on upserts and alias ARNs. No CHANGELOG entry or message key.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.