[READ-ONLY] Mirror of https://github.com/FoxxMD/docker-proxy-filter. Filter the contents of Docker API responses
docker docker-socket-proxy filter
0

Configure Feed

Select the types of activity you want to include in your feed.

implement env scrubbing

FoxxMD (Oct 7, 2025, 4:46 PM UTC) 90b1a52e 820f3ce8

+25 -15
+25 -15
src/main.rs
··· 80 80 forward_url: web::types::State<url::Url>, 81 81 container_name: web::types::State<String>, 82 82 log: web::types::State<Logger>, 83 + scrub_env: web::types::State<bool>, 83 84 data: web::types::State<AppStateWithContainerMap> 84 85 ) -> Result<web::HttpResponse, web::Error> { 85 86 let mut new_url = forward_url.get_ref().clone(); ··· 99 100 100 101 if new_url.path().contains("containers/json") { 101 102 102 - //let fresp = web::HttpResponse::build(res.status()).json(&filtered_containers); 103 - 104 - 105 - //let txt = String::from_utf8(res.body().await.unwrap().to_vec()).unwrap(); 106 - 107 103 let containers = &res.json::<Vec<ContainerSummary>>().await.unwrap(); 108 104 109 105 let filtered_containers = containers.into_iter() ··· 112 108 113 109 let fresp = web::HttpResponse::build(res.status()).json(&filtered_containers); 114 110 115 - //client_resp.json(&filtered_containers); 116 - 117 - //let stream = res.into_stream(); 118 111 Ok(fresp) 119 112 } else { 120 113 ··· 139 132 match name_val { 140 133 Some(n) => { 141 134 if n.contains(container_name.get_ref()) { //n.iter().any(|x| x.contains(container_name.get_ref())) { 142 - let stream = res.into_stream(); 135 + 143 136 client_resp.content_type("application/json"); 144 - Ok(client_resp.streaming(stream)) 137 + 138 + if *scrub_env.get_ref() { 139 + let mut container = res.json::<ContainerInspect>().await.unwrap(); 140 + container.config.as_mut().unwrap().env = Some(Vec::new()); 141 + Ok(client_resp.json(&container)) 142 + } else { 143 + Ok(client_resp.streaming(res.into_stream())) 144 + } 145 145 } else { 146 146 client_resp.status(StatusCode::NOT_FOUND); 147 147 Ok(client_resp.finish()) ··· 207 207 async fn get_container_name(u: &String, container_id: &String, log: &Logger) -> Result<String, Box<dyn std::error::Error>> { 208 208 209 209 let url = format!("{}containers/{id}/json", u, id = container_id); 210 - debug!(log, "Get Container URL: {}", url); 210 + //debug!(log, "Get Container URL: {}", url); 211 211 let resp = reqwest::get(&url) 212 212 .await? 213 213 .json::<ContainerInspect>() ··· 222 222 Ok(v) 223 223 } 224 224 None => { 225 - return Err("Container has no names".into()) 225 + return Err("Container has no name".into()) 226 226 } 227 227 } 228 - // Ok(json_res.names.unwrap()) 229 228 } 230 229 Err(e) => { 231 230 return Err(Box::new(e)); 232 231 } 233 232 } 234 - 235 - //Ok(id) 236 233 } 237 234 238 235 #[ntex::main] ··· 273 270 }, 274 271 } 275 272 273 + let scub_env = match env::var("SCRUB_ENVS") { 274 + Ok(val) => { 275 + let truthy = val == "true"; 276 + info!(log, "SCRUB_ENVS: {}", truthy); 277 + truthy 278 + }, 279 + Err(e) => { 280 + info!(log, "SCRUB_ENVS: false"); 281 + false 282 + }, 283 + }; 284 + 276 285 let cm = AppStateWithContainerMap { 277 286 container_map: Arc::new(Mutex::new(HashMap::<String, Option<String>>::new())) 278 287 }; ··· 286 295 .state(container_name.clone()) 287 296 .state(log.clone()) 288 297 .state(cm.clone()) 298 + .state(scub_env.clone()) 289 299 .wrap(web::middleware::Logger::default()) 290 300 .default_service(web::route().to(forward)) 291 301 })