-
Notifications
You must be signed in to change notification settings - Fork 24
Add initial (unused) RSA envelope encryption #756
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
base: master
Are you sure you want to change the base?
Conversation
c4f2051 to
ef671fe
Compare
This commit adds support for envelope encryption using an RSA key. Note: This encryption is specifically for disco-agent and not for venafi-kubernetes-agent although the code here is not used in either agent yet. Signed-off-by: Ashley Davis <ashley.davis@cyberark.com>
|
I'm surprised we are relying on RSA for encryption rather than something faster and more robust (EC based like ECDH?). Is that because the DisCo backend is old or something? I thought the proper way to do hybrid public key encryption would be to use Go 1.26's ML-KEM support? Is that because the lib is too bleeding edge? The RFC is from 2022, I imagine we would be OK using it... Sorry about the dumb questions, I haven't looked at any of the design docs or anything related to this feature 😅 |
The agent is ultimately going to have to react to whatever public key it gets from the server. I don't think the backend is old - I think RSA is just the "first thing" getting implemented. There are discussions ongoing around what this looks like longer term, but RSA is secure enough today and the amount of data being encrypted with RSA is so small that performance shouldn't be a concern.
The gold standard today would be to use HPKE, which go will support in its stdlib from 1.26. We could absolutely use that instead, but the initial decision for now is RSA. |
wallrj-cyberark
left a comment
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 @SgtCoDFish
It looks good, but I'd like a bit more documentation with references to the principles and best-practices of Envelope encryption. Perhaps a doc.go. I'm no crypto expert.
I'm happy to review followup PRs as you develop this further.
Here's the copilot review I referred to, above:
| // Nonce is the 12-byte nonce used for AES-GCM encryption. | ||
| // This is intentionally plaintext. | ||
| Nonce []byte `json:"nonce"` | ||
| } |
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 is serializable to JSON, but does the EncryptedKey, EncryptedData, and nonce need to be base64 encoded first?
Maybe add a test to demonstrate that the json serialization works.
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.
stdlib encoding/json converts byte slices to b64 by default, so I don't think there's too much value in explicitly testing the serialization
From go doc json Marshal:
Array and slice values encode as JSON arrays, except that []byte encodes as
a base64-encoded string, and a nil slice encodes as the null JSON value.
Mostly this focuses on documentation to make the purpose of the chosen functions clear Also moves Encryptor to a better home Signed-off-by: Ashley Davis <ashley.davis@cyberark.com>
Signed-off-by: Ashley Davis <ashley.davis@cyberark.com>
|
Great review @wallrj-cyberark thanks! I've addressed all comments, and also refactored this with a view towards the future where we could add a similar version supporting HPKE instead of using RSA. |
Summary
Add RSA-based envelope encryption capabilities to secure secrets sent from disco-agent to the DisCo backend. This PR introduces the
internal/envelopepackage which provides envelope encryption types and an initial implementation using RSAMotivation
The disco-agent needs to encrypt sensitive secrets before transmitting them to the DisCo backend. This PR provides the cryptographic building blocks to enable end-to-end encryption of secrets, ensuring that sensitive data is protected in transit and at rest.
Note: This encryption is specifically for disco-agent and not for venafi-kubernetes-agent although the code here is not used in either agent yet.
Changes
internal/envelopePackageDefines some basic types for the kinds of encryption we're doing. Leaves space for us to use other algorithms + schemes down the road (e.g. HPKE).
internal/envelope/rsaPackageImplements envelope encryption using RSA for key wrapping and AES-256-GCM for data encryption:
Encryptor:
Key Management:
PUBLIC KEY) and PKCS1 (RSA PUBLIC KEY) formatsData Structures:
EncryptedDatacontaining encrypted key, encrypted data, and nonceDependencies
No new external dependencies required - uses Go standard library crypto packages.
Technical Details
Envelope Encryption Flow
Design Choices
Testing
Run tests:
go test ./internal/envelope/...Next Steps