diff --git a/Cargo.lock b/Cargo.lock index d1e454077..71bf41376 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -494,6 +494,7 @@ version = "4.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "956ffc5b0ec7d7a6949e3f21fd63ba5af4cffdc2ba1e0b7bf62b481458c4ae7f" dependencies = [ + "serde", "utf8-width", ] diff --git a/meilisearch-http/Cargo.toml b/meilisearch-http/Cargo.toml index 14687ccf0..d1f2ead7d 100644 --- a/meilisearch-http/Cargo.toml +++ b/meilisearch-http/Cargo.toml @@ -30,7 +30,7 @@ arc-swap = "1.3.2" async-stream = "0.3.2" async-trait = "0.1.51" bstr = "0.2.17" -byte-unit = { version = "4.0.12", default-features = false, features = ["std"] } +byte-unit = { version = "4.0.12", default-features = false, features = ["std", "serde"] } bytes = "1.1.0" chrono = { version = "0.4.19", features = ["serde"] } crossbeam-channel = "0.5.1" diff --git a/meilisearch-http/src/analytics/segment_analytics.rs b/meilisearch-http/src/analytics/segment_analytics.rs index 597da7523..ab161c3dc 100644 --- a/meilisearch-http/src/analytics/segment_analytics.rs +++ b/meilisearch-http/src/analytics/segment_analytics.rs @@ -1,6 +1,6 @@ use std::collections::{BinaryHeap, HashMap, HashSet}; use std::fs; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::sync::Arc; use std::time::{Duration, Instant}; @@ -211,10 +211,30 @@ impl Segment { "server_provider": std::env::var("MEILI_SERVER_PROVIDER").ok(), }) }); - let infos = json!({ - "env": opt.env.clone(), - "has_snapshot": opt.schedule_snapshot, - }); + // The infos are all cli option except every option containing sensitive information. + // We consider an information as sensible if it contains a path, an address or a key. + let infos = { + // First we see if any sensitive fields were used. + let db_path = opt.db_path != PathBuf::from("./data.ms"); + let import_dump = opt.import_dump.is_some(); + let dumps_dir = opt.dumps_dir != PathBuf::from("dumps/"); + let import_snapshot = opt.import_snapshot.is_some(); + let snapshots_dir = opt.snapshot_dir != PathBuf::from("snapshots/"); + let http_addr = opt.http_addr != "127.0.0.1:7700"; + + let mut infos = serde_json::to_value(opt).unwrap(); + + // Then we overwrite all sensitive field with a boolean representing if + // the feature was used or not. + infos["db_path"] = json!(db_path); + infos["import_dump"] = json!(import_dump); + infos["dumps_dir"] = json!(dumps_dir); + infos["import_snapshot"] = json!(import_snapshot); + infos["snapshot_dir"] = json!(snapshots_dir); + infos["http_addr"] = json!(http_addr); + + infos + }; let number_of_documents = stats .indexes diff --git a/meilisearch-http/src/option.rs b/meilisearch-http/src/option.rs index a128a1db3..5fa26ae62 100644 --- a/meilisearch-http/src/option.rs +++ b/meilisearch-http/src/option.rs @@ -14,10 +14,11 @@ use rustls::{ RootCertStore, }; use rustls_pemfile::{certs, pkcs8_private_keys, rsa_private_keys}; +use serde::Serialize; const POSSIBLE_ENV: [&str; 2] = ["development", "production"]; -#[derive(Debug, Clone, Parser)] +#[derive(Debug, Clone, Parser, Serialize)] pub struct Opt { /// The destination where the database must be created. #[clap(long, env = "MEILI_DB_PATH", default_value = "./data.ms")] @@ -28,6 +29,7 @@ pub struct Opt { pub http_addr: String, /// The master key allowing you to do everything on the server. + #[serde(skip)] #[clap(long, env = "MEILI_MASTER_KEY")] pub master_key: Option, @@ -59,33 +61,40 @@ pub struct Opt { /// This should contain PEM-format certificates /// in the right order (the first certificate should /// certify KEYFILE, the last should be a root CA). + #[serde(skip)] #[clap(long, env = "MEILI_SSL_CERT_PATH", parse(from_os_str))] pub ssl_cert_path: Option, /// Read private key from KEYFILE. This should be a RSA /// private key or PKCS8-encoded private key, in PEM format. + #[serde(skip)] #[clap(long, env = "MEILI_SSL_KEY_PATH", parse(from_os_str))] pub ssl_key_path: Option, /// Enable client authentication, and accept certificates /// signed by those roots provided in CERTFILE. #[clap(long, env = "MEILI_SSL_AUTH_PATH", parse(from_os_str))] + #[serde(skip)] pub ssl_auth_path: Option, /// Read DER-encoded OCSP response from OCSPFILE and staple to certificate. /// Optional + #[serde(skip)] #[clap(long, env = "MEILI_SSL_OCSP_PATH", parse(from_os_str))] pub ssl_ocsp_path: Option, /// Send a fatal alert if the client does not complete client authentication. + #[serde(skip)] #[clap(long, env = "MEILI_SSL_REQUIRE_AUTH")] pub ssl_require_auth: bool, /// SSL support session resumption + #[serde(skip)] #[clap(long, env = "MEILI_SSL_RESUMPTION")] pub ssl_resumption: bool, /// SSL support tickets. + #[serde(skip)] #[clap(long, env = "MEILI_SSL_TICKETS")] pub ssl_tickets: bool, @@ -127,6 +136,7 @@ pub struct Opt { #[clap(long, env = "MEILI_LOG_LEVEL", default_value = "info")] pub log_level: String, + #[serde(skip)] #[clap(skip)] pub indexer_options: IndexerOpts, }