-
Notifications
You must be signed in to change notification settings - Fork 49
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
KVv2 secrets are always entirely removed from Vault when RandomSecret is deleted from Kubernetes since v0.8.17 #196
Comments
I find this very disturbing as well. As for me, I'd completely block the secret removal instead of even the version removal. If the secret has only one version and then this version gets removed, the entire secret is removed as well, if I get it right? |
With v0.8.17+, the entire secret is removed from Vault, irrespective of the number of versions. In some cases, the entire removal could be useful as well, such as a testing system with a lot of automation around it: not removing these secrets from Vault would leave a lot of useless mess behind, even potentially creating unexpected behaviour if reusing the same secrets across testing sessions. So what I suggest is that the deletion logic should be made configurable to suit the use case at hand. My point is that there is no one-suits-all deletion logic and should be made configurable... |
I agree it would be safer to keep it configurable. The conditional should probably apply to both KVv1 and KVv2 RandomSecret types - completely remove the secret in vault or not upon RandomSecret deletion. I don't see the point in worrying about deleting specific versions in a KVv2 secret, are there use cases anyone cares to share? I think it would be good to keep the deletion logic consistent/simple... completely delete or do nothing to the secret in vault. |
@trevorbox thanks for the feedback.
Ok, that makes sense. Second, is there a need to override this settings at
I can imagine some as written above (an additional one was to maintain previous versions behavior), but I personally have no such need. |
Probably it makes sense to reuse the k8s naming convention that they use for https://kubernetes.io/docs/concepts/storage/persistent-volumes/#reclaiming |
@smnbbrv you suggest to use the word "retain" instead of "keep" so that the environment variable is named something like |
@davoustp might be better to add another option to the the RandomSecretSpec for more granular control of deletion behavior? The retainVaulltKVSecretOnRemoval option should default to false to match existing behavior. Perhaps a RETAIN_VAULT_KV_SECRET_ON_REMOVAL_OVERRIDE env variable could override any individual option to make things simpler. |
@trevorbox agreed, more granular control is better. |
Not really, I would just call it policy. KV_SECRET_RETAIN_POLICY or similar, that can further accept values like |
We need to decide if it would be useful to override any and all settings, if not then I don't see the point in an env var. I could see a use case to be able to override for testing purposes. Thoughts @davoustp @smnbbrv ?
I think that's a good idea, the field in the spec could be kvSecretRetainPolicy to default to |
@trevorbox when running in production, I would shoot for the safest policy - that is, retaining the Vault KV secret on deletion. If there is no way to set this globally as the default value, then it would mean that we need to explicitly set the flag on each and every RandomSecret resource, which is a pain.
Agreed. |
guys I have been following the discussion.
|
@raffaelespazzoli thanks for the (very relevant) questions! :-)
I think so - the envvar would be here to control the default policy, and the field to override this policy at resource level.
Unless the RandomSecret have periodic rotation defined, if it exists, leave it alone, as the sole goal of the rotation-less RandomSecret is to generate a Vault secret, which already exists in this case. |
To be totally honest, the downside that I see with the environment variable defining the default policy is that the behavior of the RandomSecret resources is not self-defined anymore: you need to know the value of the envvar (if set) in addition to the resource spec to understand how it behaves globally. And I dislike this situation - a lot. It could prove useful, but it will also create headaches: each time a new issue is created with RandomSecrets will raise the question about the envvar... or deploying the same resources in two similar environments may lead to different behavior just because this envvar is not set to the same value. So now, I'm backtracking on this envvar proposal of mine - I think that we should drop it and keep only the resource field. Suggestions? |
I think it most reasonable to simply add the retention policy to the CR and default to |
Ok. Let me summarize, this means:
@trevorbox @raffaelespazzoli @smnbbrv agreed? If yes, I'll work along those lines and propose a PR. |
@davoustp LGTM, thank you! The default delete would also be aligned with https://kubernetes.io/docs/concepts/storage/storage-classes/#reclaim-policy |
@davoustp I like it. |
…and logic Including one-off existing Vault secret overwrite protection
…and logic Including one-off existing Vault secret overwrite protection
Hi @trevorbox , @smnbbrv and @raffaelespazzoli I just implemented what was discussed above a while ago (you can can have a look at fork above, code changes are quite small):
However, and before I create the PR, I failed to find any existing RandomSecret integration tests that I could enrich with these use cases. |
Hi @raffaelespazzoli @trevorbox , |
Release v0.8.17 changes the logic to delete the KVv2 secret entirely from Vault whenever the
RandomSecret
Kubernetes resource is deleted, instead of removing only the last version of the Vault secret (releases v0.8.16 and below).As mentioned in #134 (comment) , there are situations where deleting only the last version of a KVv2 secret is still desirable.
A very common example is to use a
RandomSecret
to generate aroot
password or database admin password.In such a case, you would like to protect this KVv2 secret at any cost - loosing it for any reason (think about an erroneous gitops operation removing the
RandomSecret
resource, or even a straightkubectl
deletion) would be catastrophic as the secret can only be recovered from a Vault backup.So I'd suggest to make this KVv2 deletion logic configurable.
The deletion logic (either
delete-last-version
ordelete-all-versions
) could be set using:RandomSecret
spec field (requires changing the CRD here)Consider .2 first, then if not set, then use 1. , and if not set either, use the current behavior.
This looks to maximize the use case coverage and flexibility.
@trevorbox @raffaelespazzoli does this make sense?
I can provide a PR along this lines.
The text was updated successfully, but these errors were encountered: