Skip to content

feat(s3tables): server-side encryption by customer managed KMS key #34229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 9, 2025

Conversation

badmintoncryer
Copy link
Contributor

Issue # (if applicable)

None

Reason for this change

AWS S3 Tables supports for server side encryption by customer managed KMS keys.

https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-tables-kms-encryption.html

And cloudformation have supported for this feature.

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3tables-tablebucket-encryptionconfiguration.html

Description of changes

Describe any new or updated permissions being added

Add resource policy to the kms key.

// add resource policy to the encryption key
    // see https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-tables-kms-permissions.html#tables-kms-maintenance-permissions
    props?.kmsKey?.addToResourcePolicy(
      new iam.PolicyStatement({
        actions: ['kms:Decrypt', 'kms:GenerateDataKey'],
        resources: ['*'],
        effect: iam.Effect.ALLOW,
        principals: [new iam.ServicePrincipal('maintenance.s3tables.amazonaws.com')],
        conditions: {
          StringLike: {
            'kms:EncryptionContext:aws:s3:arn': `${Stack.of(this).formatArn({
              service: 's3tables',
              resource: 'bucket',
              resourceName: props.tableBucketName,
            })}/*`,
          },
        },
      }),
    );

Description of how you validated changes

Add both unit and integ tests.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team April 23, 2025 14:17
@github-actions github-actions bot added p2 distinguished-contributor [Pilot] contributed 50+ PRs to the CDK labels Apr 23, 2025
@badmintoncryer badmintoncryer changed the title feat(s3tables): kms key encryption feat(s3tables): server-side encryption by customer managed KMS key Apr 23, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

(This review is outdated)

