-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
feat: audit logs #994
base: main
Are you sure you want to change the base?
feat: audit logs #994
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,8 +25,15 @@ use actix_web::{ | |
http::header::{self, HeaderName}, | ||
Error, Route, | ||
}; | ||
use base64::Engine; | ||
use chrono::Utc; | ||
use futures_util::future::LocalBoxFuture; | ||
|
||
use reqwest::header::{HeaderMap, HeaderValue}; | ||
use reqwest::Client; | ||
use serde_json::json; | ||
use std::collections::HashMap; | ||
|
||
use crate::{ | ||
handlers::{ | ||
AUTHORIZATION_KEY, KINESIS_COMMON_ATTRIBUTES_KEY, LOG_SOURCE_KEY, LOG_SOURCE_KINESIS, | ||
|
@@ -164,6 +171,31 @@ where | |
/* ## Section end */ | ||
|
||
let auth_result: Result<_, Error> = (self.auth_method)(&mut req, self.action); | ||
let body = json!([ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will work on the Schema, will get back to you in a week's time There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @de-sh, just following up. Did you get a chance to work on this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey, sorry that this got lost, here is what I was able to come up with and Nitish has updated: {
"version": "1",
"deploymentID": "String: uuid",
"auditID": "String: uuid",
"timestamp": "String: Datetime",
"stream": "String",
"actor": {
"remoteHost": "127.0.0.1",
"userAgent": "String",
"userName": "String: username",
"authorizationMethod": "Enum: basic/oauth/jwt"
},
"request": {
"method": "Enum: POST/GET/PUT",
"path": "String",
"host": "String",
"protocol": "Enum: kafka/http/https",
"headers": {
"key": "value"
}
},
"response": {
"statusCode": "int"
}
} |
||
{ | ||
"version": "1.0", | ||
"user-agent":&req | ||
.headers() | ||
.get("user-agent") | ||
.and_then(|value| value.to_str().ok()) | ||
.unwrap_or("unknown"), | ||
"datetime": Utc::now(), | ||
"action":self.action, | ||
"Actor":{ | ||
"type": &req | ||
.headers() | ||
.get("user-agent") | ||
.and_then(|value| value.to_str().ok()) | ||
.unwrap_or("unknown"), | ||
"id": "user123" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this hardcoded, and what is the intention behind using user-agent as type? |
||
}, | ||
"ip-address":&req | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you intending to use the addr of the client? |
||
.headers() | ||
.get("host") | ||
.and_then(|value| value.to_str().ok()) | ||
.unwrap_or("unknown"), | ||
} | ||
]); | ||
let fut = self.service.call(req); | ||
Box::pin(async move { | ||
match auth_result? { | ||
|
@@ -175,10 +207,60 @@ where | |
), | ||
_ => {} | ||
} | ||
if let Err(err) = send_post_request(body).await { | ||
eprintln!("Error sending POST request: {}", err); | ||
} | ||
fut.await | ||
}) | ||
} | ||
} | ||
fn to_header_map(headers: &HashMap<String, String>) -> Result<HeaderMap, String> { | ||
let mut header_map = HeaderMap::new(); | ||
for (key, value) in headers { | ||
let header_name = reqwest::header::HeaderName::from_bytes(key.as_bytes()) | ||
.map_err(|_| format!("Invalid header name: {}", key))?; | ||
let header_value = HeaderValue::from_str(value) | ||
.map_err(|_| format!("Invalid header value for {}: {}", key, value))?; | ||
header_map.insert(header_name, header_value); | ||
} | ||
Ok(header_map) | ||
} | ||
async fn send_post_request(body: serde_json::Value) -> Result<(), reqwest::Error> { | ||
let client = Client::new(); | ||
match CONFIG.parseable.audit_log_target.as_deref() { | ||
Some(_target) => { | ||
let audit_log_auth_token = format!( | ||
"Basic {}", | ||
base64::prelude::BASE64_STANDARD.encode(format!( | ||
"{}:{}", | ||
CONFIG | ||
.parseable | ||
.audit_log_target_username | ||
.as_deref() | ||
.unwrap(), | ||
CONFIG | ||
.parseable | ||
.audit_log_target_password | ||
.as_deref() | ||
.unwrap() | ||
)) | ||
); | ||
let headers = to_header_map(&CONFIG.parseable.audit_log_target_headers) | ||
.expect("Failed to convert audit_log_target_headers to HeaderMap"); | ||
let body = body; | ||
let target_url = CONFIG.parseable.audit_log_target.as_ref().unwrap(); | ||
let _response = client | ||
.post(target_url) | ||
.headers(headers) | ||
.header(reqwest::header::AUTHORIZATION, &audit_log_auth_token) | ||
.json(&body) | ||
.send() | ||
.await?; | ||
Ok(()) | ||
} | ||
None => Ok(()), | ||
} | ||
} | ||
|
||
pub fn auth_no_context(req: &mut ServiceRequest, action: Action) -> Result<rbac::Response, Error> { | ||
let creds = extract_session_key(req); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could just as well be an
http::HeaderMap
after collection from the CLI args