opentofu: Secrets should not be stored in state

OpenTofu Version

N/a

Use Cases

There are tons of reasons to have TF generate secrets at deploy time - a database, a private key, etc. I am specifically not talking about providing a secret (e.g as a parameter, in the TF files). I am only referring to apply time generation of secrets, or use of things like a secrets store resource/data. Right now, TF will stubbornly store the secret in state even though is is completely unnecessary. This makes the state an unsecured secrets store which undermines all of the strict secrets manager controls.

Attempted Solutions

N/a

Proposal

TF should never store secrets in state, period. If a value absolutely must be compared (which seems unlikely), then a random token hash should be used (and specifically NOT a hash of the secret itself).

To know if a secret was generated or not, TF can simply store that boolean in the state. This way, it does not need to know what the secret is. An alternative solution is for the ignore_lifecycle block (which is currently a hacky way to change secrets post apply so the state secret is not valid) to not write the secret or secret has into state when it is set.

Essentially, we should have a clear method to not store secrets in state. Hashicorp has not managed to solve this in over nine years.

References

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 9
  • Comments: 19 (1 by maintainers)

Most upvoted comments

I’m not saying that this does get solved by #297 but I do think there is a large overlap here.

In general these 2 issues together are both a bit of an XY-Problem. And it may be a good idea for us to create a more general discussion around safe storage of sensitive information overall.

I’m happy to keep this open and discuss this individual idea as I feel it’s important, but I do feel there is more of an over-arching story that is here too.

Hi @dmurvihill we discussed your comment with the core team and the main problem is that this would require a protocol change to implement. Currently, providers are allowed to and do rely on the data in the state. Removing it would break providers.

The protocol is currently in the hands of HashiCorp and we cannot modify it for OpenTofu only as it would split the ecosystem. As far as we can tell, HashiCorp are evaluating ephemeral support which would likely cause the requisite protocol change. If and when that happens, we’d be open to discussing ephemeral support in OpenTofu based on their protocol implementation. (The protocol implementation is still MPL-licensed.)

Thank you for this. Being blocked by the provider profile is a lot more understandable.

FWIW, HashiCorp has also been saying they are blocked by the provider protocol, even though they control it 🙄.

Hey folks, thank you very much for this issue and the related discussion. We discussed this issue in the core team and feel that the majority of the use cases where this would be used can be solved by #874 (state encryption), which we are currently working on.

The rest of the use cases would be solved by moving sensitive values only to a key management system for storage, but that presents numerous problems, such as the lack of atomic changes and so on, which would likely result in large-scale architectural changes to OpenTofu. As such, we are not planning to implement this and will be closing this issue. If you have a use case that is not covered by state encryption and you cannot solve in any other way, please comment on that use case below.

I firmly disagree with this call. Encrypting an unnecessary copy of a secret does not solve the problem. You still have an unnecessary copy of a secret.

When I generate a database password and store it in AWS Secrets Manager, there is absolutely no reason for it to be stored anywhere other than there and in the virtual memory of the application that uses it. There is no reason for Terraform to use that value. Not for interpolation, not for difference checking, never.

This has been the overwhelming opinion on Terraform #516 for nearly ten years and a consistent source of frustration with Hashicorp. The fact that OpenTofu’s position is even worse is very disappointing.

I support the openTofu’s practice on state file encryption. It best protects secrets and credentials based on current technical restrictions.

In my practice, I even developed an independent encryption module to protect the .tf files because cloud AK and SK or other secrets are in them.

Hi @dmurvihill we discussed your comment with the core team and the main problem is that this would require a protocol change to implement. Currently, providers are allowed to and do rely on the data in the state. Removing it would break providers.

The protocol is currently in the hands of HashiCorp and we cannot modify it for OpenTofu only as it would split the ecosystem. As far as we can tell, HashiCorp are evaluating ephemeral support which would likely cause the requisite protocol change. If and when that happens, we’d be open to discussing ephemeral support in OpenTofu based on their protocol implementation. (The protocol implementation is still MPL-licensed.)

Hey folks, thank you very much for this issue and the related discussion. We discussed this issue in the core team and feel that the majority of the use cases where this would be used can be solved by #874 (state encryption), which we are currently working on.

The rest of the use cases would be solved by moving sensitive values only to a key management system for storage, but that presents numerous problems, such as the lack of atomic changes and so on, which would likely result in large-scale architectural changes to OpenTofu. As such, we are not planning to implement this and will be closing this issue. If you have a use case that is not covered by state encryption and you cannot solve in any other way, please comment on that use case below.

I firmly disagree with this call. Encrypting an unnecessary copy of a secret does not solve the problem. You still have an unnecessary copy of a secret.

When I generate a database password and store it in AWS Secrets Manager, there is absolutely no reason for it to be stored anywhere other than there and in the virtual memory of the application that uses it. There is no reason for Terraform to use that value. Not for interpolation, not for difference checking, never.

This has been the overwhelming opinion on Terraform #516 for nearly ten years and a consistent source of frustration with Hashicorp. The fact that OpenTofu’s position is even worse is very disappointing.

@bgshacklett there are a number of pitfalls with the proposed approach. For example, assume the provider has no way to retrieve a secret value, but has an “update if different” function. In this case no amount of hashing would help.

The main problem is that the provider SDK and protocol is in the hands of Hashicorp and a split would mean that hundreds if not thousands of provider authors need to build, test and ship providers for two systems. This would almost certainly put a huge dampener on the enthusiasm for OpenTofu for an edge case benefit.

I would also give my opinion on this topic. I completely agree with you, @iloveicedgreentea. I had this as my opinion: we really don’t need to store secrets in the state files in TF. If this could be implemented, it would resolve a major security issue with the state file being exposed. The encryption solution, #297, isn’t really a solution to this problem, just an additional security layer. But let’s keep in mind that you cannot steal something that isn’t there.