Skip to content

Commit

Permalink
Add infrastructure for supporting multiple token slots per unlock method
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaublitz committed Jan 7, 2025
1 parent 0706663 commit c0a1a70
Show file tree
Hide file tree
Showing 44 changed files with 2,537 additions and 1,676 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ version = "0.2.155"
optional = true

[dependencies.libcryptsetup-rs]
version = "0.11.0"
version = "0.11.2"
features = ["mutex"]
optional = true

Expand Down
9 changes: 2 additions & 7 deletions src/bin/stratis-legacy-pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use serde_json::{json, Map, Value};

use stratisd::{
engine::{
register_clevis_token, EncryptionInfo, KeyDescription, ProcessedPathInfos, StratPool,
register_clevis_token, InputEncryptionInfo, KeyDescription, ProcessedPathInfos, StratPool,
CLEVIS_TANG_TRUST_URL,
},
stratis::StratisResult,
Expand Down Expand Up @@ -120,12 +120,7 @@ fn main() -> StratisResult<()> {
)?
.unpack()
.1;
let encryption_info = match (key_desc, clevis_info) {
(Some(kd), Some(ci)) => Some(EncryptionInfo::Both(kd, ci)),
(Some(kd), _) => Some(EncryptionInfo::KeyDesc(kd)),
(_, Some(ci)) => Some(EncryptionInfo::ClevisInfo(ci)),
(_, _) => None,
};
let encryption_info = InputEncryptionInfo::new_legacy(key_desc, clevis_info);
register_clevis_token()?;
StratPool::initialize(name.as_str(), unowned, encryption_info.as_ref())?;
Ok(())
Expand Down
310 changes: 214 additions & 96 deletions src/bin/stratis-min/stratis-min.rs

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions src/dbus_api/api/manager_3_0/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ use crate::{
util::{engine_to_dbus_err_tuple, get_next_arg, tuple_to_option},
},
engine::{
CreateAction, DeleteAction, EncryptionInfo, EngineAction, IntegritySpec, KeyDescription,
MappingCreateAction, MappingDeleteAction, PoolIdentifier, PoolUuid, SetUnlockAction,
UnlockMethod,
CreateAction, DeleteAction, EngineAction, InputEncryptionInfo, IntegritySpec,
KeyDescription, MappingCreateAction, MappingDeleteAction, PoolIdentifier, PoolUuid,
SetUnlockAction, UnlockMethod,
},
stratis::StratisError,
};
Expand Down Expand Up @@ -322,12 +322,13 @@ pub fn create_pool(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodResult {
},
None => None,
};
let encryption_info = InputEncryptionInfo::new_legacy(key_desc, clevis_info);

let dbus_context = m.tree.get_data();
let create_result = handle_action!(block_on(dbus_context.engine.create_pool(
name,
&devs.map(Path::new).collect::<Vec<&Path>>(),
EncryptionInfo::from_options((key_desc, clevis_info)).as_ref(),
encryption_info.as_ref(),
IntegritySpec::default(),
)));
match create_result {
Expand Down
4 changes: 2 additions & 2 deletions src/dbus_api/api/manager_3_2/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
types::{DbusErrorEnum, TData, OK_STRING},
util::{engine_to_dbus_err_tuple, get_next_arg, tuple_to_option},
},
engine::{PoolIdentifier, PoolUuid, StartAction, StopAction, UnlockMethod},
engine::{PoolIdentifier, PoolUuid, StartAction, StopAction, TokenUnlockMethod, UnlockMethod},
stratis::StratisError,
};

