What administrators and the server itself do to the control plane is now recorded, from inbuxa-drafts/specs/audit-hold-lock.md (AU-1 to AU-12): settings, accounts, domains, roles and every other registry change, with each field's before and after (secrets only as "changed"); the fork's own settings objects; administrator sign-ins (and failed ones to administrator accounts), master-user and recovery-admin sign-ins, once an hour per account, method and address; access to another account's data through impersonation or FetchAnyBlob, once an hour; exports and tamper checks; and registry writes the server makes on its own, named by subsystem (system:AcmeRenewal, system:auto-ban, system:directory-sync, ...), with a spam rules update as one summary record. No change without its record (AU-3): before a set method changes anything, a pending record per requested create, update and destroy is written; if that fails, the method is refused with serverFail. Its outcome follows as a later entry. A change interrupted by a crash stays "unfinished". Records live in the fork's subspace under L, as one SHA-256 hash chain per node. The chain's head is stored, never cached, and every append asserts it, so two writers can't take the same place. Nothing can edit or delete a record; the daily purge removes the oldest past the retention (default 730 days, minimum 90) and records where the chain now starts, so verification still passes. security.audit-recorded (647) copies each record to webhooks, OpenTelemetry and the log; security.audit-write-failed (648) reports a failed write. New JMAP objects under urn:inbuxa:jmap: inbuxa:AuditEvent/get and /query (filters: time, actor, action, target, account, tenant, outcome, address, text), inbuxa:AuditSettings, inbuxa:AuditExport (CSV or JSON Lines built on the server, each line with its chain hash, ending in a manifest; the created object names the blob and its SHA-256) and inbuxa:AuditVerification. New permissions sysAuditGet, sysAuditExport and sysAuditSettingsUpdate: the Administrator role gets all three, the Tenant Administrator role gets read and export, once, on existing installs too. A tenant administrator sees records whose actor or target is in its tenant, including a server administrator's changes there. Sign-in method on the session: access tokens now remember how they signed in (password, app password, API key, OAuth client, directory, master user, recovery admin), including across the HTTP credential cache. New OAuth access tokens carry their client id in the sealed claims; older ones show as client "unknown" until they expire. The schema gains the permissions, the two events and a Management > Compliance > Audit Log link. Stack: the request layer boxes every inner future where it's made. Without that, a debug build overflowed the default 2 MB worker stack on a registry set; measured with the same request, the branch and main now overflow at the same stack size (between 1856 and 1920 KiB, debug), so the layer adds nothing measurable. Tests: unit tests in inbuxa-features and jmap; system::audit::audit_log_tests (run with --ignored) passes on RocksDB, SQLite, PostgreSQL, PostgreSQL with a read replica, MySQL, MySQL with a replica and FoundationDB. The system, JMAP and SCIM suites pass. authorization.rs skipped fork permissions that guard no registry object; the audit suite checks a plain user is refused instead.
155 lines
6.2 KiB
Rust
155 lines
6.2 KiB
Rust
/*
|
|
* 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 common::{Server, auth::AccessToken};
|
|
use email::cache::MessageCacheFetch;
|
|
use email::cache::email::MessageCacheAccess;
|
|
use email::message::metadata::MessageMetadata;
|
|
use groupware::cache::GroupwareCache;
|
|
use registry::schema::enums::Permission;
|
|
use std::future::Future;
|
|
use store::ValueKey;
|
|
use store::write::{AlignedBytes, Archive};
|
|
use trc::AddContext;
|
|
use types::acl::Acl;
|
|
use types::blob::{BlobClass, BlobId};
|
|
use types::collection::{Collection, SyncCollection};
|
|
use types::field::EmailField;
|
|
use utils::chained_bytes::ChainedBytes;
|
|
|
|
pub trait BlobDownload: Sync + Send {
|
|
fn blob_download(
|
|
&self,
|
|
blob_id: &BlobId,
|
|
access_token: &AccessToken,
|
|
) -> impl Future<Output = trc::Result<Option<Vec<u8>>>> + Send;
|
|
|
|
fn has_access_blob(
|
|
&self,
|
|
blob_id: &BlobId,
|
|
access_token: &AccessToken,
|
|
) -> impl Future<Output = trc::Result<bool>> + Send;
|
|
}
|
|
|
|
impl BlobDownload for Server {
|
|
#[allow(clippy::blocks_in_conditions)]
|
|
async fn blob_download(
|
|
&self,
|
|
blob_id: &BlobId,
|
|
access_token: &AccessToken,
|
|
) -> trc::Result<Option<Vec<u8>>> {
|
|
if self.has_access_blob(blob_id, access_token).await? {
|
|
if let Some(section) = &blob_id.section {
|
|
self.get_blob_section(&blob_id.hash, section)
|
|
.await
|
|
.caused_by(trc::location!())
|
|
} else {
|
|
let blob = self
|
|
.blob_store()
|
|
.get_blob(blob_id.hash.as_slice(), 0..usize::MAX)
|
|
.await
|
|
.caused_by(trc::location!());
|
|
match (&blob_id.class, blob) {
|
|
(
|
|
BlobClass::Linked {
|
|
account_id,
|
|
collection,
|
|
document_id,
|
|
},
|
|
Ok(Some(data)),
|
|
) if *collection == Collection::Email as u8 => {
|
|
let Some(archive) = self
|
|
.store()
|
|
.get_value::<Archive<AlignedBytes>>(ValueKey::property(
|
|
*account_id,
|
|
Collection::Email,
|
|
*document_id,
|
|
EmailField::Metadata,
|
|
))
|
|
.await
|
|
.caused_by(trc::location!())?
|
|
else {
|
|
return Ok(Some(data));
|
|
};
|
|
let metadata = archive
|
|
.to_unarchived::<MessageMetadata>()
|
|
.caused_by(trc::location!())?;
|
|
let body_offset = metadata.inner.blob_body_offset.to_native();
|
|
if metadata.inner.root_part().offset_body.to_native() != body_offset {
|
|
let raw_message = ChainedBytes::new(
|
|
metadata.inner.raw_headers.as_ref(),
|
|
)
|
|
.with_last(data.get(body_offset as usize..).unwrap_or_default());
|
|
Ok(Some(raw_message.to_bytes()))
|
|
} else {
|
|
Ok(Some(data))
|
|
}
|
|
}
|
|
(_, blob) => blob,
|
|
}
|
|
}
|
|
} else {
|
|
Ok(None)
|
|
}
|
|
}
|
|
|
|
async fn has_access_blob(
|
|
&self,
|
|
blob_id: &BlobId,
|
|
access_token: &AccessToken,
|
|
) -> trc::Result<bool> {
|
|
Ok(
|
|
(blob_id.class.is_superuser() && access_token.has_permission(Permission::FetchAnyBlob))
|
|
|| (self
|
|
.store()
|
|
.blob_has_access(&blob_id.hash, &blob_id.class)
|
|
.await
|
|
.caused_by(trc::location!())?
|
|
&& match &blob_id.class {
|
|
BlobClass::Linked {
|
|
account_id,
|
|
collection,
|
|
document_id,
|
|
} => {
|
|
if access_token.is_member(*account_id) {
|
|
// inbuxa: AU-1.6: another account's blob
|
|
self.audit_foreign_access(access_token, *account_id, true)
|
|
.await;
|
|
true
|
|
} else {
|
|
match Collection::from(*collection) {
|
|
Collection::Email => self
|
|
.get_cached_messages(*account_id)
|
|
.await
|
|
.caused_by(trc::location!())?
|
|
.shared_messages(access_token, Acl::ReadItems)
|
|
.contains(*document_id),
|
|
collection @ (Collection::FileNode
|
|
| Collection::ContactCard
|
|
| Collection::CalendarEvent) => self
|
|
.fetch_dav_resources(
|
|
access_token.account_id(),
|
|
*account_id,
|
|
SyncCollection::from(collection),
|
|
)
|
|
.await
|
|
.caused_by(trc::location!())?
|
|
.shared_items(access_token, [Acl::ReadItems], true)
|
|
.contains(*document_id),
|
|
_ => false,
|
|
}
|
|
}
|
|
}
|
|
BlobClass::Reserved { account_id, .. } => {
|
|
access_token.is_member(*account_id)
|
|
}
|
|
}),
|
|
)
|
|
}
|
|
}
|