Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement REST password provider support #3193

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
52aecc4
implement rest password provider support
raphaelbadawi Sep 10, 2024
7b03e3e
Merge branch 'main' into rbadawi/rest-password-provider-support
raphaelbadawi Sep 10, 2024
93a4638
commit missing query data for rest password provider support
raphaelbadawi Sep 10, 2024
bdf6859
Merge branch 'main' into rbadawi/rest-password-provider-support
raphaelbadawi Sep 10, 2024
ef90a35
replicate instantly on synapse on login registration occurring with r…
raphaelbadawi Sep 11, 2024
0bb7c52
amend rust style
raphaelbadawi Sep 11, 2024
93fc3f1
remove native-tls dependency
raphaelbadawi Sep 11, 2024
b2b1d6d
normalize schema update
raphaelbadawi Sep 11, 2024
b174586
pass all unit tests
raphaelbadawi Sep 11, 2024
1c8db8b
Merge branch 'main' into rbadawi/rest-password-provider-support
raphaelbadawi Sep 11, 2024
42604b1
Merge branch 'main' into rbadawi/rest-password-provider-support
raphaelbadawi Sep 18, 2024
81d04b2
fix linter errors
raphaelbadawi Sep 18, 2024
f536e96
Merge branch 'main' into rbadawi/rest-password-provider-support
raphaelbadawi Sep 25, 2024
fe19a27
Merge branch 'main' into rbadawi/rest-password-provider-support
raphaelbadawi Oct 2, 2024
dded23b
Merge branch 'main' into rbadawi/rest-password-provider-support
raphaelbadawi Oct 2, 2024
5226f80
fix fmt errors
raphaelbadawi Oct 2, 2024
7dafef0
Merge branch 'main' into rbadawi/rest-password-provider-support
raphaelbadawi Oct 14, 2024
6fe85f1
Merge branch 'main' into rbadawi/rest-password-provider-support
raphaelbadawi Oct 22, 2024
8f8f871
Merge branch 'main' into rbadawi/rest-password-provider-support
raphaelbadawi Oct 22, 2024
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
36 changes: 36 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion crates/cli/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ pub async fn password_manager_from_config(
(version, hasher)
});

PasswordManager::new(config.minimum_complexity(), schemes)
PasswordManager::new(
config.minimum_complexity(),
config.rest_auth_provider().cloned(),
schemes,
)
}

pub fn mailer_from_config(
Expand Down
2 changes: 1 addition & 1 deletion crates/config/src/sections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub use self::{
Resource as HttpResource, TlsConfig as HttpTlsConfig, UnixOrTcp,
},
matrix::MatrixConfig,
passwords::{Algorithm as PasswordAlgorithm, PasswordsConfig},
passwords::{Algorithm as PasswordAlgorithm, PasswordsConfig, RestAuthProviderConfig},
policy::PolicyConfig,
rate_limiting::RateLimitingConfig,
secrets::SecretsConfig,
Expand Down
28 changes: 28 additions & 0 deletions crates/config/src/sections/passwords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ fn default_minimum_complexity() -> u8 {
3
}

/// Configuration for REST password provider
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct RestAuthProviderConfig {
/// The base URL where the identity service is implemented
pub url: String,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does that work in terms of authentication, etc? It would be useful to include links here to specifications for the API of such services, if there is any

Copy link
Author

@raphaelbadawi raphaelbadawi Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REST password providers are a kind of Synapse modules. What they do is calling an identity provider on login (e. g. MA1SD), which itself implements a Matrix Identity Service API.

It takes over all API login calls (e. g. all authentications using the login API are authenticated against the identity provider), and creates an account in the Synapse database when an authentication is successful for a user which doesn't exist yet in the database.

/// Implemented version of the identity service ("v1", "v2")
pub version: String,
}

impl RestAuthProviderConfig {
/// Constructor for `RestAuthProviderConfig`
#[must_use]
pub fn new(url: String, version: String) -> Self {
Self { url, version }
}
}

/// User password hashing config
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct PasswordsConfig {
Expand All @@ -52,6 +69,10 @@ pub struct PasswordsConfig {
/// - 4: any more than that
#[serde(default = "default_minimum_complexity")]
minimum_complexity: u8,

/// The REST authentication provider URL
#[serde(skip_serializing_if = "Option::is_none")]
rest_auth_provider: Option<RestAuthProviderConfig>,
}

impl Default for PasswordsConfig {
Expand All @@ -60,6 +81,7 @@ impl Default for PasswordsConfig {
enabled: default_enabled(),
schemes: default_schemes(),
minimum_complexity: default_minimum_complexity(),
rest_auth_provider: None,
}
}
}
Expand Down Expand Up @@ -152,6 +174,12 @@ impl PasswordsConfig {

Ok(mapped_result)
}

/// Get the REST authentication config, if set.
#[must_use]
pub fn rest_auth_provider(&self) -> Option<&RestAuthProviderConfig> {
self.rest_auth_provider.as_ref()
}
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
Expand Down
2 changes: 1 addition & 1 deletion crates/data-model/src/compat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod session;
mod sso_login;

pub use self::{
device::Device,
device::{Device, InvalidDeviceID},
session::{CompatSession, CompatSessionState},
sso_login::{CompatSsoLogin, CompatSsoLoginState},
};
Expand Down
2 changes: 1 addition & 1 deletion crates/data-model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub use ulid::Ulid;
pub use self::{
compat::{
CompatAccessToken, CompatRefreshToken, CompatRefreshTokenState, CompatSession,
CompatSessionState, CompatSsoLogin, CompatSsoLoginState, Device,
CompatSessionState, CompatSsoLogin, CompatSsoLoginState, Device, InvalidDeviceID,
},
oauth2::{
AuthorizationCode, AuthorizationGrant, AuthorizationGrantStage, Client, DeviceCodeGrant,
Expand Down
2 changes: 2 additions & 0 deletions crates/handlers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ tower-http.workspace = true
axum.workspace = true
axum-macros = "0.4.2"
axum-extra.workspace = true
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So pulling reqwest might be something we want to do in the whole project. Right now we have a bit of a manual HTTP client based on hyper with a lot of metrics/tracing capabilities, and that use the right CA certificates & co.

I'll try to do a PR to move to reqwest overall, because it feels a lot simpler, but I would like to avoid having a mix of both reqwest and the current http client

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's true such change should actually be in its own PR and be global. So for now I should use the current hyper implementation (I must admit, I didn't manage to make it work in my first attempts, but I will try again ;-) ).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, I replaced the hyper stack with reqwest recently in #3424

rustls.workspace = true

aide.workspace = true
Expand Down Expand Up @@ -104,4 +105,5 @@ zxcvbn = "3.1.0"
insta.workspace = true
tracing-subscriber.workspace = true
cookie_store = "0.21.0"
mockito = "1.5"
sqlx.workspace = true
Loading
Loading