Skip to content

Conversation

jnewton03
Copy link

Summary

This PR adds a new optional json-secret-keys parameter that allows users to specify which keys from JSON secrets should be extracted as environment variables. This solves the over-masking problem where ALL values in JSON secrets get marked as secrets, making debugging nearly impossible.

Problem Description

When using parse-json-secrets: true, all JSON values are marked as secrets via core.setSecret(), causing over-masking where innocent values like usernames, hostnames, and API endpoints get redacted throughout GitHub Action logs.

Example: A JSON secret containing {"DOCKER_USERNAME": "liquibase", "DOCKER_PASSWORD": "secret123"} would mask the word "liquibase" everywhere in logs, making debugging very difficult.

Solution

The new json-secret-keys parameter allows selective extraction:

- name: Get secrets with selective key extraction
  uses: aws-actions/aws-secretsmanager-get-secrets@v2
  with:
    secret-ids: database/credentials
    parse-json-secrets: true
    json-secret-keys: |
      password
      api_key

This would only extract and mask the password and api_key values, leaving other non-sensitive values like username and host unmasked.

Key Features

  • Backward Compatible: If json-secret-keys is not provided, all keys are extracted (existing behavior)
  • Flexible: Supports both simple and nested JSON structures
  • Cost-Effective: Maintains the cost benefit of storing multiple secrets in one JSON object
  • Selective Masking: Only specified values are marked as secrets, reducing over-masking

Changes Made

  • Added json-secret-keys input parameter to action.yml
  • Modified injectSecret() function in utils.ts to support selective key filtering
  • Updated index.ts to read and pass the new parameter
  • Added comprehensive unit tests covering various scenarios
  • Added integration tests for the new functionality
  • Updated README.md with parameter documentation and usage examples

Testing

  • ✅ All existing tests pass (maintaining backward compatibility)
  • ✅ New unit tests cover selective key extraction scenarios
  • ✅ Integration tests verify end-to-end functionality
  • ✅ Test coverage maintained at 98.75% statements, 98.55% branches
  • ✅ Linting passes without errors
  • ✅ Build successfully updates dist/ directory

Examples

Before: All JSON values get masked, making debugging difficult

{
  "username": "admin",        // Gets masked everywhere
  "password": "secret123",    // Gets masked (correctly)
  "host": "db.example.com",   // Gets masked everywhere  
  "port": "5432"              // Gets masked everywhere
}

After: Only sensitive values get masked

json-secret-keys: |
  password
  • ✅ Only password value gets masked
  • username, host, port remain visible in logs for debugging

Fixes #263

🤖 Generated with Claude Code

This feature allows users to specify which keys from JSON secrets should be
extracted as environment variables, preventing over-masking of non-sensitive
values like usernames, hostnames, and ports.

Key changes:
- Add json-secret-keys input parameter to action.yml
- Modify injectSecret() function to support selective key filtering
- Add comprehensive unit and integration tests
- Update README.md with parameter documentation and examples

Fixes over-masking issue where all JSON values were marked as secrets,
making debugging difficult when innocent values got redacted in logs.

Fixes aws-actions#263

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

Co-Authored-By: Claude <[email protected]>
@jnewton03 jnewton03 requested a review from a team as a code owner September 10, 2025 19:42
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.

Feature Request: Selective JSON key extraction to prevent over-masking of secret values
1 participant