diff --git a/meilisearch/src/analytics/segment_analytics.rs b/meilisearch/src/analytics/segment_analytics.rs index 880d34c9a..8bde71688 100644 --- a/meilisearch/src/analytics/segment_analytics.rs +++ b/meilisearch/src/analytics/segment_analytics.rs @@ -277,6 +277,7 @@ impl From for Infos { indexer_options, scheduler_options, config_file_path, + generate_master_key: _, #[cfg(all(not(debug_assertions), feature = "analytics"))] no_analytics: _, } = options; diff --git a/meilisearch/src/main.rs b/meilisearch/src/main.rs index 01aeae457..3c4e314f8 100644 --- a/meilisearch/src/main.rs +++ b/meilisearch/src/main.rs @@ -33,6 +33,10 @@ async fn main() -> anyhow::Result<()> { setup(&opt)?; + if opt.generate_master_key { + println!("{}", generate_master_key()); + return Ok(()); + } match (opt.env.as_ref(), &opt.master_key) { ("production", Some(master_key)) if master_key.len() < MASTER_KEY_MIN_SIZE => { @@ -180,6 +184,7 @@ Anonymous telemetry:\t\"Enabled\"" "The provided Master Key is too short (< {MASTER_KEY_MIN_SIZE} characters)" ); eprintln!("A Master Key of at least {MASTER_KEY_MIN_SIZE} characters will be required when switching to the production environment."); + eprintln!("Restart Meilisearch with the `--generate-master-key` flag to generate a secure Master Key you can use"); } } ("development", None) => { diff --git a/meilisearch/src/option.rs b/meilisearch/src/option.rs index 40535305b..952c33a46 100644 --- a/meilisearch/src/option.rs +++ b/meilisearch/src/option.rs @@ -230,6 +230,13 @@ pub struct Opt { #[serde(default = "default_log_level")] pub log_level: String, + /// Generates a string of characters that can be used as a Master Key and exits. + /// + /// Pass the generated Master Key using the `--master-key` argument or the `MEILI_MASTER_KEY` environment variable in a subsequent Meilisearch invocation. + #[clap(long)] + #[serde(default)] + pub generate_master_key: bool, + /// Enables Prometheus metrics and /metrics route. #[cfg(feature = "metrics")] #[clap(long, env = MEILI_ENABLE_METRICS_ROUTE)] @@ -328,6 +335,7 @@ impl Opt { ignore_missing_snapshot: _, ignore_snapshot_if_db_exists: _, import_dump: _, + generate_master_key: _, ignore_missing_dump: _, ignore_dump_if_db_exists: _, config_file_path: _,