Stringify AWS Secrets Manager values#1833
Open
seeday wants to merge 1 commit intobasecamp:mainfrom
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes AWS Secrets Manager secret extraction to avoid Ruby 4.0+ JSON.parse returning non-Hash primitives (e.g., integers/booleans/null) and crashing the adapter when iterating, while also normalizing parsed JSON values to strings for more predictable downstream handling.
Changes:
- Guard
JSON.parseresults in the AWS Secrets Manager adapter to only expand secrets when the parsed value is aHash. - Stringify non-string JSON values via
JSON.dumpto ensure secret values behave consistently as strings. - Add regression tests covering bare JSON primitives and non-string JSON fields within JSON objects.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
lib/kamal/secrets/adapters/aws_secrets_manager.rb |
Prevents crashes on non-Hash JSON.parse results and coerces parsed values to strings for downstream consumers. |
test/secrets/aws_secrets_manager_adapter_test.rb |
Adds coverage for bare JSON primitive secrets and coercion behavior for non-string JSON object fields. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
* fix behavior on JSON primitives * stringify values that are bound to keys when JSON is a Hash/object
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.
When working with the AWS Secrets Manager, secrets that are stored as JSON are subject to unexpected type changes. In particular, when calling
kamal secrets extractJSON objects that contain integers get unconditionally #chomp-ed, causing a crash.Fix
This fix
JSON.dumps non-string values to allow chomp to succeed, and also should produce fewer surprises for end users via better handling of JSON values.This issue is related to #1816 (they hit the primitive-only path) and should fix it as well. For non-hash secret strings, we simply stringify the whole thing.
Edge Cases
null. I feel like this produces fewer surprises than an empty string or omission.JSON.parseable.Alternatives
#to_sinstead ofJSON.dump. This produces odd behavior with complex JSON types andnull.