Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions pkgs/id/src/commands/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,18 @@ fn serve_pull_policy(started: Option<&StartedServerConfig>) -> crate::pull_polic
})
}

/// The freshness window seitan admission serves under (#8487): the loaded
/// server config's `[policy] freshness_window_seconds`, resolved through
/// [`crate::server_config::ServerConfig::freshness`], when a config was
/// loaded, else [`crate::seitan::DEFAULT_WINDOW`] — so a `serve` without
/// `--server-config` behaves exactly as before.
#[cfg(feature = "world")]
fn serve_freshness_window(started: Option<&StartedServerConfig>) -> std::time::Duration {
started.map_or(crate::seitan::DEFAULT_WINDOW, |started| {
started.config.freshness().window()
})
}

/// The world protocol serve registers for a hub: the loaded operator
/// config's #2247 budget policy when a server config was given, the
/// coded defaults when none was. Before this wire, the budgets
Expand Down Expand Up @@ -1934,6 +1946,21 @@ pub async fn cmd_serve(opts: ServeOptions) -> Result<()> {
WebContentTarget::Program(world) => Some(world.clone()),
})
.collect();
// #8487: the seitan admission state the web surface
// serves: the freshness window resolved from the loaded
// server config (the code default without one), and the
// server-config directory journal beside the groups log
// opened after provisioning persisted into it, so the
// admit path's account check sees the provisioned
// accounts and its `AccountVerified` appends land in the
// same journal.
#[cfg(feature = "world")]
let seitan_state = crate::web::SeitanState::new(
crate::directory::Directory::open(&server_config_directory_path(&groups_log))?,
serve_freshness_window(started_server_config.as_ref()),
Comment thread
dezren39 marked this conversation as resolved.
Resolved
);
#[cfg(not(feature = "world"))]
let seitan_state = crate::web::SeitanState::default();
let web_routers = crate::web::web_routers(
store_handle.clone(),
Some(peer_discovery.clone()),
Expand All @@ -1947,6 +1974,7 @@ pub async fn cmd_serve(opts: ServeOptions) -> Result<()> {
event_events.as_ref().map(Arc::clone),
surfaces,
Some(groups_log.clone()),
seitan_state,
)
.await?;
for ((listener_addr, listener, target), web_router) in
Expand Down Expand Up @@ -3753,6 +3781,34 @@ mod tests {
let _ = std::fs::remove_dir_all(&dir);
}

/// #8487: without a server config, seitan admission serves under
/// the code default window (5 minutes), exactly as before.
#[cfg(feature = "world")]
#[test]
fn serve_freshness_window_defaults_without_a_config() {
assert_eq!(
serve_freshness_window(None),
crate::seitan::DEFAULT_WINDOW
);
}

/// #8487: the live admission path takes its window from the
/// loaded config's `[policy] freshness_window_seconds`, not from
/// the code default.
#[cfg(feature = "world")]
#[test]
fn serve_freshness_window_reads_the_configured_window() {
let dir = serve_config_dir("freshness-window");
let path = dir.join("server.toml");
std::fs::write(&path, "[policy]\nfreshness_window_seconds = 60\n").unwrap();
let started = start_server_config(&path).unwrap();
assert_eq!(
serve_freshness_window(Some(&started)),
std::time::Duration::from_secs(60)
);
let _ = std::fs::remove_dir_all(&dir);
}

// #2247: the loaded [budgets] must reach the world protocol serve
// registers, not just the parser.

Expand Down
16 changes: 16 additions & 0 deletions pkgs/id/src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ mod identity;
mod markdown;
mod routes;
mod security;
mod seitan;
mod tags_ws;
mod templates;
pub mod world_ws;
Expand Down Expand Up @@ -82,6 +83,7 @@ pub use identity::IdentityStore;
#[doc(hidden)]
pub use identity::crash_gate;
pub use routes::{create_program_router, create_router, create_router_for_app};
pub use seitan::SeitanState;
pub use security::WebSecurity;
pub use templates::{AssetUrls, render_page};

Expand Down Expand Up @@ -257,6 +259,12 @@ pub struct AppState {
/// (`id serve` passes its `--groups-log` resolution); `None` reads
/// the default `groups.jsonl`, as the group CLI does.
pub groups_log: Option<std::path::PathBuf>,
/// Seitan admission state for `/api/seitan/*` (#8487): the invite
/// registry, the directory admissions append to, and the freshness
/// window. `id serve` replaces the default (empty in-memory
/// directory, default window) with the server-config directory
/// journal and the configured window; see [`SeitanState`].
pub seitan: SeitanState,
}

impl std::fmt::Debug for AppState {
Expand All @@ -274,6 +282,7 @@ impl std::fmt::Debug for AppState {
.field("world", &self.world)
.field("cookie_secure", &self.cookie_secure)
.field("groups_log", &self.groups_log)
.field("seitan", &self.seitan)
.finish()
}
}
Expand Down Expand Up @@ -343,6 +352,7 @@ impl AppState {
program_world: None,
cookie_secure: false,
groups_log: None,
seitan: SeitanState::default(),
})
}
}
Expand Down Expand Up @@ -438,6 +448,7 @@ pub async fn web_router(
cookie_secure,
None,
groups_log,
SeitanState::default(),
))
}

Expand Down Expand Up @@ -474,6 +485,7 @@ pub async fn web_router_with_local_events(
cookie_secure,
None,
groups_log,
SeitanState::default(),
))
}

Expand Down Expand Up @@ -501,6 +513,7 @@ pub async fn web_routers(
local_events: Option<Arc<Mutex<crate::local_events::LocalEvents>>>,
surfaces: Vec<Option<String>>,
groups_log: Option<std::path::PathBuf>,
seitan: SeitanState,
) -> anyhow::Result<Vec<Router>> {
let state = match local_events {
Some(events) => {
Expand Down Expand Up @@ -538,6 +551,7 @@ pub async fn web_routers(
cookie_secure,
surface,
groups_log.clone(),
seitan.clone(),
)
})
.collect())
Expand All @@ -556,9 +570,11 @@ fn finish_router(
cookie_secure: bool,
surface: Option<String>,
groups_log: Option<std::path::PathBuf>,
seitan: SeitanState,
) -> Router {
state.world = world;
state.groups_log = groups_log;
state.seitan = seitan;
state.cookie_secure = cookie_secure;
let security = WebSecurity {
cookie_secure,
Expand Down
Loading
Loading