Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ pub(crate) async fn do_update_instance(
instance.disable_all_traffic = instance_info.disable_all_traffic;
instance.enterprise_enabled = instance_info.enterprise_enabled;
instance.openid_display_name = instance_info.openid_display_name;
instance.uuid = instance_info.id;
// Token may be empty if it was not issued
// This happens during polling, as core doesn't issue a new token for polling request
if response.token.is_some() {
Expand Down
105 changes: 3 additions & 102 deletions src-tauri/src/enterprise/periodic/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,6 @@ pub async fn poll_instance(
return Ok(());
}

if check_uuid_mismatch(&response, instance, handle)? {
warn!("Instance {}({}) has UUID mismatch, it's config won't be automatically updated. Remove \
the instance and add it again, or contact your administrator.",
instance.name, instance.id
);
return Ok(());
}

debug!(
"Config for instance {}({}) changed",
instance.name, instance.id
Expand Down Expand Up @@ -277,102 +269,11 @@ fn build_request(instance: &Instance<Id>) -> Result<InstanceInfoRequest, Error>
})
}

#[derive(PartialEq, Eq, Hash)]
enum NotificationType {
VersionMismatch,
UuidMismatch,
}

/// Tracks instance IDs that for which we already sent notification about version mismatches
/// to prevent duplicate notifications in the app's lifetime.
static NOTIFIED_INSTANCES: LazyLock<Mutex<HashSet<(Id, NotificationType)>>> =
static NOTIFIED_INSTANCES: LazyLock<Mutex<HashSet<Id>>> =
LazyLock::new(|| Mutex::new(HashSet::new()));

#[derive(Clone, Serialize)]
struct UuidMismatchPayload {
instance_name: String,
}

fn check_uuid_mismatch(
response: &InstanceInfoResponse,
instance: &Instance<Id>,
handle: &AppHandle,
) -> Result<bool, Error> {
debug!(
"Checking UUID mismatch for instance {}({})",
instance.name, instance.id
);

let mut notified_instances = NOTIFIED_INSTANCES.lock().unwrap();

debug!(
"Instance {}({}) local UUID: {}, checking against response...",
instance.name, instance.id, instance.uuid
);

if let Some(device_config) = &response.device_config {
debug!(
"Found device_config for instance {}({})",
instance.name, instance.id
);

if let Some(info) = &device_config.instance {
debug!(
"Found instance info in device_config for instance {}({}), core UUID: {}",
instance.name, instance.id, info.id
);

if info.id != instance.uuid {
error!(
"Instance {}({}) has mismatching UUIDs: local {}, remote {}",
instance.name, instance.id, instance.uuid, info.id
);

if !notified_instances.contains(&(instance.id, NotificationType::UuidMismatch)) {
if let Err(err) = handle.emit(
EventKey::UuidMismatch.into(),
UuidMismatchPayload {
instance_name: instance.name.clone(),
},
) {
error!("Failed to emit UUID mismatch event to the frontend: {err}");
} else {
debug!(
"Successfully emitted UUID mismatch event for instance {}({})",
instance.name, instance.id
);
notified_instances.insert((instance.id, NotificationType::UuidMismatch));
}
} else {
debug!(
"Instance {}({}) already notified about UUID mismatch, skipping",
instance.name, instance.id
);
}

return Ok(true);
} else {
debug!(
"UUIDs match for instance {}({}): {}",
instance.name, instance.id, instance.uuid
);
}
} else {
debug!(
"No instance info found in device_config for instance {}({})",
instance.name, instance.id
);
}
} else {
debug!(
"No device_config found in response for instance {}({})",
instance.name, instance.id
);
}

Ok(false)
}

const CORE_VERSION_HEADER: &str = "defguard-core-version";
const PROXY_VERSION_HEADER: &str = "defguard-component-version";

Expand All @@ -394,7 +295,7 @@ fn check_min_version(
handle: &AppHandle,
) -> Result<(), Error> {
let mut notified_instances = NOTIFIED_INSTANCES.lock().unwrap();
if notified_instances.contains(&(instance.id, NotificationType::VersionMismatch)) {
if notified_instances.contains(&instance.id) {
debug!(
"Instance {}({}) already notified about version mismatch, skipping",
instance.name, instance.id
Expand Down Expand Up @@ -490,7 +391,7 @@ fn check_min_version(
if let Err(err) = handle.emit(EventKey::VersionMismatch.into(), payload) {
error!("Failed to emit version mismatch event to the frontend: {err}");
} else {
notified_instances.insert((instance.id, NotificationType::VersionMismatch));
notified_instances.insert(instance.id);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export const MFAModal = () => {
return;
}

if (errorData === 'selected MFA method is not available') {
if (errorData === 'selected MFA method not available') {
toaster.error(localLL.errors.mfaNotConfigured());
} else {
toaster.error(localLL.errors.mfaStartGeneric());
Expand Down