Skip to content
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

Metadata rework #3637

Merged
merged 32 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
23f0477
Add field for metadata version in static header
jbaublitz Mar 8, 2023
fc21a8f
Lift crypt module up one level
jbaublitz Jun 21, 2023
c62b149
Separate new and legacy versions of the crypt handle
jbaublitz Jun 30, 2023
451fc4a
Separate new and legacy versions of Stratis block devices
jbaublitz Jun 30, 2023
42e476b
Abstract BlockDevMgr across both block devices
jbaublitz Jun 30, 2023
c164cc6
Abstract CacheTier and DataTier across both blockdev types
jbaublitz Jun 30, 2023
2dba1f2
Diverge legacy and new backstore to reflect layering change
jbaublitz Jul 6, 2023
b2f88a4
Abstract thinpool across both backstores
jbaublitz Jul 6, 2023
87752a3
Diverge new pool from legacy pool and update liminal device code
jbaublitz Jul 6, 2023
e806e07
Add and remove attributes
jbaublitz Jun 30, 2023
e96dbab
Add test executable to build legacy pools
jbaublitz Jul 11, 2023
1143b24
Bump minimum dependency for stratisd_proc_macros
jbaublitz Sep 7, 2023
0e24178
Expose metadata version on D-Bus
jbaublitz Sep 8, 2023
8b49e4a
Fix up tests plan and tests for legacy pool script
jbaublitz Sep 22, 2023
696554e
Merge encryption info and crypt handle into one field
jbaublitz Nov 1, 2023
67d832d
Fix for case where metadata needs to be read but device is not activated
jbaublitz Nov 9, 2023
3caa9e7
Add space for metadata in unencrypted use case
jbaublitz Nov 6, 2023
4d89fab
Add infrastructure for allocating from either end of device
jbaublitz Nov 20, 2023
a07a6f7
Allocate space for dm-integrity and md-raid
jbaublitz Jan 24, 2024
46bce40
Add lower bound for filesystem snapshot tests
jbaublitz Mar 18, 2024
c40d40b
Add record of enabled features in metdata V2
jbaublitz May 22, 2024
42d7352
Add ability to specify passphrase over D-Bus API for locked pools
jbaublitz May 29, 2024
c9d2318
Update introspect data
jbaublitz May 30, 2024
fb2c2aa
Fix StartPool usage in udev tests
jbaublitz May 30, 2024
d4af956
Fix Clevis tests by setting up udev and allocating from backstore
jbaublitz May 31, 2024
36c0a8e
Add test for passphrase unlock
jbaublitz Jun 3, 2024
a548926
Add metadata version to StoppedPools
jbaublitz Jun 3, 2024
7264bcf
Add ability to report features on stopped pools
jbaublitz Jun 7, 2024
664ebc5
Run tests on both legacy and v2 pools
mulkieran Jul 5, 2024
7df5a6b
Allow test_encryption_simple_event to handle metadata V2
jbaublitz Jul 15, 2024
0e91c93
Allow test_duplicate_pool_name to handle metadata V2
jbaublitz Jul 15, 2024
d69a78f
Reflect changes to encryption layering in sim pool
jbaublitz Jul 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export PROFILEDIR=debug
make fmt-ci &&
make build &&
make stratisd-tools &&
make build-test-extras &&
make build-min &&
make build-no-ipc &&
make test &&
Expand Down
59 changes: 54 additions & 5 deletions .github/workflows/fedora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ jobs:
- task: PROFILEDIR=debug make -f Makefile build
toolchain: 1.79.0 # CURRENT DEVELOPMENT RUST TOOLCHAIN
components: cargo
- task: PROFILEDIR=debug make -f Makefile build-test-extras
toolchain: 1.72.0 # CURRENT DEVELOPMENT RUST TOOLCHAIN
components: cargo
- task: PROFILEDIR=debug make -f Makefile build-min
toolchain: 1.79.0 # CURRENT DEVELOPMENT RUST TOOLCHAIN
components: cargo
Expand All @@ -66,14 +69,12 @@ jobs:
- task: make -f Makefile test
toolchain: 1.79.0 # CURRENT DEVELOPMENT RUST TOOLCHAIN
components: cargo
- task: >-
TANG_URL=localhost
make -f Makefile test-clevis-loop-should-fail
toolchain: 1.79.0 # CURRENT DEVELOPMENT RUST TOOLCHAIN
components: cargo
- task: make -f Makefile build
toolchain: 1.79.0 # CURRENT DEVELOPMENT RUST TOOLCHAIN
components: cargo
- task: make -f Makefile build-test-extras
toolchain: 1.72.0 # CURRENT DEVELOPMENT RUST TOOLCHAIN
components: cargo
- task: make -f Makefile build-min
toolchain: 1.79.0 # CURRENT DEVELOPMENT RUST TOOLCHAIN
components: cargo
Expand Down Expand Up @@ -151,3 +152,51 @@ jobs:
run: udevadm control --reload
- name: Test ${{ matrix.task }} on ${{ matrix.toolchain }} toolchain
run: ${{ matrix.task }}

# TESTS WITH UDEV
checks_with_tang_should_fail:
strategy:
matrix:
include:
- task: >-
TANG_URL=localhost
make -f Makefile test-clevis-loop-should-fail
toolchain: 1.78.0 # CURRENT DEVELOPMENT RUST TOOLCHAIN
components: cargo
runs-on: ubuntu-22.04
container:
image: fedora:40 # CURRENT DEVELOPMENT ENVIRONMENT
options: --privileged -v /dev:/dev -v /run/udev:/run/udev -v /usr/lib/udev:/usr/lib/udev --ipc=host
steps:
- uses: actions/checkout@v4
- name: Install dependencies for Fedora
run: >
dnf install -y
asciidoc
clang
clevis
cryptsetup-devel
curl
dbus-devel
glibc-static
device-mapper-devel
device-mapper-persistent-data
libblkid-devel
make
ncurses
sudo
systemd-devel
systemd-udev
xfsprogs
- uses: dtolnay/rust-toolchain@master
with:
components: ${{ matrix.components }}
toolchain: ${{ matrix.toolchain }}
- name: Build stratisd
run: PROFILEDIR=debug make -f Makefile build-all
- name: Install stratisd
run: PROFILEDIR=debug make -f Makefile install
- name: Reload udev
run: udevadm control --reload
- name: Test ${{ matrix.task }} on ${{ matrix.toolchain }} toolchain
run: ${{ matrix.task }}
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ required-features = ["udev_scripts"]
name = "stratis-utils"
required-features = ["engine"]

[[bin]]
name = "stratis-legacy-pool"
required-features = ["test_extras"]

[dependencies.async-trait]
version = "0.1.51"
optional = true
Expand Down Expand Up @@ -205,7 +209,7 @@ version = "0.10.1"
optional = true

[dependencies.stratisd_proc_macros]
version = "0.2.0"
version = "0.2.1"
optional = true
path = "./stratisd_proc_macros"

Expand Down Expand Up @@ -285,6 +289,7 @@ extras = ["pretty-hex"]
min = ["termios"]
systemd_compat = ["bindgen"]
udev_scripts = ["data-encoding"]
test_extras = ["engine"]

[package.metadata.vendor-filter]
platforms = ["*-unknown-linux-gnu"]
Expand Down
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ MIN_FEATURES = --no-default-features --features engine,min
NO_IPC_FEATURES = --no-default-features --features engine
SYSTEMD_FEATURES = --no-default-features --features engine,min,systemd_compat
EXTRAS_FEATURES = --no-default-features --features engine,extras,min
TEST_EXTRAS_FEATURES = --no-default-features --features test_extras
UDEV_FEATURES = --no-default-features --features udev_scripts
UTILS_FEATURES = --no-default-features --features engine,systemd_compat

Expand Down Expand Up @@ -293,6 +294,14 @@ stratisd-tools:
cargo ${BUILD} ${RELEASE_FLAG} \
--bin=stratisd-tools ${EXTRAS_FEATURES} ${TARGET_ARGS}

## Build the test extras
build-test-extras:
PKG_CONFIG_ALLOW_CROSS=1 \
RUSTFLAGS="${DENY}" \
cargo build ${RELEASE_FLAG} \
--bin=stratis-legacy-pool ${TEST_EXTRAS_FEATURES} ${TARGET_ARGS}

## Build the stratis-dumpmetadata program
## Build stratis-min for early userspace
stratis-min:
PKG_CONFIG_ALLOW_CROSS=1 \
Expand Down Expand Up @@ -514,8 +523,12 @@ clippy-utils:
clippy-no-ipc:
RUSTFLAGS="${DENY}" cargo clippy ${CLIPPY_OPTS} ${NO_IPC_FEATURES} -- ${CLIPPY_DENY} ${CLIPPY_PEDANTIC} ${CLIPPY_PEDANTIC_USELESS}

## Run clippy on no-ipc-build
clippy-test-extras:
RUSTFLAGS="${DENY}" cargo clippy ${CLIPPY_OPTS} ${TEST_EXTRAS_FEATURES} -- ${CLIPPY_DENY} ${CLIPPY_PEDANTIC} ${CLIPPY_PEDANTIC_USELESS}

## Run clippy on the current source tree
clippy: clippy-macros clippy-min clippy-udev-utils clippy-no-ipc clippy-utils
clippy: clippy-macros clippy-min clippy-udev-utils clippy-no-ipc clippy-utils clippy-test-extras
RUSTFLAGS="${DENY}" cargo clippy ${CLIPPY_OPTS} -- ${CLIPPY_DENY} ${CLIPPY_PEDANTIC} ${CLIPPY_PEDANTIC_USELESS}

## Lint Python parts of the source code
Expand All @@ -530,6 +543,7 @@ pylint:
build-all-man
build-all-rust
build-min
build-test-extras
build-udev-utils
build-stratis-base32-decode
build-stratis-str-cmp
Expand All @@ -542,6 +556,7 @@ pylint:
clippy-macros
clippy-min
clippy-no-ipc
clippy-test-extras
clippy-udev-utils
docs-ci
docs-rust
Expand Down
36 changes: 32 additions & 4 deletions plans/all.fmf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
summary: top level management

enabled: true
adjust:
when: plan == cockpit
enabled: false
Expand All @@ -11,28 +12,55 @@ prepare:
- name: Install packages
how: install
package:
- tang
- cargo
- clang
- cryptsetup-devel
- curl
- dbus-devel
- device-mapper-devel
- libblkid-devel
- make
- ncurses
- rust
- systemd
- swtpm
- swtpm-tools
- tpm2-tools
- systemd-devel
- tang
- name: Start TPM2 emulation
how: shell
script: mkdir /var/tmp/swtpm; swtpm_setup --tpm-state /var/tmp/swtpm --tpm2; swtpm chardev --vtpm-proxy --tpmstate dir=/var/tmp/swtpm --tpm2 &> /var/log/swtpm &
- name: Start tang server
how: shell
script: systemctl enable tangd.socket --now
- name: Reload udev
how: shell
script: udevadm control --reload
- name: Show test system information
how: shell
script: free -m; lsblk -i; lscpu; cat /proc/1/sched
- name: Record mkfs.xfs version
how: shell
script: mkfs.xfs -V

discover:
how: fmf

execute:
how: tmt
exit-first: false

/python:
jbaublitz marked this conversation as resolved.
Show resolved Hide resolved
prepare+:
- name: Build and install legacy pool script
how: shell
script:
- PROFILEDIR=debug make build-test-extras
- mv target/debug/stratis-legacy-pool /usr/local/bin
discover+:
filter: "tag:python"

/rust:
discover+:
filter: "tag:rust"
execute:
how: tmt
exit-first: false
132 changes: 132 additions & 0 deletions src/bin/stratis-legacy-pool.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// 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::{env, path::PathBuf};

use clap::{Arg, ArgAction, ArgGroup, Command};
use serde_json::{json, Map, Value};

use stratisd::{
engine::{
register_clevis_token, EncryptionInfo, KeyDescription, ProcessedPathInfos, StratPool,
CLEVIS_TANG_TRUST_URL,
},
stratis::StratisResult,
};

fn stratis_legacy_pool_args() -> Command {
Command::new("stratis-legacy-pool")
.arg(Arg::new("pool_name").num_args(1).required(true))
.arg(
Arg::new("blockdevs")
.action(ArgAction::Append)
.required(true),
)
.arg(
Arg::new("key_desc")
.long("key-desc")
.num_args(1)
.required(false),
)
.arg(
Arg::new("clevis")
.long("clevis")
.num_args(1)
.required(false)
.value_parser(["nbde", "tang", "tpm2"])
.requires_if("nbde", "tang_args")
.requires_if("tang", "tang_args"),
)
.arg(
Arg::new("tang_url")
.long("tang-url")
.num_args(1)
.required_if_eq("clevis", "nbde")
.required_if_eq("clevis", "tang"),
)
.arg(Arg::new("thumbprint").long("thumbprint").num_args(1))
.arg(Arg::new("trust_url").long("trust-url").num_args(0))
.group(
ArgGroup::new("tang_args")
.arg("thumbprint")
.arg("trust_url"),
)
}

type ParseReturn = StratisResult<(
String,
Vec<PathBuf>,
Option<KeyDescription>,
Option<(String, Value)>,
)>;

fn parse_args() -> ParseReturn {
let args = env::args().collect::<Vec<_>>();
let parser = stratis_legacy_pool_args();
let matches = parser.get_matches_from(args);

let pool_name = matches
.get_one::<String>("pool_name")
.expect("required")
.clone();
let blockdevs = matches
.get_many::<String>("blockdevs")
.expect("required")
.map(PathBuf::from)
.collect::<Vec<_>>();
let key_desc = match matches.get_one::<String>("key_desc") {
Some(kd) => Some(KeyDescription::try_from(kd)?),
None => None,
};
let pin = matches.get_one::<String>("clevis");
let clevis_info = match pin.map(|s| s.as_str()) {
Some("nbde" | "tang") => {
let mut json = Map::new();
json.insert(
"url".to_string(),
Value::from(
matches
.get_one::<String>("tang_url")
.expect("Required")
.clone(),
),
);
if matches.get_flag("trust_url") {
json.insert(CLEVIS_TANG_TRUST_URL.to_string(), Value::from(true));
} else if let Some(thp) = matches.get_one::<String>("thumbprint") {
json.insert("thp".to_string(), Value::from(thp.clone()));
}
pin.map(|p| (p.to_string(), Value::from(json)))
}
Some("tpm2") => Some(("tpm2".to_string(), json!({}))),
Some(_) => unreachable!("Validated by parser"),
None => None,
};

Ok((pool_name, blockdevs, key_desc, clevis_info))
}

fn main() -> StratisResult<()> {
env_logger::init();

let (name, devices, key_desc, clevis_info) = parse_args()?;
let unowned = ProcessedPathInfos::try_from(
devices
.iter()
.map(|p| p.as_path())
.collect::<Vec<_>>()
.as_slice(),
)?
.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,
};
register_clevis_token()?;
StratPool::initialize(name.as_str(), unowned, encryption_info.as_ref())?;
Ok(())
}
8 changes: 1 addition & 7 deletions src/bin/stratis-min/stratis-min.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use stratisd::{
CLEVIS_TANG_TRUST_URL,
},
jsonrpc::client::{filesystem, key, pool, report},
stratis::{StratisError, VERSION},
stratis::VERSION,
};

fn parse_args() -> Command {
Expand Down Expand Up @@ -244,12 +244,6 @@ fn main() -> Result<(), String> {
None => None,
};
let prompt = args.get_flag("prompt");
if prompt && unlock_method == Some(UnlockMethod::Clevis) {
return Err(Box::new(StratisError::Msg(
"--prompt and an unlock_method of clevis are mutually exclusive"
.to_string(),
)));
}
pool::pool_start(id, unlock_method, prompt)?;
Ok(())
} else if let Some(args) = subcommand.subcommand_matches("stop") {
Expand Down
Loading
Loading