hyprstream_core/cli/commands/user.rs
1//! User management CLI commands
2
3use clap::Subcommand;
4
5#[derive(Debug, Subcommand)]
6pub enum UserCommand {
7 /// Create a user AND enroll a signing key in one step
8 ///
9 /// Generates (default) or adopts a signing key, installs it as the client's
10 /// actual signing key, registers the user record, binds the derived public
11 /// key, and grants a role — collapsing the multi-step enrollment that,
12 /// done wrong, silently authenticates as `anonymous` (#439).
13 Create {
14 /// Username to enroll (defaults to the OS user, matching the CLI's `sub`)
15 #[arg(default_value_t = os_user_string())]
16 username: String,
17 /// Role to grant (default `operator`; use `admin` for full access)
18 #[arg(long, default_value = "operator")]
19 role: String,
20 /// Generate a fresh Ed25519 signing key (default)
21 #[arg(long, conflicts_with_all = ["key", "ssh"])]
22 generate: bool,
23 /// Adopt a raw 32-byte Ed25519 seed file as the signing key
24 #[arg(long, value_name = "PATH", conflicts_with_all = ["generate", "ssh"])]
25 key: Option<String>,
26 /// Adopt an OpenSSH Ed25519 private key as the signing key
27 /// (passphrase-prompted if encrypted)
28 #[arg(long, value_name = "PATH", conflicts_with_all = ["generate", "key"])]
29 ssh: Option<String>,
30 /// Skip granting the role even if services are running
31 #[arg(long)]
32 no_role: bool,
33 },
34 /// Create a user account (no key required at registration)
35 Register {
36 /// Username
37 username: String,
38 },
39 /// Remove a registered user
40 Remove {
41 /// Username
42 username: String,
43 /// Skip confirmation prompt
44 #[arg(long)]
45 force: bool,
46 },
47 /// List all registered users
48 List,
49 /// Manage public keys for a user
50 Keys {
51 #[command(subcommand)]
52 command: UserKeysCommand,
53 },
54}
55
56/// Resolve the OS username exactly as the CLI presents it in `sub`
57/// (`$USER` → `$LOGNAME` → `"anonymous"`), so `user create`'s default matches
58/// the subject the CLI authenticates as. Kept in lockstep with
59/// `sign_challenge.rs::load_user_signing_key`.
60fn os_user_string() -> String {
61 std::env::var("USER")
62 .or_else(|_| std::env::var("LOGNAME"))
63 .unwrap_or_else(|_| "anonymous".to_owned())
64}
65
66#[derive(Debug, Subcommand)]
67pub enum UserKeysCommand {
68 /// List keys registered for a user
69 List {
70 /// Username
71 username: String,
72 },
73 /// Import a public key for a user
74 Import {
75 /// Username
76 username: String,
77 #[command(subcommand)]
78 format: UserKeysImportFormat,
79 },
80 /// Remove a key by fingerprint (from 'keys list')
81 Remove {
82 /// Username
83 username: String,
84 /// Key fingerprint (SHA256:...)
85 fingerprint: String,
86 },
87}
88
89#[derive(Debug, Subcommand)]
90pub enum UserKeysImportFormat {
91 /// SSH Ed25519 public key (ssh-ed25519 AAAA... line or .pub file)
92 #[command(name = "ssh-ed25519")]
93 SshEd25519 {
94 /// Path to .pub file, or - to read from stdin
95 #[arg(short = 'f', long = "file")]
96 file: Option<String>,
97 /// Inline key data (ssh-ed25519 AAAA...)
98 data: Option<String>,
99 /// Label for this key (e.g., "laptop", "yubikey")
100 #[arg(long)]
101 label: Option<String>,
102 },
103 /// Raw Ed25519 public key (32 bytes, standard base64)
104 Raw {
105 /// Path to file containing raw base64 key, or - to read from stdin
106 #[arg(short = 'f', long = "file")]
107 file: Option<String>,
108 /// Inline base64 key data
109 data: Option<String>,
110 /// Label for this key
111 #[arg(long)]
112 label: Option<String>,
113 },
114}