Browse Source

Merge branch 'main' into feature/trusted-device-encryption

pull/7534/head
tom27052006 6 days ago
parent
commit
9a80ca1341
  1. 3
      .env.template
  2. 19
      Cargo.lock
  3. 1
      Cargo.toml
  4. 42
      migrations/mysql/2024-03-13-170000_sso_users_cascade/up.sql
  5. 2
      playwright/docker-compose.yml
  6. 6
      src/api/admin.rs
  7. 39
      src/api/core/accounts.rs
  8. 30
      src/api/core/ciphers.rs
  9. 6
      src/api/core/events.rs
  10. 52
      src/api/core/organizations.rs
  11. 14
      src/api/core/two_factor/mod.rs
  12. 28
      src/api/identity.rs
  13. 20
      src/config.rs
  14. 8
      src/db/models/org_policy.rs

3
.env.template

@ -518,6 +518,9 @@
## Prevent users from logging in directly without going through SSO ## Prevent users from logging in directly without going through SSO
# SSO_ONLY=false # SSO_ONLY=false
## Allow SSO flow to create account. You probably want to disable it when using a public provider.
# SSO_SIGNUPS_ALLOWED=true
## On SSO Signup if a user with a matching email already exists make the association ## On SSO Signup if a user with a matching email already exists make the association
# SSO_SIGNUPS_MATCH_EMAIL=true # SSO_SIGNUPS_MATCH_EMAIL=true

19
Cargo.lock

@ -934,6 +934,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "cfg_aliases"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527"
[[package]] [[package]]
name = "chacha20" name = "chacha20"
version = "0.10.1" version = "0.10.1"
@ -3228,6 +3234,18 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b" checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b"
[[package]]
name = "nix"
version = "0.31.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf20d2fde8ff38632c426f1165ed7436270b44f199fc55284c38276f9db47c3d"
dependencies = [
"bitflags 2.13.1",
"cfg-if",
"cfg_aliases",
"libc",
]
[[package]] [[package]]
name = "nom" name = "nom"
version = "7.1.3" version = "7.1.3"
@ -5867,6 +5885,7 @@ dependencies = [
"macros", "macros",
"mimalloc", "mimalloc",
"moka", "moka",
"nix",
"num-derive", "num-derive",
"num-traits", "num-traits",
"opendal", "opendal",

1
Cargo.toml

@ -58,6 +58,7 @@ oidc-accept-string-booleans = ["openidconnect/accept-string-booleans"]
unstable = [] unstable = []
[target."cfg(unix)".dependencies] [target."cfg(unix)".dependencies]
nix = { version = "0.31.3", features = ["fs"] }
# Logging # Logging
syslog = "7.0.0" syslog = "7.0.0"

42
migrations/mysql/2024-03-13-170000_sso_users_cascade/up.sql

@ -1,15 +1,31 @@
-- Dynamically create DROP FOREIGN KEY SELECT if (
-- Some versions of MySQL or MariaDB might fail if the key doesn't exists EXISTS(
-- This checks if the key exists, and if so, will drop it. SELECT CONSTRAINT_NAME FROM information_schema.table_constraints
SET @drop_sso_fk = IF((SELECT true FROM information_schema.TABLE_CONSTRAINTS WHERE WHERE TABLE_SCHEMA = DATABASE()
CONSTRAINT_SCHEMA = DATABASE() AND AND TABLE_NAME = 'sso_users'
TABLE_NAME = 'sso_users' AND AND CONSTRAINT_TYPE = 'FOREIGN KEY'
CONSTRAINT_NAME = 'sso_users_ibfk_1' AND AND CONSTRAINT_NAME = 'sso_users_ibfk_1'
CONSTRAINT_TYPE = 'FOREIGN KEY') = true, )
'ALTER TABLE sso_users DROP FOREIGN KEY sso_users_ibfk_1', ,'ALTER TABLE sso_users DROP FOREIGN KEY `sso_users_ibfk_1`'
'SELECT 1'); ,'SELECT "info: FK sso_users_ibfk_1 does not exist."'
PREPARE stmt FROM @drop_sso_fk; ) INTO @drop_stmt;
EXECUTE stmt; PREPARE drop_stmt FROM @drop_stmt;
DEALLOCATE PREPARE stmt; EXECUTE drop_stmt;
SELECT if (
EXISTS(
SELECT CONSTRAINT_NAME FROM information_schema.table_constraints
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'sso_users'
AND CONSTRAINT_TYPE = 'FOREIGN KEY'
AND CONSTRAINT_NAME = '1'
)
,'ALTER TABLE sso_users DROP FOREIGN KEY `1`'
,'SELECT "info: FK sso_users 1 does not exist."'
) INTO @drop_stmt;
PREPARE drop_stmt FROM @drop_stmt;
EXECUTE drop_stmt;
DEALLOCATE PREPARE drop_stmt;
ALTER TABLE sso_users ADD FOREIGN KEY(user_uuid) REFERENCES users(uuid) ON UPDATE CASCADE ON DELETE CASCADE; ALTER TABLE sso_users ADD FOREIGN KEY(user_uuid) REFERENCES users(uuid) ON UPDATE CASCADE ON DELETE CASCADE;

