diff --git a/src/agent/src/rpc.rs b/src/agent/src/rpc.rs index 5f2a3eb955..8dc50ea996 100644 --- a/src/agent/src/rpc.rs +++ b/src/agent/src/rpc.rs @@ -649,11 +649,11 @@ impl AgentService { async fn do_read_stream( &self, - req: protocols::agent::ReadStreamRequest, + req: &protocols::agent::ReadStreamRequest, stdout: bool, ) -> Result { - let cid = req.container_id; - let eid = req.exec_id; + let cid = &req.container_id; + let eid = &req.exec_id; let term_exit_notifier; let reader = { @@ -900,8 +900,12 @@ impl agent_ttrpc::AgentService for AgentService { _ctx: &TtrpcContext, req: protocols::agent::ReadStreamRequest, ) -> ttrpc::Result { - is_allowed(&req).await?; - self.do_read_stream(req, true).await.map_ttrpc_err(same) + let mut response = self.do_read_stream(&req, true).await.map_ttrpc_err(same)?; + if is_allowed(&req).await.is_err() { + // Policy does not allow reading logs, so we redact the log messages. + response.clear_data(); + } + Ok(response) } async fn read_stderr( @@ -909,8 +913,12 @@ impl agent_ttrpc::AgentService for AgentService { _ctx: &TtrpcContext, req: protocols::agent::ReadStreamRequest, ) -> ttrpc::Result { - is_allowed(&req).await?; - self.do_read_stream(req, false).await.map_ttrpc_err(same) + let mut response = self.do_read_stream(&req, false).await.map_ttrpc_err(same)?; + if is_allowed(&req).await.is_err() { + // Policy does not allow reading logs, so we redact the log messages. + response.clear_data(); + } + Ok(response) } async fn close_stdin(