signstar_configure_build/
cli.rs1use clap::{Parser, crate_name};
4use clap_verbosity_flag::Verbosity;
5use signstar_common::{
6 config::{
7 get_default_config_file_path,
8 get_etc_override_config_file_path,
9 get_run_override_config_file_path,
10 get_usr_local_override_config_file_path,
11 },
12 ssh::{get_ssh_authorized_key_base_dir, get_sshd_config_dropin_dir},
13 system_user::get_home_base_dir_path,
14};
15use strum::VariantNames;
16
17use crate::{ConfigPath, SshForceCommand};
18
19const BIN_NAME: &str = crate_name!();
21const SSH_FORCE_COMMAND_VARIANTS: &[&str] = SshForceCommand::VARIANTS;
23
24#[derive(Debug, Parser)]
26#[command(
27 about = "A command-line interface for Signstar image build configuration",
28 name = BIN_NAME,
29 long_about = format!("A command-line interface for Signstar image build configuration
30
31NOTE: This command must be run as root!
32
33This executable is meant to be used to configure relevant system users of a Signstar system during build.
34
35It creates system users and their integration based on a central configuration file.
36
37By default, one of the following configuration files is used if it exists, in the following order:
38
39- {:?}
40
41- {:?}
42
43- {:?}
44
45If none of the above are found, the default location {:?} is used.
46Alternatively a custom configuration file location can be specified using the \"--config\"/ \"-c\" option.
47
48System users, if they don't exist already, are created with the help of `useradd`.
49The users are created without a passphrase and setup with a home below {:?}.
50However, their home directory is not created automatically.
51The system user accounts are then unlocked with the help of `usermod`.
52For each system user a tmpfiles.d integration is provided below \"/usr/lib/tmpfiles.d\", to allow automatic creation of their home directory.
53
54If the used configuration file associates the system user with SSH public keys, a dedicated \"authorized_keys\" file containing the SSH public keys for the user is created below {:?}.
55Additionally, an \"sshd_config\" drop-in configuration is created below {:?}.
56This \"sshd_config\" drop-in configuration enforces the use of the user's \"authorized_keys\" and the use of a specific command (i.e. one of {SSH_FORCE_COMMAND_VARIANTS:?}) depending on the user's role.",
57 get_usr_local_override_config_file_path(),
58 get_run_override_config_file_path(),
59 get_etc_override_config_file_path(),
60 get_default_config_file_path(),
61 get_home_base_dir_path(),
62 get_ssh_authorized_key_base_dir(),
63 get_sshd_config_dropin_dir(),
64 ),
65 version
66)]
67pub struct Cli {
68 #[arg(
70 env = "SIGNSTAR_CONFIG",
71 global = true,
72 help = "The path to a custom configuration file",
73 long_help = format!("The path to a custom configuration file
74
75If specified, the custom configuration file is used instead of the default configuration file location.
76
77If unspecified, one of the following configuration files is used if it exists, in the following order:
78
79- {:?}
80
81- {:?}
82
83- {:?}
84
85If none of the above are found, the default location {:?} is used.",
86 get_usr_local_override_config_file_path(),
87 get_run_override_config_file_path(),
88 get_etc_override_config_file_path(),
89 get_default_config_file_path(),
90),
91 long,
92 short
93 )]
94 pub config: Option<ConfigPath>,
95
96 #[command(flatten)]
98 pub verbosity: Verbosity,
99}