From a2bd8190f5d708811bcbd1a1cccd048ad1b5dff6 Mon Sep 17 00:00:00 2001 From: RWDai <27391645+RWDai@users.noreply.github.com> Date: Mon, 15 Jan 2024 17:02:35 +0800 Subject: [PATCH] fix(auth): fix auth log level (#592) * fix(auth): fix auth log level * update --- gateway/spacegate-lib/src/plugin/auth.rs | 34 +++++++++++------------- services/spacegate/Dockerfile | 22 +++++++-------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/gateway/spacegate-lib/src/plugin/auth.rs b/gateway/spacegate-lib/src/plugin/auth.rs index 5ca72b00a..0effda9ad 100644 --- a/gateway/spacegate-lib/src/plugin/auth.rs +++ b/gateway/spacegate-lib/src/plugin/auth.rs @@ -35,7 +35,7 @@ use std::{ use tardis::{ async_trait, basic::{error::TardisError, result::TardisResult}, - config::config_dto::{AppConfig, CacheModuleConfig, FrameworkConfig, LogConfig, TardisConfig}, + config::config_dto::{AppConfig, CacheModuleConfig, FrameworkConfig, TardisConfig}, log, serde_json::{self, json, Value}, tokio::{sync::RwLock, task::JoinHandle}, @@ -124,20 +124,6 @@ impl SgPluginFilter for SgFilterAuth { } async fn init(&mut self, init_dto: &SgPluginFilterInitDto) -> TardisResult<()> { - if let Some(log_level) = &init_dto.gateway_parameters.log_level { - let mut log_config = TardisFuns::fw_config().log().clone(); - fn directive(path: &str, lvl: &str) -> Directive { - let s = format!("{path}={lvl}"); - format!("{path}={lvl}").parse().unwrap_or_else(|e| { - tracing::error!("[SG.Filter.Auth] failed to parse directive {:?}: {}", s, e); - Default::default() - }) - } - log_config.directives.push(directive(crate::PACKAGE_NAME, log_level)); - log_config.directives.push(directive(bios_auth::auth_constants::PACKAGE_NAME, log_level)); - TardisFuns::tracing().update_config(&log_config)?; - } - let config_md5 = TardisFuns::crypto.digest.md5(TardisFuns::json.obj_to_string(self)?)?; let mut instance = INSTANCE.get_or_init(Default::default).write().await; @@ -177,15 +163,25 @@ impl SgPluginFilter for SgFilterAuth { .build() .into(), ), - log: init_dto.gateway_parameters.log_level.as_ref().map(|l| LogConfig { - level: Some(l.parse().unwrap_or_default()), - ..Default::default() - }), ..Default::default() }, }) .await?; + if let Some(log_level) = &init_dto.gateway_parameters.log_level { + let mut log_config = TardisFuns::fw_config().log().clone(); + fn directive(path: &str, lvl: &str) -> Directive { + let s = format!("{path}={lvl}"); + format!("{path}={lvl}").parse().unwrap_or_else(|e| { + tracing::error!("[SG.Filter.Auth] failed to parse directive {:?}: {}", s, e); + Default::default() + }) + } + log_config.directives.push(directive(crate::PACKAGE_NAME, log_level)); + log_config.directives.push(directive(bios_auth::auth_constants::PACKAGE_NAME, log_level)); + TardisFuns::tracing().update_config(&log_config)?; + } + let handle = auth_initializer::init().await?; *instance = Some((config_md5, handle)); log::info!("[SG.Filter.Auth] init done"); diff --git a/services/spacegate/Dockerfile b/services/spacegate/Dockerfile index ef38418eb..8c89f95c5 100644 --- a/services/spacegate/Dockerfile +++ b/services/spacegate/Dockerfile @@ -2,24 +2,24 @@ FROM ubuntu # Set time zone RUN apt-get update && \ - apt-get install -yq tzdata && \ - ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ - dpkg-reconfigure -f noninteractive tzdata + apt-get install -yq tzdata && \ + ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ + dpkg-reconfigure -f noninteractive tzdata # When error: `libssl. so.1.1: cannot open shared object file: No such file or directory` appears, please use the following statement to install libssl -# RUN apt update && apt install -y wget && wget http://nz2.archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2.19_amd64.deb && dpkg -i libssl1.1_1.1.1f-1ubuntu2.19_amd64.deb +# RUN apt update && apt install -y wget && wget http://nz2.archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2.20_amd64.deb && dpkg -i libssl1.1_1.1.1f-1ubuntu2.20_amd64.deb RUN apt update && apt install -y --reinstall ca-certificates RUN update-ca-certificates -f RUN echo 'ca_certificate=/etc/ssl/certs/ca-certificates.crt' >> /root/.wgetrc RUN sed -i '1i\openssl_conf = default_conf' /usr/lib/ssl/openssl.cnf RUN echo '[ default_conf ] \n\ -ssl_conf = ssl_sect \n\ -[ssl_sect] \n\ -system_default = system_default_sect \n\ -[system_default_sect] \n\ -MinProtocol = TLSv1 \n\ -CipherString = DEFAULT:@SECLEVEL=1 \n'\ ->>/usr/lib/ssl/openssl.cnf + ssl_conf = ssl_sect \n\ + [ssl_sect] \n\ + system_default = system_default_sect \n\ + [system_default_sect] \n\ + MinProtocol = TLSv1 \n\ + CipherString = DEFAULT:@SECLEVEL=1 \n'\ + >>/usr/lib/ssl/openssl.cnf COPY ./bios-spacegate ./spacegate