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
22 changes: 18 additions & 4 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
- 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: 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)
Expand Down
2 changes: 1 addition & 1 deletion credentialsd-common/src/meson.build
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
2 changes: 1 addition & 1 deletion credentialsd-ui/src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
5 changes: 5 additions & 0 deletions credentialsd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ authors = ["Isaiah Inuwa <isaiah.inuwa@gmail.com>", "Martin Sirringhaus <martin.
edition = "2024"
license = "LGPL-3.0-only"

[features]
# Lets CREDSD_TRUSTED_CALLERS and CREDSD_TRUSTED_APP_IDS add trusted callers
# and privileged app IDs. For development only.
trusted-client-overrides = []

[dependencies]
credentialsd-common = { path = "../credentialsd-common" }

Expand Down
4 changes: 4 additions & 0 deletions credentialsd/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ endif
if get_option('cargo_offline') == true
cargo_options += ['--offline']
endif
if get_option('enable_trusted_client_overrides')
cargo_options += ['--features', 'trusted-client-overrides']
warning('CREDSD_TRUSTED_CALLERS and CREDSD_TRUSTED_APP_IDS are enabled. Do not use this build outside development.')
endif

subdir('src')
subdir('tests')
40 changes: 32 additions & 8 deletions credentialsd/src/gateway/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,7 @@ async fn should_trust_app_id(connection: &Connection, pidfd: BorrowedFd<'_>) ->
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());
Expand Down Expand Up @@ -348,6 +347,19 @@ async fn read_pid_from_pidfd<'a>(pidfd: BorrowedFd<'a>) -> Option<u32> {
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<String> {
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,
Expand All @@ -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
};
Expand Down Expand Up @@ -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<NavigationContext, WebAuthnError> {
Expand Down Expand Up @@ -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()));
}
}
13 changes: 13 additions & 0 deletions credentialsd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion credentialsd/src/meson.build
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
8 changes: 7 additions & 1 deletion meson.options
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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(
Expand Down