Skip to content

Stringify AWS Secrets Manager values#1833

Open
seeday wants to merge 1 commit intobasecamp:mainfrom
seeday:main
Open

Stringify AWS Secrets Manager values#1833
seeday wants to merge 1 commit intobasecamp:mainfrom
seeday:main

Conversation

@seeday
Copy link
Copy Markdown

@seeday seeday commented Apr 21, 2026

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 extract JSON 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

  • For null handling, I chose to emit the string null. I feel like this produces fewer surprises than an empty string or omission.
  • Quoted strings in a secret will have their quotes stripped as they are JSON.parseable.

Alternatives

  • I considered supporting recursive JSON documents. "Flat" secrets are most common, and this would require extra cli options if the value was needed raw instead of parsed.
  • Rejecting or omitting non-primitives.
  • Calling #to_s instead of JSON.dump. This produces odd behavior with complex JSON types and null.

Copilot AI review requested due to automatic review settings April 21, 2026 16:38
Copy link
Copy Markdown
Contributor

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 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.parse results in the AWS Secrets Manager adapter to only expand secrets when the parsed value is a Hash.
  • Stringify non-string JSON values via JSON.dump to 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.

Comment thread lib/kamal/secrets/adapters/aws_secrets_manager.rb Outdated
* fix behavior on JSON primitives
* stringify values that are bound to keys when JSON is a Hash/object
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