kanidm/server/daemon/src/opt.rs

290 lines
10 KiB
Rust
Raw Normal View History

2022-06-11 07:24:29 +02:00
#[derive(Debug, Args)]
struct CommonOpt {
/// Path to the server's configuration file.
#[clap(short, long = "config", env = "KANIDM_CONFIG")]
2023-07-24 02:05:10 +02:00
config_path: Option<PathBuf>,
/// Log format (still in very early development)
#[clap(short, long = "output", env = "KANIDM_OUTPUT", default_value = "text")]
output_mode: String,
}
2022-06-11 07:24:29 +02:00
#[derive(Debug, Args)]
struct BackupOpt {
#[clap(value_parser)]
/// Output path for the backup content.
path: PathBuf,
2022-06-11 07:24:29 +02:00
#[clap(flatten)]
commonopts: CommonOpt,
}
2022-06-11 07:24:29 +02:00
#[derive(Debug, Args)]
struct RestoreOpt {
#[clap(value_parser)]
/// Restore from this path. Should be created with "backup".
path: PathBuf,
2022-06-11 07:24:29 +02:00
#[clap(flatten)]
commonopts: CommonOpt,
}
2022-07-07 05:03:08 +02:00
#[derive(Debug, Subcommand)]
enum DomainSettingsCmds {
/// Show the current domain
20240301 systemd uid (#2602) Fixes #2601 Fixes #393 - gid numbers can be part of the systemd nspawn range. Previously we allocated gid numbers based on the fact that uid_t is a u32, so we allowed 65536 through u32::max. However, there are two major issues with this that I didn't realise. The first is that anything greater than i32::max (2147483648) can confuse the linux kernel. The second is that systemd allocates 524288 through 1879048191 to itself for nspawn. This leaves with with only a few usable ranges. 1000 through 60000 60578 through 61183 65520 through 65533 65536 through 524287 1879048192 through 2147483647 The last range being the largest is the natural and obvious area we should allocate from. This happens to nicely fall in the pattern of 0x7000_0000 through 0x7fff_ffff which allows us to take the last 24 bits of the uuid then applying a bit mask we can ensure that we end up in this range. There are now two major issues. We have now changed our validation code to enforce a tighter range, but we may have already allocated users into these ranges. External systems like FreeIPA allocated uid/gid numbers with reckless abandon directly into these ranges. As a result we need to make two concessions. We *secretly* still allow manual allocation of id's from 65536 through to 1879048191 which is the nspawn container range. This happens to be the range that freeipa allocates into. We will never generate an ID in this range, but we will allow it to ease imports since the users of these ranges already have shown they 'don't care' about that range. This also affects SCIM imports for longer term migrations. Second is id's that fall outside the valid ranges. In the extremely unlikely event this has occurred, a startup migration has been added to regenerate these id values for affected entries to prevent upgrade issues. An accidental effect of this is freeing up the range 524288 to 1879048191 for other subuid uses.
2024-03-07 04:25:54 +01:00
#[clap(name = "show")]
Show {
#[clap(flatten)]
commonopts: CommonOpt,
},
/// Change the IDM domain name based on the values in the configuration
20240301 systemd uid (#2602) Fixes #2601 Fixes #393 - gid numbers can be part of the systemd nspawn range. Previously we allocated gid numbers based on the fact that uid_t is a u32, so we allowed 65536 through u32::max. However, there are two major issues with this that I didn't realise. The first is that anything greater than i32::max (2147483648) can confuse the linux kernel. The second is that systemd allocates 524288 through 1879048191 to itself for nspawn. This leaves with with only a few usable ranges. 1000 through 60000 60578 through 61183 65520 through 65533 65536 through 524287 1879048192 through 2147483647 The last range being the largest is the natural and obvious area we should allocate from. This happens to nicely fall in the pattern of 0x7000_0000 through 0x7fff_ffff which allows us to take the last 24 bits of the uuid then applying a bit mask we can ensure that we end up in this range. There are now two major issues. We have now changed our validation code to enforce a tighter range, but we may have already allocated users into these ranges. External systems like FreeIPA allocated uid/gid numbers with reckless abandon directly into these ranges. As a result we need to make two concessions. We *secretly* still allow manual allocation of id's from 65536 through to 1879048191 which is the nspawn container range. This happens to be the range that freeipa allocates into. We will never generate an ID in this range, but we will allow it to ease imports since the users of these ranges already have shown they 'don't care' about that range. This also affects SCIM imports for longer term migrations. Second is id's that fall outside the valid ranges. In the extremely unlikely event this has occurred, a startup migration has been added to regenerate these id values for affected entries to prevent upgrade issues. An accidental effect of this is freeing up the range 524288 to 1879048191 for other subuid uses.
2024-03-07 04:25:54 +01:00
#[clap(name = "rename")]
Change {
#[clap(flatten)]
commonopts: CommonOpt,
},
20240301 systemd uid (#2602) Fixes #2601 Fixes #393 - gid numbers can be part of the systemd nspawn range. Previously we allocated gid numbers based on the fact that uid_t is a u32, so we allowed 65536 through u32::max. However, there are two major issues with this that I didn't realise. The first is that anything greater than i32::max (2147483648) can confuse the linux kernel. The second is that systemd allocates 524288 through 1879048191 to itself for nspawn. This leaves with with only a few usable ranges. 1000 through 60000 60578 through 61183 65520 through 65533 65536 through 524287 1879048192 through 2147483647 The last range being the largest is the natural and obvious area we should allocate from. This happens to nicely fall in the pattern of 0x7000_0000 through 0x7fff_ffff which allows us to take the last 24 bits of the uuid then applying a bit mask we can ensure that we end up in this range. There are now two major issues. We have now changed our validation code to enforce a tighter range, but we may have already allocated users into these ranges. External systems like FreeIPA allocated uid/gid numbers with reckless abandon directly into these ranges. As a result we need to make two concessions. We *secretly* still allow manual allocation of id's from 65536 through to 1879048191 which is the nspawn container range. This happens to be the range that freeipa allocates into. We will never generate an ID in this range, but we will allow it to ease imports since the users of these ranges already have shown they 'don't care' about that range. This also affects SCIM imports for longer term migrations. Second is id's that fall outside the valid ranges. In the extremely unlikely event this has occurred, a startup migration has been added to regenerate these id values for affected entries to prevent upgrade issues. An accidental effect of this is freeing up the range 524288 to 1879048191 for other subuid uses.
2024-03-07 04:25:54 +01:00
/// Perform a pre-upgrade-check of this domains content. This will report possible
/// incompatibilities that can block a successful upgrade to the next version of
/// Kanidm. This is a safe read only operation.
#[clap(name = "upgrade-check")]
UpgradeCheck {
#[clap(flatten)]
commonopts: CommonOpt,
},
/// ⚠️ Do not use this command unless directed by a project member. ⚠️
/// - Raise the functional level of this domain to the maximum available.
#[clap(name = "raise")]
Raise {
#[clap(flatten)]
commonopts: CommonOpt,
},
20240301 systemd uid (#2602) Fixes #2601 Fixes #393 - gid numbers can be part of the systemd nspawn range. Previously we allocated gid numbers based on the fact that uid_t is a u32, so we allowed 65536 through u32::max. However, there are two major issues with this that I didn't realise. The first is that anything greater than i32::max (2147483648) can confuse the linux kernel. The second is that systemd allocates 524288 through 1879048191 to itself for nspawn. This leaves with with only a few usable ranges. 1000 through 60000 60578 through 61183 65520 through 65533 65536 through 524287 1879048192 through 2147483647 The last range being the largest is the natural and obvious area we should allocate from. This happens to nicely fall in the pattern of 0x7000_0000 through 0x7fff_ffff which allows us to take the last 24 bits of the uuid then applying a bit mask we can ensure that we end up in this range. There are now two major issues. We have now changed our validation code to enforce a tighter range, but we may have already allocated users into these ranges. External systems like FreeIPA allocated uid/gid numbers with reckless abandon directly into these ranges. As a result we need to make two concessions. We *secretly* still allow manual allocation of id's from 65536 through to 1879048191 which is the nspawn container range. This happens to be the range that freeipa allocates into. We will never generate an ID in this range, but we will allow it to ease imports since the users of these ranges already have shown they 'don't care' about that range. This also affects SCIM imports for longer term migrations. Second is id's that fall outside the valid ranges. In the extremely unlikely event this has occurred, a startup migration has been added to regenerate these id values for affected entries to prevent upgrade issues. An accidental effect of this is freeing up the range 524288 to 1879048191 for other subuid uses.
2024-03-07 04:25:54 +01:00
/// ⚠️ Do not use this command unless directed by a project member. ⚠️
/// - Rerun migrations of this domains database, optionally nominating the level
/// to start from.
20240301 systemd uid (#2602) Fixes #2601 Fixes #393 - gid numbers can be part of the systemd nspawn range. Previously we allocated gid numbers based on the fact that uid_t is a u32, so we allowed 65536 through u32::max. However, there are two major issues with this that I didn't realise. The first is that anything greater than i32::max (2147483648) can confuse the linux kernel. The second is that systemd allocates 524288 through 1879048191 to itself for nspawn. This leaves with with only a few usable ranges. 1000 through 60000 60578 through 61183 65520 through 65533 65536 through 524287 1879048192 through 2147483647 The last range being the largest is the natural and obvious area we should allocate from. This happens to nicely fall in the pattern of 0x7000_0000 through 0x7fff_ffff which allows us to take the last 24 bits of the uuid then applying a bit mask we can ensure that we end up in this range. There are now two major issues. We have now changed our validation code to enforce a tighter range, but we may have already allocated users into these ranges. External systems like FreeIPA allocated uid/gid numbers with reckless abandon directly into these ranges. As a result we need to make two concessions. We *secretly* still allow manual allocation of id's from 65536 through to 1879048191 which is the nspawn container range. This happens to be the range that freeipa allocates into. We will never generate an ID in this range, but we will allow it to ease imports since the users of these ranges already have shown they 'don't care' about that range. This also affects SCIM imports for longer term migrations. Second is id's that fall outside the valid ranges. In the extremely unlikely event this has occurred, a startup migration has been added to regenerate these id values for affected entries to prevent upgrade issues. An accidental effect of this is freeing up the range 524288 to 1879048191 for other subuid uses.
2024-03-07 04:25:54 +01:00
#[clap(name = "remigrate")]
Remigrate {
#[clap(flatten)]
commonopts: CommonOpt,
level: Option<u32>,
},
2022-07-07 05:03:08 +02:00
}
#[derive(Debug, Subcommand)]
enum DbCommands {
#[clap(name = "vacuum")]
/// Vacuum the database to reclaim space or change db_fs_type/page_size (offline)
Vacuum(CommonOpt),
#[clap(name = "backup")]
/// Backup the database content (offline)
Backup(BackupOpt),
#[clap(name = "restore")]
/// Restore the database content (offline)
Restore(RestoreOpt),
#[clap(name = "verify")]
/// Verify database and entity consistency.
Verify(CommonOpt),
#[clap(name = "reindex")]
/// Reindex the database (offline)
Reindex(CommonOpt),
}
2022-06-11 07:24:29 +02:00
#[derive(Debug, Args)]
struct DbScanListIndex {
/// The name of the index to list
index_name: String,
2022-06-11 07:24:29 +02:00
#[clap(flatten)]
commonopts: CommonOpt,
}
#[derive(Debug, Parser)]
struct HealthCheckArgs {
/// Disable TLS verification
#[clap(short, long, action)]
verify_tls: bool,
/// Check the 'origin' URL from the server configuration file, instead of the 'address'
#[clap(short = 'O', long, action)]
check_origin: bool,
#[clap(flatten)]
commonopts: CommonOpt,
}
2022-06-11 07:24:29 +02:00
#[derive(Debug, Args)]
struct DbScanGetId2Entry {
/// The id of the entry to display
id: u64,
2022-06-11 07:24:29 +02:00
#[clap(flatten)]
commonopts: CommonOpt,
}
2022-06-11 07:24:29 +02:00
#[derive(Debug, Subcommand)]
enum DbScanOpt {
#[clap(name = "list-all-indexes")]
/// List all index tables that exist on the system.
ListIndexes(CommonOpt),
#[clap(name = "list-index")]
/// List all content of a named index
ListIndex(DbScanListIndex),
// #[structopt(name = "get_index")]
// /// Display the content of a single index key
// GetIndex(DbScanGetIndex),
#[clap(name = "list-id2entry")]
/// List all id2entry values with reduced entry content
ListId2Entry(CommonOpt),
#[clap(name = "get-id2entry")]
/// View the data of a specific entry from id2entry
GetId2Entry(DbScanGetId2Entry),
#[clap(name = "list-index-analysis")]
/// List all content of index analysis
ListIndexAnalysis(CommonOpt),
#[clap(name = "quarantine-id2entry")]
/// Given an entry id, quarantine the entry in a hidden db partition
QuarantineId2Entry {
/// The id of the entry to display
id: u64,
#[clap(flatten)]
commonopts: CommonOpt,
},
#[clap(name = "list-quarantined")]
/// List the entries in quarantine
ListQuarantined {
#[clap(flatten)]
commonopts: CommonOpt,
},
#[clap(name = "restore-quarantined")]
/// Given an entry id, restore the entry from the hidden db partition
RestoreQuarantined {
/// The id of the entry to display
id: u64,
#[clap(flatten)]
commonopts: CommonOpt,
},
}
2022-06-11 07:24:29 +02:00
#[derive(Debug, Parser)]
#[command(name = "kanidmd")]
2022-06-11 07:24:29 +02:00
struct KanidmdParser {
#[command(subcommand)]
2022-06-11 07:24:29 +02:00
commands: KanidmdOpt,
}
impl KanidmdParser {
/// Returns the configuration path that was specified on the command line, if any.
fn config_path(&self) -> Option<PathBuf> {
match self.commands {
KanidmdOpt::Server(ref c) => c.config_path.clone(),
KanidmdOpt::ConfigTest(ref c) => c.config_path.clone(),
KanidmdOpt::CertGenerate(ref c) => c.config_path.clone(),
KanidmdOpt::RecoverAccount { ref commonopts, .. } => commonopts.config_path.clone(),
KanidmdOpt::ShowReplicationCertificate { ref commonopts, .. } => {
commonopts.config_path.clone()
}
KanidmdOpt::RenewReplicationCertificate { ref commonopts, .. } => {
commonopts.config_path.clone()
}
KanidmdOpt::RefreshReplicationConsumer { ref commonopts, .. } => {
commonopts.config_path.clone()
}
KanidmdOpt::DbScan { ref commands } => match commands {
DbScanOpt::ListIndexes(ref c) => c.config_path.clone(),
DbScanOpt::ListIndex(ref c) => c.commonopts.config_path.clone(),
DbScanOpt::ListId2Entry(ref c) => c.config_path.clone(),
DbScanOpt::GetId2Entry(ref c) => c.commonopts.config_path.clone(),
DbScanOpt::ListIndexAnalysis(ref c) => c.config_path.clone(),
DbScanOpt::QuarantineId2Entry { ref commonopts, .. } => {
commonopts.config_path.clone()
}
DbScanOpt::ListQuarantined { ref commonopts } => commonopts.config_path.clone(),
DbScanOpt::RestoreQuarantined { ref commonopts, .. } => {
commonopts.config_path.clone()
}
},
KanidmdOpt::Database { ref commands } => match commands {
DbCommands::Vacuum(ref c) => c.config_path.clone(),
DbCommands::Backup(ref c) => c.commonopts.config_path.clone(),
DbCommands::Restore(ref c) => c.commonopts.config_path.clone(),
DbCommands::Verify(ref c) => c.config_path.clone(),
DbCommands::Reindex(ref c) => c.config_path.clone(),
},
KanidmdOpt::DomainSettings { ref commands } => match commands {
DomainSettingsCmds::Show { ref commonopts } => commonopts.config_path.clone(),
DomainSettingsCmds::Change { ref commonopts } => commonopts.config_path.clone(),
20240301 systemd uid (#2602) Fixes #2601 Fixes #393 - gid numbers can be part of the systemd nspawn range. Previously we allocated gid numbers based on the fact that uid_t is a u32, so we allowed 65536 through u32::max. However, there are two major issues with this that I didn't realise. The first is that anything greater than i32::max (2147483648) can confuse the linux kernel. The second is that systemd allocates 524288 through 1879048191 to itself for nspawn. This leaves with with only a few usable ranges. 1000 through 60000 60578 through 61183 65520 through 65533 65536 through 524287 1879048192 through 2147483647 The last range being the largest is the natural and obvious area we should allocate from. This happens to nicely fall in the pattern of 0x7000_0000 through 0x7fff_ffff which allows us to take the last 24 bits of the uuid then applying a bit mask we can ensure that we end up in this range. There are now two major issues. We have now changed our validation code to enforce a tighter range, but we may have already allocated users into these ranges. External systems like FreeIPA allocated uid/gid numbers with reckless abandon directly into these ranges. As a result we need to make two concessions. We *secretly* still allow manual allocation of id's from 65536 through to 1879048191 which is the nspawn container range. This happens to be the range that freeipa allocates into. We will never generate an ID in this range, but we will allow it to ease imports since the users of these ranges already have shown they 'don't care' about that range. This also affects SCIM imports for longer term migrations. Second is id's that fall outside the valid ranges. In the extremely unlikely event this has occurred, a startup migration has been added to regenerate these id values for affected entries to prevent upgrade issues. An accidental effect of this is freeing up the range 524288 to 1879048191 for other subuid uses.
2024-03-07 04:25:54 +01:00
DomainSettingsCmds::UpgradeCheck { ref commonopts } => commonopts.config_path.clone(),
DomainSettingsCmds::Raise { ref commonopts } => commonopts.config_path.clone(),
DomainSettingsCmds::Remigrate { ref commonopts, .. } => {
commonopts.config_path.clone()
}
},
KanidmdOpt::HealthCheck(ref c) => c.commonopts.config_path.clone(),
KanidmdOpt::Version(ref c) => c.config_path.clone(),
}
}
}
2022-06-11 07:24:29 +02:00
#[derive(Debug, Subcommand)]
enum KanidmdOpt {
2022-06-11 07:24:29 +02:00
#[clap(name = "server")]
/// Start the IDM Server
Server(CommonOpt),
2022-06-11 07:24:29 +02:00
#[clap(name = "configtest")]
/// Test the IDM Server configuration, without starting network listeners.
ConfigTest(CommonOpt),
#[clap(name = "cert-generate")]
/// Create a self-signed ca and tls certificate in the locations listed from the
/// configuration. These certificates should *not* be used in production, they
/// are for testing and evaluation only!
CertGenerate(CommonOpt),
#[clap(name = "recover-account")]
/// Recover an account's password
2023-07-24 02:05:10 +02:00
RecoverAccount {
#[clap(value_parser)]
/// The account name to recover credentials for.
name: String,
#[clap(flatten)]
commonopts: CommonOpt,
},
/// Display this server's replication certificate
ShowReplicationCertificate {
#[clap(flatten)]
commonopts: CommonOpt,
},
/// Renew this server's replication certificate
RenewReplicationCertificate {
#[clap(flatten)]
commonopts: CommonOpt,
},
/// Refresh this servers database content with the content from a supplier. This means
/// that all local content will be deleted and replaced with the supplier content.
RefreshReplicationConsumer {
#[clap(flatten)]
commonopts: CommonOpt,
/// Acknowledge that this database content will be refreshed from a supplier.
#[clap(long = "i-want-to-refresh-this-servers-database")]
proceed: bool,
},
2022-06-11 07:24:29 +02:00
// #[clap(name = "reset_server_id")]
// ResetServerId(CommonOpt),
#[clap(name = "db-scan")]
/// Inspect the internal content of the database datastructures.
2022-06-11 07:24:29 +02:00
DbScan {
#[clap(subcommand)]
commands: DbScanOpt,
},
2022-07-07 05:03:08 +02:00
/// Database maintenance, backups, restoration etc.
#[clap(name = "database")]
Database {
#[clap(subcommand)]
commands: DbCommands,
},
/// Change domain settings
#[clap(name = "domain")]
DomainSettings {
#[clap(subcommand)]
commands: DomainSettingsCmds,
},
2023-07-24 02:05:10 +02:00
/// Load the server config and check services are listening
#[clap(name = "healthcheck")]
HealthCheck(HealthCheckArgs),
/// Print the program version and exit
#[clap(name = "version")]
Version(CommonOpt),
}