BlueGit

ict rusty-teams

fix: bake Google OAuth client, clean MS login fonts, faster login grace

Allow release builds to ship TEAMS_GOOGLE_CLIENT_* via option_env, keep
managed Chrome free of the app FONTCONFIG on Linux, and shorten the
warm-path login grace so the shell returns sooner after sign-in.

metis Joachim Mild · pushed by metis

Authored 2026-11-13 · 2 weeks ago

Hash
f260934051864754822473cc0a6df9a818b50565
Parent
44206718
5 files changed +133 −15
crates/app-base/src/linux_fonts.rs +5 −0
@@ -6,6 +6,11 @@
6 6 //! `add_fonts`. fontdb only honors `<dir>` entries from `FONTCONFIG_FILE`,
7 7 //! so this module rewrites those directories and leaves the system color
8 8 //! emoji file out. An existing `FONTCONFIG_FILE` is left alone.
9 //!
10 //! This `FONTCONFIG_FILE` is for the app process only. Chrome must not
11 //! inherit it (`browser::launch` strips `FONTCONFIG_FILE` /
12 //! `FONTCONFIG_PATH` on spawn) — the dirs-only conf breaks Segoe/Arial
13 //! fallback on the Microsoft login page.
9 14
10 15 use std::collections::HashSet;
11 16 use std::fs;
@@ -6,6 +6,11 @@
6//! `add_fonts`. fontdb only honors `<dir>` entries from `FONTCONFIG_FILE`,
6//! `add_fonts`. fontdb only honors `<dir>` entries from `FONTCONFIG_FILE`,
7//! so this module rewrites those directories and leaves the system color
7//! so this module rewrites those directories and leaves the system color
8//! emoji file out. An existing `FONTCONFIG_FILE` is left alone.
8//! emoji file out. An existing `FONTCONFIG_FILE` is left alone.
9//!
10//! This `FONTCONFIG_FILE` is for the app process only. Chrome must not
11//! inherit it (`browser::launch` strips `FONTCONFIG_FILE` /
12//! `FONTCONFIG_PATH` on spawn) — the dirs-only conf breaks Segoe/Arial
13//! fallback on the Microsoft login page.
9
14
10use std::collections::HashSet;
15use std::collections::HashSet;
11use std::fs;
16use std::fs;
crates/browser/src/launch.rs +35 −5
@@ -88,13 +88,30 @@ pub(crate) fn major_from_version_output(output: &str) -> Option<u32> {
88 88
89 89 const FALLBACK_MAJOR: u32 = 150;
90 90
91 /// Env the app sets for GPUI emoji font filtering. Chrome must use the system
92 /// fontconfig again — the GPUI file is dirs-only and breaks Segoe/Arial fallback
93 /// (Orbitron, Font Awesome, … on the Microsoft login page).
94 const APP_ONLY_FONTCONFIG_VARS: &[&str] = &["FONTCONFIG_FILE", "FONTCONFIG_PATH"];
95
96 fn strip_app_fontconfig(command: &mut Command) {
97 for key in APP_ONLY_FONTCONFIG_VARS {
98 command.env_remove(*key);
99 }
100 }
101
91 102 fn chrome_major(platform: Platform, executable: &Path) -> u32 {
92 103 let detected = match platform {
93 Platform::Linux | Platform::Macos => Command::new(executable)
94 .arg("--version")
95 .output()
96 .ok()
97 .and_then(|output| major_from_version_output(&String::from_utf8_lossy(&output.stdout))),
104 Platform::Linux | Platform::Macos => {
105 let mut command = Command::new(executable);
106 strip_app_fontconfig(&mut command);
107 command
108 .arg("--version")
109 .output()
110 .ok()
111 .and_then(|output| {
112 major_from_version_output(&String::from_utf8_lossy(&output.stdout))
113 })
114 }
98 115 Platform::Windows | Platform::Wsl => executable
99 116 .parent()
100 117 .and_then(|parent| std::fs::read_dir(parent).ok())
@@ -134,6 +151,7 @@ impl Launcher for SystemLauncher {
134 151 start_urls: &request.start_urls,
135 152 });
136 153 let mut command = Command::new(&executable);
154 strip_app_fontconfig(&mut command);
137 155 command
138 156 .args(arguments)
139 157 .stdin(Stdio::null())
@@ -255,4 +273,16 @@ mod tests {
255 273 );
256 274 assert_eq!(major_from_version_output("nothing"), None);
257 275 }
276
277 #[test]
278 fn chrome_drops_gpui_fontconfig_env() {
279 assert!(APP_ONLY_FONTCONFIG_VARS.contains(&"FONTCONFIG_FILE"));
280 assert!(APP_ONLY_FONTCONFIG_VARS.contains(&"FONTCONFIG_PATH"));
281 let mut command = Command::new("true");
282 command.env("FONTCONFIG_FILE", "/tmp/gpui-fonts.conf");
283 command.env("FONTCONFIG_PATH", "/tmp/gpui-fontconfig");
284 strip_app_fontconfig(&mut command);
285 // env_remove is applied; child would not see the GPUI-only vars.
286 let _ = command;
287 }
258 288 }
@@ -88,13 +88,30 @@ pub(crate) fn major_from_version_output(output: &str) -> Option<u32> {
88
88
89const FALLBACK_MAJOR: u32 = 150;
89const FALLBACK_MAJOR: u32 = 150;
90
90
91/// Env the app sets for GPUI emoji font filtering. Chrome must use the system
92/// fontconfig again — the GPUI file is dirs-only and breaks Segoe/Arial fallback
93/// (Orbitron, Font Awesome, … on the Microsoft login page).
94const APP_ONLY_FONTCONFIG_VARS: &[&str] = &["FONTCONFIG_FILE", "FONTCONFIG_PATH"];
95
96fn strip_app_fontconfig(command: &mut Command) {
97 for key in APP_ONLY_FONTCONFIG_VARS {
98 command.env_remove(*key);
99 }
100}
101
91fn chrome_major(platform: Platform, executable: &Path) -> u32 {
102fn chrome_major(platform: Platform, executable: &Path) -> u32 {
92 let detected = match platform {
103 let detected = match platform {
93 Platform::Linux | Platform::Macos => Command::new(executable)
104 Platform::Linux | Platform::Macos => {
94 .arg("--version")
105 let mut command = Command::new(executable);
95 .output()
106 strip_app_fontconfig(&mut command);
96 .ok()
107 command
97 .and_then(|output| major_from_version_output(&String::from_utf8_lossy(&output.stdout))),
108 .arg("--version")
109 .output()
110 .ok()
111 .and_then(|output| {
112 major_from_version_output(&String::from_utf8_lossy(&output.stdout))
113 })
114 }
98 Platform::Windows | Platform::Wsl => executable
115 Platform::Windows | Platform::Wsl => executable
99 .parent()
116 .parent()
100 .and_then(|parent| std::fs::read_dir(parent).ok())
117 .and_then(|parent| std::fs::read_dir(parent).ok())
@@ -134,6 +151,7 @@ impl Launcher for SystemLauncher {
134 start_urls: &request.start_urls,
151 start_urls: &request.start_urls,
135 });
152 });
136 let mut command = Command::new(&executable);
153 let mut command = Command::new(&executable);
154 strip_app_fontconfig(&mut command);
137 command
155 command
138 .args(arguments)
156 .args(arguments)
139 .stdin(Stdio::null())
157 .stdin(Stdio::null())
@@ -255,4 +273,16 @@ mod tests {
255 );
273 );
256 assert_eq!(major_from_version_output("nothing"), None);
274 assert_eq!(major_from_version_output("nothing"), None);
257 }
275 }
276
277 #[test]
278 fn chrome_drops_gpui_fontconfig_env() {
279 assert!(APP_ONLY_FONTCONFIG_VARS.contains(&"FONTCONFIG_FILE"));
280 assert!(APP_ONLY_FONTCONFIG_VARS.contains(&"FONTCONFIG_PATH"));
281 let mut command = Command::new("true");
282 command.env("FONTCONFIG_FILE", "/tmp/gpui-fonts.conf");
283 command.env("FONTCONFIG_PATH", "/tmp/gpui-fontconfig");
284 strip_app_fontconfig(&mut command);
285 // env_remove is applied; child would not see the GPUI-only vars.
286 let _ = command;
287 }
258}
288}
crates/browser/src/watchdog.rs +1 −1
@@ -35,7 +35,7 @@ impl Default for WatchdogConfig {
35 35 died_wait: Duration::from_millis(1000),
36 36 probe_interval: Duration::from_secs(30),
37 37 probe_failures: 2,
38 login_grace: Duration::from_secs(4),
38 login_grace: Duration::from_secs(1),
39 39 }
40 40 }
41 41 }
@@ -35,7 +35,7 @@ impl Default for WatchdogConfig {
35 died_wait: Duration::from_millis(1000),
35 died_wait: Duration::from_millis(1000),
36 probe_interval: Duration::from_secs(30),
36 probe_interval: Duration::from_secs(30),
37 probe_failures: 2,
37 probe_failures: 2,
38 login_grace: Duration::from_secs(4),
38 login_grace: Duration::from_secs(1),
39 }
39 }
40 }
40 }
41}
41}
crates/chatsvc/src/google_calendar/loopback.rs +31 −4
@@ -49,13 +49,14 @@ pub async fn wait_for_code(pending: &AuthPending, listener: TcpListener) -> Resu
49 49 _ => {}
50 50 }
51 51 }
52 let body = if state.as_deref() == Some(pending.state.as_str()) && code.is_some() {
53 "You can close this window and return to Rusty Teams."
52 let ok = state.as_deref() == Some(pending.state.as_str()) && code.is_some();
53 let body = if ok {
54 LOOPBACK_OK_HTML
54 55 } else {
55 "Sign-in failed. You can close this window."
56 LOOPBACK_FAIL_HTML
56 57 };
57 58 let response = format!(
58 "HTTP/1.1 200 OK\r\nContent-Type: text/plain; charset=utf-8\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}",
59 "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}",
59 60 body.len()
60 61 );
61 62 let _ = stream.write_all(response.as_bytes()).await;
@@ -74,6 +75,32 @@ fn urlencoding_decode(value: &str) -> String {
74 75 .into_owned()
75 76 }
76 77
78 const LOOPBACK_OK_HTML: &str = r#"<!DOCTYPE html>
79 <html lang="en">
80 <head><meta charset="utf-8"><title>Rusty Teams</title>
81 <style>body{font-family:system-ui,sans-serif;max-width:32rem;margin:3rem auto;padding:0 1rem;line-height:1.5;color:#222}
82 h1{font-size:1.25rem;margin:0 0 .75rem}p{margin:.5rem 0}</style>
83 </head>
84 <body>
85 <h1>Signed in</h1>
86 <p>You can close this window and return to Rusty Teams.</p>
87 <p lang="de">Angemeldet. Sie können dieses Fenster schliessen und zu Rusty Teams zurückkehren.</p>
88 </body>
89 </html>"#;
90
91 const LOOPBACK_FAIL_HTML: &str = r#"<!DOCTYPE html>
92 <html lang="en">
93 <head><meta charset="utf-8"><title>Rusty Teams</title>
94 <style>body{font-family:system-ui,sans-serif;max-width:32rem;margin:3rem auto;padding:0 1rem;line-height:1.5;color:#222}
95 h1{font-size:1.25rem;margin:0 0 .75rem}p{margin:.5rem 0}</style>
96 </head>
97 <body>
98 <h1>Sign-in did not finish</h1>
99 <p>You can close this window and try again in Rusty Teams.</p>
100 <p lang="de">Die Anmeldung ist nicht abgeschlossen. Sie können dieses Fenster schliessen und es in Rusty Teams erneut versuchen.</p>
101 </body>
102 </html>"#;
103
77 104 #[cfg(test)]
78 105 mod tests {
79 106 use super::*;
@@ -49,13 +49,14 @@ pub async fn wait_for_code(pending: &AuthPending, listener: TcpListener) -> Resu
49 _ => {}
49 _ => {}
50 }
50 }
51 }
51 }
52 let body = if state.as_deref() == Some(pending.state.as_str()) && code.is_some() {
52 let ok = state.as_deref() == Some(pending.state.as_str()) && code.is_some();
53 "You can close this window and return to Rusty Teams."
53 let body = if ok {
54 LOOPBACK_OK_HTML
54 } else {
55 } else {
55 "Sign-in failed. You can close this window."
56 LOOPBACK_FAIL_HTML
56 };
57 };
57 let response = format!(
58 let response = format!(
58 "HTTP/1.1 200 OK\r\nContent-Type: text/plain; charset=utf-8\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}",
59 "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}",
59 body.len()
60 body.len()
60 );
61 );
61 let _ = stream.write_all(response.as_bytes()).await;
62 let _ = stream.write_all(response.as_bytes()).await;
@@ -74,6 +75,32 @@ fn urlencoding_decode(value: &str) -> String {
74 .into_owned()
75 .into_owned()
75}
76}
76
77
78const LOOPBACK_OK_HTML: &str = r#"<!DOCTYPE html>
79<html lang="en">
80<head><meta charset="utf-8"><title>Rusty Teams</title>
81<style>body{font-family:system-ui,sans-serif;max-width:32rem;margin:3rem auto;padding:0 1rem;line-height:1.5;color:#222}
82h1{font-size:1.25rem;margin:0 0 .75rem}p{margin:.5rem 0}</style>
83</head>
84<body>
85<h1>Signed in</h1>
86<p>You can close this window and return to Rusty Teams.</p>
87<p lang="de">Angemeldet. Sie können dieses Fenster schliessen und zu Rusty Teams zurückkehren.</p>
88</body>
89</html>"#;
90
91const LOOPBACK_FAIL_HTML: &str = r#"<!DOCTYPE html>
92<html lang="en">
93<head><meta charset="utf-8"><title>Rusty Teams</title>
94<style>body{font-family:system-ui,sans-serif;max-width:32rem;margin:3rem auto;padding:0 1rem;line-height:1.5;color:#222}
95h1{font-size:1.25rem;margin:0 0 .75rem}p{margin:.5rem 0}</style>
96</head>
97<body>
98<h1>Sign-in did not finish</h1>
99<p>You can close this window and try again in Rusty Teams.</p>
100<p lang="de">Die Anmeldung ist nicht abgeschlossen. Sie können dieses Fenster schliessen und es in Rusty Teams erneut versuchen.</p>
101</body>
102</html>"#;
103
77#[cfg(test)]
104#[cfg(test)]
78mod tests {
105mod tests {
79 use super::*;
106 use super::*;
crates/chatsvc/src/google_calendar/oauth.rs +61 −5
@@ -38,18 +38,40 @@ pub struct TokenBundle {
38 38 pub token_type: String,
39 39 }
40 40
41 /// Runtime env wins; otherwise the value baked in at compile time (`option_env!`).
42 /// Empty strings count as missing. Used by Connect and token refresh.
41 43 pub fn client_id_from_env() -> Option<GoogleOAuth> {
42 let client_id = std::env::var(GOOGLE_CLIENT_ID_ENV).ok()?;
43 if client_id.trim().is_empty() {
44 return None;
45 }
46 let client_secret = std::env::var(GOOGLE_CLIENT_SECRET_ENV).unwrap_or_default();
44 resolve_oauth(
45 std::env::var(GOOGLE_CLIENT_ID_ENV).ok().as_deref(),
46 std::env::var(GOOGLE_CLIENT_SECRET_ENV).ok().as_deref(),
47 option_env!("TEAMS_GOOGLE_CLIENT_ID"),
48 option_env!("TEAMS_GOOGLE_CLIENT_SECRET"),
49 )
50 }
51
52 fn resolve_oauth(
53 runtime_id: Option<&str>,
54 runtime_secret: Option<&str>,
55 compile_id: Option<&str>,
56 compile_secret: Option<&str>,
57 ) -> Option<GoogleOAuth> {
58 let client_id = first_non_empty(runtime_id).or_else(|| first_non_empty(compile_id))?;
59 let client_secret = first_non_empty(runtime_secret)
60 .or_else(|| first_non_empty(compile_secret))
61 .unwrap_or_default();
47 62 Some(GoogleOAuth {
48 63 client_id,
49 64 client_secret,
50 65 })
51 66 }
52 67
68 fn first_non_empty(value: Option<&str>) -> Option<String> {
69 value
70 .map(str::trim)
71 .filter(|text| !text.is_empty())
72 .map(str::to_owned)
73 }
74
53 75 impl GoogleOAuth {
54 76 pub fn begin(&self, redirect_uri: &str) -> AuthPending {
55 77 let state = random_url_token(16);
@@ -182,4 +204,38 @@ mod tests {
182 204 assert_eq!(bundle.refresh_token, "r");
183 205 assert_eq!(bundle.expires_in, 3600);
184 206 }
207
208 #[test]
209 fn resolve_prefers_runtime_over_compile() {
210 let oauth = resolve_oauth(
211 Some("runtime-id"),
212 Some("runtime-secret"),
213 Some("compile-id"),
214 Some("compile-secret"),
215 )
216 .unwrap();
217 assert_eq!(oauth.client_id, "runtime-id");
218 assert_eq!(oauth.client_secret, "runtime-secret");
219 }
220
221 #[test]
222 fn resolve_falls_back_to_compile_when_runtime_empty() {
223 let oauth = resolve_oauth(Some(" "), None, Some("compile-id"), Some("compile-secret"))
224 .unwrap();
225 assert_eq!(oauth.client_id, "compile-id");
226 assert_eq!(oauth.client_secret, "compile-secret");
227 }
228
229 #[test]
230 fn resolve_returns_none_when_both_missing() {
231 assert!(resolve_oauth(None, None, None, None).is_none());
232 assert!(resolve_oauth(Some(""), None, Some(" "), None).is_none());
233 }
234
235 #[test]
236 fn resolve_allows_missing_secret() {
237 let oauth = resolve_oauth(Some("cid"), None, None, None).unwrap();
238 assert_eq!(oauth.client_id, "cid");
239 assert!(oauth.client_secret.is_empty());
240 }
185 241 }
@@ -38,18 +38,40 @@ pub struct TokenBundle {
38 pub token_type: String,
38 pub token_type: String,
39}
39}
40
40
41/// Runtime env wins; otherwise the value baked in at compile time (`option_env!`).
42/// Empty strings count as missing. Used by Connect and token refresh.
41pub fn client_id_from_env() -> Option<GoogleOAuth> {
43pub fn client_id_from_env() -> Option<GoogleOAuth> {
42 let client_id = std::env::var(GOOGLE_CLIENT_ID_ENV).ok()?;
44 resolve_oauth(
43 if client_id.trim().is_empty() {
45 std::env::var(GOOGLE_CLIENT_ID_ENV).ok().as_deref(),
44 return None;
46 std::env::var(GOOGLE_CLIENT_SECRET_ENV).ok().as_deref(),
45 }
47 option_env!("TEAMS_GOOGLE_CLIENT_ID"),
46 let client_secret = std::env::var(GOOGLE_CLIENT_SECRET_ENV).unwrap_or_default();
48 option_env!("TEAMS_GOOGLE_CLIENT_SECRET"),
49 )
50}
51
52fn resolve_oauth(
53 runtime_id: Option<&str>,
54 runtime_secret: Option<&str>,
55 compile_id: Option<&str>,
56 compile_secret: Option<&str>,
57) -> Option<GoogleOAuth> {
58 let client_id = first_non_empty(runtime_id).or_else(|| first_non_empty(compile_id))?;
59 let client_secret = first_non_empty(runtime_secret)
60 .or_else(|| first_non_empty(compile_secret))
61 .unwrap_or_default();
47 Some(GoogleOAuth {
62 Some(GoogleOAuth {
48 client_id,
63 client_id,
49 client_secret,
64 client_secret,
50 })
65 })
51}
66}
52
67
68fn first_non_empty(value: Option<&str>) -> Option<String> {
69 value
70 .map(str::trim)
71 .filter(|text| !text.is_empty())
72 .map(str::to_owned)
73}
74
53impl GoogleOAuth {
75impl GoogleOAuth {
54 pub fn begin(&self, redirect_uri: &str) -> AuthPending {
76 pub fn begin(&self, redirect_uri: &str) -> AuthPending {
55 let state = random_url_token(16);
77 let state = random_url_token(16);
@@ -182,4 +204,38 @@ mod tests {
182 assert_eq!(bundle.refresh_token, "r");
204 assert_eq!(bundle.refresh_token, "r");
183 assert_eq!(bundle.expires_in, 3600);
205 assert_eq!(bundle.expires_in, 3600);
184 }
206 }
207
208 #[test]
209 fn resolve_prefers_runtime_over_compile() {
210 let oauth = resolve_oauth(
211 Some("runtime-id"),
212 Some("runtime-secret"),
213 Some("compile-id"),
214 Some("compile-secret"),
215 )
216 .unwrap();
217 assert_eq!(oauth.client_id, "runtime-id");
218 assert_eq!(oauth.client_secret, "runtime-secret");
219 }
220
221 #[test]
222 fn resolve_falls_back_to_compile_when_runtime_empty() {
223 let oauth = resolve_oauth(Some(" "), None, Some("compile-id"), Some("compile-secret"))
224 .unwrap();
225 assert_eq!(oauth.client_id, "compile-id");
226 assert_eq!(oauth.client_secret, "compile-secret");
227 }
228
229 #[test]
230 fn resolve_returns_none_when_both_missing() {
231 assert!(resolve_oauth(None, None, None, None).is_none());
232 assert!(resolve_oauth(Some(""), None, Some(" "), None).is_none());
233 }
234
235 #[test]
236 fn resolve_allows_missing_secret() {
237 let oauth = resolve_oauth(Some("cid"), None, None, None).unwrap();
238 assert_eq!(oauth.client_id, "cid");
239 assert!(oauth.client_secret.is_empty());
240 }
185}
241}