Tenancy: tenants verify the domain names they add (MT-24, 2026.x) #504
No files matched your search
@@ -73,6 +73,8 @@ pub const DOMAIN_FLAG_RELAY: u8 = 1;
|
||||
pub const DOMAIN_FLAG_SUB_ADDRESSING: u8 = 1 << 1;
|
||||
// inbuxa: SCIM-15, SCIM-58
|
||||
pub const DOMAIN_FLAG_SCIM: u8 = 1 << 2;
|
||||
// inbuxa: MT-24: a tenant added the domain and hasn't proven it owns its name
|
||||
pub const DOMAIN_FLAG_UNVERIFIED: u8 = 1 << 3;
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct AccountCache {
|
||||
@@ -361,4 +363,21 @@ impl DomainCache {
|
||||
pub fn allows_scim(&self) -> bool {
|
||||
self.flags & DOMAIN_FLAG_SCIM != 0
|
||||
}
|
||||
|
||||
// inbuxa: MT-24: whether the domain's own name is proven. An unproven
|
||||
// domain receives no mail, gives its accounts no addresses to send as
|
||||
// and signs nothing; its unproven aliases are left out of `names`.
|
||||
pub fn is_verified(&self) -> bool {
|
||||
self.flags & DOMAIN_FLAG_UNVERIFIED == 0
|
||||
}
|
||||
|
||||
// inbuxa: MT-24: whether mail for `name` is this domain's: a proven
|
||||
// domain and one of its proven names
|
||||
pub fn serves(&self, name: &str) -> bool {
|
||||
self.is_verified()
|
||||
&& self
|
||||
.names
|
||||
.iter()
|
||||
.any(|known| known.eq_ignore_ascii_case(name))
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -125,11 +125,16 @@ impl CacheInvalidationBuilder {
|
||||
// so turning SCIM's authority on or off has to take effect
|
||||
// without a restart
|
||||
|| (current.allow_scim_provisioning != new.allow_scim_provisioning)
|
||||
// inbuxa: MT-24, a name proven or put back to unproven
|
||||
|| (current.unverified_names != new.unverified_names)
|
||||
{
|
||||
self.invalidate(CacheInvalidation::Domain(id));
|
||||
}
|
||||
|
||||
if (current.name != new.name) || (current.aliases != new.aliases) {
|
||||
if (current.name != new.name)
|
||||
|| (current.aliases != new.aliases)
|
||||
|| (current.unverified_names != new.unverified_names)
|
||||
{
|
||||
self.invalidate(CacheInvalidation::DomainNegative);
|
||||
}
|
||||
|
||||
|
||||
+24
-10
@@ -66,7 +66,8 @@ impl Server {
|
||||
// Domain no longer exists, remove from name cache
|
||||
domain_names.remove(domain);
|
||||
}
|
||||
Ok(result)
|
||||
// inbuxa: MT-24: an unproven name is no local domain
|
||||
Ok(result.filter(|cached| cached.serves(domain)))
|
||||
} else {
|
||||
let domain_names_negative = &self.inner.cache.domain_names_negative;
|
||||
if domain_names_negative.get(domain).is_none() {
|
||||
@@ -91,17 +92,18 @@ impl Server {
|
||||
.caused_by(trc::location!())?;
|
||||
}
|
||||
|
||||
if let Some(domain) = object {
|
||||
if let Some(object) = object {
|
||||
// Cache positive result
|
||||
let domain_id = domain.id().document_id();
|
||||
let domain = self.domain_by_id(domain_id).await?;
|
||||
if let Some(domain) = &domain {
|
||||
for name in domain.names.iter() {
|
||||
let domain_id = object.id().document_id();
|
||||
let found = self.domain_by_id(domain_id).await?;
|
||||
if let Some(found) = &found {
|
||||
for name in found.names.iter() {
|
||||
domain_names.insert(name.clone(), domain_id);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(domain)
|
||||
// inbuxa: MT-24: an unproven name is no local domain
|
||||
Ok(found.filter(|cached| cached.serves(domain)))
|
||||
} else {
|
||||
// Cache negative result
|
||||
domain_names_negative.insert(
|
||||
@@ -153,7 +155,8 @@ impl Server {
|
||||
Key = domain_id,
|
||||
Collection = "domainId",
|
||||
);
|
||||
let Some(domain) = self.registry().object::<Domain>(domain_id.into()).await? else {
|
||||
let Some(mut domain) = self.registry().object::<Domain>(domain_id.into()).await?
|
||||
else {
|
||||
return Ok(None);
|
||||
};
|
||||
let mut flags = 0;
|
||||
@@ -165,6 +168,11 @@ impl Server {
|
||||
if domain.allow_scim_provisioning {
|
||||
flags |= crate::auth::DOMAIN_FLAG_SCIM;
|
||||
}
|
||||
// inbuxa: MT-24: names a tenant hasn't proven it owns
|
||||
if domain.unverified_names.contains(&domain.name) {
|
||||
flags |= crate::auth::DOMAIN_FLAG_UNVERIFIED;
|
||||
}
|
||||
let unverified = std::mem::take(&mut domain.unverified_names);
|
||||
|
||||
let sub_addressing_custom = match domain.sub_addressing {
|
||||
SubAddressing::Enabled => {
|
||||
@@ -195,6 +203,7 @@ impl Server {
|
||||
domain
|
||||
.aliases
|
||||
.into_iter()
|
||||
.filter(|alias| !unverified.contains(alias))
|
||||
.map(|alias| alias.into_boxed_str()),
|
||||
)
|
||||
.collect(),
|
||||
@@ -700,7 +709,10 @@ impl Server {
|
||||
let mut addresses =
|
||||
Vec::with_capacity(account.id_member_of.len() + account.addresses.len());
|
||||
for address in account.addresses.iter() {
|
||||
if let Some(domain) = self.domain_by_id(address.domain_id).await? {
|
||||
// inbuxa: MT-24: no addresses on a domain nobody has proven
|
||||
if let Some(domain) = self.domain_by_id(address.domain_id).await?
|
||||
&& domain.is_verified()
|
||||
{
|
||||
for name in domain.names.iter() {
|
||||
let mut addr = String::with_capacity(name.len() + address.local_part.len() + 1);
|
||||
addr.push_str(address.local_part.as_ref());
|
||||
@@ -714,7 +726,9 @@ impl Server {
|
||||
for &group_id in &account.id_member_of {
|
||||
if let Some(group) = self.try_account(group_id).await? {
|
||||
for address in group.addresses.iter() {
|
||||
if let Some(domain) = self.domain_by_id(address.domain_id).await? {
|
||||
if let Some(domain) = self.domain_by_id(address.domain_id).await?
|
||||
&& domain.is_verified()
|
||||
{
|
||||
for name in domain.names.iter() {
|
||||
let mut addr =
|
||||
String::with_capacity(name.len() + address.local_part.len() + 1);
|
||||
|
||||
@@ -152,7 +152,12 @@ pub async fn plan(
|
||||
|
||||
// The destination's limits, the domain itself included
|
||||
if let Some(tenant_id) = to {
|
||||
*adding.entry(TenantStorageQuota::MaxDomains).or_default() += 1;
|
||||
// the domain itself, each of its names (MT-24)
|
||||
let names = match registry.get(domain).await? {
|
||||
Some(object) => quota::domain_names(&object.inner),
|
||||
None => 1,
|
||||
};
|
||||
*adding.entry(TenantStorageQuota::MaxDomains).or_default() += names;
|
||||
let mut quotas = adding.into_iter().collect::<Vec<_>>();
|
||||
quotas.sort_unstable_by_key(|(quota, _)| *quota as u16);
|
||||
for (quota, count) in quotas {
|
||||
|
||||
@@ -91,11 +91,35 @@ pub async fn count(
|
||||
if let Some(kind) = kind {
|
||||
query = query.equal(Property::Type, kind);
|
||||
}
|
||||
registry
|
||||
let ids = registry
|
||||
.query::<Vec<Id>>(query)
|
||||
.await
|
||||
.map(|ids| ids.len() as u64)
|
||||
.caused_by(trc::location!())
|
||||
.caused_by(trc::location!())?;
|
||||
|
||||
// MT-24: every name a tenant's domains answer to counts, aliases too
|
||||
if quota == TenantStorageQuota::MaxDomains {
|
||||
let mut total = 0u64;
|
||||
for id in ids {
|
||||
if let Some(object) = registry
|
||||
.get(ObjectId::new(ObjectType::Domain, id))
|
||||
.await
|
||||
.caused_by(trc::location!())?
|
||||
{
|
||||
total += domain_names(&object.inner);
|
||||
}
|
||||
}
|
||||
return Ok(total);
|
||||
}
|
||||
Ok(ids.len() as u64)
|
||||
}
|
||||
|
||||
/// How many names a domain counts as against maxDomains (MT-24): its own
|
||||
/// and each alias. 1 for anything else.
|
||||
pub fn domain_names(object: &ObjectInner) -> u64 {
|
||||
match object {
|
||||
ObjectInner::Domain(domain) => 1 + domain.aliases.len() as u64,
|
||||
_ => 1,
|
||||
}
|
||||
}
|
||||
|
||||
/// A count limit that adding objects would cross.
|
||||
|
||||
@@ -121,8 +121,15 @@ pub async fn check(
|
||||
&& let Some(quota) = quota::limit_for(&new.inner)
|
||||
{
|
||||
let limit = limits(registry, tenant_id).await?;
|
||||
if let Err(reached) =
|
||||
quota::check(registry, tenant_id.document_id(), quota, limit(quota), 1).await?
|
||||
let adding = quota::domain_names(&new.inner);
|
||||
if let Err(reached) = quota::check(
|
||||
registry,
|
||||
tenant_id.document_id(),
|
||||
quota,
|
||||
limit(quota),
|
||||
adding,
|
||||
)
|
||||
.await?
|
||||
{
|
||||
return Ok(Err(over_quota(reached, tenant_id)));
|
||||
}
|
||||
@@ -143,6 +150,29 @@ pub async fn check(
|
||||
}
|
||||
}
|
||||
|
||||
// MT-24: a domain given more aliases counts each one against maxDomains
|
||||
if let (Some(old), Some(tenant_id), ObjectInner::Domain(_)) = (old, tenant, &new.inner)
|
||||
&& old.inner.member_tenant_id() == tenant
|
||||
{
|
||||
let before = quota::domain_names(&old.inner);
|
||||
let now = quota::domain_names(&new.inner);
|
||||
if now > before {
|
||||
let quota = TenantStorageQuota::MaxDomains;
|
||||
let limit = limits(registry, tenant_id).await?;
|
||||
if let Err(reached) = quota::check(
|
||||
registry,
|
||||
tenant_id.document_id(),
|
||||
quota,
|
||||
limit(quota),
|
||||
now - before,
|
||||
)
|
||||
.await?
|
||||
{
|
||||
return Ok(Err(over_quota(reached, tenant_id)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Ok(after))
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2026 Coffey Labs LLC
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
//! MT-24: a tenant proves it owns the domain names it adds.
|
||||
//!
|
||||
//! A domain name or alias a tenant administrator adds is saved as unverified.
|
||||
//! An unverified name receives no mail, gives no addresses to send as and
|
||||
//! signs nothing (see `DomainCache::serves`), so a tenant can't take mail
|
||||
//! meant for a name it doesn't own. The tenant proves a name by publishing a
|
||||
//! TXT record at `_inbuxa-verification.<name>` with
|
||||
//! `inbuxa-verification=<token>`, the domain's `verificationToken`, then
|
||||
//! taking the name off `unverifiedNames`: the save looks the record up and
|
||||
//! is refused if it isn't there. Names a server administrator adds are
|
||||
//! trusted, and a server administrator can clear or add entries freely.
|
||||
|
||||
use common::{Server, auth::AccessToken};
|
||||
use jmap_proto::error::set::SetError;
|
||||
use rand::{RngExt, distr::Alphanumeric};
|
||||
use registry::schema::{prelude::Property, structs::Domain};
|
||||
|
||||
/// The TXT record's owner name, without the trailing dot.
|
||||
pub fn record_name(name: &str) -> String {
|
||||
format!("_inbuxa-verification.{name}")
|
||||
}
|
||||
|
||||
/// What the TXT record must contain.
|
||||
pub fn record_value(token: &str) -> String {
|
||||
format!("inbuxa-verification={token}")
|
||||
}
|
||||
|
||||
fn new_token() -> String {
|
||||
rand::rng()
|
||||
.sample_iter(Alphanumeric)
|
||||
.take(32)
|
||||
.map(char::from)
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn names(domain: &Domain) -> impl Iterator<Item = &String> {
|
||||
std::iter::once(&domain.name).chain(domain.aliases.iter())
|
||||
}
|
||||
|
||||
/// Applies MT-24 to a domain about to be saved: names the domain no longer
|
||||
/// has are forgotten, names a tenant adds start unverified, and names a
|
||||
/// tenant takes off the list must be proven in DNS now.
|
||||
pub async fn check(
|
||||
server: &Server,
|
||||
access_token: &AccessToken,
|
||||
domain: &mut Domain,
|
||||
old: Option<&Domain>,
|
||||
) -> trc::Result<Result<(), SetError<Property>>> {
|
||||
let current = names(domain).cloned().collect::<Vec<_>>();
|
||||
domain
|
||||
.unverified_names
|
||||
.inner_mut()
|
||||
.retain(|name| current.contains(name));
|
||||
|
||||
if access_token.tenant_id().is_some() {
|
||||
let before = old.map(|old| names(old).collect::<Vec<_>>());
|
||||
for name in ¤t {
|
||||
if before.as_ref().is_none_or(|before| !before.contains(&name))
|
||||
&& !domain.unverified_names.contains(name)
|
||||
{
|
||||
domain.unverified_names.push(name.clone());
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(old) = old {
|
||||
let to_prove = old
|
||||
.unverified_names
|
||||
.iter()
|
||||
.filter(|name| current.contains(name) && !domain.unverified_names.contains(name))
|
||||
.collect::<Vec<_>>();
|
||||
if !to_prove.is_empty() {
|
||||
let Some(token) = old.verification_token.as_deref() else {
|
||||
return Ok(Err(unproven(to_prove[0], None)));
|
||||
};
|
||||
for name in to_prove {
|
||||
if !proven(server, name, token).await {
|
||||
return Ok(Err(unproven(name, Some(token))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !domain.unverified_names.is_empty() && domain.verification_token.is_none() {
|
||||
domain.verification_token = Some(new_token());
|
||||
}
|
||||
Ok(Ok(()))
|
||||
}
|
||||
|
||||
/// Records the system tests publish, as they have no DNS of their own.
|
||||
#[cfg(feature = "test_mode")]
|
||||
pub static TEST_RECORDS: std::sync::LazyLock<
|
||||
std::sync::Mutex<std::collections::HashMap<String, String>>,
|
||||
> = std::sync::LazyLock::new(Default::default);
|
||||
|
||||
/// Whether `name`'s verification record carries `token`.
|
||||
async fn proven(server: &Server, name: &str, token: &str) -> bool {
|
||||
let expected = record_value(token);
|
||||
#[cfg(feature = "test_mode")]
|
||||
if let Some(found) = TEST_RECORDS.lock().unwrap().get(&record_name(name)) {
|
||||
return record_matches(found.as_bytes(), &expected);
|
||||
}
|
||||
match server
|
||||
.core
|
||||
.smtp
|
||||
.resolvers
|
||||
.dns
|
||||
.txt_raw_lookup(format!("{}.", record_name(name)))
|
||||
.await
|
||||
{
|
||||
Ok(found) => record_matches(&found, &expected),
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// The record's text holds the expected value as a whole word.
|
||||
fn record_matches(found: &[u8], expected: &str) -> bool {
|
||||
std::str::from_utf8(found).is_ok_and(|text| {
|
||||
text.split(|c: char| c.is_whitespace() || c == '"')
|
||||
.any(|part| part == expected)
|
||||
})
|
||||
}
|
||||
|
||||
fn unproven(name: &str, token: Option<&str>) -> SetError<Property> {
|
||||
SetError::invalid_properties()
|
||||
.with_property(Property::UnverifiedNames)
|
||||
.with_description(match token {
|
||||
Some(token) => format!(
|
||||
"{name} isn't proven yet. Publish a TXT record at {} with the value {}, \
|
||||
then try again. DNS changes can take a few minutes to appear.",
|
||||
record_name(name),
|
||||
record_value(token),
|
||||
),
|
||||
None => format!("{name} has no verification token to check against."),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn the_record_must_hold_the_whole_value() {
|
||||
let expected = record_value("abc123");
|
||||
assert!(record_matches(b"inbuxa-verification=abc123", &expected));
|
||||
assert!(record_matches(
|
||||
b"v=spf1 -all inbuxa-verification=abc123",
|
||||
&expected
|
||||
));
|
||||
assert!(record_matches(b"\"inbuxa-verification=abc123\"", &expected));
|
||||
assert!(!record_matches(b"inbuxa-verification=abc1234", &expected));
|
||||
assert!(!record_matches(b"xinbuxa-verification=abc123", &expected));
|
||||
assert!(!record_matches(b"", &expected));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn names_and_values() {
|
||||
assert_eq!(
|
||||
record_name("example.org"),
|
||||
"_inbuxa-verification.example.org"
|
||||
);
|
||||
assert_eq!(record_value("t"), "inbuxa-verification=t");
|
||||
assert_eq!(new_token().len(), 32);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ pub mod deleted_account;
|
||||
pub mod deliverability; // inbuxa: the deliverability check
|
||||
pub mod directory_test;
|
||||
pub mod dlp_settings;
|
||||
pub mod domain_verification; // inbuxa: MT-24
|
||||
pub mod explanation;
|
||||
pub mod fastmail;
|
||||
pub mod front_ends;
|
||||
|
||||
@@ -65,6 +65,14 @@ pub(crate) async fn validate_domain(
|
||||
.with_description(err)));
|
||||
}
|
||||
|
||||
// inbuxa: MT-24: a tenant proves the names it adds
|
||||
if let Err(err) =
|
||||
crate::inbuxa::domain_verification::check(set.server, set.access_token, domain, old_domain)
|
||||
.await?
|
||||
{
|
||||
return Ok(Err(err));
|
||||
}
|
||||
|
||||
// Validate that names and aliases do not collide with another domain
|
||||
let registry = set.server.registry();
|
||||
if old_domain.is_none_or(|old| old.name != domain.name)
|
||||
|
||||
@@ -11,8 +11,9 @@ use crate::{
|
||||
schema::{
|
||||
enums::OidcOpaqueTokens,
|
||||
prelude::{ObjectImpl, ObjectInner, ObjectType},
|
||||
structs::{Bootstrap, Directory, DirectoryBootstrap, OidcDirectory},
|
||||
structs::{Bootstrap, Directory, DirectoryBootstrap, Domain, OidcDirectory},
|
||||
},
|
||||
types::map::Map,
|
||||
};
|
||||
|
||||
/// An OIDC directory as it was stored before the opaque-token fields.
|
||||
@@ -108,3 +109,40 @@ fn oidc_directories_saved_before_the_opaque_token_policy_keep_userinfo() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// MT-24: a domain saved before verification (version 1) reads back with every
|
||||
// name trusted. Saved now it's version 4, laid out as 27.1 stores it: 27.1's
|
||||
// logoDark and passkeysAllowed at their defaults, then the verification fields
|
||||
#[test]
|
||||
fn domains_saved_before_verification_trust_their_names() {
|
||||
let domain = Domain {
|
||||
name: "example.org".to_string(),
|
||||
aliases: Map::new(vec!["example.net".to_string()]),
|
||||
allow_scim_provisioning: true,
|
||||
..Default::default()
|
||||
};
|
||||
let mut tail = Vec::new();
|
||||
None::<String>.pickle(&mut tail);
|
||||
true.pickle(&mut tail);
|
||||
Map::<String>::default().pickle(&mut tail);
|
||||
None::<String>.pickle(&mut tail);
|
||||
let mut bytes = domain.to_pickled_vec();
|
||||
assert_eq!(bytes[0], 4);
|
||||
assert!(bytes.ends_with(&tail));
|
||||
bytes.truncate(bytes.len() - tail.len());
|
||||
bytes[0] = 1;
|
||||
assert_eq!(
|
||||
read(ObjectType::Domain, &bytes),
|
||||
ObjectInner::Domain(domain.clone())
|
||||
);
|
||||
|
||||
let domain = Domain {
|
||||
unverified_names: Map::new(vec!["example.net".to_string()]),
|
||||
verification_token: Some("token".to_string()),
|
||||
..domain
|
||||
};
|
||||
assert_eq!(
|
||||
read(ObjectType::Domain, &domain.to_pickled_vec()),
|
||||
ObjectInner::Domain(domain)
|
||||
);
|
||||
}
|
||||
@@ -1162,6 +1162,7 @@ pub enum Property {
|
||||
TsigAlgorithm = 338,
|
||||
Ttl = 310,
|
||||
UnpackDirectory = 54,
|
||||
UnverifiedNames = 948,
|
||||
UpdateRecords = 812,
|
||||
UploadQuota = 445,
|
||||
UploadTtl = 446,
|
||||
@@ -1182,6 +1183,7 @@ pub enum Property {
|
||||
ValidateDomain = 413,
|
||||
Value = 492,
|
||||
VariableName = 675,
|
||||
VerificationToken = 949,
|
||||
VerifyAfterWrite = 874,
|
||||
Version = 80,
|
||||
ViewName = 884,
|
||||
|
||||
@@ -1314,6 +1314,7 @@ impl EnumImpl for Property {
|
||||
b"tsigAlgorithm" => Property::TsigAlgorithm,
|
||||
b"ttl" => Property::Ttl,
|
||||
b"unpackDirectory" => Property::UnpackDirectory,
|
||||
b"unverifiedNames" => Property::UnverifiedNames,
|
||||
b"updateRecords" => Property::UpdateRecords,
|
||||
b"uploadQuota" => Property::UploadQuota,
|
||||
b"uploadTtl" => Property::UploadTtl,
|
||||
@@ -1334,6 +1335,7 @@ impl EnumImpl for Property {
|
||||
b"validateDomain" => Property::ValidateDomain,
|
||||
b"value" => Property::Value,
|
||||
b"variableName" => Property::VariableName,
|
||||
b"verificationToken" => Property::VerificationToken,
|
||||
b"verifyAfterWrite" => Property::VerifyAfterWrite,
|
||||
b"version" => Property::Version,
|
||||
b"viewName" => Property::ViewName,
|
||||
@@ -2258,6 +2260,8 @@ impl EnumImpl for Property {
|
||||
Property::TsigAlgorithm => "tsigAlgorithm",
|
||||
Property::Ttl => "ttl",
|
||||
Property::UnpackDirectory => "unpackDirectory",
|
||||
Property::UnverifiedNames => "unverifiedNames",
|
||||
Property::VerificationToken => "verificationToken",
|
||||
Property::UpdateRecords => "updateRecords",
|
||||
Property::UploadQuota => "uploadQuota",
|
||||
Property::UploadTtl => "uploadTtl",
|
||||
@@ -3033,6 +3037,8 @@ impl EnumImpl for Property {
|
||||
936 => Some(Property::IntrospectionUrl),
|
||||
937 => Some(Property::IntrospectionClientId),
|
||||
938 => Some(Property::IntrospectionClientSecret),
|
||||
948 => Some(Property::UnverifiedNames),
|
||||
949 => Some(Property::VerificationToken),
|
||||
615 => Some(Property::RequireClientRegistration),
|
||||
608 => Some(Property::RequireScopes),
|
||||
525 => Some(Property::RequireTls),
|
||||
@@ -3244,7 +3250,7 @@ impl EnumImpl for Property {
|
||||
}
|
||||
}
|
||||
|
||||
const COUNT: usize = 939;
|
||||
const COUNT: usize = 950;
|
||||
}
|
||||
|
||||
impl serde::Serialize for Property {
|
||||
|
||||
@@ -2737,6 +2737,12 @@ pub struct Domain {
|
||||
pub description: Option<String>,
|
||||
#[serde(rename = "logo")]
|
||||
pub logo: Option<String>,
|
||||
// inbuxa: MT-24: names a tenant added that nobody has proven it owns
|
||||
// yet, and the token its TXT records must carry
|
||||
#[serde(rename = "unverifiedNames")]
|
||||
pub unverified_names: Map<String>,
|
||||
#[serde(rename = "verificationToken")]
|
||||
pub verification_token: Option<String>,
|
||||
#[serde(rename = "certificateManagement")]
|
||||
pub certificate_management: CertificateManagement,
|
||||
#[serde(rename = "dkimManagement")]
|
||||
|
||||
@@ -19842,7 +19842,11 @@ impl RegistryJsonPropertyPatch for DnsServerYandexCloud {
|
||||
|
||||
impl ObjectImpl for Domain {
|
||||
const FLAGS: u64 = OBJ_FILTER_TENANT | OBJ_SEQ_ID;
|
||||
const VERSION: u8 = 1;
|
||||
// inbuxa: 4: unverifiedNames, verificationToken (MT-24). Versions 2 and 3
|
||||
// hold 27.1's logoDark and passkeysAllowed, which this series doesn't have:
|
||||
// it writes their defaults in their place and skips them when reading, so
|
||||
// a record upgraded to 27.1 reads back the same
|
||||
const VERSION: u8 = 4;
|
||||
const OBJECT: ObjectType = ObjectType::Domain;
|
||||
|
||||
fn validate(&self, errors: &mut Vec<ValidationError>) -> bool {
|
||||
@@ -19899,6 +19903,11 @@ impl ObjectImpl for Domain {
|
||||
errors.push(ValidationError::required(Property::ReportAddressUri));
|
||||
}
|
||||
}
|
||||
for value in self.unverified_names.iter() {
|
||||
if value.is_empty() {
|
||||
errors.push(ValidationError::required(Property::UnverifiedNames));
|
||||
}
|
||||
}
|
||||
errors.len() == neb
|
||||
}
|
||||
|
||||
@@ -19942,6 +19951,12 @@ impl Pickle for Domain {
|
||||
self.allow_relaying.pickle(out);
|
||||
self.report_address_uri.pickle(out);
|
||||
self.allow_scim_provisioning.pickle(out);
|
||||
// inbuxa: 27.1's logoDark (version 2) and passkeysAllowed (version 3),
|
||||
// at their defaults
|
||||
None::<String>.pickle(out);
|
||||
true.pickle(out);
|
||||
self.unverified_names.pickle(out);
|
||||
self.verification_token.pickle(out);
|
||||
}
|
||||
|
||||
fn unpickle(stream: &mut crate::pickle::PickledStream<'_>) -> Option<Self> {
|
||||
@@ -19964,6 +19979,19 @@ impl Pickle for Domain {
|
||||
if stream.version() >= 1 {
|
||||
this.allow_scim_provisioning = Pickle::unpickle(stream)?;
|
||||
}
|
||||
// inbuxa: 27.1's logoDark (version 2) and passkeysAllowed (version 3),
|
||||
// not kept in this series
|
||||
if stream.version() >= 2 {
|
||||
let _: Option<String> = Pickle::unpickle(stream)?;
|
||||
}
|
||||
if stream.version() >= 3 {
|
||||
let _: bool = Pickle::unpickle(stream)?;
|
||||
}
|
||||
// inbuxa: MT-24, stored from version 4; names saved before are trusted
|
||||
if stream.version() >= 4 {
|
||||
this.unverified_names = Pickle::unpickle(stream)?;
|
||||
this.verification_token = Pickle::unpickle(stream)?;
|
||||
}
|
||||
Some(this)
|
||||
}
|
||||
}
|
||||
@@ -19977,6 +20005,8 @@ impl Default for Domain {
|
||||
created_at: Default::default(),
|
||||
description: Default::default(),
|
||||
logo: Default::default(),
|
||||
unverified_names: Default::default(),
|
||||
verification_token: None,
|
||||
certificate_management: Default::default(),
|
||||
dkim_management: Default::default(),
|
||||
dns_management: Default::default(),
|
||||
@@ -19993,7 +20023,7 @@ impl Default for Domain {
|
||||
|
||||
impl IntoValue for Domain {
|
||||
fn into_value(self) -> JmapValue<'static> {
|
||||
let mut map = jmap_tools::Map::with_capacity(18);
|
||||
let mut map = jmap_tools::Map::with_capacity(20);
|
||||
map.insert_unchecked(Property::Name, self.name.into_value());
|
||||
map.insert_unchecked(Property::Aliases, self.aliases.into_value());
|
||||
map.insert_unchecked(Property::IsEnabled, self.is_enabled.into_value());
|
||||
@@ -20022,6 +20052,14 @@ impl IntoValue for Domain {
|
||||
Property::AllowScimProvisioning,
|
||||
self.allow_scim_provisioning.into_value(),
|
||||
);
|
||||
map.insert_unchecked(
|
||||
Property::UnverifiedNames,
|
||||
self.unverified_names.into_value(),
|
||||
);
|
||||
map.insert_unchecked(
|
||||
Property::VerificationToken,
|
||||
self.verification_token.into_value(),
|
||||
);
|
||||
JmapValue::Object(map)
|
||||
}
|
||||
}
|
||||
@@ -20064,6 +20102,11 @@ impl RegistryJsonPropertyPatch for Domain {
|
||||
Some(Property::AllowScimProvisioning) => {
|
||||
self.allow_scim_provisioning.patch(pointer, value)
|
||||
}
|
||||
// inbuxa: MT-24: what a tenant may change here is checked on save
|
||||
Some(Property::UnverifiedNames) => self
|
||||
.unverified_names
|
||||
.patch(pointer.with_validators(&[StringValidator::Domain]), value),
|
||||
Some(Property::VerificationToken) => pointer.assert_server_set(),
|
||||
Some(Property::Type) => Ok(MaybeUnpatched::Unpatched {
|
||||
property: Property::Type,
|
||||
value,
|
||||
|
||||
@@ -263,6 +263,25 @@ Each requirement has an ID, and tests name the IDs they check.
|
||||
`usedDiskQuota` from its members' actual usage. `resetTenantQuotas`
|
||||
recomputes every tenant. Both can run while the server is live.
|
||||
|
||||
- **MT-24.** A tenant proves it owns the domain names it adds. A domain
|
||||
name or alias that a tenant administrator adds is saved in the domain's
|
||||
`unverifiedNames`, and the domain gets a `verificationToken` (32
|
||||
characters, set by the server, read-only). An unverified name is not a
|
||||
local domain: mail for it isn't taken in, it gives no addresses to send
|
||||
as, and nothing is signed for it. A domain whose own name is unverified is
|
||||
all of that for every name it has. The tenant proves a name by publishing
|
||||
a TXT record at `_inbuxa-verification.<name>` with the value
|
||||
`inbuxa-verification=<token>`, then taking the name off `unverifiedNames`.
|
||||
The save looks the record up and is refused with `invalidProperties`
|
||||
naming the record if it isn't there. Names a server administrator adds are
|
||||
trusted, and a server administrator may clear or add entries freely.
|
||||
Names saved before MT-24 are trusted. Every name counts against
|
||||
`maxDomains`: a domain is 1 plus its aliases, on create, on an update that
|
||||
adds aliases, and on a move into a tenant.
|
||||
**Why:** a domain name on a server belongs to whoever controls it in DNS,
|
||||
and a tenant's names should be its own, the same rule hosted mail
|
||||
services use (inbuxa-admin#257 follow-up).
|
||||
|
||||
### Branding
|
||||
|
||||
- **MT-22.** A signed-in principal can read the logo that applies to it: its
|
||||
@@ -343,7 +362,7 @@ Built 2026-09-18 from this spec, clean-room (hand-off brief
|
||||
`inbuxa: MT-n`. Acceptance tests 1 to 14 pass as `tests/src/system/tenant.rs`,
|
||||
called from `system_tests` with no gate.
|
||||
|
||||
- **MT-1 to MT-18, MT-20 to MT-23:** built.
|
||||
- **MT-1 to MT-18, MT-20 to MT-24:** built.
|
||||
- **MT-19, MT-19a:** built, except the submission-time warning, **deferred**
|
||||
(see MT-19a) until the contract defines a warnings shape.
|
||||
- **ihasmail changes** (the section above) belong to inbuxa-webmail and
|
||||
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
mF1m1A-76ThstOP9qsGUtzCS3tgqAF0rKBrla9jY5xI
|
||||
kb3N4xMMpWKw0bFaNm03Dx6o6f7uwuUF1TP4zH8c5lE
|
||||
+151
-1
@@ -830,7 +830,7 @@ pub async fn test(test: &mut TestServer) {
|
||||
// Acceptance test 13: the tenant's disk limit bounds all its members
|
||||
// together (MT-19, MT-20)
|
||||
let d_id = admin.create_tenant("Tenant D").await;
|
||||
admin
|
||||
let d_domain = admin
|
||||
.create_tenant_domain("d.example.org", Some(d_id))
|
||||
.await;
|
||||
let d_admin = admin
|
||||
@@ -963,6 +963,156 @@ pub async fn test(test: &mut TestServer) {
|
||||
test.wait_for_tasks().await;
|
||||
assert_eq!(admin.tenant_usage(d_id).await, two, "test 14");
|
||||
|
||||
// MT-24: a tenant proves the domain names it adds, and every name counts
|
||||
// against maxDomains
|
||||
admin
|
||||
.set_tenant_quota(d_id, TenantStorageQuota::MaxDomains, 3)
|
||||
.await;
|
||||
let claimed = "claimed.example.net";
|
||||
d_admin
|
||||
.registry_update_object(
|
||||
ObjectType::Domain,
|
||||
d_domain,
|
||||
json!({ Property::Aliases: { claimed: true } }),
|
||||
)
|
||||
.await;
|
||||
let stored = admin.registry_get::<Domain>(d_domain).await;
|
||||
assert_eq!(stored.unverified_names.as_slice(), [claimed.to_string()]);
|
||||
let token = stored.verification_token.clone().expect("MT-24: a token");
|
||||
assert!(
|
||||
test.server.domain(claimed).await.unwrap().is_none(),
|
||||
"MT-24: an unproven alias takes no mail"
|
||||
);
|
||||
assert!(test.server.domain("d.example.org").await.unwrap().is_some());
|
||||
// Taking it off the list without the record is refused, naming it
|
||||
d_admin
|
||||
.registry_update_object_expect_err(
|
||||
ObjectType::Domain,
|
||||
d_domain,
|
||||
json!({ Property::UnverifiedNames: {} }),
|
||||
)
|
||||
.await
|
||||
.assert_type(SetErrorType::InvalidProperties)
|
||||
.assert_description_contains("_inbuxa-verification.claimed.example.net");
|
||||
// A record with another token doesn't do either
|
||||
::jmap::inbuxa::domain_verification::TEST_RECORDS
|
||||
.lock()
|
||||
.unwrap()
|
||||
.insert(
|
||||
format!("_inbuxa-verification.{claimed}"),
|
||||
"inbuxa-verification=someone-else".to_string(),
|
||||
);
|
||||
d_admin
|
||||
.registry_update_object_expect_err(
|
||||
ObjectType::Domain,
|
||||
d_domain,
|
||||
json!({ Property::UnverifiedNames: {} }),
|
||||
)
|
||||
.await
|
||||
.assert_type(SetErrorType::InvalidProperties);
|
||||
// With the record, it's proven and takes mail
|
||||
::jmap::inbuxa::domain_verification::TEST_RECORDS
|
||||
.lock()
|
||||
.unwrap()
|
||||
.insert(
|
||||
format!("_inbuxa-verification.{claimed}"),
|
||||
format!("inbuxa-verification={token}"),
|
||||
);
|
||||
d_admin
|
||||
.registry_update_object(
|
||||
ObjectType::Domain,
|
||||
d_domain,
|
||||
json!({ Property::UnverifiedNames: {} }),
|
||||
)
|
||||
.await;
|
||||
assert!(
|
||||
test.server.domain(claimed).await.unwrap().is_some(),
|
||||
"MT-24: a proven alias takes mail"
|
||||
);
|
||||
// The token can't be set by anyone
|
||||
d_admin
|
||||
.registry_update_object_expect_err(
|
||||
ObjectType::Domain,
|
||||
d_domain,
|
||||
json!({ Property::VerificationToken: "mine" }),
|
||||
)
|
||||
.await;
|
||||
// Two names in use of three: two more aliases don't fit
|
||||
d_admin
|
||||
.registry_update_object_expect_err(
|
||||
ObjectType::Domain,
|
||||
d_domain,
|
||||
json!({ Property::Aliases: { claimed: true, "a1.example.net": true, "a2.example.net": true } }),
|
||||
)
|
||||
.await
|
||||
.assert_type(SetErrorType::OverQuota)
|
||||
.assert_description_contains("maxDomains");
|
||||
// A domain the tenant creates is unproven as a whole
|
||||
let created = d_admin
|
||||
.registry_create_object(Domain {
|
||||
name: "new.example.net".to_string(),
|
||||
is_enabled: true,
|
||||
certificate_management: CertificateManagement::Manual,
|
||||
dns_management: DnsManagement::Manual,
|
||||
dkim_management: DkimManagement::Manual,
|
||||
..Default::default()
|
||||
})
|
||||
.await;
|
||||
assert!(
|
||||
test.server
|
||||
.domain("new.example.net")
|
||||
.await
|
||||
.unwrap()
|
||||
.is_none(),
|
||||
"MT-24: an unproven domain takes no mail"
|
||||
);
|
||||
assert_eq!(
|
||||
admin
|
||||
.registry_get::<Domain>(created)
|
||||
.await
|
||||
.unverified_names
|
||||
.as_slice(),
|
||||
["new.example.net".to_string()]
|
||||
);
|
||||
// An alias the server administrator adds is trusted, and so is clearing
|
||||
// the list for the tenant
|
||||
admin
|
||||
.registry_update_object(
|
||||
ObjectType::Domain,
|
||||
created,
|
||||
json!({ Property::UnverifiedNames: {} }),
|
||||
)
|
||||
.await;
|
||||
assert!(
|
||||
test.server
|
||||
.domain("new.example.net")
|
||||
.await
|
||||
.unwrap()
|
||||
.is_some()
|
||||
);
|
||||
admin
|
||||
.registry_destroy(ObjectType::Domain, [created])
|
||||
.await
|
||||
.assert_destroyed(&[created]);
|
||||
admin
|
||||
.registry_update_object(
|
||||
ObjectType::Domain,
|
||||
d_domain,
|
||||
json!({ Property::Aliases: { claimed: true, "by-admin.example.net": true } }),
|
||||
)
|
||||
.await;
|
||||
assert!(
|
||||
test.server
|
||||
.domain("by-admin.example.net")
|
||||
.await
|
||||
.unwrap()
|
||||
.is_some()
|
||||
);
|
||||
::jmap::inbuxa::domain_verification::TEST_RECORDS
|
||||
.lock()
|
||||
.unwrap()
|
||||
.clear();
|
||||
|
||||
// Clean up, leaving the server as the other tests expect it
|
||||
for account in [
|
||||
t_admin, t_user, t_group, u_admin, u_user, u_group, p_admin, p_user, s_user, d_admin,
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <[email protected]>
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*
|
||||
* Modified by Coffey Labs in 2026 for INBUXA.
|
||||
*/
|
||||
|
||||
use crate::utils::{
|
||||
@@ -458,6 +460,7 @@ fn remove_server_set_props(typ: ObjectType, value: &mut serde_json::Value) {
|
||||
"retireAt",
|
||||
"accountKey",
|
||||
"accountUri",
|
||||
"verificationToken",
|
||||
]
|
||||
.contains(&k.as_str())
|
||||
|| (is_app_pass && k == "secret")
|
||||
|
||||
Reference in new issue
Block a user