sealed-secrets: `encryptedData` in SealedSecret is not deterministic
I’m trying to understand why whenever I regenerate an SealedSecret, the encryptedData changes, even though the value being encrypted has not changed.
EDIT 2020/03/16 20:57 PST
A simple example is the one from the readme:
echo -n bar | kubectl create secret generic mysecret --dry-run --from-file=foo=/dev/stdin -o json >mysecret.json
kubeseal <mysecret.json >mysealedsecret.json
--- a/mysealedsecret.json
+++ b/mysealedsecret.json
@@ -15,7 +15,7 @@
}
},
"encryptedData": {
- "foo": "AgB+AygEDUkf1j+uOi8ZzxT140RklBcljElh6gIdlMDcMIidWadSOKaYIOKhAg/fL8JRn6OO6if+uOJjGipdZcMdmdE1COCJX1Y38sRVwwuNo2ObW5fkaKkBCkepbuxHX60EJ0C7cfFdIzQtPg4nqXRxZW+7ArIR+s+ZPwjVkjQPsKbQCo8rZxCoRYLtbitKeeHaVOgAZpvelAffe6ewHEyhZgqjK24B9dbq3DICiR+4iQPmXk4zdcYFLvsgmadIeK/7wpAGzqpdI6rmsiex55IVOkELeaZZwXl+TlxceOEk4Ub07iedXNZQs29iU+yesYgGOQCzNYoPxoLzV98i5MiSRhaiyM8EWU7kZSNx3ZCmch37LRwmBeqlypiNI7BmfWnJQ+KwBe3hyOqi7QComs0YzVXHQ5DXQRwoorUwwNEsoDT5Fy7ZTcMKI4vIaVULG/YOSrHYGFBYq8Q8eB3G5cEvxHne/iUEqWZEWfJxO+O4Fs2h6DzoqMT13o7sBhzHcY2TIHedlsLI7HpJNwcVioDGWFcG/XU80wRHRj+NqnxEzqa8e0+VHaVWBBQa7ggur92vVOd9wCzCiMfBsKSocoOAx/aa26exMmE+4yS1ZQ5Djlt3WM7whZ6MTXq5tOp4GfJy57xpzIwh6YkpELm0VQOnYnArIdqLDxnNb3+Mm/2cWEBXy7+yGCiSWqHhZyMLap1SMU8="
+ "foo": "AgAuOYUW77sFylgELezKAdmlMznGtUJTBtvFOq0k5zesa46Y1PA1BDLlpZbL6KeNi83Cg+O+j0kBZxO5Ca3PH6kv/qMD12y5qg+Z2AftlFHPEapotgWODD+cRxspZNiDtuAAmruUxmT7dCzbEQ2tm+2aelKh3JntoaFAdwVbEuHxgM2VMKpIArrzEoqijg+RPXo9JcLm8RiZW5QcL3ZPWNZoXS/WGkd91MSJcnCktRCVSmIedgX8tsfLPT6Ad2uugTGuPHiRyVzGRgi4Xmsq1h1UFVzpWOblviGyHHkkIsTlC7y3uJi5Q0NQcjHCN+wdfKKsh35lNwsPtkhugbH4NvFi0ZUJt41rZbNgUPy7brCJOUxLPag8uiPkeEZPt6nsIQbKUJqdT9/zaJ0ad4G6x/lvnAKhWNcBDQjFoFk78WPJBT8DyaZwYQV1wg6Wo7LpotPFR1MIjxpaqv6Z+RNWPc2N53rneK0xm0hD1laMZ//tdB9yA5FxDYm33Ms9ZpzkKH0su8wWudYxMw3zk7DRD+Uw7CqtAAtdtK2QsNIA8aZDEhAyfFpLoXee2AscqnfOhhJ0nBaw9bAy83hWIAGw+2dFJIk0gYpMu2AkpHg128RfUg2zSzfpbtahDLpQfKYD5dxQt0fl74ZEsk3qnUsuQ7TI1Af9La9MuHX2LmFJrBsCuTUzTw/tZ8RhBTcuy/1n6Eq8BX8="
}
},
"status": {
I don’t necessarily mind if this changes when the sealing keys are rotated, since that’s the very point of that, but if the sealing key has remained the same, then wouldn’t the encrypted value also be the same?
I don’t want my users to think that the sealed secret has actually changed, or to force them to needlessly commit a new sealed secret every PR (since I would like to do some sort of automation around recreating the sealed secret automatically).
Can someone provide some clarity around this?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 15 (7 by maintainers)
Yeah I really like the idea of only changing the value that changed.
I’d love if somebody reviews the details of my proposal though before implementing it
yeah, indeed sealed-secrets is designed as a one-way secret store: a human puts a secrets in and the k8s cluster can consume the secret.
If you need to read the secrets later you either:
The main use case are the class of secrets that you don’t really ever need to look at twice. “Throw-away” secrets that are easy to regenerate and for which it’s a good idea to regenerate them anyway. Think of a database password; think of why would you need to see that password again: a) you’re an admin and need to troubleshoot b) you need to reuse this password in some other workload.
In the former case, such admins should either have access to the cluster and thus be able to access the unencrypted secret, or be external users for whom it would be a good idea to create a dedicated account on the DB anyway (for nonrepudiation). In the latter case, just create another account.
Being designed this way doesn’t mean you can’t use it otherwise, it just means the whole workflow is designed to naturally match this use case.
You have a different workflow: you’re storing the secret somewhere else and you want to use sealed-secrets as a way to “snapshot” your secrets into an encrypted form that is decoupled from your authoritative secrets storage mechanism.
Unfortunately your workflow collides with encryption best practices that mandate that encrypting the same message multiple times shouldn’t be encrypted to same cyphertext. There are many reasons for that, including the fact that an attacker has no way to know whether two given versions of the secret have the same value or not. The current implementation leaks the less possible amount of information to an attacker; relaxing this would weaken the general case and so I’d be hesitant of doing it.
That said, there might be other solutions to your use case and I’m open to improving the sealed-secrets tool and ecosystem to accommodate that workflow, if possible.
What about this proposal:
Kubeseal gets a new
--merge-if-modified-hmac keyflag. For cleartext secret intem in the input secret, kubeseal would computeHMAC(item, key)and compare it to the value stored in thesealedsecrets.bitnami.com/item-hmacsfor that item. If the HMAC matches, kubeseal doesn’t merge the item, otherwise it merges it and updates thesealedsecrets.bitnami.com/item-hmacsannotation.The key passed to the HMAC should be used by your automation but otherwise kept secret.
The rationale is the same as for random nonce/session key: if an attacker speculates the secret is
bar, having a sha256 in the secret (or a deterministic encryption) would confirm this speculation.Example (where the whole sealed secret is not updated because
HMAC(bar, hmac_key) = 6d848505114d8cc5b7ed8306f7a3db96a996ef304b822bd999b37fb76e186771and thus your automation knows it hasn’t changed.I was originally going to ask if allowing
kubesealto specify the AES-GCM nonce would better solve this issue. But looking at the code, I see that it’s more complicated. A static GCM nonce is already used coupled with a one-time, random AES key. It’s this AES key, as well as therandomparameter passed toEncryptOAEP, that would have to be made non-random in order for the SealedSecret to be deterministic.My use case is similar to @ghostsquad’s. I have a build pipeline that pulls down secrets from the source of truth, calls
kubesealon them, and then sends off the resulting manifests to be applied to the cluster. But non-deterministic output fromkubesealmeans we have to be a little smarter about this, e.g. by checking the mtime on our secrets and only resealing them if they’ve been modified. Otherwise, we’ll see a lot of changes to SealedSecrets that make audits and reviews really hard (it’s impossible to tell if a Secret actually changed, or if it was just re-encrypted verbatim).