feat(secrets): auto-extract API key from JSON-structured Secrets Manager secrets#1146
feat(secrets): auto-extract API key from JSON-structured Secrets Manager secrets#1146litianningdatadog wants to merge 2 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for JSON-structured Secrets Manager secrets by introducing a new DD_API_KEY_SECRET_JSON_KEY environment variable. When set alongside DD_API_KEY_SECRET_ARN, the extension parses the secret value as JSON and extracts the named field as the API key, addressing the need for teams that store secrets in key/value format (e.g., {"apiKey": "<key>"}).
Changes:
- Added JSON extraction logic to
decrypt_aws_sm()function that parses secrets as JSON whenjson_keyis provided - Added
api_key_secret_json_keyfield to all three config layers (Config,EnvConfig,YamlConfig) with proper merge logic - Added three unit tests covering successful extraction, missing key error handling, and backward compatibility with plain secrets
- Updated configuration examples in YAML and environment config tests
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| bottlecap/src/secrets/decrypt.rs | Added JSON extraction logic with new json_key parameter; includes three new unit tests |
| bottlecap/src/config/mod.rs | Added api_key_secret_json_key field to Config struct and its Default impl |
| bottlecap/src/config/env.rs | Added api_key_secret_json_key field to EnvConfig with documentation; updated merge logic and test fixtures |
| bottlecap/src/config/yaml.rs | Added api_key_secret_json_key field to YamlConfig; updated merge logic, example YAML config, and test fixtures |
duncanista
left a comment
There was a problem hiding this comment.
Honestly, not super happy about having a new env var just for this, we should talk as a team if this is something we want to actually support
I think the user makes a valid point for below reasons:
Without introducing a new key, I do not think there is a better candidate for this. |
47611b4 to
055a5f2
Compare
…ger secrets When DD_API_KEY_SECRET_ARN is set and the fetched secret is a JSON object, automatically extract the value of the hardcoded "dd_api_key" field as the API key. Falls back to using the raw secret string if the value is not valid JSON or the "dd_api_key" field is absent, preserving existing behavior for plain-string secrets. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
055a5f2 to
d5c7644
Compare
Summary
DD_API_KEY_SECRET_ARNis set and the fetched secret is a JSON object, automatically extract thedd_api_keyfield as the API keydd_api_keyfield is absent — preserving existing behavior for plain-string secretsdd_api_keyTest Plan
dd_api_keypresent), fallback to raw (key absent), and plain string secrets{"dd_api_key": "<your-key>"}