-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
JetStream TPM driven encryption #5273
Conversation
Signed-off-by: Colin Sullivan <colin@luxantsolutions.com>
Signed-off-by: Colin Sullivan <colin@luxantsolutions.com>
Signed-off-by: Colin Sullivan <colin@luxantsolutions.com>
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.
I haven't ran any tests on a real machine yet but a few first-pass comments.
server/tpm/js_ek_tpm_windows.go
Outdated
return fmt.Errorf("unable to marshal keys to JSON: %v", err) | ||
} | ||
// Write the JSON to a file | ||
if err := os.WriteFile(filename, keysJSON, 0644); err != nil { |
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.
Another world-readable as above.
server/tpm/js_ek_tpm_windows.go
Outdated
// Reads the private and public blobs from a single file. If the file does not exist, | ||
// or the file cannot be read and the keys decoded, an error is returned. | ||
func readTPMKeysFromFile(filename string) ([]byte, []byte, error) { | ||
if _, err := os.Stat(filename); os.IsNotExist(err) { |
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.
Wondering if this is necessary or whether os.ReadFile(...)
would return an os.IsNotExist(err)
too.
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.
I believe that's what I started with and ended up here but will double check.
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.
I might be wrong of course 😄 Curious about what you find.
server/tpm/js_ek_tpm_windows.go
Outdated
// used to decrypt the key in future sessions will be saved to disk in the file provided. | ||
// The key will be unsealed and returned only with the correct password and PCR value. | ||
func LoadJetStreamEncryptionKeyFromTPM(srkPassword, jsKeyFile, jsKeyPassword string, pcr int) (string, error) { | ||
var err error |
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.
Probably unnecessary as it is overshadowed by the following line.
Thank you for the review @neilalexander, much appreciated! I aim to have these addressed by the end of the day tomorrow. |
Signed-off-by: Colin Sullivan <colin@luxantsolutions.com>
I believe I've addressed the requested changes - thanks for the suggestions. Certainly let me know if there are additional changes. It'd be great if someone could independently run the tests. |
Signed-off-by: Colin Sullivan <colin@luxantsolutions.com>
Where are we on this in terms of getting it merged? |
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.
LGTM, although I don't have appropriate hardware to test it with.
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.
using hyper-v Windows 11 dev environment image:
- Ran with above config successfully; data was encrypted, password and keys json worked as expected.
- Also ran the TPM tests successfully.
LGTM
Is there a way to disable the PCR part of the TPM policy with this feature? |
JetStream TPM based Encryption
This PR applies to Windows Platforms. uses the seal/unseal functionality of the TPM to encrypt and decrypt a JetStream encryption key, similar to how disk encryption works on windows platforms.
How it works:
Create an instance of the Storage Root Key (SRK) in the TPM.
If existing JS Encryption keys do not exist on disk:
Otherwise (keys exist on disk)
Configuration (full):
Configuration (Usual/Minimal):
The configured defaults should work on factory settings of windows TPMs.
The created JS Key is simply an NKEY, but can be anything truly random serialized to a string.
Applies to windows builds although could be extended to linux in the future.
Note: Before merging another maintainer should test this on a windows 10+ laptop with a TPM version 2.0.
Hat tip to @philpennock for assistance in reviewing the approach and initial test code.
Signed-off-by: Colin Sullivan colin@luxantsolutions.com