Expand Down Expand Up @@ -63,7 +63,7 @@ pub fn start_pool(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodResult {

let ret = match handle_action!(block_on(dbus_context.engine.start_pool(
PoolIdentifier::Uuid(pool_uuid),
unlock_method,
TokenUnlockMethod::from(unlock_method),
None
))) {
Ok(StartAction::Started(_)) => {
Expand Down
4 changes: 2 additions & 2 deletions src/dbus_api/api/manager_3_4/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
types::{DbusErrorEnum, TData, OK_STRING},
util::{engine_to_dbus_err_tuple, get_next_arg, tuple_to_option},
},
engine::{Name, PoolIdentifier, PoolUuid, StartAction, UnlockMethod},
engine::{Name, PoolIdentifier, PoolUuid, StartAction, TokenUnlockMethod, UnlockMethod},
stratis::StratisError,
};

Expand Down Expand Up @@ -69,7 +69,7 @@ pub fn start_pool(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodResult {

let ret = match handle_action!(block_on(dbus_context.engine.start_pool(
id.clone(),
unlock_method,
TokenUnlockMethod::from(unlock_method),
None
))) {
Ok(StartAction::Started(_)) => {
Expand Down
4 changes: 2 additions & 2 deletions src/dbus_api/api/manager_3_5/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
types::{DbusErrorEnum, TData, OK_STRING},
util::{engine_to_dbus_err_tuple, get_next_arg, tuple_to_option},
},
engine::{CreateAction, EncryptionInfo, IntegritySpec, KeyDescription, PoolIdentifier},
engine::{CreateAction, InputEncryptionInfo, IntegritySpec, KeyDescription, PoolIdentifier},
stratis::StratisError,
};

Expand Down Expand Up @@ -64,7 +64,7 @@ pub fn create_pool(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodResult {
let create_result = handle_action!(block_on(dbus_context.engine.create_pool(
name,
&devs.map(Path::new).collect::<Vec<&Path>>(),
EncryptionInfo::from_options((key_desc, clevis_info)).as_ref(),
InputEncryptionInfo::new_legacy(key_desc, clevis_info).as_ref(),
IntegritySpec::default(),
)));
match create_result {
Expand Down
8 changes: 4 additions & 4 deletions src/dbus_api/api/manager_3_8/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use crate::{
util::{engine_to_dbus_err_tuple, get_next_arg, tuple_to_option},
},
engine::{
CreateAction, EncryptionInfo, IntegritySpec, IntegrityTagSpec, KeyDescription, Name,
PoolIdentifier, PoolUuid, StartAction, UnlockMethod,
CreateAction, InputEncryptionInfo, IntegritySpec, IntegrityTagSpec, KeyDescription, Name,
PoolIdentifier, PoolUuid, StartAction, TokenUnlockMethod, UnlockMethod,
},
stratis::StratisError,
};
Expand Down Expand Up @@ -86,7 +86,7 @@ pub fn start_pool(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodResult {

let ret = match handle_action!(block_on(dbus_context.engine.start_pool(
id.clone(),
unlock_method,
TokenUnlockMethod::from(unlock_method),
fd.map(|f| f.into_fd()),
))) {
Ok(StartAction::Started(_)) => {
Expand Down Expand Up @@ -208,7 +208,7 @@ pub fn create_pool(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodResult {
let create_result = handle_action!(block_on(dbus_context.engine.create_pool(
name,
&devs.map(Path::new).collect::<Vec<&Path>>(),
EncryptionInfo::from_options((key_desc, clevis_info)).as_ref(),
InputEncryptionInfo::new_legacy(key_desc, clevis_info).as_ref(),
IntegritySpec {
journal_size,
tag_spec,
Expand Down
38 changes: 24 additions & 14 deletions src/dbus_api/pool/pool_3_0/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use crate::{
util::{engine_to_dbus_err_tuple, get_next_arg, tuple_to_option},
},
engine::{
CreateAction, DeleteAction, EngineAction, FilesystemUuid, KeyDescription, Name, PoolUuid,
RenameAction,
CreateAction, DeleteAction, EngineAction, FilesystemUuid, KeyDescription, Name,
OptionalTokenSlotInput, PoolUuid, RenameAction,
},
stratis::StratisError,
};
Expand Down Expand Up @@ -376,15 +376,16 @@ pub fn bind_clevis(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodResult {
}
};
let msg = match handle_action!(
pool.bind_clevis(pin.as_str(), &json),
pool.bind_clevis(OptionalTokenSlotInput::Legacy, pin.as_str(), &json),
dbus_context,
pool_path.get_name()
) {
Ok(CreateAction::Identity) => {
return_message.append3(false, DbusErrorEnum::OK as u16, OK_STRING.to_string())
}
Ok(CreateAction::Created(_)) => {
dbus_context.push_pool_clevis_info_change(pool_path.get_name(), pool.encryption_info());
dbus_context
.push_pool_clevis_info_change(pool_path.get_name(), pool.encryption_info_legacy());
return_message.append3(true, DbusErrorEnum::OK as u16, OK_STRING.to_string())
}
Err(e) => {
Expand Down Expand Up @@ -416,12 +417,13 @@ pub fn unbind_clevis(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodResult {

let mut pool = get_mut_pool!(dbus_context.engine; pool_uuid; default_return; return_message);

let msg = match handle_action!(pool.unbind_clevis(), dbus_context, pool_path.get_name()) {
let msg = match handle_action!(pool.unbind_clevis(None), dbus_context, pool_path.get_name()) {
Ok(DeleteAction::Identity) => {
return_message.append3(false, DbusErrorEnum::OK as u16, OK_STRING.to_string())
}
Ok(DeleteAction::Deleted(_)) => {
dbus_context.push_pool_clevis_info_change(pool_path.get_name(), pool.encryption_info());
dbus_context
.push_pool_clevis_info_change(pool_path.get_name(), pool.encryption_info_legacy());
return_message.append3(true, DbusErrorEnum::OK as u16, OK_STRING.to_string())
}
Err(e) => {
Expand Down Expand Up @@ -464,15 +466,16 @@ pub fn bind_keyring(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodResult {
let mut pool = get_mut_pool!(dbus_context.engine; pool_uuid; default_return; return_message);

let msg = match handle_action!(
pool.bind_keyring(&key_desc),
pool.bind_keyring(OptionalTokenSlotInput::Legacy, &key_desc),
dbus_context,
pool_path.get_name()
) {
Ok(CreateAction::Identity) => {
return_message.append3(false, DbusErrorEnum::OK as u16, OK_STRING.to_string())
}
Ok(CreateAction::Created(_)) => {
dbus_context.push_pool_key_desc_change(pool_path.get_name(), pool.encryption_info());
dbus_context
.push_pool_key_desc_change(pool_path.get_name(), pool.encryption_info_legacy());
return_message.append3(true, DbusErrorEnum::OK as u16, OK_STRING.to_string())
}
Err(e) => {
Expand Down Expand Up @@ -504,12 +507,17 @@ pub fn unbind_keyring(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodResult

let mut pool = get_mut_pool!(dbus_context.engine; pool_uuid; default_return; return_message);

let msg = match handle_action!(pool.unbind_keyring(), dbus_context, pool_path.get_name()) {
let msg = match handle_action!(
pool.unbind_keyring(None),
dbus_context,
pool_path.get_name()
) {
Ok(DeleteAction::Identity) => {
return_message.append3(false, DbusErrorEnum::OK as u16, OK_STRING.to_string())
}
Ok(DeleteAction::Deleted(_)) => {
dbus_context.push_pool_key_desc_change(pool_path.get_name(), pool.encryption_info());
dbus_context
.push_pool_key_desc_change(pool_path.get_name(), pool.encryption_info_legacy());
return_message.append3(true, DbusErrorEnum::OK as u16, OK_STRING.to_string())
}
Err(e) => {
Expand Down Expand Up @@ -552,15 +560,16 @@ pub fn rebind_keyring(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodResult
let mut pool = get_mut_pool!(dbus_context.engine; pool_uuid; default_return; return_message);

let msg = match handle_action!(
pool.rebind_keyring(&key_desc),
pool.rebind_keyring(None, &key_desc),
dbus_context,
pool_path.get_name()
) {
Ok(RenameAction::Identity) => {
return_message.append3(false, DbusErrorEnum::OK as u16, OK_STRING.to_string())
}
Ok(RenameAction::Renamed(_)) => {
dbus_context.push_pool_key_desc_change(pool_path.get_name(), pool.encryption_info());
dbus_context
.push_pool_key_desc_change(pool_path.get_name(), pool.encryption_info_legacy());
return_message.append3(true, DbusErrorEnum::OK as u16, OK_STRING.to_string())
}
Ok(RenameAction::NoSource) => {
Expand Down Expand Up @@ -599,9 +608,10 @@ pub fn rebind_clevis(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodResult {

let mut pool = get_mut_pool!(dbus_context.engine; pool_uuid; default_return; return_message);

let msg = match handle_action!(pool.rebind_clevis(), dbus_context, pool_path.get_name()) {
let msg = match handle_action!(pool.rebind_clevis(None), dbus_context, pool_path.get_name()) {
Ok(_) => {
dbus_context.push_pool_clevis_info_change(pool_path.get_name(), pool.encryption_info());
dbus_context
.push_pool_clevis_info_change(pool_path.get_name(), pool.encryption_info_legacy());
return_message.append3(true, DbusErrorEnum::OK as u16, OK_STRING.to_string())
}
Err(e) => {
Expand Down
4 changes: 2 additions & 2 deletions src/dbus_api/pool/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,12 @@ pub fn pool_avail_actions_prop(pool: &dyn Pool) -> String {

/// Generate D-Bus representation of a pool key description property.
pub fn pool_key_desc_prop(pool: &dyn Pool) -> (bool, (bool, String)) {
prop_conv::key_desc_to_prop(pool.encryption_info())
prop_conv::key_desc_to_prop(pool.encryption_info_legacy())
}

/// Generate D-Bus representation of a pool Clevis info property.
pub fn pool_clevis_info_prop(pool: &dyn Pool) -> (bool, (bool, (String, String))) {
prop_conv::clevis_info_to_prop(pool.encryption_info())
prop_conv::clevis_info_to_prop(pool.encryption_info_legacy())
}

/// Generate D-Bus representation of a boolean indicating whether the pool
Expand Down
2 changes: 1 addition & 1 deletion src/dbus_api/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl DbusTreeHandler {
opath
.get_data()
.as_ref()
.map_or(false, |op_cxt| op_cxt.parent == item)
.is_some_and(|op_cxt| op_cxt.parent == item)
}) {
if let StratisUuid::Fs(_) = opath
.get_data()
Expand Down
Loading

0 comments on commit c0a1a70

Please sign in to comment.