Recovery mode: switch off an imported Stalwart web interface (#638) #639

Merged
jcoffey-dev merged 1 commits from fix/638-recovery-imported-webui into main 2026-11-25 19:11:18 +00:00
4 changed files with 83 additions and 22 deletions

No files matched your search

+5
View File
@@ -88,6 +88,11 @@ async fn insert_safe_defaults(bp: &mut Bootstrap) -> trc::Result<()> {
}
if is_recovery_mode {
// inbuxa: #638: a store brought over from Stalwart is often opened in
// recovery mode first, to move its paths; upstream's web interface is
// switched off there too, before the applications load
super::first_party::disable_imported_web_interface(bp).await?;
// inbuxa: a server that has never started normally is still a new
// install after recovery mode, even once a role is made there (#265)
if bp.registry.count_object(ObjectType::Role).await? == 0 {
+32 -11
View File
@@ -45,8 +45,9 @@ use store::{
bootstrap::Bootstrap,
write::{RegistryWrite, RegistryWriteResult},
},
write::AnyKey,
write::{AnyClass, AnyKey, BatchBuilder, ValueClass},
};
use trc::AddContext;
/// The client id the upstream web interface uses when its application names none.
pub const WEB_INTERFACE_CLIENT_ID: &str = "inbuxa-webui";
@@ -309,22 +310,29 @@ pub async fn ensure_first_party_clients(bp: &mut Bootstrap) -> trc::Result<()> {
Ok(())
}
/// Set once a start has looked for upstream's web interface, so an operator
/// who switches it back on keeps it on.
pub const IMPORTED_WEB_INTERFACE_CHECKED_KEY: &[u8] = b"Fw";
/// A store brought over from Stalwart still lists upstream's web interface,
/// which would be downloaded and served at `/admin` (docs/spec/import-0.16.md).
/// The first time inbuxa opens a store, before it has inbuxa's store version,
/// that application is switched off, and the record is kept so an operator can
/// switch it back on. The version is written later in the same start, so an
/// application switched back on stays on.
/// It can't work here: it asks for upstream's registry capability by its old
/// name. The first start that opens a store, normal or in recovery mode,
/// switches that application off and keeps the record, so an operator can
/// switch it back on, and then notes that it looked, so it stays on.
///
/// #638: this used to key off the store version mark, but recovery mode
/// skipped the switch-off and still wrote the mark, so a store that went
/// through recovery mode first served upstream's interface from then on.
pub async fn disable_imported_web_interface(bp: &mut Bootstrap) -> trc::Result<()> {
let marked = bp
let checked = bp
.data_store
.get_value::<u32>(AnyKey {
.key_exists(AnyKey {
subspace: SUBSPACE_INBUXA,
key: crate::INBUXA_STORE_VERSION_KEY.to_vec(),
key: IMPORTED_WEB_INTERFACE_CHECKED_KEY.to_vec(),
})
.await?
.is_some();
if marked {
.await?;
if checked {
return Ok(());
}
@@ -358,6 +366,19 @@ pub async fn disable_imported_web_interface(bp: &mut Bootstrap) -> trc::Result<(
);
}
let mut batch = BatchBuilder::new();
batch.set(
ValueClass::Any(AnyClass {
subspace: SUBSPACE_INBUXA,
key: IMPORTED_WEB_INTERFACE_CHECKED_KEY.to_vec(),
}),
vec![1u8],
);
bp.data_store
.write(batch.build_all())
.await
.caused_by(trc::location!())?;
Ok(())
}
+10 -6
View File
@@ -80,12 +80,16 @@ Each of these is done in place on first start, and each is listed in
restores passwords on JMAP for an operator who needs it while clients move
to OAuth.
- **The 0.16 web interface.** Its application record carries over and points
at upstream's `webui` release on GitHub. inbuxa switches it off the first
time it opens the store (`first_party.rs`,
`disable_imported_web_interface`, test `imported_web_interface`), keeps the
record, and logs that it did. An operator who still wants that interface at
`/admin` switches the application back on, and it stays on. Applications of
the operator's own aren't touched.
at upstream's `webui` release on GitHub. It can't work against inbuxa: it
asks for upstream's registry capability by its old name, and every call is
refused. inbuxa switches it off the first time it opens the store, in
recovery mode too (`first_party.rs`, `disable_imported_web_interface`, test
`imported_web_interface`), keeps the record, logs that it did, and notes
that it looked (`_` key `Fw`). An operator who switches the application
back on keeps it on. Applications of the operator's own aren't touched.
Before #638 the check keyed off the store version mark, which a
recovery-mode start wrote without switching anything off; such a store has
the interface switched off on its first start after the fix.
## Not covered
+36 -5
View File
@@ -7,7 +7,8 @@
//! inbuxa: the store version mark. A store without it gets it on start, a
//! marked store is left alone, and a store marked by a newer release is
//! refused before anything is written to it. A store opened for the first
//! time has upstream's web interface switched off (docs/spec/import-0.16.md).
//! time, normally or in recovery mode, has upstream's web interface switched
//! off (docs/spec/import-0.16.md).
//! A store at an older layout version is brought up to this one, by one node
//! at a time (docs/spec/features/store-layout.md). Step 2 -> 3 moves the
//! audit log, journal, holds and undelete notes out of `_`.
@@ -15,7 +16,7 @@
use crate::utils::server::TestServerBuilder;
use common::{
INBUXA_STORE_VERSION, INBUXA_STORE_VERSION_KEY, Server,
manager::first_party::disable_imported_web_interface,
manager::first_party::{IMPORTED_WEB_INTERFACE_CHECKED_KEY, disable_imported_web_interface},
};
use futures::FutureExt;
use inbuxa_features::audit::{Action, Actor, AuditLog, Outcome, Record, Target, log};
@@ -452,8 +453,8 @@ async fn imported_web_interface() {
]
);
// Once the store has its version, an operator who switches it back on
// keeps it on.
// Once a start has looked, an operator who switches it back on keeps it
// on.
migration::try_migrate(server).await.unwrap();
let upstream = server
.registry()
@@ -484,7 +485,37 @@ async fn imported_web_interface() {
applications(server)
.await
.contains(&(UPSTREAM_WEBUI.to_string(), true)),
"a marked store's web interface is left as the operator set it"
"a checked store's web interface is left as the operator set it"
);
// #638: a store that recovery mode opened before the switch-off ran
// there has the version mark but was never checked. It still has
// upstream's interface switched off on its next start.
assert!(read_mark(server).await.is_some());
let mut batch = BatchBuilder::new();
batch.clear(ValueClass::Any(AnyClass {
subspace: SUBSPACE_INBUXA,
key: IMPORTED_WEB_INTERFACE_CHECKED_KEY.to_vec(),
}));
server.store().write(batch.build_all()).await.unwrap();
let mut bp = Bootstrap::new(server.registry().clone()).await;
disable_imported_web_interface(&mut bp).await.unwrap();
assert!(
applications(server)
.await
.contains(&(UPSTREAM_WEBUI.to_string(), false)),
"a marked but unchecked store has upstream's web interface switched off"
);
assert!(
server
.store()
.key_exists(AnyKey {
subspace: SUBSPACE_INBUXA,
key: IMPORTED_WEB_INTERFACE_CHECKED_KEY.to_vec(),
})
.await
.unwrap(),
"the check is noted"
);
}