@ -71,9 +71,16 @@ macro_rules! make_config {
( @ type $ty :ty , option ) = > { Option < $ty > } ;
( @ type $ty :ty , option ) = > { Option < $ty > } ;
( @ type $ty :ty , $id :ident ) = > { $ty } ;
( @ type $ty :ty , $id :ident ) = > { $ty } ;
// Options that only builds with the `unsafe_test_mode` feature read
( @ test_only test_def ) = > { true } ;
( @ test_only $none_action :ident ) = > { false } ;
// Generate the values depending on none_action
// Generate the values depending on none_action
( @ build $value :expr , $config :expr , option , ) = > { $value } ;
( @ build $value :expr , $config :expr , option , ) = > { $value } ;
( @ build $value :expr , $config :expr , def , $default :expr ) = > { $value . unwrap_or ( $default ) } ;
( @ build $value :expr , $config :expr , def , $default :expr ) = > { $value . unwrap_or ( $default ) } ;
( @ build $value :expr , $config :expr , test_def , $default :expr ) = > {
if cfg ! ( feature = "unsafe_test_mode" ) { $value . unwrap_or ( $default ) } else { $default }
} ;
( @ build $value :expr , $config :expr , auto , $default_fn :expr ) = > { {
( @ build $value :expr , $config :expr , auto , $default_fn :expr ) = > { {
match $value {
match $value {
Some ( v ) = > v ,
Some ( v ) = > v ,
@ -286,6 +293,22 @@ macro_rules! make_config {
) + ) +
) + ) +
}
}
/// Warns about each set `test_def` option in a build without the `unsafe_test_mode` feature, which ignores them.
fn warn_test_only_options ( & self ) {
if cfg ! ( feature = "unsafe_test_mode" ) {
return ;
}
$( $(
if make_config ! { @ test_only $none_action } & & self . $name . is_some ( ) {
// We can't use warn! here because logging isn't setup yet.
println ! (
"[WARNING] {} is only read by builds with the `unsafe_test_mode` feature, ignoring it." ,
pastey ::paste ! ( stringify ! ( [ < $name :upper > ] ) )
) ;
}
) + ) +
}
/// Merges the values of both builders into a new builder.
/// Merges the values of both builders into a new builder.
/// If both have the same element, `other` wins.
/// If both have the same element, `other` wins.
fn merge ( & self , other : & Self , show_overrides : bool , overrides : & mut Vec < & str > ) -> Self {
fn merge ( & self , other : & Self , show_overrides : bool , overrides : & mut Vec < & str > ) -> Self {
@ -352,6 +375,8 @@ macro_rules! make_config {
r#type : & 'static str ,
r#type : & 'static str ,
doc : ElementDoc ,
doc : ElementDoc ,
overridden : bool ,
overridden : bool ,
#[ serde(skip) ]
test_only : bool ,
}
}
#[ derive(Serialize) ]
#[ derive(Serialize) ]
@ -411,10 +436,20 @@ macro_rules! make_config {
r#type : get_form_type ( stringify ! ( $ty ) ) ,
r#type : get_form_type ( stringify ! ( $ty ) ) ,
doc : get_doc ( concat ! ( $( $doc ) , + ) ) ,
doc : get_doc ( concat ! ( $( $doc ) , + ) ) ,
overridden : overridden . contains ( & pastey ::paste ! ( stringify ! ( [ < $name :upper > ] ) ) ) ,
overridden : overridden . contains ( & pastey ::paste ! ( stringify ! ( [ < $name :upper > ] ) ) ) ,
test_only : make_config ! { @ test_only $none_action } ,
} ,
} ,
) + ] , // End of elements repetition
) + ] , // End of elements repetition
} ,
} ,
) + ] ; // End of groups repetition
) + ] ; // End of groups repetition
// Options only test builds read aren't shown in the others
let data : Vec < GroupData > = data
. into_iter ( )
. map ( | mut group | {
group . elements . retain ( | e | ! e . test_only | | cfg ! ( feature = "unsafe_test_mode" ) ) ;
group
} )
. collect ( ) ;
serde_json ::to_value ( data ) . unwrap ( )
serde_json ::to_value ( data ) . unwrap ( )
}
}
@ -513,6 +548,8 @@ macro_rules! make_config {
//
//
// Where action applied when the value wasn't provided and can be:
// Where action applied when the value wasn't provided and can be:
// def: Use a default value
// def: Use a default value
// test_def: Use a default value, which only builds with the `unsafe_test_mode` feature let you change. Other builds
// warn at startup when it's set, ignore it, and don't show it in the admin panel
// auto: Value is auto generated based on other values
// auto: Value is auto generated based on other values
// option: Value is optional
// option: Value is optional
// generated: Value is always autogenerated and it's original value ignored
// generated: Value is always autogenerated and it's original value ignored
@ -682,6 +719,8 @@ make_config! {
client {
client {
/// Control whether clients onboarding interstitials are suppressed |> post-login welcome dialogs, extension install prompts, setup extension redirects, and premium upsell modals
/// Control whether clients onboarding interstitials are suppressed |> post-login welcome dialogs, extension install prompts, setup extension redirects, and premium upsell modals
client_suppress_onboarding : bool , true , def , false ;
client_suppress_onboarding : bool , true , def , false ;
/// In most cases this value is set by the client |> Will block clients from setting too low of a value in `accounts::post_kdf`
client_kdf_iter : i32 , false , test_def , 600_000 ;
} ,
} ,
/// Advanced settings
/// Advanced settings
@ -961,6 +1000,17 @@ make_config! {
} ,
} ,
}
}
fn check_iterations ( iterations : i32 , key : & str ) -> Result < ( ) , Error > {
if iterations < 100_000 {
#[ cfg(feature = " unsafe_test_mode " ) ]
println ! ( "[WARNING] {key} should be at least 100000 or higher. The default is 600000!" ) ;
#[ cfg(not(feature = " unsafe_test_mode " )) ]
err ! ( format ! ( "{key} should be at least 100000 or higher. The default is 600000!" ) ) ;
}
Ok ( ( ) )
}
fn validate_config ( cfg : & ConfigItems , on_update : bool ) -> Result < ( ) , Error > {
fn validate_config ( cfg : & ConfigItems , on_update : bool ) -> Result < ( ) , Error > {
// Validate connection URL is valid and DB feature is enabled
// Validate connection URL is valid and DB feature is enabled
#[ cfg(sqlite) ]
#[ cfg(sqlite) ]
@ -995,9 +1045,8 @@ fn validate_config(cfg: &ConfigItems, on_update: bool) -> Result<(), Error> {
}
}
}
}
if cfg . password_iterations < 100_000 {
check_iterations ( cfg . password_iterations , "PASSWORD_ITERATIONS" ) ? ;
err ! ( "PASSWORD_ITERATIONS should be at least 100000 or higher. The default is 600000!" ) ;
check_iterations ( cfg . client_kdf_iter , "CLIENT_KDF_ITER" ) ? ;
}
let limit = 256 ;
let limit = 256 ;
if ! ( 1 . . = limit ) . contains ( & cfg . database_max_conns ) {
if ! ( 1 . . = limit ) . contains ( & cfg . database_max_conns ) {
@ -1554,6 +1603,7 @@ impl Config {
// Fill any missing with defaults
// Fill any missing with defaults
let config = builder . build ( ) ;
let config = builder . build ( ) ;
if ! SKIP_CONFIG_VALIDATION . load ( Ordering ::Relaxed ) {
if ! SKIP_CONFIG_VALIDATION . load ( Ordering ::Relaxed ) {
builder . warn_test_only_options ( ) ;
validate_config ( & config , false ) ? ;
validate_config ( & config , false ) ? ;
}
}