props?.kmsKey?.addToResourcePolicy(
new iam.PolicyStatement({
actions: ['kms:Decrypt', 'kms:GenerateDataKey'],
resources: ['*'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While the documentation specifies using the KMS Key ARN as resource section, I am using a wildcard (*) for the following reasons:

@aws-cdk-automation aws-cdk-automation dismissed their stale review April 23, 2025 14:33

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Apr 23, 2025
@aws-cdk-automation aws-cdk-automation added pr/needs-maintainer-review This PR needs a review from a Core Team Member and removed pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. labels Apr 24, 2025
kmsKey,
});

Template.fromStack(stack).hasResourceProperties('AWS::KMS::Key', {
Copy link
Contributor

@QuantumNeuralCoder QuantumNeuralCoder May 5, 2025

Choose a reason for hiding this comment

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

Can you run the security-guardian tool locally? I am sure it will complain :). Refer README.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the execution result. Is it OK?

❯ yarn security-guardian
yarn run v1.22.21
$ ts-node src/index.ts --rule_set_path=./rules
Created working directory: ./changed_templates
Detecting changed .template.json files from origin/main to HEAD
[command]/opt/homebrew/bin/git diff --name-status origin/main HEAD
M       packages/@aws-cdk/aws-s3tables-alpha/README.md
M       packages/@aws-cdk/aws-s3tables-alpha/lib/table-bucket.ts
M       packages/@aws-cdk/aws-s3tables-alpha/rosetta/default.ts-fixture
A       packages/@aws-cdk/aws-s3tables-alpha/test/integration/integ.table-bucket-kms-key.js.snapshot/cdk.out
A       packages/@aws-cdk/aws-s3tables-alpha/test/integration/integ.table-bucket-kms-key.js.snapshot/integ.json
A       packages/@aws-cdk/aws-s3tables-alpha/test/integration/integ.table-bucket-kms-key.js.snapshot/kms-key-s3tables-stack.assets.json
A       packages/@aws-cdk/aws-s3tables-alpha/test/integration/integ.table-bucket-kms-key.js.snapshot/kms-key-s3tables-stack.template.json
A       packages/@aws-cdk/aws-s3tables-alpha/test/integration/integ.table-bucket-kms-key.js.snapshot/kmskeys3tablesintegDefaultTestDeployAssertC8AB8C4E.assets.json
A       packages/@aws-cdk/aws-s3tables-alpha/test/integration/integ.table-bucket-kms-key.js.snapshot/kmskeys3tablesintegDefaultTestDeployAssertC8AB8C4E.template.json
A       packages/@aws-cdk/aws-s3tables-alpha/test/integration/integ.table-bucket-kms-key.js.snapshot/manifest.json
A       packages/@aws-cdk/aws-s3tables-alpha/test/integration/integ.table-bucket-kms-key.js.snapshot/tree.json
A       packages/@aws-cdk/aws-s3tables-alpha/test/integration/integ.table-bucket-kms-key.ts
M       packages/@aws-cdk/aws-s3tables-alpha/test/table-bucket.test.ts
[command]/opt/homebrew/bin/git rev-parse --show-toplevel
/Users/kazuhoshinozuka/git/aws-cdk
fullpath: /Users/kazuhoshinozuka/git/aws-cdk/packages/@aws-cdk/aws-s3tables-alpha/test/integration/integ.table-bucket-kms-key.js.snapshot/kms-key-s3tables-stack.template.json
Copied: packages/@aws-cdk/aws-s3tables-alpha/test/integration/integ.table-bucket-kms-key.js.snapshot/kms-key-s3tables-stack.template.json
[command]/opt/homebrew/bin/git rev-parse --show-toplevel
/Users/kazuhoshinozuka/git/aws-cdk
fullpath: /Users/kazuhoshinozuka/git/aws-cdk/packages/@aws-cdk/aws-s3tables-alpha/test/integration/integ.table-bucket-kms-key.js.snapshot/kmskeys3tablesintegDefaultTestDeployAssertC8AB8C4E.template.json
Copied: packages/@aws-cdk/aws-s3tables-alpha/test/integration/integ.table-bucket-kms-key.js.snapshot/kmskeys3tablesintegDefaultTestDeployAssertC8AB8C4E.template.json
Running cfn-guard with rule set: ./rules
[command]/opt/homebrew/bin/cfn-guard validate --data ./changed_templates --rules ./rules --show-summary fail --output-format json
{
  "name": "/Users/kazuhoshinozuka/git/aws-cdk/tools/@aws-cdk/security-guardian/changed_templates/packages_@aws-cdk_aws-s3tables-alpha_test_integration_integ.table-bucket-kms-key.js.snapshot_kms-key-s3tables-stack.template.json",
  "metadata": {},
  "status": "SKIP",
  "not_compliant": [],
  "not_applicable": [
    "IAM_ROLE_NO_BROAD_PRINCIPALS"
  ],
  "compliant": []
}{
  "name": "/Users/kazuhoshinozuka/git/aws-cdk/tools/@aws-cdk/security-guardian/changed_templates/packages_@aws-cdk_aws-s3tables-alpha_test_integration_integ.table-bucket-kms-key.js.snapshot_kmskeys3tablesintegDefaultTestDeployAssertC8AB8C4E.template.json",
  "metadata": {},
  "status": "SKIP",
  "not_compliant": [],
  "not_applicable": [
    "IAM_ROLE_NO_BROAD_PRINCIPALS"
  ],
  "compliant": []
}Running scanner for intrinsics
Scanning JSON files in: ./changed_templates
Processing: changed_templates/packages_@aws-cdk_aws-s3tables-alpha_test_integration_integ.table-bucket-kms-key.js.snapshot_kms-key-s3tables-stack.template.json
Match found in: changed_templates/packages_@aws-cdk_aws-s3tables-alpha_test_integration_integ.table-bucket-kms-key.js.snapshot_kms-key-s3tables-stack.template.json (statements: 1)
Processing: changed_templates/packages_@aws-cdk_aws-s3tables-alpha_test_integration_integ.table-bucket-kms-key.js.snapshot_kmskeys3tablesintegDefaultTestDeployAssertC8AB8C4E.template.json
detailed_output File: changed_templates/packages_@aws-cdk_aws-s3tables-alpha_test_integration_integ.table-bucket-kms-key.js.snapshot_kms-key-s3tables-stack.template.json
{
  "Action": "kms:*",
  "Effect": "Allow",
  "Principal": {
    "AWS": {
      "Fn::Join": [
        "",
        [
          "arn:",
          {
            "Ref": "AWS::Partition"
          },
          ":iam::",
          {
            "Ref": "AWS::AccountId"
          },
          ":root"
        ]
      ]
    }
  },
  "Resource": "*"
} |n| ============================================================

 Scan complete!
 Files scanned : 2
 Matches found : 1
::warning::Intrinsic scan found 1 issue(s).

::set-output name=issues_found::1
::error::Action completed with issues: Intrinsic scan found 1 issue(s).
Removed working directory: ./changed_templates
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. The results are fine.

Copy link
Contributor

@QuantumNeuralCoder QuantumNeuralCoder left a comment

Choose a reason for hiding this comment

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

Noting the kms* pattern also caught by security guardian. Approving this.

Copy link
Contributor

mergify bot commented May 9, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 882f81b
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 488f0db into aws:main May 9, 2025
13 of 15 checks passed
Copy link
Contributor

mergify bot commented May 9, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Copy link
Contributor

github-actions bot commented May 9, 2025

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 9, 2025
@badmintoncryer badmintoncryer deleted the s3tables-kms branch May 9, 2025 23:19
@godwingrs22
Copy link
Member

Hi @badmintoncryer,

First of all, thank you for taking the time to contribute to this feature. We truly value community contributions and the effort you put into implementing this feature.

I need to revert this PR as there was a parallel implementation #34281 being developed by the service team that includes some additional internal considerations. I apologize for not catching this overlap earlier in the review process.

Thanks for your understanding!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
distinguished-contributor [Pilot] contributed 50+ PRs to the CDK p2 pr/needs-maintainer-review This PR needs a review from a Core Team Member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants