Skip to content

Document KMS key policy requirements for SOPS decryption - #127

Draft
plumdog with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-46
Draft

Document KMS key policy requirements for SOPS decryption#127
plumdog with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-46

Conversation

Copilot AI commented Jun 25, 2025

Copy link
Copy Markdown

This PR adds comprehensive documentation for KMS key policy requirements to address decryption failures when the Lambda function cannot access the KMS key used by SOPS.

Problem

While this CDK construct grants the Lambda execution role broad KMS permissions (kms:*) via IAM policies, KMS key policies are resource-based policies that can override IAM permissions. If the KMS key policy doesn't explicitly allow the Lambda execution role to decrypt, SOPS decryption will fail at runtime.

Solution

Added a new "KMS Key Policy Requirements" section to the README that includes:

  • Clear explanation of why both IAM and KMS key policies must allow access
  • Required KMS permissions (kms:Decrypt, kms:DescribeKey)
  • Example key policy statement with specific role ARN
  • Instructions for finding the Lambda execution role ARN
  • Alternative approach using conditions for more flexible access control

Example Usage

Users can now add a policy statement like this to their KMS key:

{
  "Sid": "AllowSopsSecretsManagerLambda",
  "Effect": "Allow",
  "Principal": {
    "AWS": "arn:aws:iam::ACCOUNT-ID:role/LAMBDA-EXECUTION-ROLE-NAME"
  },
  "Action": [
    "kms:Decrypt",
    "kms:DescribeKey"
  ],
  "Resource": "*"
}

This documentation provides users with actionable guidance to prevent SOPS decryption failures due to insufficient KMS key policy permissions.

Fixes #46.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: plumdog <2348591+plumdog@users.noreply.github.com>
Copilot AI changed the title [WIP] Document the requirements of the KMS key policy Document KMS key policy requirements for SOPS decryption Jun 25, 2025
Copilot AI requested a review from plumdog June 25, 2025 15:26
Comment thread README.md Outdated
Comment on lines +93 to +98
### Required KMS Key Policy Permissions

The KMS key policy must allow the Lambda execution role to perform the following actions:

- `kms:Decrypt` - Required to decrypt the SOPS file
- `kms:DescribeKey` - May be required for key metadata operations

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Make it clearer that this is the minimum permissions that should be granted for this construct to function correctly.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated the text to clarify that these are the minimum permissions required for the construct to function correctly. (d9054b9)

Comment thread README.md
For the Lambda function to successfully decrypt SOPS files, the KMS key used for encryption must have a key policy that allows the Lambda execution role to perform decryption operations. While this CDK construct grants the Lambda broad KMS permissions via IAM policies (`kms:*`), KMS key policies are resource-based policies that can override IAM permissions.

Both the IAM policy (granted by this construct) AND the KMS key policy must allow the Lambda execution role to use the key.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add here the simplest approach, which is to just delegate all permissions for the KMS key over to IAM, then suggest the others as more refined alternatives. So work from simplest (and least secure) to more complex (but more secure).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Restructured the KMS key policy documentation to start with the simplest approach (delegating all permissions to IAM) and progress to more secure alternatives. The three approaches are now ordered from least to most secure with clear security considerations for each. (commit: c5d45f2)

Co-authored-by: plumdog <2348591+plumdog@users.noreply.github.com>
… approach

Co-authored-by: plumdog <2348591+plumdog@users.noreply.github.com>
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.

Document the requirements of the KMS key policy

2 participants