Skip to content

Commit ad6274e

Browse files
committed
Extract key-manager-types crate to break illumos-utils dependency
Create a new key-manager-types crate containing the disk encryption key types (Aes256GcmDiskEncryptionKey and VersionedAes256GcmDiskEncryptionKey) that were previously defined in key-manager. This breaks the dependency from illumos-utils to key-manager, allowing illumos-utils to depend only on the minimal types crate. The key-manager crate re-exports VersionedAes256GcmDiskEncryptionKey for backwards compatibility.
1 parent e45b10d commit ad6274e

10 files changed

Lines changed: 84 additions & 32 deletions

File tree

Cargo.lock

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ members = [
7474
"internal-dns/types/versions",
7575
"ipcc",
7676
"key-manager",
77+
"key-manager/types",
7778
"live-tests",
7879
"live-tests/macros",
7980
"nexus",
@@ -247,6 +248,7 @@ default-members = [
247248
"internal-dns/types/versions",
248249
"ipcc",
249250
"key-manager",
251+
"key-manager/types",
250252
"live-tests",
251253
"live-tests/macros",
252254
"nexus",
@@ -553,6 +555,7 @@ ipnetwork = { version = "0.21", features = ["schemars", "serde"] }
553555
ispf = { git = "https://github.com/oxidecomputer/ispf" }
554556
jiff = "0.2.15"
555557
key-manager = { path = "key-manager" }
558+
key-manager-types = { path = "key-manager/types" }
556559
kstat-rs = "0.2.4"
557560
libc = "0.2.174"
558561
libipcc = { git = "https://github.com/oxidecomputer/ipcc-rs", rev = "524eb8f125003dff50b9703900c6b323f00f9e1b" }

illumos-utils/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ futures.workspace = true
2424
http.workspace = true
2525
ipnetwork.workspace = true
2626
itertools.workspace = true
27-
key-manager.workspace = true
27+
key-manager-types.workspace = true
2828
libc.workspace = true
2929
macaddr.workspace = true
3030
nix.workspace = true

illumos-utils/src/zfs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ impl Zfs {
16011601
/// epoch is committed.
16021602
pub async fn change_key(
16031603
dataset: &str,
1604-
key: &key_manager::VersionedAes256GcmDiskEncryptionKey,
1604+
key: &key_manager_types::VersionedAes256GcmDiskEncryptionKey,
16051605
) -> Result<(), ChangeKeyError> {
16061606
// FIXME: Replace the use of `zfs_atomic_change_key` with a native
16071607
// invocation of `zfs change-key` using the `-o oxide:epoch` option to

key-manager/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ workspace = true
1010
[dependencies]
1111
async-trait.workspace = true
1212
hkdf.workspace = true
13+
key-manager-types.workspace = true
1314
omicron-common.workspace = true
1415
secrecy.workspace = true
1516
sha3.workspace = true

key-manager/src/lib.rs

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ use std::fmt::Debug;
99

1010
use async_trait::async_trait;
1111
use hkdf::Hkdf;
12-
use secrecy::{ExposeSecret, ExposeSecretMut, SecretBox};
12+
use key_manager_types::Aes256GcmDiskEncryptionKey;
13+
pub use key_manager_types::VersionedAes256GcmDiskEncryptionKey;
14+
use secrecy::{ExposeSecret, SecretBox};
1315
use sha3::Sha3_256;
1416
use slog::{Logger, o, warn};
1517
use tokio::sync::{mpsc, oneshot};
@@ -52,28 +54,6 @@ pub enum Error {
5254
SecretRetrieval(#[from] SecretRetrieverError),
5355
}
5456

55-
/// Derived Disk Encryption key
56-
#[derive(Debug, Default)]
57-
struct Aes256GcmDiskEncryptionKey(SecretBox<[u8; 32]>);
58-
59-
/// A Disk encryption key for a given epoch to be used with ZFS datasets for
60-
/// U.2 devices
61-
#[derive(Debug)]
62-
pub struct VersionedAes256GcmDiskEncryptionKey {
63-
epoch: u64,
64-
key: Aes256GcmDiskEncryptionKey,
65-
}
66-
67-
impl VersionedAes256GcmDiskEncryptionKey {
68-
pub fn epoch(&self) -> u64 {
69-
self.epoch
70-
}
71-
72-
pub fn expose_secret(&self) -> &[u8; 32] {
73-
&self.key.0.expose_secret()
74-
}
75-
}
76-
7757
/// A request sent from a [`StorageKeyRequester`] to the [`KeyManager`].
7858
enum StorageKeyRequest {
7959
GetKey {
@@ -256,11 +236,11 @@ impl<S: SecretRetriever> KeyManager<S> {
256236
disk_id.model.as_bytes(),
257237
disk_id.serial.as_bytes(),
258238
],
259-
key.0.expose_secret_mut(),
239+
key.expose_secret_mut(),
260240
)
261241
.unwrap();
262242

263-
Ok(VersionedAes256GcmDiskEncryptionKey { epoch, key })
243+
Ok(VersionedAes256GcmDiskEncryptionKey::new(epoch, key))
264244
}
265245

266246
/// Return the epochs for all secrets which are loaded
@@ -406,7 +386,7 @@ mod tests {
406386
};
407387
let epoch = 0;
408388
let key = km.disk_encryption_key(epoch, &disk_id).await.unwrap();
409-
assert_eq!(key.epoch, epoch);
389+
assert_eq!(key.epoch(), epoch);
410390

411391
// Key derivation is deterministic based on disk_id and loaded secrets
412392
let key2 = km.disk_encryption_key(epoch, &disk_id).await.unwrap();
@@ -437,8 +417,8 @@ mod tests {
437417
let epoch = 0;
438418
let key1 = km.disk_encryption_key(epoch, &id_1).await.unwrap();
439419
let key2 = km.disk_encryption_key(epoch, &id_2).await.unwrap();
440-
assert_eq!(key1.epoch, epoch);
441-
assert_eq!(key2.epoch, epoch);
420+
assert_eq!(key1.epoch(), epoch);
421+
assert_eq!(key2.epoch(), epoch);
442422
assert_ne!(key1.expose_secret(), key2.expose_secret());
443423
}
444424

key-manager/types/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "key-manager-types"
3+
version = "0.1.0"
4+
edition.workspace = true
5+
license = "MPL-2.0"
6+
7+
[lints]
8+
workspace = true
9+
10+
[dependencies]
11+
secrecy.workspace = true
12+
omicron-workspace-hack.workspace = true

key-manager/types/src/lib.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
//! Types for disk encryption keys used by the key-manager crate.
6+
7+
use secrecy::{ExposeSecret, ExposeSecretMut, SecretBox};
8+
9+
/// Derived Disk Encryption key
10+
#[derive(Debug, Default)]
11+
pub struct Aes256GcmDiskEncryptionKey(SecretBox<[u8; 32]>);
12+
13+
impl Aes256GcmDiskEncryptionKey {
14+
/// Expose the secret key bytes mutably for writing.
15+
///
16+
/// This is intended for use by the key-manager crate during key derivation.
17+
pub fn expose_secret_mut(&mut self) -> &mut [u8; 32] {
18+
self.0.expose_secret_mut()
19+
}
20+
}
21+
22+
/// A Disk encryption key for a given epoch to be used with ZFS datasets for
23+
/// U.2 devices
24+
#[derive(Debug)]
25+
pub struct VersionedAes256GcmDiskEncryptionKey {
26+
epoch: u64,
27+
key: Aes256GcmDiskEncryptionKey,
28+
}
29+
30+
impl VersionedAes256GcmDiskEncryptionKey {
31+
/// Create a new versioned disk encryption key.
32+
///
33+
/// This is intended for use by the key-manager crate during key derivation.
34+
pub fn new(epoch: u64, key: Aes256GcmDiskEncryptionKey) -> Self {
35+
Self { epoch, key }
36+
}
37+
38+
pub fn epoch(&self) -> u64 {
39+
self.epoch
40+
}
41+
42+
pub fn expose_secret(&self) -> &[u8; 32] {
43+
&self.key.0.expose_secret()
44+
}
45+
}

sled-agent/config-reconciler/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ iddqd.workspace = true
2525
illumos-utils.workspace = true
2626
installinator-common.workspace = true
2727
key-manager.workspace = true
28+
key-manager-types.workspace = true
2829
sled-agent-types-versions.workspace = true
2930
ntp-admin-client.workspace = true
3031
omicron-common.workspace = true

sled-agent/config-reconciler/src/dataset_serialization_task.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use illumos_utils::zfs::DestroyDatasetError;
2626
use illumos_utils::zfs::Mountpoint;
2727
use illumos_utils::zfs::WhichDatasets;
2828
use illumos_utils::zfs::Zfs;
29-
use key_manager::VersionedAes256GcmDiskEncryptionKey;
29+
use key_manager_types::VersionedAes256GcmDiskEncryptionKey;
3030
use omicron_common::disk::DatasetConfig;
3131
use omicron_common::disk::DatasetKind;
3232
use omicron_common::disk::DatasetName;

0 commit comments

Comments
 (0)