Skip to content

Commit 5e32460

Browse files
sarroutbiclaude
authored andcommitted
Improve logging consistency and coherency
This commit implements comprehensive logging improvements to ensure coherent and consistent HTTP request/response logging throughout the Keylime system. Changes made: 1. Centralized HTTP Logging in ResilientClient: - Added consistent response code and header logging at DEBUG level - All HTTP requests now have uniform logging behavior across the codebase - Request headers already logged, now response headers match the same format 2. Fixed JSON Logging Issues: - Request JSON now logged as proper JSON string instead of Rust debug format - Changed from `{:?}` format to `serde_json::to_string()` for clean output - All JSON logging moved from INFO to DEBUG level for consistency - Added proper error handling for JSON serialization failures 3. Eliminated Duplicate Response Logging: - Removed redundant response body logging in state_machine.rs - Response information now logged exactly once per HTTP request - Maintained necessary response data for application logic 4. Enhanced URL Logging Context: - Added HTTP methods to URL logging (POST/PATCH) - Improved chronological order: Phase 1 logs negotiation URL, Phase 2 logs evidence URL - Made location header source explicit ("from 201 Created response") - Consistent format: "Purpose URL (METHOD): {url}" 5. Protocol Flow Clarity: - Capabilities negotiation URL logged in Phase 1 where it's used - Evidence handling URL logged in Phase 2 where it's used - Clear separation between configuration URLs and runtime URLs The logging system now provides: - Consistent DEBUG-level JSON and header logging - No duplication of response information - Clear chronological flow for the two-phase attestation protocol - Centralized HTTP logging behavior via ResilientClient middleware Co-Authored-By: Claude <[email protected]> Signed-off-by: Sergio Arroutbi <[email protected]>
1 parent f310fac commit 5e32460

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

keylime-push-model-agent/src/attestation.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,16 @@ impl AttestationClient {
8484
config: &NegotiationConfig<'_>,
8585
) -> Result<ResponseInformation> {
8686
info!("--- Phase 1: Sending Capabilities Negotiation ---");
87+
info!("Capabilities negotiation URL (POST): {}", config.url);
8788
let mut context_info =
8889
context_info_handler::get_context_info(config.avoid_tpm)?;
8990
let mut filler =
9091
struct_filler::get_filler_request(context_info.as_mut());
9192

9293
let req = filler.get_attestation_request();
93-
debug!("Request body: {:?}", serde_json::to_string(&req));
94+
if let Ok(json_str) = serde_json::to_string(&req) {
95+
debug!("Request body: {}", json_str);
96+
}
9497

9598
let request_builder = self.client.get_json_request_from_struct(
9699
reqwest::Method::POST,
@@ -103,12 +106,10 @@ impl AttestationClient {
103106

104107
let sc = response.status();
105108
let headers = response.headers().clone();
106-
info!("Response code:{}", response.status());
107-
info!("Response headers: {headers:?}");
108109

109110
let response_body = response.text().await?;
110111
if !response_body.is_empty() {
111-
info!("Response body: {response_body}");
112+
debug!("Response body: {response_body}");
112113
}
113114

114115
let rsp = ResponseInformation {
@@ -154,7 +155,7 @@ impl AttestationClient {
154155
}
155156

156157
if !response_body.is_empty() {
157-
info!("PATCH Response body: {response_body}");
158+
debug!("PATCH Response body: {response_body}");
158159
}
159160

160161
Ok(ResponseInformation {
@@ -194,9 +195,8 @@ impl AttestationClient {
194195
},
195196
);
196197

197-
info!("Config URL: {}", config.url);
198-
info!("Location header: {location_header}");
199-
info!("Sending evidence (PATCH) to: {patch_url}");
198+
info!("Location header from 201 Created response: {location_header}");
199+
info!("Evidence handling URL (PATCH): {patch_url}");
200200

201201
// Use struct_filler to handle evidence collection and construction
202202
let mut context_info =

keylime-push-model-agent/src/state_machine.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ impl<'a> StateMachine<'a> {
179179
Ok(res) => {
180180
if res.status_code == reqwest::StatusCode::ACCEPTED {
181181
info!("SUCCESS! Evidence accepted by the Verifier.");
182-
info!("Response body: {}", res.body);
183182

184183
// Extract seconds_to_next_attestation from verifier response.
185184
let next_interval =

keylime/src/resilient_client.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,16 @@ impl Middleware for LoggingMiddleware {
4545
for (key, value) in req.headers() {
4646
debug!(" {key}: {value:?}");
4747
}
48-
next.run(req, extensions).await
48+
49+
let response = next.run(req, extensions).await?;
50+
51+
debug!("Response code: {}", response.status());
52+
debug!("Response headers:");
53+
for (key, value) in response.headers() {
54+
debug!(" {key}: {value:?}");
55+
}
56+
57+
Ok(response)
4958
}
5059
}
5160

0 commit comments

Comments
 (0)