Skip to content

Fix sensitive values being replaced with '(sensitive value)' in Helm deployments #1644

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

Merged
merged 4 commits into from
Jun 20, 2025

Conversation

abatilo
Copy link
Contributor

@abatilo abatilo commented Jun 19, 2025

When using set_sensitive in the helm provider, the actual values deployed to
Kubernetes were incorrectly replaced with the string '(sensitive value)' instead
of the real sensitive value.

Root cause:
The logValues() function was using maps.Clone() which only creates a shallow
copy. Since Helm values are nested maps (e.g., {'configmap': {'foo': 'test'}}),
the inner maps were shared between the original and clone. When cloakSetValues()
modified the 'cloned' map to mask sensitive values for logging, it was actually
modifying the original map that was then passed to Helm for deployment.

Fix:

  • Implemented deepCloneMap() function that recursively clones nested maps
  • Updated logValues() to use deepCloneMap instead of maps.Clone
  • Updated setReleaseAttributes() to use deepCloneMap for consistency
  • Removed unused 'maps' import

This ensures sensitive values are properly masked in logs and Terraform state
display while the actual values are correctly deployed to Kubernetes.

Fixes the issue where ConfigMaps would contain '(sensitive value)' instead of
the actual sensitive data when using set_sensitive blocks.

@abatilo abatilo requested a review from a team as a code owner June 19, 2025 14:06
…deployments

When using set_sensitive in the helm provider, the actual values deployed to
Kubernetes were incorrectly replaced with the string '(sensitive value)' instead
of the real sensitive value.

Root cause:
The logValues() function was using maps.Clone() which only creates a shallow
copy. Since Helm values are nested maps (e.g., {'configmap': {'foo': 'test'}}),
the inner maps were shared between the original and clone. When cloakSetValues()
modified the 'cloned' map to mask sensitive values for logging, it was actually
modifying the original map that was then passed to Helm for deployment.

Fix:
- Implemented deepCloneMap() function that recursively clones nested maps
- Updated logValues() to use deepCloneMap instead of maps.Clone
- Updated setReleaseAttributes() to use deepCloneMap for consistency
- Removed unused 'maps' import

This ensures sensitive values are properly masked in logs and Terraform state
display while the actual values are correctly deployed to Kubernetes.

Fixes the issue where ConfigMaps would contain '(sensitive value)' instead of
the actual sensitive data when using set_sensitive blocks.
@abatilo
Copy link
Contributor Author

abatilo commented Jun 19, 2025

@jrhouston would you mind taking a look?

@abatilo
Copy link
Contributor Author

abatilo commented Jun 19, 2025

This PR fixes the (sensitive value) bug described here:
#1637 (comment)

@github-actions github-actions bot added size/M and removed size/XS labels Jun 19, 2025
@jrhouston
Copy link
Collaborator

jrhouston commented Jun 19, 2025

Thanks for jumping in to fix this @abatilo. I've pushed a reproducer test for this to your branch, which passes with your change.

It looks like the code that got missed in the migration from SDKv2 is this janky JSON Unmarshal/Marshal step which I guess is a cheat way to do a deep copy.

// copy array to avoid change values by the cloak function.
asJSON, _ := json.Marshal(values)
var c map[string]interface{}
err := json.Unmarshal(asJSON, &c)
if err != nil {
return err
}

@abatilo
Copy link
Contributor Author

abatilo commented Jun 19, 2025

Of course @jrhouston , happy to try and contribute.

Sorry, can you help me understand what I should do next? I see some acceptance tests are failing. Should I be the one trying to fix those? Or are you taking over the branch, etc?

@jrhouston
Copy link
Collaborator

jrhouston commented Jun 20, 2025

My apologies, that test was failing because I added a secret to the test chart for testing the sensitive values but forgot to update one of the tests which asserts the number of templates in the chart. I've fixed the test and pushed it, everything should turn green now.

I think this PR will be good to go, we will need a second approval from @jaylonmcshan19-x before I can hit merge.

@abatilo
Copy link
Contributor Author

abatilo commented Jun 20, 2025

Amazing. Thank you so much.

@jgournet
Copy link

I know this does not help in any way, but:
Thank you very much for addressing this so fast !

Copy link
Collaborator

@jaylonmcshan19-x jaylonmcshan19-x left a comment

Choose a reason for hiding this comment

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

Thanks for addressing this bug @abatilo @jrhouston :)

@jrhouston jrhouston merged commit 287bffc into hashicorp:main Jun 20, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants