Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
55 changes: 27 additions & 28 deletions cryptpilot-crypt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,46 +93,45 @@ cryptpilot-crypt show data0 --json

Example table output:
```
╭────────┬───────────────────┬─────────────────┬──────────────┬──────────────────┬──────────────┬────────╮
│ Volume ┆ Volume Path ┆ Underlay Device ┆ Key Provider ┆ Extra Options ┆ Initialized ┆ Opened
╞════════╪═══════════════════╪═════════════════╪══════════════╪══════════════════╪══════════════╪════════╡
│ data0 ┆ /dev/mapper/data0 ┆ /dev/nvme1n1p1 ┆ otp ┆ auto_open = true ┆ Not Required ┆ True
│ ┆ ┆ ┆ ┆ makefs = "ext4" ┆
│ ┆ ┆ ┆ ┆ integrity = true ┆
╰────────┴───────────────────┴─────────────────┴──────────────┴──────────────────┴──────────────┴────────╯
╭────────┬───────────────────┬─────────────────┬──────────────┬──────────────────┬───────────────╮
│ Volume ┆ Volume Path ┆ Underlay Device ┆ Key Provider ┆ Extra Options ┆ Status
╞════════╪═══════════════════╪═════════════════╪══════════════╪══════════════════╪═══════════════╡
│ data0 ┆ /dev/mapper/data0 ┆ /dev/nvme1n1p1 ┆ otp ┆ auto_open = true ┆ ReadyToOpen
│ ┆ ┆ ┆ ┆ makefs = "ext4" ┆ │
│ ┆ ┆ ┆ ┆ integrity = true ┆ │
╰────────┴───────────────────┴─────────────────┴──────────────┴──────────────────┴───────────────╯
```

Example JSON output:
```json
[
{
"volume": "data0",
"volume_path": "/dev/mapper/data0",
"underlay_device": "/dev/nvme1n1p1",
"device_exists": true,
"key_provider": "otp",
"extra_options": {
"auto_open": true,
"makefs": "ext4",
"integrity": true
},
"needs_initialize": false,
"initialized": true,
"opened": true
}
]
{
"volumes": [
{
"volume": "data0",
"volume_path": "/dev/mapper/data0",
"underlay_device": "/dev/nvme1n1p1",
"key_provider": "otp",
"extra_options": {
"auto_open": true,
"makefs": "ext4",
"integrity": true
},
"status": "ReadyToOpen",
"description": "Volume 'data0' uses otp key provider (temporary volume) and is ready to open"
}
]
}
```

JSON output fields:
- `volumes`: Array of volume status objects
- `volume`: Volume name
- `volume_path`: Path to the decrypted volume (always shows the mapper path)
- `underlay_device`: Underlying encrypted block device path
- `device_exists`: Whether the underlying device exists
- `key_provider`: Key provider type (e.g., `otp`, `kbs`, `kms`, `oidc`, `exec`)
- `extra_options`: Additional volume configuration (`null` if serialization fails)
- `needs_initialize`: Whether the volume needs initialization (false for temporary volumes like OTP, true for persistent volumes)
- `initialized`: Whether LUKS2 is initialized (false if device doesn't exist or initialization check fails, true if device exists and volume doesn't need initialization, or actual initialization status for persistent volumes)
- `opened`: Whether the volume is currently opened/decrypted
- `status`: Current status of the volume (`DeviceNotFound`, `CheckFailed`, `RequiresInit`, `ReadyToOpen`, `Opened`)
- `description`: Human-readable description of the current status

### `cryptpilot-crypt init`

Expand Down
55 changes: 27 additions & 28 deletions cryptpilot-crypt/README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,46 +93,45 @@ cryptpilot-crypt show data0 --json

表格输出示例:
```
╭────────┬───────────────────┬─────────────────┬──────────────┬──────────────────┬──────────────┬────────╮
│ Volume ┆ Volume Path ┆ Underlay Device ┆ Key Provider ┆ Extra Options ┆ Initialized ┆ Opened
╞════════╪═══════════════════╪═════════════════╪══════════════╪══════════════════╪══════════════╪════════╡
│ data0 ┆ /dev/mapper/data0 ┆ /dev/nvme1n1p1 ┆ otp ┆ auto_open = true ┆ Not Required ┆ True
│ ┆ ┆ ┆ ┆ makefs = "ext4" ┆
│ ┆ ┆ ┆ ┆ integrity = true ┆
╰────────┴───────────────────┴─────────────────┴──────────────┴──────────────────┴──────────────┴────────╯
╭────────┬───────────────────┬─────────────────┬──────────────┬──────────────────┬───────────────╮
│ Volume ┆ Volume Path ┆ Underlay Device ┆ Key Provider ┆ Extra Options ┆ Status
╞════════╪═══════════════════╪═════════════════╪══════════════╪══════════════════╪═══════════════╡
│ data0 ┆ /dev/mapper/data0 ┆ /dev/nvme1n1p1 ┆ otp ┆ auto_open = true ┆ ReadyToOpen
│ ┆ ┆ ┆ ┆ makefs = "ext4" ┆ │
│ ┆ ┆ ┆ ┆ integrity = true ┆ │
╰────────┴───────────────────┴─────────────────┴──────────────┴──────────────────┴───────────────╯
```

JSON 输出示例:
```json
[
{
"volume": "data0",
"volume_path": "/dev/mapper/data0",
"underlay_device": "/dev/nvme1n1p1",
"device_exists": true,
"key_provider": "otp",
"extra_options": {
"auto_open": true,
"makefs": "ext4",
"integrity": true
},
"needs_initialize": false,
"initialized": true,
"opened": true
}
]
{
"volumes": [
{
"volume": "data0",
"volume_path": "/dev/mapper/data0",
"underlay_device": "/dev/nvme1n1p1",
"key_provider": "otp",
"extra_options": {
"auto_open": true,
"makefs": "ext4",
"integrity": true
},
"status": "ReadyToOpen",
"description": "Volume 'data0' uses otp key provider (temporary volume) and is ready to open"
}
]
}
```

JSON 输出字段说明:
- `volumes`:卷状态对象数组
- `volume`:卷名称
- `volume_path`:解密后的卷路径(始终显示 mapper 路径)
- `underlay_device`:底层加密块设备路径
- `device_exists`:底层设备是否存在
- `key_provider`:密钥提供者类型(如 `otp`、`kbs`、`kms`、`oidc`、`exec`)
- `extra_options`:额外的卷配置(序列化失败时为 `null`)
- `needs_initialize`:卷是否需要初始化(临时卷如 OTP 为 false,持久化卷为 true)
- `initialized`:LUKS2 是否已初始化(设备不存在或初始化检查失败时为 false,设备存在且卷无需初始化时为 true,持久化卷为实际初始化状态)
- `opened`:卷当前是否已打开/解密
- `status`:卷的当前状态(`DeviceNotFound`、`CheckFailed`、`RequiresInit`、`ReadyToOpen`、`Opened`)
- `description`:当前状态的人类可读描述

### `cryptpilot-crypt init`

Expand Down
14 changes: 7 additions & 7 deletions cryptpilot-crypt/docs/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ cryptpilot-crypt show
Example output:

```
╭────────┬───────────────────┬─────────────────┬──────────────┬──────────────────┬──────────────┬────────╮
│ Volume ┆ Volume Path ┆ Underlay Device ┆ Key Provider ┆ Extra Options ┆ Initialized ┆ Opened
╞════════╪═══════════════════╪═════════════════╪══════════════╪══════════════════╪══════════════╪════════╡
│ data0 ┆ /dev/mapper/data0 ┆ /dev/nvme1n1p1 ┆ otp ┆ auto_open = true ┆ Not Required ┆ True
│ ┆ ┆ ┆ ┆ makefs = "ext4" ┆
│ ┆ ┆ ┆ ┆ integrity = true ┆
╰────────┴───────────────────┴─────────────────┴──────────────┴──────────────────┴──────────────┴────────╯
╭────────┬───────────────────┬─────────────────┬──────────────┬──────────────────┬───────────────╮
│ Volume ┆ Volume Path ┆ Underlay Device ┆ Key Provider ┆ Extra Options ┆ Status
╞════════╪═══════════════════╪═════════════════╪══════════════╪══════════════════╪═══════════════╡
│ data0 ┆ /dev/mapper/data0 ┆ /dev/nvme1n1p1 ┆ otp ┆ auto_open = true ┆ ReadyToOpen
│ ┆ ┆ ┆ ┆ makefs = "ext4" ┆ │
│ ┆ ┆ ┆ ┆ integrity = true ┆ │
╰────────┴───────────────────┴─────────────────┴──────────────┴──────────────────┴───────────────╯
```

### Step 6: Mount and Use
Expand Down
14 changes: 7 additions & 7 deletions cryptpilot-crypt/docs/quick-start_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ cryptpilot-crypt show
示例输出:

```
╭────────┬───────────────────┬─────────────────┬──────────────┬──────────────────┬──────────────┬────────╮
│ Volume ┆ Volume Path ┆ Underlay Device ┆ Key Provider ┆ Extra Options ┆ Initialized ┆ Opened
╞════════╪═══════════════════╪═════════════════╪══════════════╪══════════════════╪══════════════╪════════╡
│ data0 ┆ /dev/mapper/data0 ┆ /dev/nvme1n1p1 ┆ otp ┆ auto_open = true ┆ Not Required ┆ True
│ ┆ ┆ ┆ ┆ makefs = "ext4" ┆
│ ┆ ┆ ┆ ┆ integrity = true ┆
╰────────┴───────────────────┴─────────────────┴──────────────┴──────────────────┴──────────────┴────────╯
╭────────┬───────────────────┬─────────────────┬──────────────┬──────────────────┬───────────────╮
│ Volume ┆ Volume Path ┆ Underlay Device ┆ Key Provider ┆ Extra Options ┆ Status
╞════════╪═══════════════════╪═════════════════╪══════════════╪══════════════════╪═══════════════╡
│ data0 ┆ /dev/mapper/data0 ┆ /dev/nvme1n1p1 ┆ otp ┆ auto_open = true ┆ ReadyToOpen
│ ┆ ┆ ┆ ┆ makefs = "ext4" ┆ │
│ ┆ ┆ ┆ ┆ integrity = true ┆ │
╰────────┴───────────────────┴─────────────────┴──────────────┴──────────────────┴───────────────╯
```

### 步骤 7:挂载并使用
Expand Down
27 changes: 21 additions & 6 deletions cryptpilot-crypt/src/cmd/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::{bail, Context, Result};
use async_trait::async_trait;
use dialoguer::{console::Term, Confirm};

use crate::cli::InitOptions;
use crate::{cli::InitOptions, cmd::show::VolumeStatusKind};
use cryptpilot::{
fs::luks2::TempLuksVolume,
provider::{IntoProvider, KeyProvider},
Expand Down Expand Up @@ -54,12 +54,27 @@ async fn persistent_disk_init(
volume_config: &VolumeConfig,
key_provider: &impl KeyProvider,
) -> Result<()> {
if cryptpilot::fs::luks2::is_initialized(&volume_config.dev).await?
&& !init_options.force_reinit
{
bail!("The device {:?} is already initialized. Use '--force-reinit' to force re-initialize the volume.", volume_config.dev);
let status = volume_config.determine_status().await;
match status.kind {
VolumeStatusKind::DeviceNotFound
| VolumeStatusKind::CheckFailed
| VolumeStatusKind::Opened => {
bail!(
"The status of device {:?} is incorrect: {:?}({})",
volume_config.dev,
status.kind,
status.description
);
}
VolumeStatusKind::RequiresInit => {
// This is expected, continue with initialization
}
VolumeStatusKind::ReadyToOpen => {
if !init_options.force_reinit {
bail!("The device {:?} is already initialized. Use '--force-reinit' to force re-initialize the volume.", volume_config.dev);
}
}
}

if !init_options.yes {
if !Term::stderr().is_term() {
bail!("Standard error is not a terminal. Please use '--yes' to confirm the operation in non-interactive mode.");
Expand Down
Loading
Loading