-
Notifications
You must be signed in to change notification settings - Fork 57
Online reencryption #3953
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
Open
jbaublitz
wants to merge
24
commits into
stratis-storage:master
Choose a base branch
from
jbaublitz:issue-stratisd-3597
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Online reencryption #3953
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
bbfdc66
Add encryption support in V2 crypt handle
jbaublitz 27e3681
Add Engine interface for encrypting pool
jbaublitz b640659
Add D-Bus interface for encrypting pool
jbaublitz 9857136
Unit test for online encryption
jbaublitz a330beb
Add reencryption support in both crypt handles
jbaublitz 9e95298
Add Engine interface for reencrypting pool
jbaublitz d596f8a
Add D-Bus interface for reencrypting pool
jbaublitz 8c45a9f
Unit test for online reencryption
jbaublitz 42c114b
Add decryption support in V2 crypt handle
jbaublitz b531e67
Add Engine interface for decrypting pool
jbaublitz 3e07d92
Add D-Bus interface for decrypting pool
jbaublitz 0b58661
Unit test for online decryption
jbaublitz e17d464
Perform rollback for setup operations in reencryption
jbaublitz 5098d07
Add last reencrypted timestamp to engine
jbaublitz 8703183
Update timestamp on successful decryption and reencryption operations
jbaublitz 21865ce
Add reencryption timestamp API to engine
jbaublitz a9bcb93
Add property to indicate when the pool was last reencrypted
jbaublitz 5ee5e78
Add change signal for last encrypted timestamp
jbaublitz ababe1a
Refactor reencryption to use a read lock during operation
jbaublitz 5858347
Add upgrade and downgrade to lock and use in reencryption
jbaublitz f446b7b
Refactor encryption to use a read lock during operation
jbaublitz 4d6f48d
Refactor decryption to use a read lock during operation
jbaublitz 9fafd3f
Add prechecks for all key description-related operations
jbaublitz f96864a
Allow parallel encryption, reencryption and decryption operations
jbaublitz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,6 +149,7 @@ jobs: | |
| dnf install -y | ||
| asciidoc | ||
| clang | ||
| cryptsetup | ||
| cryptsetup-devel | ||
| dbus-daemon | ||
| dbus-tools | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -130,6 +130,7 @@ jobs: | |
| apt-get install -y | ||
| asciidoc | ||
| clang | ||
| cryptsetup | ||
| curl | ||
| git | ||
| libblkid-dev | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,6 +73,7 @@ jobs: | |
| dnf install -y | ||
| asciidoc | ||
| clang | ||
| cryptsetup | ||
| cryptsetup-devel | ||
| curl | ||
| device-mapper-persistent-data | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,249 @@ | ||
| // This Source Code Form is subject to the terms of the Mozilla Public | ||
| // License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| // file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
|
||
| use std::sync::Arc; | ||
|
|
||
| use futures::executor::block_on; | ||
| use serde_json::from_str; | ||
| use tokio::sync::RwLock; | ||
| use zbus::Connection; | ||
|
|
||
| use crate::{ | ||
| dbus::{ | ||
| consts::OK_STRING, | ||
| manager::Manager, | ||
| types::DbusErrorEnum, | ||
| util::{ | ||
| engine_to_dbus_err_tuple, send_clevis_info_signal, send_encrypted_signal, | ||
| send_keyring_signal, send_last_reencrypted_signal, tuple_to_option, | ||
| }, | ||
| }, | ||
| engine::{ | ||
| CreateAction, DeleteAction, EncryptedDevice, Engine, InputEncryptionInfo, KeyDescription, | ||
| Lockable, PoolIdentifier, PoolUuid, | ||
| }, | ||
| stratis::StratisError, | ||
| }; | ||
|
|
||
| pub async fn encrypt_pool_method( | ||
| engine: &Arc<dyn Engine>, | ||
| connection: &Arc<Connection>, | ||
| manager: &Lockable<Arc<RwLock<Manager>>>, | ||
| pool_uuid: PoolUuid, | ||
| key_descs: Vec<((bool, u32), KeyDescription)>, | ||
| clevis_infos: Vec<((bool, u32), &str, &str)>, | ||
| ) -> (bool, u16, String) { | ||
| let default_return = false; | ||
|
|
||
| let key_descs_parsed = | ||
| match key_descs | ||
| .into_iter() | ||
| .try_fold(Vec::new(), |mut vec, (ts_opt, kd)| { | ||
| let token_slot = tuple_to_option(ts_opt); | ||
| vec.push((token_slot, kd)); | ||
| Ok(vec) | ||
| }) { | ||
| Ok(kds) => kds, | ||
| Err(e) => { | ||
| let (rc, rs) = engine_to_dbus_err_tuple(&e); | ||
| return (default_return, rc, rs); | ||
| } | ||
| }; | ||
|
|
||
| let clevis_infos_parsed = | ||
| match clevis_infos | ||
| .into_iter() | ||
| .try_fold(Vec::new(), |mut vec, (ts_opt, pin, json_str)| { | ||
| let token_slot = tuple_to_option(ts_opt); | ||
| let json = from_str(json_str)?; | ||
| vec.push((token_slot, (pin.to_owned(), json))); | ||
| Ok(vec) | ||
| }) { | ||
| Ok(cis) => cis, | ||
| Err(e) => { | ||
| let (rc, rs) = engine_to_dbus_err_tuple(&e); | ||
| return (default_return, rc, rs); | ||
| } | ||
| }; | ||
|
|
||
| let iei = match InputEncryptionInfo::new(key_descs_parsed, clevis_infos_parsed) { | ||
| Ok(Some(info)) => info, | ||
| Ok(None) => { | ||
| return ( | ||
| default_return, | ||
| DbusErrorEnum::ERROR as u16, | ||
| "No unlock methods provided".to_string(), | ||
| ); | ||
| } | ||
| Err(e) => { | ||
| let (rc, rs) = engine_to_dbus_err_tuple(&e); | ||
| return (default_return, rc, rs); | ||
| } | ||
| }; | ||
|
|
||
| let guard_res = engine | ||
| .get_mut_pool(PoolIdentifier::Uuid(pool_uuid)) | ||
| .await | ||
| .ok_or_else(|| StratisError::Msg(format!("No pool associated with uuid {pool_uuid}"))); | ||
| let cloned_engine = Arc::clone(engine); | ||
| match tokio::task::spawn_blocking(move || { | ||
| let mut guard = guard_res?; | ||
|
|
||
| handle_action!(guard | ||
| .start_encrypt_pool(pool_uuid, &iei) | ||
| .and_then(|action| match action { | ||
| CreateAction::Identity => Ok(CreateAction::Identity), | ||
| CreateAction::Created((sector_size, key_info)) => { | ||
| let guard = guard.downgrade(); | ||
| guard | ||
| .do_encrypt_pool(pool_uuid, sector_size, key_info) | ||
| .map(|_| guard) | ||
| .and_then(|guard| { | ||
| let mut guard = block_on(cloned_engine.upgrade_pool(guard)); | ||
| let (name, _, _) = guard.as_mut_tuple(); | ||
| guard.finish_encrypt_pool(&name, pool_uuid) | ||
| }) | ||
| .map(|_| CreateAction::Created(EncryptedDevice(pool_uuid))) | ||
| } | ||
| })) | ||
| }) | ||
| .await | ||
| { | ||
| Ok(Ok(CreateAction::Created(_))) => { | ||
| match manager.read().await.pool_get_path(&pool_uuid) { | ||
| Some(p) => { | ||
| send_keyring_signal(connection, &p.as_ref(), true).await; | ||
| send_clevis_info_signal(connection, &p.as_ref(), true).await; | ||
| send_encrypted_signal(connection, &p.as_ref()).await; | ||
| } | ||
| None => { | ||
| warn!("No pool path associated with UUID {pool_uuid}; failed to send encryption related signals"); | ||
| } | ||
| } | ||
| (true, DbusErrorEnum::OK as u16, OK_STRING.to_string()) | ||
| } | ||
| Ok(Ok(CreateAction::Identity)) => (false, DbusErrorEnum::OK as u16, OK_STRING.to_string()), | ||
| Ok(Err(e)) => { | ||
| let (rc, rs) = engine_to_dbus_err_tuple(&e); | ||
| (default_return, rc, rs) | ||
| } | ||
| Err(e) => { | ||
| let (rc, rs) = engine_to_dbus_err_tuple(&StratisError::from(e)); | ||
| (default_return, rc, rs) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub async fn reencrypt_pool_method( | ||
| engine: &Arc<dyn Engine>, | ||
| connection: &Arc<Connection>, | ||
| manager: &Lockable<Arc<RwLock<Manager>>>, | ||
| pool_uuid: PoolUuid, | ||
| ) -> (bool, u16, String) { | ||
| let default_return = false; | ||
|
|
||
| let guard_res = engine | ||
| .get_mut_pool(PoolIdentifier::Uuid(pool_uuid)) | ||
| .await | ||
| .ok_or_else(|| StratisError::Msg(format!("No pool associated with uuid {pool_uuid}"))); | ||
| let cloned_engine = Arc::clone(engine); | ||
| match tokio::task::spawn_blocking(move || { | ||
| let mut guard = guard_res?; | ||
|
|
||
| let (name, _, _) = guard.as_mut_tuple(); | ||
|
|
||
| let result = guard.start_reencrypt_pool(); | ||
| let result = result.and_then(|key_info| { | ||
| let guard = guard.downgrade(); | ||
| let result = guard.do_reencrypt_pool(pool_uuid, key_info); | ||
| result.map(|inner| (guard, inner)) | ||
| }); | ||
| let result = result.and_then(|(guard, _)| { | ||
| let mut guard = block_on(cloned_engine.upgrade_pool(guard)); | ||
| guard.finish_reencrypt_pool(&name, pool_uuid) | ||
| }); | ||
| handle_action!(result) | ||
| }) | ||
| .await | ||
| { | ||
| Ok(Ok(_)) => { | ||
| match manager.read().await.pool_get_path(&pool_uuid) { | ||
| Some(p) => { | ||
| send_last_reencrypted_signal(connection, &p.as_ref()).await; | ||
| } | ||
| None => { | ||
| warn!("No pool path associated with UUID {pool_uuid}; failed to send encryption related signals"); | ||
| } | ||
| } | ||
| (true, DbusErrorEnum::OK as u16, OK_STRING.to_string()) | ||
| } | ||
| Ok(Err(e)) => { | ||
| let (rc, rs) = engine_to_dbus_err_tuple(&e); | ||
| (default_return, rc, rs) | ||
| } | ||
| Err(e) => { | ||
| let (rc, rs) = engine_to_dbus_err_tuple(&StratisError::from(e)); | ||
| (default_return, rc, rs) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub async fn decrypt_pool_method( | ||
| engine: &Arc<dyn Engine>, | ||
| connection: &Arc<Connection>, | ||
| manager: &Lockable<Arc<RwLock<Manager>>>, | ||
| pool_uuid: PoolUuid, | ||
| ) -> (bool, u16, String) { | ||
| let default_return = false; | ||
|
|
||
| let guard_res = engine | ||
| .get_mut_pool(PoolIdentifier::Uuid(pool_uuid)) | ||
| .await | ||
| .ok_or_else(|| StratisError::Msg(format!("No pool associated with uuid {pool_uuid}"))); | ||
| let cloned_engine = Arc::clone(engine); | ||
| match tokio::task::spawn_blocking(move || { | ||
| let mut guard = guard_res?; | ||
|
|
||
| handle_action!(match guard.decrypt_pool_idem_check(pool_uuid) { | ||
| Ok(DeleteAction::Identity) => Ok(DeleteAction::Identity), | ||
| Ok(DeleteAction::Deleted(d)) => { | ||
| let guard = guard.downgrade(); | ||
| guard | ||
| .do_decrypt_pool(pool_uuid) | ||
| .and_then(|_| { | ||
| let mut guard = block_on(cloned_engine.upgrade_pool(guard)); | ||
| let (name, _, _) = guard.as_mut_tuple(); | ||
| guard.finish_decrypt_pool(pool_uuid, &name) | ||
| }) | ||
| .map(|_| DeleteAction::Deleted(d)) | ||
| } | ||
| Err(e) => Err(e), | ||
| }) | ||
| }) | ||
| .await | ||
| { | ||
| Ok(Ok(DeleteAction::Deleted(_))) => { | ||
| match manager.read().await.pool_get_path(&pool_uuid) { | ||
| Some(p) => { | ||
| send_keyring_signal(connection, &p.as_ref(), true).await; | ||
| send_clevis_info_signal(connection, &p.as_ref(), true).await; | ||
| send_encrypted_signal(connection, &p.as_ref()).await; | ||
| } | ||
| None => { | ||
| warn!("No pool path associated with UUID {pool_uuid}; failed to send encryption related signals"); | ||
| } | ||
| } | ||
| (true, DbusErrorEnum::OK as u16, OK_STRING.to_string()) | ||
| } | ||
| Ok(Ok(DeleteAction::Identity)) => (false, DbusErrorEnum::OK as u16, OK_STRING.to_string()), | ||
| Ok(Err(e)) => { | ||
| let (rc, rs) = engine_to_dbus_err_tuple(&e); | ||
| (default_return, rc, rs) | ||
| } | ||
| Err(e) => { | ||
| let (rc, rs) = engine_to_dbus_err_tuple(&StratisError::from(e)); | ||
| (default_return, rc, rs) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // This Source Code Form is subject to the terms of the Mozilla Public | ||
| // License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| // file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
|
||
| use chrono::SecondsFormat; | ||
|
|
||
| use crate::{ | ||
| dbus::util::option_to_tuple, | ||
| engine::{Pool, PoolUuid, SomeLockReadGuard}, | ||
| }; | ||
|
|
||
| pub fn last_reencrypted_timestamp_prop( | ||
| guard: SomeLockReadGuard<PoolUuid, dyn Pool>, | ||
| ) -> (bool, String) { | ||
| option_to_tuple( | ||
| guard | ||
| .last_reencrypt() | ||
| .map(|t| t.to_rfc3339_opts(SecondsFormat::Secs, true)), | ||
| String::new(), | ||
| ) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.