-
Notifications
You must be signed in to change notification settings - Fork 4k
core: add preamble format #20124
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
core: add preamble format #20124
Conversation
Encryption-at-rest work: part 1. This adds support for per-store "preamble" format. Specified through the store flag with `format=preamble`. The default value is `classic`. Setting the preamble format causes a higher `COCKROACHDB_VERSION` value as well as the `format=preamble` field to be set. For now, stores created without `format=preamble` will not increase the `COCKROACHDB_VERSION` value to allow downgrade. This allows: * old binaries to fail if preamble is enabled. * new binaries to understand the new version but fail if not specified on an existing preamble-formatted store * stores in classic format can progress to future versions The preamble format is currently plaintext only, encryption to be added in a future PR.
c-deps/libroach/preamble.h
Outdated
|
|
||
| // PlaintextCipherStream implements BlockAccessCipherStream with | ||
| // no-op encrypt/decrypt operations. | ||
| class PlaintextCipherStream final : public rocksdb::BlockAccessCipherStream { |
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 forgot how this works. How do I get a concrete class without overriding the pure protected methods?
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.
Er, isn't the point that you have to override the pure protected methods to get a concrete class?
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.
yeah, I know. I suppose my complaint is about those protected methods being required.
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.
Yeah, the encryption support in RocksDB that landed seems pretty specialized for the use case it was extracted from.
| // special severity value DEFAULT instead. | ||
| pf.Lookup(logflags.LogToStderrName).NoOptDefVal = log.Severity_DEFAULT.String() | ||
|
|
||
| // Security flags. |
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.
Just saw this in passing, that comment has nothing to do here.
3feb890 to
ee20868
Compare
ee20868 to
c8bb7cf
Compare
|
LGTM, aside from doubts about whether we should be using this EncryptedEnv vs building our own. Reviewed 8 of 10 files at r1, 6 of 7 files at r2, 2 of 4 files at r3, 1 of 1 files at r4, 3 of 3 files at r5. c-deps/libroach/db.cc, line 1705 at r5 (raw file):
What's wrong with using the preamble format in memory? c-deps/libroach/preamble.cc, line 40 at r5 (raw file):
Weird in that you're writing this big-endian while protobuf uses little-endian? I don't think that's too bad; I'd rather use big-endian here and not even know what protobuf uses internally. c-deps/libroach/preamble.cc, line 42 at r5 (raw file):
s/message_size/encoded_size/g c-deps/libroach/preamble.cc, line 46 at r5 (raw file):
I'd go with Corruption, same as below. c-deps/libroach/preamble.h, line 24 at r5 (raw file):
s/default/k/ This is also required to be a multiple of the page size, right? Mention that in the comment. Unless you need them for tests, both constants in this header probably belong in the .cc file instead. c-deps/libroach/preamble.h, line 48 at r5 (raw file):
It looks like every write gets padded to a multiple of the block size, so setting it too high would waste space (but setting it too low wastes CPU to iterate over the data to do nothing in small chunks). I'd set this to 16 for now to match the block size of the AES cipher version. In the long run, we should probably refactor the EncryptionProvider interface so it can return something other than a BlockAccessCipherStream that can be an efficient no-op. c-deps/libroach/preamble.h, line 76 at r5 (raw file):
Don't mix tabs and spaces. We use two-space indents in our c++ code. pkg/cli/cliflags/flags.go, line 448 at r5 (raw file):
One day the preamble format will be the default and then the "classic" behind whatever comes next. Let's just give these numbers instead of names. pkg/storage/engine/version.go, line 26 at r5 (raw file):
This two-level versioning scheme is confusing and needs more documentation. Or maybe two version numbers is the wrong approach - is the "format" a sequence of versions or is it a set of features that may or may not be present? It's really unfortunate that EncryptedEnv doesn't give us any feasible migration path so we'll have to keep supporting the old format forever. It ought to be possible to make an Env that lets us encode the format somehow (maybe in the filename?) instead of an all-or-nothing cutover. Then we could treat this like a normal version upgrade and eventually get all files written with the preamble format. pkg/storage/engine/version_test.go, line 84 at r5 (raw file):
What do you mean? Just that the new Format field is ignored by old code? Comments from Reviewable |
|
Review status: all files reviewed at latest revision, 11 unresolved discussions, all commit checks successful. c-deps/libroach/db.cc, line 1705 at r5 (raw file): Previously, bdarnell (Ben Darnell) wrote…
I haven't actually checked that it works properly, but there's no reason to right now. c-deps/libroach/preamble.cc, line 40 at r5 (raw file): Previously, bdarnell (Ben Darnell) wrote…
Ok, removing the TODO. c-deps/libroach/preamble.cc, line 42 at r5 (raw file): Previously, bdarnell (Ben Darnell) wrote…
Done. c-deps/libroach/preamble.cc, line 46 at r5 (raw file): Previously, bdarnell (Ben Darnell) wrote…
Done. c-deps/libroach/preamble.h, line 24 at r5 (raw file): Previously, bdarnell (Ben Darnell) wrote…
Renamed, added "page size" command (not actually a requirement, just preferred). c-deps/libroach/preamble.h, line 48 at r5 (raw file): Previously, bdarnell (Ben Darnell) wrote…
Done. c-deps/libroach/preamble.h, line 76 at r5 (raw file): Previously, bdarnell (Ben Darnell) wrote…
Done. I was copy/pasting. I miss pkg/cli/cliflags/flags.go, line 448 at r5 (raw file): Previously, bdarnell (Ben Darnell) wrote…
We can certainly use numbers instead, but this feels more user-friendly. The docs will have to mention the need for the preamble format, skipping a level of indirection ("which number is preamble again?") seems convenient. pkg/storage/engine/version.go, line 26 at r5 (raw file): Previously, bdarnell (Ben Darnell) wrote…
The format is a "feature" of the storage. We still want to be able to have "version 2 with preamble" and "version 2 without preamble'. As for a different env, I mentioned this is the RFC. We could perform our own mapping of pkg/storage/engine/version_test.go, line 84 at r5 (raw file): Previously, bdarnell (Ben Darnell) wrote…
Yup. Technically the json parsing code does not fail on unknown fields, but that's about to become an option. If someone turns that on, I want the test to fail. Comments from Reviewable |
|
I've added a "custom env" section in the rfc under "Rationale and alternatives". Review status: 18 of 20 files reviewed at latest revision, 11 unresolved discussions, all commit checks successful. Comments from Reviewable |
|
Closing in favor of the switching env. See updated RFC. |
This is to be contrasted to the preamble method in cockroachdb#20124. This method is discussed in the `Custom env for encryption state` section of the [Encryption RFC](cockroachdb#19785) When encryption is enabled, use a switching env that can redirect each Env method to one of: * base env for plaintext (same format as currently, no overhead) * encrypted env (with or without preamble) for encrypted files The switching env will hold the list of encrypted files to know which env to pick.
This is to be contrasted to the preamble method in cockroachdb#20124. This method is discussed in the `Custom env for encryption state` section of the [Encryption RFC](cockroachdb#19785) When encryption is enabled, use a switching env that can redirect each Env method to one of: * base env for plaintext (same format as currently, no overhead) * encrypted env (with or without preamble) for encrypted files The switching env will hold the list of encrypted files to know which env to pick.
Encryption at rest: part 1 of N.
Add preamble format for on-disk rocksdb instances:
--storeflag:format=preamble(empty defaults toclassic)The on-disk version gets set to 2 iff we use the preamble format. This allows:
Eventually, we may want to always write version 2. We may need to give it some time to give enough people to upgrade their binaries.
A few todos to resolve before merging this:
errorfinrocksdb::Status