Repository navigation
librbd: add encryption format support for clones (part 1/2) - #40363
Conversation
ee29748 to
0285ee0
Compare
|
@trociny for the flattening operation, I will need to read/write the LUKS header.
Thoughts? |
Sorry, I am still not quite familiar with the crypto code. I am not sure I understand why you need to read/write the LUKS header on flatten? I thought the child header, written on the clone operation, was going to be used for all child objects. Why would you need to overwrite? it on flatten? |
I will be changing the LUKS magic string in the LUKS header to prevent external applications (e.g. dm-crypt) to try and open the cloned formatted volume. When flattening an image, I will restore the LUKS magic to re-allow parsing the image by external tools. |
Sorry for a dumb question, but why do we need to prevent external applications from doing this? |
Ah, it is because krbd has not implemented the encryption yet. I see. Ok. Then am I right understanding the problem is that when you want to change the "non-compatible" header to "compatible" after flatten is complete, for only this operation you have to write (read?) bypassing the crypto layer. If this is the case, then may be just open a new image context (with crypto disabled) for this update? |
|
@orozery sorry, I seemed to edit your comment and writing my response there instead of making a new comment. Restoring your response (to my dumb question) here:
|
Yep, so I need to read the old header, modify it and write. So I should do something like to duplicate an image_ctx: ? |
Yes. I would try this way. |
|
@trociny another question: Currently I see these relevant places that we need to address: It would be nice to cover other places as well, e.g. |
I suppose it should rather be
How do you suppose the spec would look? Actually I thought you would need to add And I think it is not necessary to update all commands in this PR, it could be done in the future requests. But sure you are free to do it in a way you like. |
I just noticed that the flatten flag is parsed at
Well you got me thinking... |
Yes. But it is just stored in the migration header on this stage. The real flattening happens on execute (if the flag was set on prepare). |
|
@trociny So I plan to add an optional encryption spec argument to: One option is to change the format of image-spec, from: This will be the easiest to implement. Second option will be to add a new optional argument like Thoughts? |
I don't like the idea of overloading the image spec. I can see reasons why qemu would need, but in our case, when it can be easily provided via optional arguments... And If you plan to avoid optional arguments this way, you will not, because we allow to specify image spec both via one positional argument and via optional arguments (like --pool and --image).
I still don't understand, why don't you want to use |
Same thing, that's what I meant. But for deep copy, we'll do: |
We are still talking about flatten case only, right? Then do we need the destination encryption? I though we just needed the source encryption settings in this case. Or are you also thinking about the case when we want to change the destination image encryption? If you are going to work only on the flatten case right now, then I think just |
Got you. |
|
And again, making flatten work could be a goal for another PR. In this PR you could just add a check and make the commands (with flatten option) fail if encryption is used. But as you wish. |
Could it be encrypted as the source? Because I suppose this will be the case when --flatten is not specified and this is what the user will likely to expect. If it requires much additional work (i.e. implementing the destination encryption) then may be just forbid flatten with encryption right now? Because we will not be able to change this behavior (encrypted -> plain) later. |
| * FLUSH | ||
| * | | ||
| * v | ||
| * <finish> (+ RESTORE_CRYPTO) |
There was a problem hiding this comment.
I am not sure I might be missing something, but is it safe just to shut down the crypto temporarily? Don't we need some protection for concurrent i/o during this window?
AFAIR our discussion long time ago you were going to open a separate image context just to be able to run it without the crypto layer. And I seem not to find that code in the current implementation?
There was a problem hiding this comment.
Well, we can add a flush, and relay on exclusive_lock, which is acquired when flattening an image (assuming image supports exclusive lock).
So maybe we can add a flush to protect against in-flight writes?
But for reads, I don't think there's any mechanism we can use?
I reverted the old method of using a new ImageCtx after this review:
#40363 (comment)
There was a problem hiding this comment.
Actually, I expect the problem only when exclusive_lock is used. I don't expect "concurent io" for the same image context, when a user runs flatten for an image without exclusive_lock. But when you run for an image with the exclusive lock enabled and the image is currently in use, the operation will be just proxied to the lock owner and you will have both flatten and user i/o there.
If we don't want to open a new image context for this then may be we can temporarily block i/o?
There was a problem hiding this comment.
If we don't want to open a new image context for this then may be we can temporarily block i/o?
I don't see any way do that in the current code (correct me if I'm wrong).
We can add a way to do this (say, by adding block_io to librbd::io::Dipspatcher), but we will also need to add a flag that allows to skip the block (for the raw IO that is triggered from luks::FlattenRequest to read/write the LUKS header).
But I think it will be easier to just add librbd::io::READ_FLAG_SKIP_CRYPTO, and librbd::io::WRITE_FLAG_SKIP_CRYPTO, which also means adding a new write_flags to ImageDispatchSpec::create_write, and changing all existing layers to properly propagate it.
What do you think?
There was a problem hiding this comment.
We already have block_writes but no block_reads...
Anyway, your idea with SKIP_CRYPTO flags looks interesting to me.
There was a problem hiding this comment.
Do you mean adding
rbd_encryption_flattenmethod to librbd API? I'm not sure I understand the need for that: couldn't today'srbd_flattenissue eitherFlattenPayloadorEncryptedFlattenPayloadRPC depending on whether encryption is loaded?
You're right, I didn't think this through :)
Thinking a bit more about it, I'm not sure we need to go out of our way to handle this case at all. If a client doesn't have encryption loaded but is actively doing something with the image, even if it properly denies encrypted flatten request from the peer, it would most likely break later because its higher level caches would get out of sync (as encrypted flatten done by the peer would change the contents the image from that client's POV). The same can happen with regular writes as well and there is no check we can add for that case.
So maybe just leave it as is?
Well there's 2 legitimate cases I can think of:
- A client which only does reads on the raw image (such as exporting). I guess in this case is fine since exclusive lock will only be held by a writing client?
- A client that intends to write, but still didn't run
rbd_encryption_load. I guess in that case, again, the exclusive lock won't be acquired by the client since he made no writes (he only didrbd_open)?
So assuming I missed no other legit case, I think I agree we can leave it as is.
@dannyharnik did I miss anything?
There was a problem hiding this comment.
While testing my flattening patch, I also discovered an I/O path bug which is present in this PR as is.
I'm working on the fix right now.
The I/O path issues are now resolved but I ran into another bug. The crux of it is that shrinking the image boils down to basically the same thing as flattening the affected range in case snapshots are involved. In addition, even if a clone doesn't have any snapshots, shrinking it to a size that isn't an object boundary is going to trigger a copyup for that object. This means that rbd_resize needs to respect the loaded encryption just as rbd_flatten does lest data corruption occurs...
I have started working on the fix -- since this resize issue is again brought by this PR as is I'm considering it a merge blocker.
There was a problem hiding this comment.
I think all blockers are addressed now. Because the additional diff is pretty large, I'm leaning towards merging this PR as is and opening a new "part 2" PR. It should be much easier to review that way. Any objections?
There was a problem hiding this comment.
Great, I'm cleaning up fixup commits right now -- should be able to push later today!
| * FLUSH | ||
| * | | ||
| * v | ||
| * <finish> (+ RESTORE_CRYPTO) |
There was a problem hiding this comment.
Hrm, this PR is already huge without these mechanical changes... I'm inclined to defer the move away from the temporary crypto shutdown to another PR and have the discussion there, just to finally land the basics to improve upon. @trociny do you agree? Do you see any other issues?
There was a problem hiding this comment.
The immutable object cache fix looks good, I think this is ready for another run through teuthology. In the meantime, please address the outstanding comments/nits (note that there are a few in #40363 (review) review from Jul 18 which Github unhelpfully collapses by default, at least for me).
| * FLUSH | ||
| * | | ||
| * v | ||
| * <finish> (+ RESTORE_CRYPTO) |
There was a problem hiding this comment.
I think I already addressed the review you posted a few weeks ago. There are a few other nits you posted a few days ago which should be addressed in the changes I pushed today.
Those are indeed addressed but there are still three nits (one in luks/test_mock_FlattenRequest.cc, one in luks/test_mock_LoadRequest.cc and one in luks/LoadRequest.cc) from July:
- librbd: add encryption format support for clones (part 1/2) #40363 (comment)
- librbd: add encryption format support for clones (part 1/2) #40363 (comment)
- librbd: add encryption format support for clones (part 1/2) #40363 (comment)
As for this flattening issue, I'm still experimenting. I believe I have something promising but it is not complete (yet to be fully compiled even -- I keep being distracted). I will update this thread when I have more.
CryptoInterface was being a reference counted for lifecycle management. In this commit, we remove the ref-counting, and instead have it owned by EncryptionFormat, which in turn is owned by ImageCtx. This commit also changes crypto::LoadRequest to actually load new encryption instances to parent images, instead of blind-copying the encryption instances from the child image. Signed-off-by: Or Ozeri <[email protected]>
Add further useful debug loggings to librbd crypto code. Additionally, increase libcryptsetup debug level to 30 (as it prints out to stdout). Signed-off-by: Or Ozeri <[email protected]>
Currently luks format operation sets the data offset to be aligned with the image object size. When using non-trivial striping, rbd objects can contain a combination of luks header and actual encrypted data, which will pose a problem later on for flattening a cloned image that was formatted. Therefore, we change the data offset to align with stripe_period instead. Furthermore, the written header is zero-padded to stripe period alignment, to ensure that parent plaintext won't be copied-up while writing it. Signed-off-by: Or Ozeri <[email protected]>
The LUKS master key is read in LoadRequest<I>::read_volume_key() and saved to the stack. Add a wipe to that key at the end of the function. Signed-off-by: Or Ozeri <[email protected]>
crypto loading involves reading image data. This data may get cached and should be invalidated before completing the load. This commit adds a complete image flush before loading, as well as complete cache invalidation after loading completes. Signed-off-by: Or Ozeri <[email protected]>
handle_read so far assumed that a successful read returns 0. This is true for the core layer which returns 0 at ObjectRequest.cc. However, this is not the case for ParentCacheObjectDispatch, which returns the (possibly positive) size of data read, instead of 0. To account for that, we change the success check from r==0 to r>=0. Signed-off-by: Or Ozeri <[email protected]>
This commit fixes ParentCacheObjectDispatch to treat read_flags, specifically READ_FLAG_DISABLE_READ_FROM_PARENT. Signed-off-by: Or Ozeri <[email protected]>
This commit changes ShutDownCryptoRequest to shutdown crypto not only on the given image context, but also for for ancestor (e.g. parent) image contexts. Signed-off-by: Or Ozeri <[email protected]>
This commit switches the luks magic from LUKS to RBDL when formatting a cloned image, so that if the user tries to load the image using external LUKS parser (such as dm-crypt) it will fail. Note that formatted clones are not valid LUKS format, and thus we aim to fail LUKS parsers. Signed-off-by: Or Ozeri <[email protected]>
This commit adds a flatten operation to EncryptionFormat, which allows defining custom format-specific flattening operation. Specifically, when flattening a LUKS format, we replace back the magic from RBDL to LUKS, to make the image parse-able again by LUKS parsers, such as dm-crypt. Furthermore, we copy the LUKS header from the parent to the child image. Signed-off-by: Or Ozeri <[email protected]>
This commits extends the crypto FormatRequest and LoadRequest to support thin formatting of cloned images. This code is shadowed, as it is currently non-reachable from the librbd external API. Signed-off-by: Or Ozeri <[email protected]>
This commit enables correct flattening of images where encryption is loaded. In particular, this means: 1. Flattening the encryption header (which is non addressable when encryption is loaded) 2. Running format-specific flattening operation (i.e. reverting the LUKS magic in the encryption header) The allow the above 2 operations, we shut-down the crypto layers, and restore them back when these operations end. The above operations are performed as part of a format-specific handler (LUKSEncryptionFormat::flatten). Signed-off-by: Or Ozeri <[email protected]>
Encryption loading (i.e. rbd_encryption_load) gets a single passphrase and tries to applies it to all ancestor images. If it fails, the entire load fails. This commits extends encryption loading to assume ancestor is actually in plaintext format if no known encryption header magic is detected. Signed-off-by: Or Ozeri <[email protected]>
This commit extends encryption_format and adds encryption_load2 to librbd API, which enables crypto formatting and loading of cloned images. i.e. the child image is encrypted with a key different from its parent, while keeping the child thinly-provisioned. Signed-off-by: Or Ozeri <[email protected]>
This commit adds the encryption format support for cloned images via the RBD cli, making the child image be encrypted with a key different from it parent, while keeping the child thinly-provisioned. Additionally, other APIs are extended to support flattening of such images. Signed-off-by: Or Ozeri <[email protected]>
This commit changes the format for encrypted disks to have the child image and the parent image encrypted with different keys. This to allow testing of the new formatted clones feature in librbd/crypto. Signed-off-by: Or Ozeri <[email protected]>
|
Seemingly no related failures but all CentOS and RHEL jobs are broken, see https://tracker.ceph.com/issues/57332. The second and third runs which look much better are with the main CentOS and RHEL facets taken out of the matrix: https://pulpito.ceph.com/dis-2022-08-27_23:30:08-rbd-wip-dis-testing-distro-default-smithi/ |
|
jenkins test make check |
|
jenkins test api |
1 similar comment
|
jenkins test api |
|
No related failures (about a dozen jobs didn't run due to infrastructure issues but this would be tested again with encrypted flatten, etc changes anyway): https://pulpito.ceph.com/dis-2022-10-24_00:37:15-rbd-wip-dis-testing-distro-default-smithi/ |
idryomov
left a comment
There was a problem hiding this comment.
Merging this as is because, if appended here, encrypted I/O path + encrypted flatten + encrypted resize fixes would grow this PR by over a half, to ~5000 lines of code.
Summary of changes:
FormatRequestandLoadRequestto store/read ancestor cryptors to/from image metadata.get_cryptoandset_cryptotoImageCtxwith relevant lock acquiring.Still to come: documentation update