Browse Source

feat(config): allow unsupported client feature flags

pull/7797/head
l5z12 2 months ago
parent
commit
5388fa406e
No known key found for this signature in database GPG Key ID: CD3BDD5C9267F050
  1. 5
      .env.template
  2. 6
      src/api/core/mod.rs
  3. 51
      src/config.rs
  4. 1
      src/util.rs

5
.env.template

@ -411,6 +411,11 @@
## - "enable-basic-auth-response": Enable HTTP Basic Auth autofill in the browser extension (Browser >= 2026.9.0) ## - "enable-basic-auth-response": Enable HTTP Basic Auth autofill in the browser extension (Browser >= 2026.9.0)
# EXPERIMENTAL_CLIENT_FEATURE_FLAGS= # EXPERIMENTAL_CLIENT_FEATURE_FLAGS=
## Allow flags in EXPERIMENTAL_CLIENT_FEATURE_FLAGS that are not in the supported list above.
## When enabled, all listed flags are sent to clients and unsupported flags do not block configuration updates.
## Unsupported flags remain visible in admin diagnostics and may require functionality Vaultwarden does not provide.
# EXPERIMENTAL_CLIENT_FEATURE_FLAGS_ALLOW_UNSUPPORTED=false
## Require new device emails. When a user logs in an email is required to be sent. ## Require new device emails. When a user logs in an email is required to be sent.
## If sending the email fails the login attempt will fail!! ## If sending the email fails the login attempt will fail!!
# REQUIRE_DEVICE_EMAIL=false # REQUIRE_DEVICE_EMAIL=false

6
src/api/core/mod.rs

@ -217,7 +217,11 @@ fn config() -> Json<Value> {
// iOS (v2026.2.1): https://github.com/bitwarden/ios/blob/cdd9ba1770ca2ffc098d02d12cc3208e3a830454/BitwardenShared/Core/Platform/Models/Enum/FeatureFlag.swift#L7 // iOS (v2026.2.1): https://github.com/bitwarden/ios/blob/cdd9ba1770ca2ffc098d02d12cc3208e3a830454/BitwardenShared/Core/Platform/Models/Enum/FeatureFlag.swift#L7
let mut feature_states = parse_experimental_client_feature_flags( let mut feature_states = parse_experimental_client_feature_flags(
&CONFIG.experimental_client_feature_flags(), &CONFIG.experimental_client_feature_flags(),
&FeatureFlagFilter::ValidOnly, &if CONFIG.experimental_client_feature_flags_allow_unsupported() {
FeatureFlagFilter::Unfiltered
} else {
FeatureFlagFilter::ValidOnly
},
); );
feature_states.insert("pm-19148-innovation-archive".to_owned(), true); feature_states.insert("pm-19148-innovation-archive".to_owned(), true);

51
src/config.rs

@ -723,6 +723,9 @@ make_config! {
/// Customize the enabled feature flags on the clients |> This is a comma separated list of feature flags to enable. /// Customize the enabled feature flags on the clients |> This is a comma separated list of feature flags to enable.
experimental_client_feature_flags: String, false, def, String::new(); experimental_client_feature_flags: String, false, def, String::new();
/// Allow unsupported client feature flags |> Pass all configured experimental client feature flags to clients, including flags outside the supported list.
/// Unsupported flags remain visible in admin diagnostics and may require functionality Vaultwarden does not provide.
experimental_client_feature_flags_allow_unsupported: bool, false, def, false;
/// Require new device emails |> When a user logs in an email is required to be sent. /// Require new device emails |> When a user logs in an email is required to be sent.
/// If sending the email fails the login attempt will fail. /// If sending the email fails the login attempt will fail.
@ -1066,7 +1069,7 @@ fn validate_config(cfg: &ConfigItems, on_update: bool) -> Result<(), Error> {
&cfg.experimental_client_feature_flags, &cfg.experimental_client_feature_flags,
&FeatureFlagFilter::InvalidOnly, &FeatureFlagFilter::InvalidOnly,
); );
if !invalid_flags.is_empty() { if !cfg.experimental_client_feature_flags_allow_unsupported && !invalid_flags.is_empty() {
let feature_flags_error = format!( let feature_flags_error = format!(
"Unrecognized experimental client feature flags: {invalid_flags:?}.\n\ "Unrecognized experimental client feature flags: {invalid_flags:?}.\n\
Please ensure all feature flags are spelled correctly and that they are supported in this version.\n\ Please ensure all feature flags are spelled correctly and that they are supported in this version.\n\
@ -1873,3 +1876,49 @@ handlebars::handlebars_helper!(webver: | web_vault_version: String |
handlebars::handlebars_helper!(vwver: | vw_version: String | handlebars::handlebars_helper!(vwver: | vw_version: String |
semver::VersionReq::parse(&vw_version).expect("Invalid Vaultwarden version compare string").matches(&VW_VERSION) semver::VersionReq::parse(&vw_version).expect("Invalid Vaultwarden version compare string").matches(&VW_VERSION)
); );
#[cfg(test)]
mod tests {
use super::{ConfigBuilder, validate_config};
fn config_with_unsupported_feature_flag() -> ConfigBuilder {
ConfigBuilder {
database_url: Some("sqlite://feature-flags-test.sqlite3".to_owned()),
experimental_client_feature_flags: Some("unsupported-test-feature".to_owned()),
..ConfigBuilder::default()
}
}
#[test]
fn unsupported_feature_flags_are_rejected_on_update_by_default() {
let config = config_with_unsupported_feature_flag().build();
assert!(!config.experimental_client_feature_flags_allow_unsupported);
assert!(validate_config(&config, false).is_ok());
let error = validate_config(&config, true).unwrap_err();
assert!(error.to_string().contains("Unrecognized experimental client feature flags"));
}
#[test]
fn unsupported_feature_flags_can_be_allowed_on_startup_and_update() {
let mut builder = config_with_unsupported_feature_flag();
builder.experimental_client_feature_flags_allow_unsupported = Some(true);
let config = builder.build();
assert!(validate_config(&config, false).is_ok());
assert!(validate_config(&config, true).is_ok());
}
#[test]
fn allowing_unsupported_feature_flags_preserves_other_validation() {
let mut builder = config_with_unsupported_feature_flag();
builder.experimental_client_feature_flags_allow_unsupported = Some(true);
builder.smtp_security = Some("invalid-security".to_owned());
let config = builder.build();
for on_update in [false, true] {
let error = validate_config(&config, on_update).unwrap_err();
assert!(error.to_string().contains("SMTP_SECURITY"));
}
}
}

1
src/util.rs

@ -815,7 +815,6 @@ pub fn convert_json_key_lcase_first(src_json: Value) -> Value {
} }
pub enum FeatureFlagFilter { pub enum FeatureFlagFilter {
#[allow(dead_code)]
Unfiltered, Unfiltered,
ValidOnly, ValidOnly,
InvalidOnly, InvalidOnly,

Loading…
Cancel
Save