Skip to content

Commit

Permalink
[identity] Reset device list and services data during password reset
Browse files Browse the repository at this point in the history
Summary:
Address [[ https://linear.app/comm/issue/ENG-9845/remove-backup-and-force-log-out-in-privileged-password-reset-rpc | ENG-9845 ]].

Depends on D14076

Test Plan:
Mocked the password reset RPC to accept me as a privileged admin, then called it. Confirmed that all devices were removed from DDB and other services. Device list became empty array.
I could then log in with a new password.

Reviewers: kamil, varun

Reviewed By: kamil

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D14087
  • Loading branch information
barthap committed Dec 6, 2024
1 parent 3121657 commit cedacdf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
45 changes: 41 additions & 4 deletions services/identity/src/database/device_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,33 @@ impl DatabaseClient {
Ok(())
}

/// Reset device list to empty array and remove devices data.
/// Ran during privileged password reset
#[tracing::instrument(skip_all)]
pub async fn reset_device_list(
&self,
user_id: &str,
) -> Result<DeviceListRow, Error> {
let mut devices_being_removed: Vec<String> = Vec::new();
let update_result = self
.transact_update_devicelist(user_id, |current_list, _| {
devices_being_removed.extend(current_list.clone());

debug!("Resetting device list");
*current_list = Vec::new();

Ok(UpdateOperationInfo::identity_generated())
})
.await?;

// delete device data and invalidate CSAT for removed devices
self
.clean_up_devices_data(user_id, devices_being_removed)
.await?;

Ok(update_result)
}

/// applies updated device list received from primary device
pub async fn apply_devicelist_update<V>(
&self,
Expand Down Expand Up @@ -1523,10 +1550,21 @@ impl DatabaseClient {
})
.await?;

if !remove_device_data {
return Ok(update_result);
if remove_device_data {
self
.clean_up_devices_data(user_id, devices_being_removed)
.await?;
}

Ok(update_result)
}

/// called internally when removing devices from device list
async fn clean_up_devices_data(
&self,
user_id: &str,
devices_being_removed: Vec<String>,
) -> Result<(), Error> {
// delete device data and invalidate CSAT for removed devices
debug!(
"{} devices have been removed from device list. Clearing data...",
Expand All @@ -1552,8 +1590,7 @@ impl DatabaseClient {
consume_error(result);
});
}

Ok(update_result)
Ok(())
}

/// Performs a transactional update of the device list for the user. Afterwards
Expand Down
7 changes: 6 additions & 1 deletion services/identity/src/grpc_services/authenticated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,9 +787,14 @@ impl IdentityClientService for AuthenticatedService {

self
.db_client
.update_user_password(state.user_id, password_file)
.update_user_password(state.user_id.clone(), password_file)
.await?;

// Delete backups, blob holders and tunnelbroker device tokens.
// This has to be done before resetting device list.
self.delete_services_data_for_user(&state.user_id).await?;
self.db_client.reset_device_list(&state.user_id).await?;

let response = Empty {};
Ok(Response::new(response))
}
Expand Down

0 comments on commit cedacdf

Please sign in to comment.