2
playwright/docker-compose.yml

@ -61,7 +61,7 @@ services:
Mariadb: Mariadb:
profiles: ["playwright"] profiles: ["playwright"]
container_name: playwright_mariadb container_name: playwright_mariadb
image: mariadb:11.2.4 image: mariadb:12.2.2
env_file: test.env env_file: test.env
healthcheck: healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"] test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]

6
src/api/admin.rs

@ -425,7 +425,7 @@ async fn delete_user(user_id: UserId, token: AdminToken, conn: DbConn) -> EmptyR
for membership in memberships { for membership in memberships {
log_event( log_event(
EventType::OrganizationUserDeleted as i32, EventType::OrganizationUserDeleted,
&membership.uuid, &membership.uuid,
&membership.org_uuid, &membership.org_uuid,
&ACTING_ADMIN_USER.into(), &ACTING_ADMIN_USER.into(),
@ -446,7 +446,7 @@ async fn delete_sso_user(user_id: UserId, token: AdminToken, conn: DbConn) -> Em
for membership in memberships { for membership in memberships {
log_event( log_event(
EventType::OrganizationUserUnlinkedSso as i32, EventType::OrganizationUserUnlinkedSso,
&membership.uuid, &membership.uuid,
&membership.org_uuid, &membership.org_uuid,
&ACTING_ADMIN_USER.into(), &ACTING_ADMIN_USER.into(),
@ -571,7 +571,7 @@ async fn update_membership_type(data: Json<MembershipTypeData>, token: AdminToke
OrgPolicy::check_user_allowed(&member_to_edit, "modify", &conn).await?; OrgPolicy::check_user_allowed(&member_to_edit, "modify", &conn).await?;
log_event( log_event(
EventType::OrganizationUserUpdated as i32, EventType::OrganizationUserUpdated,
&member_to_edit.uuid, &member_to_edit.uuid,
&data.org_uuid, &data.org_uuid,
&ACTING_ADMIN_USER.into(), &ACTING_ADMIN_USER.into(),

39
src/api/core/accounts.rs

@ -721,29 +721,52 @@ async fn post_keys(data: Json<KeysData>, headers: Headers, conn: DbConn) -> Json
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
struct ChangePassData { struct ChangePassData {
master_password_hash: String, master_password_hash: String,
new_master_password_hash: String,
master_password_hint: Option<String>, master_password_hint: Option<String>,
key: String, authentication_data: Option<AuthenticationData>,
unlock_data: Option<UnlockData>,
// Outdated values, might still be used by older clients
new_master_password_hash: Option<String>,
key: Option<String>,
} }
#[post("/accounts/password", data = "<data>")] #[post("/accounts/password", data = "<data>")]
async fn post_password(data: Json<ChangePassData>, headers: Headers, conn: DbConn, nt: Notify<'_>) -> EmptyResult { async fn post_password(data: Json<ChangePassData>, headers: Headers, conn: DbConn, nt: Notify<'_>) -> EmptyResult {
let data: ChangePassData = data.into_inner(); let data: ChangePassData = data.into_inner();
let mut user = headers.user; let user = headers.user;
if !user.check_valid_password(&data.master_password_hash) { if !user.check_valid_password(&data.master_password_hash) {
err!("Invalid password") err!("Invalid password")
} }
user.password_hint = clean_password_hint(data.master_password_hint.as_ref());
enforce_password_hint_setting(user.password_hint.as_ref())?;
log_user_event(EventType::UserChangedPassword as i32, &user.uuid, headers.device.atype, &headers.ip.ip, &conn) log_user_event(EventType::UserChangedPassword as i32, &user.uuid, headers.device.atype, &headers.ip.ip, &conn)
.await; .await;
let (new_master_password_hash, new_key) =
if let (Some(unlock_data), Some(authentication_data)) = (data.unlock_data, data.authentication_data) {
if authentication_data.kdf != unlock_data.kdf {
err!("KDF settings must be equal for authentication and unlock")
}
if user.email != authentication_data.salt || user.email != unlock_data.salt {
err!("Invalid master password salt")
}
(authentication_data.master_password_authentication_hash, unlock_data.master_key_wrapped_user_key)
} else if let (Some(new_master_password_hash), Some(new_key)) = (data.new_master_password_hash, data.key) {
(new_master_password_hash, new_key)
} else {
err!("Invalid request!")
};
let mut user = user;
user.password_hint = clean_password_hint(data.master_password_hint.as_ref());
enforce_password_hint_setting(user.password_hint.as_ref())?;
user.set_password( user.set_password(
&data.new_master_password_hash, &new_master_password_hash,
Some(data.key), Some(new_key),
true, true,
Some(vec![ Some(vec![
String::from("post_rotatekey"), String::from("post_rotatekey"),

30
src/api/core/ciphers.rs

@ -167,7 +167,7 @@ async fn sync(data: SyncData, headers: Headers, client_version: Option<ClientVer
api::core::get_eq_domains(&headers, true).into_inner() api::core::get_eq_domains(&headers, true).into_inner()
}; };
// This is very similar to the the userDecryptionOptions sent in connect/token, // This is very similar to the userDecryptionOptions sent in connect/token,
// but as of 2025-12-19 they're both using different casing conventions. // but as of 2025-12-19 they're both using different casing conventions.
let has_master_password = !headers.user.password_hash.is_empty(); let has_master_password = !headers.user.password_hash.is_empty();
let master_password_unlock = if has_master_password { let master_password_unlock = if has_master_password {
@ -553,16 +553,8 @@ pub async fn update_cipher_from_data(
(_, _) => EventType::CipherUpdated, (_, _) => EventType::CipherUpdated,
}; };
log_event( log_event(event_type, &cipher.uuid, org_id, &headers.user.uuid, headers.device.atype, &headers.ip.ip, conn)
event_type as i32, .await;
&cipher.uuid,
org_id,
&headers.user.uuid,
headers.device.atype,
&headers.ip.ip,
conn,
)
.await;
} }
nt.send_cipher_update( nt.send_cipher_update(
ut, ut,
@ -850,7 +842,7 @@ async fn post_collections_update(
.await; .await;
log_event( log_event(
EventType::CipherUpdatedCollections as i32, EventType::CipherUpdatedCollections,
&cipher.uuid, &cipher.uuid,
org_uuid, org_uuid,
&headers.user.uuid, &headers.user.uuid,
@ -930,7 +922,7 @@ async fn post_collections_admin(
.await; .await;
log_event( log_event(
EventType::CipherUpdatedCollections as i32, EventType::CipherUpdatedCollections,
&cipher.uuid, &cipher.uuid,
org_uuid, org_uuid,
&headers.user.uuid, &headers.user.uuid,
@ -1335,7 +1327,7 @@ async fn save_attachment(
if let Some(org_id) = &cipher.organization_uuid { if let Some(org_id) = &cipher.organization_uuid {
log_event( log_event(
EventType::CipherAttachmentCreated as i32, EventType::CipherAttachmentCreated,
&cipher.uuid, &cipher.uuid,
org_id, org_id,
&headers.user.uuid, &headers.user.uuid,
@ -1696,7 +1688,7 @@ async fn purge_org_vault(
nt.send_user_update(UpdateType::SyncVault, &user, headers.device.push_uuid.as_ref(), &conn).await; nt.send_user_update(UpdateType::SyncVault, &user, headers.device.push_uuid.as_ref(), &conn).await;
log_event( log_event(
EventType::OrganizationPurgedVault as i32, EventType::OrganizationPurgedVault,
&organization.org_id, &organization.org_id,
&organization.org_id, &organization.org_id,
&user.uuid, &user.uuid,
@ -1824,9 +1816,9 @@ async fn delete_cipher_by_uuid(
let event_type = if *delete_options == CipherDeleteOptions::SoftSingle let event_type = if *delete_options == CipherDeleteOptions::SoftSingle
|| *delete_options == CipherDeleteOptions::SoftMulti || *delete_options == CipherDeleteOptions::SoftMulti
{ {
EventType::CipherSoftDeleted as i32 EventType::CipherSoftDeleted
} else { } else {
EventType::CipherDeleted as i32 EventType::CipherDeleted
}; };
log_event(event_type, &cipher.uuid, &org_id, &headers.user.uuid, headers.device.atype, &headers.ip.ip, conn) log_event(event_type, &cipher.uuid, &org_id, &headers.user.uuid, headers.device.atype, &headers.ip.ip, conn)
@ -1895,7 +1887,7 @@ async fn restore_cipher_by_uuid(
if let Some(org_id) = &cipher.organization_uuid { if let Some(org_id) = &cipher.organization_uuid {
log_event( log_event(
EventType::CipherRestored as i32, EventType::CipherRestored,
&cipher.uuid.clone(), &cipher.uuid.clone(),
org_id, org_id,
&headers.user.uuid, &headers.user.uuid,
@ -1972,7 +1964,7 @@ async fn delete_cipher_attachment_by_id(
if let Some(ref org_id) = cipher.organization_uuid { if let Some(ref org_id) = cipher.organization_uuid {
log_event( log_event(
EventType::CipherAttachmentDeleted as i32, EventType::CipherAttachmentDeleted,
&cipher.uuid, &cipher.uuid,
org_id, org_id,
&headers.user.uuid, &headers.user.uuid,

6
src/api/core/events.rs

@ -10,7 +10,7 @@ use crate::{
auth::{AdminHeaders, Headers}, auth::{AdminHeaders, Headers},
db::{ db::{
DbConn, DbPool, DbConn, DbPool,
models::{Cipher, CipherId, Event, Membership, MembershipId, OrganizationId, UserId}, models::{Cipher, CipherId, Event, EventType, Membership, MembershipId, OrganizationId, UserId},
}, },
util::parse_date, util::parse_date,
}; };
@ -267,7 +267,7 @@ async fn log_user_event_impl(
} }
pub async fn log_event( pub async fn log_event(
event_type: i32, event_type: EventType,
source_uuid: &str, source_uuid: &str,
org_id: &OrganizationId, org_id: &OrganizationId,
act_user_id: &UserId, act_user_id: &UserId,
@ -278,7 +278,7 @@ pub async fn log_event(
if !CONFIG.org_events_enabled() { if !CONFIG.org_events_enabled() {
return; return;
} }
log_event_impl(event_type, source_uuid, org_id, act_user_id, device_type, None, ip, conn).await; log_event_impl(event_type as i32, source_uuid, org_id, act_user_id, device_type, None, ip, conn).await;
} }
#[expect(clippy::too_many_arguments)] #[expect(clippy::too_many_arguments)]

52
src/api/core/organizations.rs

@ -278,7 +278,7 @@ async fn leave_organization(org_id: OrganizationId, headers: OrgMemberHeaders, c
} }
log_event( log_event(
EventType::OrganizationUserLeft as i32, EventType::OrganizationUserLeft,
&membership.uuid, &membership.uuid,
&org_id, &org_id,
&headers.user.uuid, &headers.user.uuid,
@ -336,7 +336,7 @@ async fn post_organization(
org.save(&conn).await?; org.save(&conn).await?;
log_event( log_event(
EventType::OrganizationUpdated as i32, EventType::OrganizationUpdated,
org_id.as_ref(), org_id.as_ref(),
&org_id, &org_id,
&headers.user.uuid, &headers.user.uuid,
@ -523,7 +523,7 @@ async fn post_organization_collections(
collection.save(&conn).await?; collection.save(&conn).await?;
log_event( log_event(
EventType::CollectionCreated as i32, EventType::CollectionCreated,
&collection.uuid, &collection.uuid,
&org_id, &org_id,
&headers.user.uuid, &headers.user.uuid,
@ -606,7 +606,7 @@ async fn post_bulk_access_collections(
collection.save(&conn).await?; collection.save(&conn).await?;
log_event( log_event(
EventType::CollectionUpdated as i32, EventType::CollectionUpdated,
&collection.uuid, &collection.uuid,
&org_id, &org_id,
&headers.user.uuid, &headers.user.uuid,
@ -683,7 +683,7 @@ async fn post_organization_collection_update(
collection.save(&conn).await?; collection.save(&conn).await?;
log_event( log_event(
EventType::CollectionUpdated as i32, EventType::CollectionUpdated,
&collection.uuid, &collection.uuid,
&org_id, &org_id,
&headers.user.uuid, &headers.user.uuid,
@ -732,7 +732,7 @@ async fn delete_organization_collection_impl(
err!("Collection not found", "Collection does not exist or does not belong to this organization") err!("Collection not found", "Collection does not exist or does not belong to this organization")
}; };
log_event( log_event(
EventType::CollectionDeleted as i32, EventType::CollectionDeleted,
&collection.uuid, &collection.uuid,
org_id, org_id,
&headers.user.uuid, &headers.user.uuid,
@ -1157,7 +1157,7 @@ async fn send_invite(
} }
log_event( log_event(
EventType::OrganizationUserInvited as i32, EventType::OrganizationUserInvited,
&new_member.uuid, &new_member.uuid,
&org_id, &org_id,
&headers.user.uuid, &headers.user.uuid,
@ -1456,7 +1456,7 @@ async fn confirm_invite_impl(
OrgPolicy::check_user_allowed(&member_to_confirm, "confirm", conn).await?; OrgPolicy::check_user_allowed(&member_to_confirm, "confirm", conn).await?;
log_event( log_event(
EventType::OrganizationUserConfirmed as i32, EventType::OrganizationUserConfirmed,
&member_to_confirm.uuid, &member_to_confirm.uuid,
org_id, org_id,
&headers.user.uuid, &headers.user.uuid,
@ -1646,7 +1646,7 @@ async fn edit_member(
} }
log_event( log_event(
EventType::OrganizationUserUpdated as i32, EventType::OrganizationUserUpdated,
&member_to_edit.uuid, &member_to_edit.uuid,
&org_id, &org_id,
&headers.user.uuid, &headers.user.uuid,
@ -1733,7 +1733,7 @@ async fn delete_member_impl(
} }
log_event( log_event(
EventType::OrganizationUserRemoved as i32, EventType::OrganizationUserRemoved,
&member_to_delete.uuid, &member_to_delete.uuid,
org_id, org_id,
&headers.user.uuid, &headers.user.uuid,
@ -2153,7 +2153,7 @@ async fn put_policy(
} }
log_event( log_event(
EventType::OrganizationUserRemoved as i32, EventType::OrganizationUserRemoved,
&member.uuid, &member.uuid,
&org_id, &org_id,
&headers.user.uuid, &headers.user.uuid,
@ -2179,7 +2179,7 @@ async fn put_policy(
policy.save(&conn).await?; policy.save(&conn).await?;
log_event( log_event(
EventType::PolicyUpdated as i32, EventType::PolicyUpdated,
policy.uuid.as_ref(), policy.uuid.as_ref(),
&org_id, &org_id,
&headers.user.uuid, &headers.user.uuid,
@ -2348,7 +2348,7 @@ async fn revoke_member_impl(
member.save(conn).await?; member.save(conn).await?;
log_event( log_event(
EventType::OrganizationUserRevoked as i32, EventType::OrganizationUserRevoked,
&member.uuid, &member.uuid,
org_id, org_id,
&headers.user.uuid, &headers.user.uuid,
@ -2446,7 +2446,7 @@ async fn restore_member_impl(
member.save(conn).await?; member.save(conn).await?;
log_event( log_event(
EventType::OrganizationUserRestored as i32, EventType::OrganizationUserRestored,
&member.uuid, &member.uuid,
org_id, org_id,
&headers.user.uuid, &headers.user.uuid,
@ -2614,7 +2614,7 @@ async fn post_groups(
let group = group_request.to_group(&org_id); let group = group_request.to_group(&org_id);
log_event( log_event(
EventType::GroupCreated as i32, EventType::GroupCreated,
&group.uuid, &group.uuid,
&org_id, &org_id,
&headers.user.uuid, &headers.user.uuid,
@ -2655,7 +2655,7 @@ async fn put_group(
GroupUser::delete_all_by_group(&group_id, &org_id, &conn).await?; GroupUser::delete_all_by_group(&group_id, &org_id, &conn).await?;
log_event( log_event(
EventType::GroupUpdated as i32, EventType::GroupUpdated,
&updated_group.uuid, &updated_group.uuid,
&org_id, &org_id,
&headers.user.uuid, &headers.user.uuid,
@ -2688,7 +2688,7 @@ async fn add_update_group(
user_entry.save(conn).await?; user_entry.save(conn).await?;
log_event( log_event(
EventType::OrganizationUserUpdatedGroups as i32, EventType::OrganizationUserUpdatedGroups,
&assigned_member, &assigned_member,
&org_id, &org_id,
&headers.user.uuid, &headers.user.uuid,
@ -2763,7 +2763,7 @@ async fn delete_group_impl(
}; };
log_event( log_event(
EventType::GroupDeleted as i32, EventType::GroupDeleted,
&group.uuid, &group.uuid,
org_id, org_id,
&headers.user.uuid, &headers.user.uuid,
@ -2874,7 +2874,7 @@ async fn put_group_members(
user_entry.save(&conn).await?; user_entry.save(&conn).await?;
log_event( log_event(
EventType::OrganizationUserUpdatedGroups as i32, EventType::OrganizationUserUpdatedGroups,
&assigned_member, &assigned_member,
&org_id, &org_id,
&headers.user.uuid, &headers.user.uuid,
@ -2912,7 +2912,7 @@ async fn post_delete_group_member(
} }
log_event( log_event(
EventType::OrganizationUserUpdatedGroups as i32, EventType::OrganizationUserUpdatedGroups,
&member_id, &member_id,
&org_id, &org_id,
&headers.user.uuid, &headers.user.uuid,
@ -3048,7 +3048,7 @@ async fn recover_account(
nt.send_logout(&user, None, &conn).await; nt.send_logout(&user, None, &conn).await;
log_event( log_event(
EventType::OrganizationUserAdminResetPassword as i32, EventType::OrganizationUserAdminResetPassword,
&member_id, &member_id,
&org_id, &org_id,
&headers.user.uuid, &headers.user.uuid,
@ -3197,10 +3197,12 @@ async fn put_reset_password_enrollment(
membership.save(&conn).await?; membership.save(&conn).await?;
} }
// Asked of the key that was just written rather than of the membership, which the branch above
// may have handed to `accept_org_invite`.
let event_type = if enrolled { let event_type = if enrolled {
EventType::OrganizationUserResetPasswordEnroll as i32 EventType::OrganizationUserResetPasswordEnroll
} else { } else {
EventType::OrganizationUserResetPasswordWithdraw as i32 EventType::OrganizationUserResetPasswordWithdraw
}; };
log_event(event_type, &membership_id, &org_id, &headers.user.uuid, headers.device.atype, &headers.ip.ip, &conn) log_event(event_type, &membership_id, &org_id, &headers.user.uuid, headers.device.atype, &headers.ip.ip, &conn)
@ -3447,9 +3449,9 @@ async fn answer_organization_auth_request(
auth_request.save(conn).await?; auth_request.save(conn).await?;
let event_type = if approved { let event_type = if approved {
EventType::OrganizationUserApprovedAuthRequest as i32 EventType::OrganizationUserApprovedAuthRequest
} else { } else {
EventType::OrganizationUserRejectedAuthRequest as i32 EventType::OrganizationUserRejectedAuthRequest
}; };
log_event(event_type, &member.uuid, org_id, &headers.user.uuid, headers.device.atype, &headers.ip.ip, conn).await; log_event(event_type, &member.uuid, org_id, &headers.user.uuid, headers.device.atype, &headers.ip.ip, conn).await;

14
src/api/core/two_factor/mod.rs

@ -190,7 +190,7 @@ pub async fn enforce_2fa_policy(
member.save(conn).await?; member.save(conn).await?;
log_event( log_event(
EventType::OrganizationUserRevoked as i32, EventType::OrganizationUserRevoked,
&member.uuid, &member.uuid,
&member.org_uuid, &member.org_uuid,
act_user_id, act_user_id,
@ -224,16 +224,8 @@ pub async fn enforce_2fa_policy_for_org(
member.revoke(); member.revoke();
member.save(conn).await?; member.save(conn).await?;
log_event( log_event(EventType::OrganizationUserRevoked, &member.uuid, org_id, act_user_id, device_type, ip, conn)
EventType::OrganizationUserRevoked as i32, .await;
&member.uuid,
org_id,
act_user_id,
device_type,
ip,
conn,
)
.await;
} }
} }

28
src/api/identity.rs

@ -234,6 +234,24 @@ async fn sso_login(
} }
) )
} }
Some((user, None))
if user.private_key.is_none()
&& !CONFIG.sso_signups_allowed()
&& !CONFIG.is_email_domain_allowed(&user.email)
&& !CONFIG.mail_enabled()
&& Invitation::find_by_mail(&user.email, conn).await.is_none() =>
{
error!(
"Login failure ({}), no invitation with email ({}) was found",
user_infos.identifier, user.email
);
err_silent!(
"Missing invitation",
ErrorEvent {
event: EventType::UserFailedLogIn
}
)
}
Some((user, None)) if user.private_key.is_some() && !CONFIG.sso_signups_match_email() => { Some((user, None)) if user.private_key.is_some() && !CONFIG.sso_signups_match_email() => {
error!( error!(
"Login failure ({}), existing non SSO user ({}) with same email ({}) and association is disabled", "Login failure ({}), existing non SSO user ({}) with same email ({}) and association is disabled",
@ -281,7 +299,15 @@ async fn sso_login(
// Will trigger 2FA flow if needed // Will trigger 2FA flow if needed
let (user, mut device, twofactor_token, sso_user) = match user_with_sso { let (user, mut device, twofactor_token, sso_user) = match user_with_sso {
None => { None => {
if !CONFIG.is_email_domain_allowed(&user_infos.email) { if !CONFIG.is_sso_signup_allowed(&user_infos.email) {
if CONFIG.signups_domains_whitelist().is_empty() {
err!(
"Signups are disabled. You will need an invitation",
ErrorEvent {
event: EventType::UserFailedLogIn
}
);
}
err!( err!(
"Email domain not allowed", "Email domain not allowed",
ErrorEvent { ErrorEvent {

20
src/config.rs

@ -817,6 +817,8 @@ make_config! {
sso_enabled: bool, true, def, false; sso_enabled: bool, true, def, false;
/// Only SSO login |> Disable Email+Master Password login /// Only SSO login |> Disable Email+Master Password login
sso_only: bool, true, def, false; sso_only: bool, true, def, false;
/// Allow SSO flow to create account |> You probably want to disable it when using a public provider
sso_signups_allowed: bool, true, def, true;
/// Allow email association |> Associate existing non-SSO user based on email /// Allow email association |> Associate existing non-SSO user based on email
sso_signups_match_email: bool, true, def, true; sso_signups_match_email: bool, true, def, true;
/// Allow unknown email verification status |> Allowing this with `SSO_SIGNUPS_MATCH_EMAIL=true` open potential account takeover. /// Allow unknown email verification status |> Allowing this with `SSO_SIGNUPS_MATCH_EMAIL=true` open potential account takeover.
@ -1170,11 +1172,8 @@ fn validate_config(cfg: &ConfigItems, on_update: bool) -> Result<(), Error> {
} }
#[cfg(unix)] #[cfg(unix)]
{ if nix::unistd::access(&path, nix::unistd::AccessFlags::X_OK).is_err() {
use std::os::unix::fs::PermissionsExt; err!(format!("sendmail command at `{path:?}` isn't executable"));
if !metadata.permissions().mode() & 0o111 != 0 {
err!(format!("sendmail command at `{path:?}` isn't executable"));
}
} }
} }
} }
@ -1555,6 +1554,17 @@ impl Config {
} }
} }
/// Tests whether SSO signup is allowed for an email address, taking into
/// account the sso_signups_allowed and signups_domains_whitelist settings.
pub fn is_sso_signup_allowed(&self, email: &str) -> bool {
if self.signups_domains_whitelist().is_empty() {
self.sso_signups_allowed()
} else {
// The whitelist setting overrides the signups_allowed setting.
self.is_email_domain_allowed(email)
}
}
// The registration link should be hidden if // The registration link should be hidden if
// - Signup is not allowed and email whitelist is empty unless mail is disabled and invitations are allowed // - Signup is not allowed and email whitelist is empty unless mail is disabled and invitations are allowed
// - The SSO is activated and password login is disabled. // - The SSO is activated and password login is disabled.

8
src/db/models/org_policy.rs

@ -91,6 +91,7 @@ impl OrgPolicy {
"type": self.atype, "type": self.atype,
"data": data_json, "data": data_json,
"enabled": self.enabled, "enabled": self.enabled,
"revisionDate": null,
"object": "policy", "object": "policy",
}); });
@ -317,6 +318,13 @@ impl OrgPolicy {
} }
pub async fn org_is_reset_password_auto_enroll(org_uuid: &OrganizationId, conn: &DbConn) -> bool { pub async fn org_is_reset_password_auto_enroll(org_uuid: &OrganizationId, conn: &DbConn) -> bool {
// Account recovery depends on outbound mail. When SMTP is disabled, treat the
// auto-enroll policy as inactive so invites/registration are not forced to
// supply a reset-password key (see check_reset_password_applicable).
if !CONFIG.mail_enabled() {
return false;
}
match OrgPolicy::find_by_org_and_type(org_uuid, OrgPolicyType::ResetPassword, conn).await { match OrgPolicy::find_by_org_and_type(org_uuid, OrgPolicyType::ResetPassword, conn).await {
Some(policy) => match serde_json::from_str::<ResetPasswordDataModel>(&policy.data) { Some(policy) => match serde_json::from_str::<ResetPasswordDataModel>(&policy.data) {
Ok(opts) => { Ok(opts) => {

Loading…
Cancel
Save