Skip to content

Add AWS KMS decryption support for environment variables #55

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Lowercases
Copy link

@Lowercases Lowercases commented Apr 19, 2025

This commit adds support for decrypting KMS-encrypted environment variables with the format '!kms base64EncodedValue'. The implementation follows these key aspects:

  • KMS encrypted values are identified by the '!kms ' prefix
  • Quoted base64-encoded values are properly decoded
  • KMS decryption is performed using the AWS SDK
  • Existing SSM parameter functionality is preserved
  • Comprehensive test suite added for KMS decryption
  • README updated with KMS usage documentation

The implementation is based on requirements detailed in the CHANGES file and follows the project patterns, including lazy initialization of AWS services and respect for the -no-fail flag. The CHANGES file will be removed in a future commit once the functionality is ready to be merged.

🤖 Generated with Claude Code

Lowercases and others added 2 commits April 18, 2025 21:39
This commit adds support for decrypting KMS-encrypted environment variables with
the format '\!kms base64EncodedValue'. The implementation follows these key aspects:

- KMS encrypted values are identified by the '\!kms ' prefix
- Quoted base64-encoded values are properly decoded
- KMS decryption is performed using the AWS SDK
- Existing SSM parameter functionality is preserved
- Comprehensive test suite added for KMS decryption
- README updated with KMS usage documentation

The implementation is based on requirements detailed in the CHANGES file and
follows the project patterns, including lazy initialization of AWS services
and respect for the -no-fail flag. The CHANGES file will be removed in a
future commit once the functionality is merged.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
This commit adds detailed comments to the KMS-related tests, making the test
suite more readable and easier to review. Each test now has a header comment
explaining:

- What the test is checking
- How it relates to existing SSM tests (when applicable)
- Specific behaviors being tested with bullet points

These comments help reviewers understand the test coverage for the new
KMS decryption functionality without having to analyze each test in detail.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@isobit isobit requested a review from Copilot April 21, 2025 18:30
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for decrypting AWS KMS–encrypted environment variables. Key changes include:

  • Introducing a lazy-initializing KMS client and corresponding decryption function.
  • Extending the environment expansion logic and tests to properly handle KMS-encrypted values.
  • Updating documentation in the README to include the new KMS parameter format.

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

File Description
main_test.go Added tests for KMS value extraction, decryption, and error handling
main.go Added lazyKMSClient, decryptKmsValue implementation, and KMS processing logic
README.md Updated parameter format instructions to include KMS-encrypted values
Files not reviewed (1)
  • CHANGES: Language not supported
Comments suppressed due to low confidence (1)

main.go:206

  • [nitpick] Consider renaming the field 'envvar' to 'envVar' to maintain consistency with common camelCase naming conventions.
type kmsVar struct {


func (c *lazyKMSClient) Decrypt(input *kms.DecryptInput) (*kms.DecryptOutput, error) {
// Initialize the KMS client (and AWS session) if it hasn't been already.
if c.kms == nil {
Copy link
Preview

Copilot AI Apr 21, 2025

Choose a reason for hiding this comment

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

The lazy initialization of the KMS client in lazyKMSClient is not thread-safe. Consider adding synchronization (e.g., a mutex) if expandEnviron might be called concurrently.

Copilot uses AI. Check for mistakes.

@isobit
Copy link
Contributor

isobit commented Apr 21, 2025

KMS encrypted values are identified by the '!kms ' prefix

This is quite different from how SSM params work, using ssm:// as the default identifying prefix. There's also the -template CLI option which gives users the ability to adjust that behavior, maybe we should have something similar for this?

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