Skip to content

Commit

Permalink
update (#650)
Browse files Browse the repository at this point in the history
  • Loading branch information
RWDai authored Mar 22, 2024
1 parent 4ae76ba commit c366c0a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions gateway/spacegate-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ bios-sdk-invoke = { path = "../../sdk/invoke", features = ["spi_log"] }

jsonpath-rust = "0.3.1"
bios-auth = { path = "../../support/auth", default-features = false }
tardis = { workspace = true, features = ["web-client", "build-info"] }
tardis = { workspace = true, features = ["web-client"] }
ipnet = "2.8.0"

http = { version = "1" }
Expand All @@ -32,4 +32,4 @@ pprof = { version = "0.12.1", features = ["flamegraph"] }
tardis = { workspace = true, features = ["test", "web-client"] }

tracing-subscriber = { version = "0.3", features = ["env-filter"] }
testcontainers-modules = { workspace = true,features = ["redis"] }
testcontainers-modules = { workspace = true, features = ["redis"] }
16 changes: 15 additions & 1 deletion gateway/spacegate-lib/src/plugin/audit_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use spacegate_shell::hyper::{Request, Response};
use spacegate_shell::kernel::extension::{EnterTime, PeerAddr, Reflect};

use spacegate_shell::kernel::helper_layers::bidirection_filter::{Bdf, BdfLayer, BoxRespFut};
use spacegate_shell::kernel::Marker;
use spacegate_shell::plugin::{JsonValue, MakeSgLayer, Plugin, PluginError};
use spacegate_shell::{BoxError, SgBody};
use tardis::basic::dto::TardisContext;
Expand All @@ -34,6 +35,7 @@ use tardis::{
use crate::extension::audit_log_param::AuditLogParam;
use crate::extension::before_encrypt_body::BeforeEncryptBody;
use crate::extension::cert_info::{CertInfo, RoleInfo};
use crate::marker::OpresKey;

pub const CODE: &str = "audit_log";
#[derive(Serialize, Deserialize, Clone)]
Expand Down Expand Up @@ -145,14 +147,26 @@ impl SgFilterAuditLog {
}

fn req(&self, mut req: Request<SgBody>) -> Result<Request<SgBody>, Response<SgBody>> {
let reflect = req.extensions_mut().get_mut::<Reflect>().expect("missing reflect");
let param = AuditLogParam {
request_path: req.uri().path().to_string(),
request_method: req.method().to_string(),
request_headers: req.headers().clone(),
request_scheme: req.uri().scheme().unwrap_or(&Scheme::HTTP).to_string(),
request_ip: req.extensions().get::<PeerAddr>().ok_or(PluginError::bad_gateway::<AuditLogPlugin>("[Plugin.AuditLog] missing peer addr"))?.0.ip().to_string(),
};
req.extensions_mut().get_mut::<Reflect>().expect("missing reflect").insert(param);
if let Some(opres_config) = OpresKey::extract(&req) {
if let Some(cert_info) = reflect.get_mut::<CertInfo>() {
cert_info.id = opres_config.ak;
} else {
reflect.insert(CertInfo {
id: opres_config.ak,
name: None,
roles: vec![],
})
}
};
reflect.insert(param);
Ok(req)
}

Expand Down
2 changes: 1 addition & 1 deletion gateway/spacegate-lib/src/plugin/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ fn success_auth_result_to_req(auth_result: AuthResult, config: &AuthConfig, req:
.map(|role| role.iter().map(|r| RoleInfo { id: r.to_string(), name: None }).collect::<Vec<_>>())
.unwrap_or_default(),
};
parts.extensions.insert(cert_info);
parts.extensions.get_mut::<Reflect>().expect("missing reflect").insert(cert_info);

if let Some(mut resp_headers) = auth_result.resp_headers.clone() {
if resp_headers.contains_key(&config.head_key_crypto) || resp_headers.contains_key(&config.head_key_crypto.to_lowercase()) {
Expand Down

0 comments on commit c366c0a

Please sign in to comment.