The switch knows who still uses legacy mail apps (LP-15, server)

The impact panel's data. Every successful sign-in over IMAP, POP3,
ManageSieve or SMTP AUTH records, per account and per protocol, one
timestamp -- nothing else: no address, no IP, no client. It is written at
most once an hour per account and protocol, so a mail app polling every
minute costs a read per sign-in and a write an hour. A record that can't be
written is logged and the sign-in goes ahead.

Both switches serve it as a read-only property, recentLegacyUse, as
wouldClose serves the confirmation: a list of {accountId, name, protocol,
lastUsedAt} for sign-ins in the last 30 days, most recent first.
inbuxa:ProtocolPolicy lists every account; inbuxa:TenantProtocolPolicy
lists only its tenant's own (MT-1). Accounts since deleted are left out. It
is computed only when the property is asked for.

The recording sits where the tenant check already runs once the account is
known, which becomes admit_legacy_session: refuse if the account's tenant
has legacy protocols off, otherwise record. A refused sign-in is never
recorded.

The spec leaves the interface to the implementation; a property on each
switch keeps the panel's data behind the same permission as the switch
itself, with no new object.

Unit tests hold the 30-day window to acceptance test 11 (three days ago
listed, forty not), the hourly throttle and the keys. The e2e proves on a
running server that the admin's IMAP and submission sign-ins are listed
with their time, that a second sign-in within the hour isn't written again,
and that a tenant's list holds its own user and nobody outside the tenant.
All 70 checks pass.
This commit is contained in:
2026-09-21 11:45:05 -07:00
parent cd99037ca4
commit 3f40b36032
12 changed files with 403 additions and 21 deletions
+52 -4
View File
@@ -19,7 +19,11 @@
//! (LP-4).
use crate::registry::mapping::{ObjectResponse, RegistrySetResponse, ValidationResult};
use common::{Server, auth::AccessToken, network::legacy::PolicyChange};
use common::{
Server,
auth::AccessToken,
network::legacy::{PolicyChange, RecentUse},
};
use inbuxa_features::security::{
listeners,
protocol_policy::{LOCKED_PROTOCOLS, LegacyProtocols, ProtocolPolicy as Policy, SavedListener},
@@ -50,6 +54,7 @@ const ALL: &[P] = &[
P::ChangedBy,
P::LockedProtocols,
P::WouldClose,
P::RecentLegacyUse,
];
fn assert_server_level(access_token: &AccessToken) -> trc::Result<()> {
@@ -86,7 +91,12 @@ fn listener_value(listener: &SavedListener) -> PValue {
Value::Object(out)
}
fn to_value(policy: &Policy, would_close: &[SavedListener], properties: &[P]) -> PValue {
fn to_value(
policy: &Policy,
would_close: &[SavedListener],
recent: &[RecentUse],
properties: &[P],
) -> PValue {
let mut out = Map::with_capacity(properties.len());
for property in properties {
let value = match property {
@@ -127,12 +137,45 @@ fn to_value(policy: &Policy, would_close: &[SavedListener], properties: &[P]) ->
// port, so the confirmation can say so before anything happens
// (LP-16).
P::WouldClose => Value::Array(would_close.iter().map(listener_value).collect()),
// Who would notice, before anything changes (LP-15).
P::RecentLegacyUse => recent_value(recent, |id| ProtocolPolicyValue::Id(Id::from(id))),
};
out.insert_unchecked(Key::Property(property.clone()), value);
}
Value::Object(out)
}
/// The impact panel's list (LP-15): who, over what, and when, in
/// milliseconds as `changedAt` is. Shared with the tenant's switch.
pub(crate) fn recent_value<Pr, V>(
recent: &[RecentUse],
id: impl Fn(u32) -> V,
) -> Value<'static, Pr, V>
where
Pr: jmap_tools::Property,
V: jmap_tools::Element<Property = Pr>,
{
Value::Array(
recent
.iter()
.map(|entry| {
let mut out = Map::with_capacity(4);
out.insert_unchecked(
Key::Borrowed("accountId"),
Value::Element(id(entry.account_id)),
);
out.insert_unchecked(Key::Borrowed("name"), Value::Str(entry.name.clone().into()));
out.insert_unchecked(Key::Borrowed("protocol"), Value::Str(entry.protocol.into()));
out.insert_unchecked(
Key::Borrowed("lastUsedAt"),
Value::Number((entry.at * 1000).into()),
);
Value::Object(out)
})
.collect(),
)
}
/// The listeners turning the switch on would close, whatever it is now.
async fn would_close(server: &Server, policy: &Policy) -> trc::Result<Vec<SavedListener>> {
let mut hypothetical = policy.clone();
@@ -164,17 +207,22 @@ pub async fn get(
} else {
Vec::new()
};
let recent = if properties.contains(&P::RecentLegacyUse) {
server.recent_legacy_use(None).await?
} else {
Vec::new()
};
match ids {
None => response
.list
.push(to_value(&policy, &would_close, &properties)),
.push(to_value(&policy, &would_close, &recent, &properties)),
Some(ids) => {
for id in ids {
if id.is_singleton() {
response
.list
.push(to_value(&policy, &would_close, &properties));
.push(to_value(&policy, &would_close, &recent, &properties));
} else {
response.push_not_found(id);
}
@@ -17,7 +17,8 @@
//! A tenant's switch closes no port (LP-13) -- sign-in and client
//! configuration read it (LP-10, LP-14a).
use common::{Server, auth::AccessToken};
use crate::inbuxa::protocol_policy::recent_value;
use common::{Server, auth::AccessToken, network::legacy::RecentUse};
use inbuxa_features::{
security::{
protocol_policy::LegacyProtocols,
@@ -47,6 +48,7 @@ const ALL: &[P] = &[
P::LegacyProtocols,
P::ChangedAt,
P::ChangedBy,
P::RecentLegacyUse,
];
/// The tenants this principal may reach: its own inside a tenant (MT-1),
@@ -58,7 +60,7 @@ async fn reachable(server: &Server, access_token: &AccessToken) -> trc::Result<V
}
}
fn to_value(tenant_id: u32, policy: &Policy, properties: &[P]) -> PValue {
fn to_value(tenant_id: u32, policy: &Policy, recent: &[RecentUse], properties: &[P]) -> PValue {
let mut out = Map::with_capacity(properties.len());
for property in properties {
let value = match property {
@@ -81,6 +83,9 @@ fn to_value(tenant_id: u32, policy: &Policy, properties: &[P]) -> PValue {
.as_ref()
.map(|by| Value::Str(by.clone().into()))
.unwrap_or(Value::Null),
P::RecentLegacyUse => {
recent_value(recent, |id| TenantProtocolPolicyValue::Id(Id::from(id)))
}
};
out.insert_unchecked(Key::Property(property.clone()), value);
}
@@ -111,9 +116,15 @@ pub async fn get(
let tenant_id = id.document_id();
if reachable.contains(&tenant_id) {
let policy = tenant_protocol_policy::get(&server.core.storage.data, tenant_id).await?;
// The tenant's own people only (LP-15, MT-1).
let recent = if properties.contains(&P::RecentLegacyUse) {
server.recent_legacy_use(Some(tenant_id)).await?
} else {
Vec::new()
};
response
.list
.push(to_value(tenant_id, &policy, &properties));
.push(to_value(tenant_id, &policy, &recent, &properties));
} else {
response.push_not_found(id);
}