-
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
security(logging): fix aes implementation in audit logging #8323
Conversation
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 can see that a unique nonce is generated for every log line and the fix seems correct.
e1d674f
to
a80c643
Compare
Any updates on when this will be merged and a security advisory created? |
8c42c19
to
d05989b
Compare
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 think we should consider writing more robust functions and test. This needs more work.
ee/audit/run_ee.go
Outdated
text := make([]byte, len(x.VerificationText)) | ||
stream := cipher.NewCTR(block, iv) | ||
stream.XORKeyStream(text, t) | ||
if string(text) != x.VerificationText { |
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 didn't realize that byte array/slice can't be declared as a constant. This article has a few ideas https://blog.boot.dev/golang/golang-constant-maps-slices/. I don't mind if we declare a function that returns the constant value. I think it is useful to avoid a allocation that converts byte slice to string.
I have already added 4 integration tests, and we have a unit test to check basic parsing. What additional tests are necessary? |
What is the purpose of this? We are doing exactly one allocation per log file (default ~200 mb), so this is not a memory issue? |
The scope of this PR is now much larger than originally intended. This PR now introduces:
This PR also does some minor refactoring to the code. |
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.
Did a quick review for now. I will review it again tomorrow.
Background
Audit logging is an enterprise feature with an option for encryption using AES. An AES cipher has three ingredients: a private key, an iv (or nonce), and plaintext. The nonce is public but it must be unique.
Problem
Currently we use a [16]byte nonce. The first 12 bytes come from a baseIv which is initialized when an audit log is created. The last 4 bytes come from the length of the log line being encrypted. This is problematic because two log lines will often have the same length, so due to these collisions we are reusing the same nonce many times. AES requires a unique nonce and without a unique nonce it is trivial to break. Many thanks to @HakuPiku for pointing this out to us.
Solution
Use crypto/rand to generate a unique nonce every time we encrypt a log line. Previously we used what was essentially a 16 byte header (12 byte baseIv and 4 byte length of line). We now use a [20] byte header, consisting of a unique nonce (16 bytes) and length of line (4 bytes).
Remarks
.enc
file checked into the PR.References