-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from sebadob/audit-part-3
Audit part 3
- Loading branch information
Showing
13 changed files
with
299 additions
and
59 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ members = [ | |
] | ||
|
||
[workspace.package] | ||
version = "0.16.1" | ||
version = "0.16.2-20231017" | ||
edition = "2021" | ||
authors = ["Sebastian Dobe <[email protected]>"] | ||
license = "AGPLv3" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use actix_web::{get, web, Responder}; | ||
use actix_web_grants::proc_macro::has_roles; | ||
use actix_web_lab::sse; | ||
use rauthy_common::constants::SSE_KEEP_ALIVE; | ||
use rauthy_common::error_response::{ErrorResponse, ErrorResponseType}; | ||
use rauthy_models::app_state::AppState; | ||
use rauthy_models::events::listener::EventRouterMsg; | ||
use std::time::Duration; | ||
|
||
#[get("/events")] | ||
// #[has_roles("rauthy_admin")] // TODO ADD BACK IN AFTER LOCAL TESTING!!! | ||
pub async fn sse_events(data: web::Data<AppState>) -> Result<impl Responder, ErrorResponse> { | ||
let (tx, sse) = sse::channel(5); | ||
|
||
if let Err(err) = data | ||
.tx_events_router | ||
.send_async(EventRouterMsg::ClientReg { | ||
ip: "".to_string(), | ||
tx, | ||
}) | ||
.await | ||
{ | ||
Err(ErrorResponse::new( | ||
ErrorResponseType::Internal, | ||
format!("Cannot register SSE client: {:?}", err), | ||
)) | ||
} else { | ||
Ok(sse.with_keep_alive(Duration::from_secs(*SSE_KEEP_ALIVE as u64))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ use rauthy_common::password_hasher; | |
use rauthy_handlers::middleware::logging::RauthyLoggingMiddleware; | ||
use rauthy_handlers::middleware::session::RauthySessionMiddleware; | ||
use rauthy_handlers::openapi::ApiDoc; | ||
use rauthy_handlers::{clients, generic, groups, oidc, roles, scopes, sessions, users}; | ||
use rauthy_handlers::{clients, events, generic, groups, oidc, roles, scopes, sessions, users}; | ||
use rauthy_models::app_state::{AppState, Caches, DbPool}; | ||
use rauthy_models::email::EMail; | ||
use rauthy_models::events::event::Event; | ||
|
@@ -167,45 +167,75 @@ async fn main() -> Result<(), Box<dyn Error>> { | |
ha_cache_config: cache_config.clone(), | ||
}; | ||
let (tx_events, rx_events) = flume::unbounded(); | ||
let app_state = web::Data::new(AppState::new(tx_email, tx_events.clone(), caches).await?); | ||
let (tx_events_router, rx_events_router) = flume::unbounded(); | ||
let app_state = web::Data::new( | ||
AppState::new( | ||
tx_email, | ||
tx_events.clone(), | ||
tx_events_router.clone(), | ||
caches, | ||
) | ||
.await?, | ||
); | ||
|
||
// TODO remove with v0.17 | ||
TEMP_migrate_passkeys_uv(&app_state.db) | ||
.await | ||
.expect("Passkey UV migration to not fail"); | ||
|
||
// events listener | ||
tokio::spawn(EventListener::listen(rx_events, app_state.db.clone())); | ||
tokio::spawn(EventListener::listen( | ||
tx_events_router, | ||
rx_events_router, | ||
rx_events, | ||
app_state.db.clone(), | ||
)); | ||
|
||
// TODO REMOVE AFTER TESTING | ||
Event::brute_force("192.15.15.1".to_string()) | ||
.send(&tx_events) | ||
.await | ||
.unwrap(); | ||
Event::dos("192.15.15.1".to_string()) | ||
.send(&tx_events) | ||
.await | ||
.unwrap(); | ||
Event::invalid_login(2, "192.15.15.1".to_string()) | ||
.send(&tx_events) | ||
.await | ||
.unwrap(); | ||
Event::invalid_login(5, "192.15.15.1".to_string()) | ||
.send(&tx_events) | ||
.await | ||
.unwrap(); | ||
Event::invalid_login(7, "192.15.15.1".to_string()) | ||
.send(&tx_events) | ||
.await | ||
.unwrap(); | ||
Event::ip_blacklisted("192.15.15.1".to_string()) | ||
.send(&tx_events) | ||
.await | ||
.unwrap(); | ||
Event::rauthy_admin("[email protected]".to_string()) | ||
.send(&tx_events) | ||
.await | ||
.unwrap(); | ||
let txe = tx_events.clone(); | ||
tokio::spawn(async move { | ||
time::sleep(Duration::from_secs(5)).await; | ||
Event::brute_force("192.15.15.1".to_string()) | ||
.send(&txe) | ||
.await | ||
.unwrap(); | ||
|
||
time::sleep(Duration::from_secs(5)).await; | ||
Event::dos("192.15.15.1".to_string()) | ||
.send(&txe) | ||
.await | ||
.unwrap(); | ||
|
||
time::sleep(Duration::from_secs(5)).await; | ||
Event::invalid_login(2, "192.15.15.1".to_string()) | ||
.send(&txe) | ||
.await | ||
.unwrap(); | ||
|
||
time::sleep(Duration::from_secs(2)).await; | ||
Event::invalid_login(5, "192.15.15.1".to_string()) | ||
.send(&txe) | ||
.await | ||
.unwrap(); | ||
|
||
time::sleep(Duration::from_secs(1)).await; | ||
Event::invalid_login(7, "192.15.15.1".to_string()) | ||
.send(&txe) | ||
.await | ||
.unwrap(); | ||
|
||
time::sleep(Duration::from_secs(5)).await; | ||
Event::ip_blacklisted("192.15.15.1".to_string()) | ||
.send(&txe) | ||
.await | ||
.unwrap(); | ||
|
||
time::sleep(Duration::from_secs(10)).await; | ||
Event::rauthy_admin("[email protected]".to_string()) | ||
.send(&txe) | ||
.await | ||
.unwrap(); | ||
}); | ||
|
||
// spawn password hash limiter | ||
tokio::spawn(password_hasher::run()); | ||
|
@@ -374,6 +404,7 @@ async fn actix_main(app_state: web::Data<AppState>) -> std::io::Result<()> { | |
.service(generic::redirect_v1) | ||
.service( | ||
web::scope("/v1") | ||
.service(events::sse_events) | ||
.service(generic::get_index) | ||
.service(generic::get_account_html) | ||
.service(generic::get_admin_html) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.