From de142646dbbf51283cee0ff10267b0189c02a2d4 Mon Sep 17 00:00:00 2001 From: K Panuragh Date: Sat, 14 Nov 2026 12:51:42 +0530 Subject: [PATCH 1/2] build: Use Cargo's release profile for release builds 4f2a648 renamed the `default` profile to `release` in meson.options, but the Cargo builds still checked for `default`, so every build ran `cargo build` without `--release`. Release packages then shipped debug binaries, with the development-only CREDSD_TRUSTED_CALLERS and CREDSD_TRUSTED_APP_IDS overrides enabled. --- CHANGELOG.md | 1 + credentialsd-common/src/meson.build | 2 +- credentialsd-ui/src/meson.build | 2 +- credentialsd/src/meson.build | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06c48f6e..2f51e85f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - daemon: Stop retrying a transport after 5 consecutive failures before user interaction; other transports keep running. - daemon: Show the UI through the backend that xdg-desktop-portal selects, passed in the new `ui_backend` option - daemon: Treat Debian's Firefox ESR (app ID `firefox-esr`) as a privileged client, like the other Firefox builds +- build: Build the Rust code with Cargo's release profile again when Meson's `profile` is `release`. Since 0.4.0 it was built in debug mode. - daemon: Build the list of devices offered to the user from libwebauthn's `available_transports()`, the same source discovery uses (#32) - daemon: Allow clients to cancel requests through xdg-desktop-portal. - ui: Pass the caller's activation token to the compositor when showing the dialog, so it can take focus when the requesting window is in the background (#152) diff --git a/credentialsd-common/src/meson.build b/credentialsd-common/src/meson.build index 2f5bc691..91c7734a 100644 --- a/credentialsd-common/src/meson.build +++ b/credentialsd-common/src/meson.build @@ -1,7 +1,7 @@ # Currently, we're not building this with meson and just letting cargo path dependencies for the other projects build this lib. # Not efficient, since the UI and daemon projects will build it separately, but leaving it this way for now. -if get_option('profile') == 'default' +if get_option('profile') == 'release' cargo_options += ['--release'] rust_profile = 'release' message('Building in release mode') diff --git a/credentialsd-ui/src/meson.build b/credentialsd-ui/src/meson.build index ac7d984f..fde85632 100644 --- a/credentialsd-ui/src/meson.build +++ b/credentialsd-ui/src/meson.build @@ -30,7 +30,7 @@ run_command( check: true, ) -if get_option('profile') == 'default' +if get_option('profile') == 'release' cargo_options += ['--release'] rust_profile = 'release' message('Building in release mode') diff --git a/credentialsd/src/meson.build b/credentialsd/src/meson.build index bf1242b9..b4dae12e 100644 --- a/credentialsd/src/meson.build +++ b/credentialsd/src/meson.build @@ -1,4 +1,4 @@ -if get_option('profile') == 'default' +if get_option('profile') == 'release' cargo_options += ['--release'] rust_profile = 'release' message('Building in release mode') From 116349b3eac881aa986a236c3186f4dbd34ce5cb Mon Sep 17 00:00:00 2001 From: K Panuragh Date: Sat, 14 Nov 2026 22:36:41 +0530 Subject: [PATCH 2/2] daemon: Make the trusted-client overrides an explicit build option CREDSD_TRUSTED_CALLERS and CREDSD_TRUSTED_APP_IDS were read in any build with debug_assertions, so a debug build was enough to let any process in the session become a privileged client. Read them only when built with -Denable_trusted_client_overrides=true, which turns on the daemon's trusted-client-overrides Cargo feature, like enable_core_dumps for the UI. Meson warns when the option is on, and the daemon logs a warning at startup. When it's off and either variable is set, the daemon logs that it's ignoring it, so existing development setups get a hint. CI also runs the daemon's unit tests with the feature on. --- BUILDING.md | 22 ++++++++++++++---- CHANGELOG.md | 1 + credentialsd/Cargo.toml | 5 +++++ credentialsd/meson.build | 4 ++++ credentialsd/src/gateway/mod.rs | 40 ++++++++++++++++++++++++++------- credentialsd/src/main.rs | 13 +++++++++++ meson.options | 8 ++++++- 7 files changed, 80 insertions(+), 13 deletions(-) diff --git a/BUILDING.md b/BUILDING.md index 57ce45f2..031b2b6d 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -145,10 +145,16 @@ ln -s ${LIBDIR}/mozilla/native-messaging-hosts/xyz.iinuwa.credentialsd_helper.js ``` git clone https://github.com/linux-credentials/credentialsd cd credentialsd -meson setup -Dprofile=development build +meson setup -Dprofile=development -Denable_trusted_client_overrides=true build ninja -C build ``` +`enable_trusted_client_overrides` lets the daemon read the +`CREDSD_TRUSTED_CALLERS` and `CREDSD_TRUSTED_APP_IDS` environment variables, +which are used [below](#running-the-server-for-development) to trust a +development build of xdg-desktop-portal. Don't use it for builds you install: +any process in your session could then request credentials for any origin. + credentialsd-ui disables core dumps for itself, because it handles the PINs that users type. To debug a crash in the UI, turn core dumps back on: @@ -221,6 +227,14 @@ enable_core_dumps false [True, False] Allow c for debugging crashes. Defaults to false because the UI handles PINs typed by the user. +enable_trusted_client_overrides + false [True, False] Let the CREDSD_TRUSTED_CALLERS and + CREDSD_TRUSTED_APP_IDS environment variables + add trusted callers and privileged app IDs + to the daemon, for development. Defaults to + false because any process in the user + session could then request credentials for + any origin. feature_daemon enabled [enabled, disabled, Whether to build the credentialsd daemon auto] feature_demo_client auto [enabled, disabled, Whether to build the demo client @@ -229,9 +243,9 @@ feature_gui enabled [enabled, disabled, Whether auto] feature_web_extension enabled [enabled, disabled, Whether to build the web extension auto] -profile release [release, development] The build profile for the targets. The - `development` profile also allows disabling - some security checks for easier development. +profile release [release, development] The build profile for the targets. To relax + the security checks for development, see + `enable_trusted_client_overrides`. ``` For the `feature_*` options, `auto` means that the feature will be enabled if its dependencies are diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f51e85f..af74d6e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - daemon: Show the UI through the backend that xdg-desktop-portal selects, passed in the new `ui_backend` option - daemon: Treat Debian's Firefox ESR (app ID `firefox-esr`) as a privileged client, like the other Firefox builds - build: Build the Rust code with Cargo's release profile again when Meson's `profile` is `release`. Since 0.4.0 it was built in debug mode. +- daemon: Only read `CREDSD_TRUSTED_CALLERS` and `CREDSD_TRUSTED_APP_IDS` when built with `-Denable_trusted_client_overrides=true`, instead of in every debug build. Since 0.4.0's release builds were debug builds, they read these variables too. - daemon: Build the list of devices offered to the user from libwebauthn's `available_transports()`, the same source discovery uses (#32) - daemon: Allow clients to cancel requests through xdg-desktop-portal. - ui: Pass the caller's activation token to the compositor when showing the dialog, so it can take focus when the requesting window is in the background (#152) diff --git a/credentialsd/Cargo.toml b/credentialsd/Cargo.toml index 5712d3dd..45d2ba61 100644 --- a/credentialsd/Cargo.toml +++ b/credentialsd/Cargo.toml @@ -5,6 +5,11 @@ authors = ["Isaiah Inuwa ", "Martin Sirringhaus ) -> PathBuf::from("/usr/local/lib/xdg-desktop-portal"), PathBuf::from("/usr/local/libexec/xdg-desktop-portal"), ]; - if cfg!(debug_assertions) { - let trusted_callers_env = std::env::var("CREDSD_TRUSTED_CALLERS").unwrap_or_default(); + if let Some(trusted_callers_env) = trusted_client_override(TRUSTED_CALLERS_ENV) { let custom_paths = trusted_callers_env .split(',') .filter_map(|path| Path::new(path).canonicalize().ok()); @@ -348,6 +347,19 @@ async fn read_pid_from_pidfd<'a>(pidfd: BorrowedFd<'a>) -> Option { Some(pid) } +pub(crate) const TRUSTED_CALLERS_ENV: &str = "CREDSD_TRUSTED_CALLERS"; +pub(crate) const TRUSTED_APP_IDS_ENV: &str = "CREDSD_TRUSTED_APP_IDS"; + +/// Reads a development-only override of the trusted callers or app IDs. +/// Always `None` unless built with `-Denable_trusted_client_overrides=true`. +fn trusted_client_override(var: &str) -> Option { + if cfg!(feature = "trusted-client-overrides") { + Some(std::env::var(var).unwrap_or_default()) + } else { + None + } +} + fn check_origin_from_app( app_id: &AppId, origin: Origin, @@ -363,12 +375,10 @@ fn check_origin_from_app( "xyz.iinuwa.credentialsd.DemoCredentialsUi", ]; let mut privileged = trusted_clients.contains(&app_id.as_ref()); - if cfg!(debug_assertions) && !privileged { - let trusted_clients_env = std::env::var("CREDSD_TRUSTED_APP_IDS").unwrap_or_default(); - privileged = trusted_clients_env - .split(',') - .map(String::from) - .any(|c| app_id.as_ref() == c); + if !privileged + && let Some(trusted_clients_env) = trusted_client_override(TRUSTED_APP_IDS_ENV) + { + privileged = trusted_clients_env.split(',').any(|c| app_id.as_ref() == c); } privileged }; @@ -553,6 +563,7 @@ mod test { use super::{ RequestKind, WebAuthnError, check_origin_from_app, check_origin_from_privileged_client, + trusted_client_override, }; fn check_same_origin(origin: &str) -> Result { @@ -597,4 +608,17 @@ mod test { RequestKind::Unprivileged(_) )) } + + // PATH is always set, so these check the feature gate without set_var. + #[cfg(not(feature = "trusted-client-overrides"))] + #[test] + fn test_env_overrides_are_ignored_without_overrides_feature() { + assert_eq!(trusted_client_override("PATH"), None); + } + + #[cfg(feature = "trusted-client-overrides")] + #[test] + fn test_env_overrides_are_read_with_overrides_feature() { + assert!(trusted_client_override("PATH").is_some_and(|p| !p.is_empty())); + } } diff --git a/credentialsd/src/main.rs b/credentialsd/src/main.rs index e7241c8b..50f88410 100644 --- a/credentialsd/src/main.rs +++ b/credentialsd/src/main.rs @@ -23,6 +23,19 @@ pub const DBUS_SERVICE_NAME: &str = "xyz.iinuwa.credentialsd.Credentials"; async fn main() { // Initialize logger tracing_subscriber::fmt::init(); + if cfg!(feature = "trusted-client-overrides") { + tracing::warn!( + "CREDSD_TRUSTED_CALLERS and CREDSD_TRUSTED_APP_IDS are enabled by the enable_trusted_client_overrides build option" + ); + } else { + for var in [gateway::TRUSTED_CALLERS_ENV, gateway::TRUSTED_APP_IDS_ENV] { + if std::env::var_os(var).is_some() { + tracing::warn!( + "Ignoring {var}: build with -Denable_trusted_client_overrides=true to use it" + ); + } + } + } println!("Starting..."); run().await.unwrap(); diff --git a/meson.options b/meson.options index b6d6c226..3ae1c0cc 100644 --- a/meson.options +++ b/meson.options @@ -5,7 +5,7 @@ option( type: 'combo', choices: ['release', 'development'], value: 'release', - description: 'The build profile for the targets. The `development` profile also allows disabling some security checks for easier development.', + description: 'The build profile for the targets. To relax the security checks for development, see `enable_trusted_client_overrides`.', ) option( 'cargo_home', @@ -30,6 +30,12 @@ option( value: false, description: 'Allow credentialsd-ui to write core dumps, for debugging crashes. Defaults to false because the UI handles PINs typed by the user.', ) +option( + 'enable_trusted_client_overrides', + type: 'boolean', + value: false, + description: 'Let the CREDSD_TRUSTED_CALLERS and CREDSD_TRUSTED_APP_IDS environment variables add trusted callers and privileged app IDs to the daemon, for development. Defaults to false because any process in the user session could then request credentials for any origin.', +) # Features option(