Skip to content
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

Include sensitive metadata from the schema when building the json state output #33059

Merged
merged 2 commits into from
Apr 24, 2023

Conversation

liamcervante
Copy link
Member

@liamcervante liamcervante commented Apr 20, 2023

This PR makes the jsonstate package include the sensitive metadata from the schema when building the sensitive_values entry in the JSON output.

Previously, we were only including information from the config (such as the sensitive()) function. This new behaviour matches the behaviour of the jsonplan package.

I am a little concerned that the tests seem to have been deliberately checking that this didn't happen, but it doesn't make sense to me that we wouldn't want this new behaviour. Basically, the tests were setting an attribute in the schema as sensitive and then were not including that attribute in the sensitive values. I'm hoping that was an oversight instead of something deliberate. I have updated the tests to reflect the new behaviour and they now require the sensitive metadata set from the schema.

Fixes #33055

Target Release

1.4.6

Draft CHANGELOG entry

BUG FIXES

  • Fix a bug where the schemas sensitive metadata was being missed when creating the JSON state output for a terraform show command.

@liamcervante liamcervante added the 1.4-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged label Apr 20, 2023
@liamcervante liamcervante requested a review from a team April 20, 2023 14:20
@apparentlymart
Copy link
Member

I'm not 100% sure because this was quite a while ago now, but I think the odd treatment of statically-defined sensitive might be something related to hashicorp/terraform-plugin-sdk#201 , which ended up in a stalled state because of some disagreement about which layers ought to be dealing with and paying attention to these sensitivity declarations.

Unfortunately I don't have the full context for this anymore so I don't really have a definitive helpful answer here, but I'm mentioning it in case it triggers a stronger memory for a different reviewer who might be able to share some context about whatever decision caused us to be testing for the apparently-incorrect behavior as the expected behavior. 🤔

@jbardin
Copy link
Member

jbardin commented Apr 20, 2023

My bet here is that as the tests were added in bulk when it was a new package, the tests were written to pass rather than for correctness. The way the values are handled internally led to attributes which are indicated as Sensitive by the schema only being marked during evaluation, hence they don't have marks going into and out of the state. I don't think that was done purposely, rather it was just an evolution of how they used to be handled before we had marks. I think this lead to the new renderer relying on the state representation which had incomplete information.

@jbardin
Copy link
Member

jbardin commented Apr 20, 2023

@apparentlymart, I don't think that is going to be related. That issue was really about the lack of structural attributes, for which there is a solution now! I don't know if the legacy SDK can or even should be updated to change how the schema is generated, but it is at least possible now.

@apparentlymart
Copy link
Member

Thanks for checking!

I don't think there are any plans to change how the legacy SDK behaves now, but indeed you're right that in principle the SDK could choose to present these computed-only objects as structured-type attributes instead of plain object type attributes, if someone did want to change it, with some risk of it subtly changing behavior.

Copy link
Member

@jbardin jbardin left a comment

Choose a reason for hiding this comment

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

It's not needed for the issue at hand, but we should probably follow up to make sure the stored state also records sensitive schema values to prevent this from being able to diverge elsewhere.

@liamcervante liamcervante merged commit 14123e2 into main Apr 24, 2023
6 checks passed
@liamcervante liamcervante deleted the liamcervante/33055 branch April 24, 2023 08:52
@github-actions
Copy link

Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch.

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1.4-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suddenly sensitive resource attributes are exposed by "terraform show" in latest Terraform version 1.4.x
3 participants