-
-
Notifications
You must be signed in to change notification settings - Fork 108
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
Generate datastore_crypto_key on install if not provided #266
Conversation
The last helm-e2e test used the templates in this PR to generate this k8s secret: datastore_crypto_key: eyJhZXNLZXlTdHJpbmciOiJTWGxSTElGYklNREtTL0ZrcEdIMG1aM3NmVHo4SVNGTGg3Qk04TkZENDZZIiwiaG1hY0tleSI6eyJobWFjS2V5U3RyaW5nIjoiVHNuYkEzOFI1WHdXdG9XMWRrTC1wcGlWVWY0SklnNmNkRTUtdFY3M1NNcyIsInNpemUiOjI1Nn0sIm1vZGUiOiJDQkMiLCJzaXplIjoyNTZ9 decoding that, we have this
Which is perfectly valid. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. A bit of extra security by default with zero effort required!
# This is used to generate st2.datastore_crypto_key on install if not defined in values. | ||
|
||
# The formula is based on an st2-specific version of python's base64.urlsafe_b64encode | ||
# randBytes returns a base64 encoded string | ||
# 32 bytes = 256 bits / 8 bits/byte | ||
|
||
aesKeyString: '{{ randBytes 32 | replace "+" "-" | replace "_" "/" | replace "=" "" }}' | ||
mode: CBC | ||
size: 256 | ||
|
||
hmacKey: | ||
hmacKeyString: '{{ randBytes 32 | replace "+" "-" | replace "_" "/" | replace "=" "" }}' | ||
size: 256 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it's making the impossible possible :)
Overall I'm worried about the implementation and if that's a good way or not to try this in the chart really.
Even the slightest security risk behind the implementation/diff is sufficient to avoid the drill here generating the K/V crypto key.
I'd rely on someone better from the @StackStorm/tsc with security to review this. Maybe @punkrokk ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is a security issue with this formula, then st2-core would need to change, and every installation everywhere would have to update their datastore crypto key. This chart would, of course, also have to be updated to match whatever formula st2-core uses to generate these keys. I think the formula is easier to understand here than in st2-core, so it should be fairly simple to migrate this if ever needed in the future.
That said, I look forward to hearing what @punkrokk or other @StackStorm/TSC members have to say about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries. To be clear, I'm good with this new feature itself.
However, I'm looking for feedback if the key generation here is cryptographically secure. I didn't look what st2 does under the hood, but I'd trust those who good at this and if trying to mimic the st2 behavior for st2-krypto-key-generation in the Helm template engine is good enough.
I think the folks would need to dig deeper into the code you provided 👍
Here is the st2 formula for generating the crypto key, trimmed down to make it easier to follow what is going on:
|
And here is the implementation of import (
...
"crypto/rand"
...
"encoding/base64"
...
)
...
func randBytes(count int) (string, error) {
buf := make([]byte, count)
if _, err := rand.Read(buf); err != nil {
return "", err
}
return base64.StdEncoding.EncodeToString(buf), nil
} This creates a bytes buffer of the desired size, and then fills that buffer with random data, and then base64 enccodes it. |
My only comment is we could probably use AES512. Nice to have not required (yet). I think the function to create the key is fine. |
If we add support for AES512 in StackStorm itself, then we can update this to use the better encryption by default. |
This reverts commit 61f5a2c.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @cognifloyd, and @punkrokk for additional review 👍
OK. I wasn't going to implement this, but I did it anyway.
Other installation methods can call
st2-generate-symmetric-crypto-key
on installto generate the key. But we need to put it in a kubernetes secret, so that is too
late to use for a new installation. Instead, we can generate the crypto key with
helm primitives.
Closes: #225