forge
Explore
Log in

Don't you dare go Hollow

the settings page says whether the feed is alive: a read-only Connection card under the profile panel names the issuer and the client id straight from the config, shows the directory stream as a green Connected dot while /directory/live is open and amber Reconnecting from the moment it ends or fails, and ages the last roster event honestly off the sync task's atomics — the client secret is never read on any path that reaches the render, every signed-in reader may see it because nothing here is per-user data, and both wordings ride the Key enum in English and Turkish

Browse files at this commit

72751ff99e27672f90e7680e6596df6ed9b681ddAhmet Kaan GümüşParent: 3134bfa
crates/in-web/src/i18n.rsmodified+21 -0
@@ -164,6 +164,13 @@ pub enum Key {
164164 // Settings.
165165 Settings,
166166 Profile,
167+ Connection,
168+ ConnectionIssuer,
169+ ConnectionClientId,
170+ ConnectionStream,
171+ ConnectionConnected,
172+ ConnectionReconnecting,
173+ ConnectionLastEvent,
167174 DisplayName,
168175 EmailAddress,
169176 QuotaUsage,
@@ -335,6 +342,13 @@ pub fn t(lang: Lang, key: Key) -> &'static str {
335342 Profile => "Profile",
336343 DisplayName => "Name",
337344 EmailAddress => "Address",
345+ Connection => "Connection",
346+ ConnectionIssuer => "Issuer",
347+ ConnectionClientId => "Client ID",
348+ ConnectionStream => "Directory stream",
349+ ConnectionConnected => "Connected",
350+ ConnectionReconnecting => "Reconnecting…",
351+ ConnectionLastEvent => "Last event",
338352 QuotaUsage => "Storage used",
339353 QuotaOf => "of",
340354 AdminPanel => "Everyone",
@@ -499,6 +513,13 @@ pub fn t(lang: Lang, key: Key) -> &'static str {
499513 EmailAddress => "Adres",
500514 QuotaUsage => "Kullanılan alan",
501515 QuotaOf => "/",
516+ Connection => "Bağlantı",
517+ ConnectionIssuer => "Sağlayıcı",
518+ ConnectionClientId => "İstemci kimliği",
519+ ConnectionStream => "Dizin akışı",
520+ ConnectionConnected => "Bağlı",
521+ ConnectionReconnecting => "Yeniden bağlanıyor…",
522+ ConnectionLastEvent => "Son etkinlik",
502523 AdminPanel => "Herkes",
503524 AllUsers => "Herkes",
504525 SetQuota => "Kotayı ayarla",
crates/in-web/src/main.rsmodified+27 -3
@@ -222,7 +222,13 @@ async fn main() {
222222 config.oidc.client_secret.clone(),
223223 );
224224 let default_quota_bytes = config.default_quota_bytes;
225- tokio::spawn(identity_sync(store.clone(), directory.clone(), default_quota_bytes));
225+ let health = in_web::server::DirectoryHealth::new();
226+ tokio::spawn(identity_sync(
227+ store.clone(),
228+ directory.clone(),
229+ default_quota_bytes,
230+ health.clone(),
231+ ));
226232
227233 // The suite the switcher's wordmarks link to is im's to keep: im's
228234 // admin panel owns the list and `/family` serves it to registered
@@ -272,6 +278,7 @@ async fn main() {
272278 shutdown: in_web::live::Shutdown(stopping),
273279 link_key: cookie_key,
274280 directory,
281+ health,
275282 })
276283 .app_context(in_client::LogoutBack(Arc::new(|cx: &Cx| {
277284 Box::pin(async move { Some(in_web::server::share_origin(cx).await) })
@@ -392,6 +399,7 @@ async fn identity_sync(
392399 store: Arc<dyn in_core::store::Store>,
393400 client: im_client::directory::DirectoryClient,
394401 default_quota_bytes: u64,
402+ health: in_web::server::DirectoryHealth,
395403 ) {
396404 let mut backoff = std::time::Duration::from_secs(1);
397405 loop {
@@ -403,29 +411,45 @@ async fn identity_sync(
403411 }
404412 match client.open_stream().await {
405413 Ok(mut stream) => {
414+ health.connected();
406415 while let Some(event) = stream.next().await {
407416 match event {
408417 Ok(im_client::directory::DirectoryEvent::Profile(member)) => {
409418 mirror_member(&store, &member, default_quota_bytes).await;
419+ // Every event is proof the feed is alive;
420+ // the card's age line reads this.
421+ health.note_event();
410422 }
411423 // A network failure ends the stream; the full
412424 // pass below re-lists before the redial.
413425 Err(problem) => {
426+ health.reconnecting();
414427 eprintln!("in: directory stream failed: {problem}");
415428 break;
416429 }
417430 }
418431 }
432+ // The stream closed cleanly — im restarting or its
433+ // window running out. The card goes amber until the
434+ // redial below opens the next one.
435+ health.reconnecting();
436+ }
437+ Err(problem) => {
438+ health.reconnecting();
439+ eprintln!("in: directory stream refused: {problem}")
419440 }
420- Err(problem) => eprintln!("in: directory stream refused: {problem}"),
421441 }
422442 }
423- Err(problem) => eprintln!("in: directory pass failed: {problem}"),
443+ Err(problem) => {
444+ health.reconnecting();
445+ eprintln!("in: directory pass failed: {problem}")
446+ }
424447 }
425448 tokio::time::sleep(backoff).await;
426449 backoff = (backoff * 2).min(IDENTITY_BACKOFF_CAP);
427450 }
428451 }
452+
429453 /// How often the suite list is re-fetched from im. Short enough that a
430454 /// service the admin adds over there shows up here before anyone goes
431455 /// looking for its wordmark, long enough that the two are not talking
crates/in-web/src/server.rsmodified+64 -0
@@ -45,6 +45,70 @@ pub struct App {
4545 /// change feed — authenticated with the same client pair the OIDC side
4646 /// holds. Built once at boot; cheap to clone.
4747 pub directory: im_client::directory::DirectoryClient,
48+ /// Whether the directory's live stream is up, read by the settings
49+ /// page's Connection card. Atomics, not locks: the sync task writes
50+ /// from its own loop, every settings render reads, neither ever blocks.
51+ pub health: DirectoryHealth,
52+}
53+
54+/// The live state of the identity-directory connection, as the Connection
55+/// card displays it. Cloned freely; every clone sees the same atomics.
56+#[derive(Clone, Debug)]
57+pub struct DirectoryHealth {
58+ /// 1 while `/directory/live` is open, 0 while connecting or
59+ /// re-connecting — the boot default is 0, and every stream end or
60+ /// error returns it there until the next open.
61+ stream: Arc<std::sync::atomic::AtomicU8>,
62+ /// Unix seconds of the last roster event the stream delivered; 0 is
63+ /// never. The age a card shows is derived at read time, so a stale
64+ /// moment ages honestly without a ticking task behind it.
65+ last_event: Arc<std::sync::atomic::AtomicI64>,
66+}
67+
68+impl DirectoryHealth {
69+ pub fn new() -> Self {
70+ Self {
71+ stream: Arc::new(std::sync::atomic::AtomicU8::new(0)),
72+ last_event: Arc::new(std::sync::atomic::AtomicI64::new(0)),
73+ }
74+ }
75+
76+ /// The stream opened.
77+ pub fn connected(&self) {
78+ use std::sync::atomic::Ordering::Relaxed;
79+ self.stream.store(1, Relaxed);
80+ }
81+
82+ /// The stream ended or failed; the task will dial again.
83+ pub fn reconnecting(&self) {
84+ use std::sync::atomic::Ordering::Relaxed;
85+ self.stream.store(0, Relaxed);
86+ }
87+
88+ /// A roster event came through the live stream: it is connected, and
89+ /// this is the moment it last said anything.
90+ pub fn note_event(&self) {
91+ use std::sync::atomic::Ordering::Relaxed;
92+ self.stream.store(1, Relaxed);
93+ self.last_event.store(now_unix(), Relaxed);
94+ }
95+
96+ /// Whether the card shows the green dot.
97+ pub fn stream_connected(&self) -> bool {
98+ use std::sync::atomic::Ordering::Relaxed;
99+ self.stream.load(Relaxed) == 1
100+ }
101+
102+ /// Seconds since the last roster event, or `None` before the first one.
103+ pub fn last_event_age_secs(&self) -> Option<i64> {
104+ use std::sync::atomic::Ordering::Relaxed;
105+ let at = self.last_event.load(Relaxed);
106+ (at > 0).then(|| (now_unix() - at).max(0))
107+ }
108+}
109+
110+fn now_unix() -> i64 {
111+ time::OffsetDateTime::now_utc().unix_timestamp()
48112 }
49113
50114 /// The application context this request runs under.
crates/in-web/src/settings.rsmodified+39 -1
@@ -301,7 +301,13 @@ async fn settings(cx: &Cx) -> Result {
301301 }
302302 };
303303 let language = lang(cx).await;
304- let store = app(cx).store;
304+ let app = app(cx);
305+ let store = app.store;
306+ // The Connection card reads only what the config already carries and
307+ // the sync task's own atomics — the client secret is never touched on
308+ // any path that reaches this render.
309+ let connected = app.health.stream_connected();
310+ let last_event = app.health.last_event_age_secs();
305311 // Re-read the row so the quota bar never shows a stale number.
306312 let fresh = store.user(&user.id).await?.unwrap_or_else(|| user.clone());
307313 let administers = fresh.admin;
@@ -438,6 +444,38 @@ async fn settings(cx: &Cx) -> Result {
438444 </form>
439445 </div>
440446 </section>
447+ // The Connection card: who this app talks to, and whether
448+ // the live feed is up right now. Read-only, every
449+ // signed-in reader — nothing here is per-user data.
450+ <section class="panel">
451+ <div class="panel-head">
452+ <h2 class="panel-title">(t(language, Key::Connection))</h2>
453+ </div>
454+ <div class="panel-body">
455+ <div class="field">
456+ <span class="field-label">(t(language, Key::ConnectionIssuer))</span>
457+ <span class="field-static">(app.config.oidc.issuer.clone())</span>
458+ </div>
459+ <div class="field">
460+ <span class="field-label">(t(language, Key::ConnectionClientId))</span>
461+ <span class="field-static">(app.config.oidc.client_id.clone())</span>
462+ </div>
463+ <div class="field">
464+ <span class="field-label">(t(language, Key::ConnectionStream))</span>
465+ <span class="field-static">
466+ <span class=(if connected { "status-dot status-dot-done" } else { "status-dot status-dot-warn" })></span>
467+ if connected {
468+ (t(language, Key::ConnectionConnected))
469+ } else {
470+ (t(language, Key::ConnectionReconnecting))
471+ }
472+ if let Some(age) = last_event {
473+ <span class="field-note">(format!("{} · {}s", t(language, Key::ConnectionLastEvent), age))</span>
474+ }
475+ </span>
476+ </div>
477+ </div>
478+ </section>
441479 }
442480 if section == Section::Links {
443481 if let Some(token) = created {
crates/in-web/tests/http.rsmodified+53 -0
@@ -312,6 +312,7 @@ struct TestApp {
312312 config: Config,
313313 client: in_client::Config,
314314 fake: FakeIm,
315+ health: in_web::server::DirectoryHealth,
315316 stop: tokio::sync::watch::Sender<bool>,
316317 }
317318
@@ -378,6 +379,7 @@ impl TestApp {
378379 defaulted: false,
379380 };
380381 let (stop, stopping) = tokio::sync::watch::channel(false);
382+ let health = in_web::server::DirectoryHealth::new();
381383 let router = in_client::mount(
382384 Router::builder()
383385 .discover()
@@ -402,6 +404,7 @@ impl TestApp {
402404 "in-test".to_string(),
403405 "s3cr3t".to_string(),
404406 ),
407+ health: health.clone(),
405408 })
406409 .app_context(in_client::LogoutBack(Arc::new(|cx: &Cx| {
407410 Box::pin(async move { Some(in_web::server::share_origin(cx).await) })
@@ -414,6 +417,7 @@ impl TestApp {
414417 config,
415418 client,
416419 fake,
420+ health,
417421 stop,
418422 }
419423 }
@@ -5293,3 +5297,52 @@ async fn an_empty_folder_says_how_to_fill_it() {
52935297 assert!(body.contains("id=\"upload-form\""), "{body}");
52945298 assert!(body.contains("__inDrop"), "{body}");
52955299 }
5300+
5301+/// The settings Connection card reads the shared health the sync task
5302+/// writes: the issuer and the client id straight from the config, the
5303+/// stream wording from the state atomics, and never the client secret —
5304+/// the one value the card must not carry onto any page.
5305+#[tokio::test]
5306+async fn connection_card_shows_issuer_client_id_and_stream_state() {
5307+ let app = TestApp::build().await;
5308+ let cookie = app.sign_in("sub-conn", "conn@in.test", "Conn").await;
5309+
5310+ // A fresh process has never opened the stream: the card is amber.
5311+ let page = app.get("/settings", Some(&cookie)).await;
5312+ assert_eq!(page.status, StatusCode::OK);
5313+ let body = page.text();
5314+ assert!(body.contains("Connection"), "no card title: {body}");
5315+ assert!(
5316+ body.contains(app.config.oidc.issuer.as_str()),
5317+ "no issuer: {body}"
5318+ );
5319+ assert!(
5320+ body.contains("in-test"),
5321+ "no client id: {body}"
5322+ );
5323+ assert!(body.contains("Reconnecting"), "no amber wording: {body}");
5324+ assert!(body.contains("status-dot-warn"), "no amber dot: {body}");
5325+ assert!(
5326+ !body.contains("s3cr3t"),
5327+ "the client secret reached the page: {body}"
5328+ );
5329+
5330+ // The sync task opens the stream: green, and the age line appears once
5331+ // an event has come through.
5332+ app.health.connected();
5333+ app.health.note_event();
5334+ let page = app.get("/settings", Some(&cookie)).await;
5335+ let body = page.text();
5336+ assert!(body.contains("Connected"), "no green wording: {body}");
5337+ assert!(body.contains("status-dot-done"), "no green dot: {body}");
5338+ assert!(!body.contains("Reconnecting"), "amber lingered: {body}");
5339+ assert!(body.contains("Last event"), "no age line: {body}");
5340+
5341+ // The stream ends: amber again, no event line retraction needed — the
5342+ // last event stays but the wording names the truth.
5343+ app.health.reconnecting();
5344+ let page = app.get("/settings", Some(&cookie)).await;
5345+ let body = page.text();
5346+ assert!(body.contains("Reconnecting"), "no amber return: {body}");
5347+ assert!(!body.contains("status-dot-done"), "green lingered: {body}");
5348+}
style/main.scssmodified+1 -0
@@ -2305,6 +2305,7 @@ img.avatar {
23052305 }
23062306
23072307 .status-dot-done { background: var(--positive); }
2308+.status-dot-warn { background: var(--warn-ink); }
23082309
23092310 // The select carries no chrome of its own: the box around it is the control.
23102311 .status-select {