Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some debug logs and change some log messages #764

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion attestation-agent/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ else
endif

build:
cd attestation-agent && $(RUST_FLAGS) cargo build $(release) --no-default-features --features "$(features)" $(binary) $(LIBC_FLAG)
cd attestation-agent && RUST_LOG=debug $(RUST_FLAGS) cargo build $(release) --no-default-features --features "$(features)" $(binary) $(LIBC_FLAG)
mv $(TARGET_DIR)/$(binary_name) $(TARGET)

TARGET := $(TARGET_DIR)/$(BIN_NAME)
Expand Down
8 changes: 8 additions & 0 deletions attestation-agent/attestation-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,11 @@ openssl = ["kbs_protocol?/openssl"]
bin = ["clap", "env_logger", "tokio/rt-multi-thread"]
grpc = ["prost", "tonic", "tonic-build", "tokio/signal"]
ttrpc = ["dep:ttrpc", "ttrpc-codegen", "protobuf", "tokio/signal"]

[profile.dev]
opt-level = 0 # No optimization
debug = true # This should be true for debug builds

[profile.release]
opt-level = 3 # Optimization level
debug = true # This should be true for release builds
43 changes: 23 additions & 20 deletions attestation-agent/attestation-agent/src/bin/ttrpc-aa/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ::ttrpc::proto::Code;
use anyhow::*;
use async_trait::async_trait;
use attestation_agent::{AttestationAPIs, AttestationAgent};
use log::{debug, error};
use log::{debug, error, info};

use std::collections::HashMap;
use std::sync::Arc;
Expand All @@ -35,17 +35,17 @@ impl AttestationAgentService for AA {
_ctx: &::ttrpc::r#async::TtrpcContext,
req: GetTokenRequest,
) -> ::ttrpc::Result<GetTokenResponse> {
debug!("AA (ttrpc): get token ...");
info!("AA (ttrpc): Received get_token request with TokenType: {}", req.TokenType);

let token = self.inner.get_token(&req.TokenType).await.map_err(|e| {
error!("AA (ttrpc): get token failed\n {e:?}");
error!("AA (ttrpc): get token failed: {e:?}");
let mut error_status = ::ttrpc::proto::Status::new();
error_status.set_code(Code::INTERNAL);
error_status.set_message(format!("[ERROR:{AGENT_NAME}] AA-KBC get token failed"));
::ttrpc::Error::RpcStatus(error_status)
})?;

debug!("AA (ttrpc): Get token successfully!");
info!("AA (ttrpc): Successfully retrieved token");

let mut reply = GetTokenResponse::new();
reply.Token = token;
Expand All @@ -58,22 +58,21 @@ impl AttestationAgentService for AA {
_ctx: &::ttrpc::r#async::TtrpcContext,
req: GetEvidenceRequest,
) -> ::ttrpc::Result<GetEvidenceResponse> {
debug!("AA (ttrpc): get evidence ...");
info!("AA (ttrpc): Received get_evidence request with RuntimeData size: {}", req.RuntimeData.len());

let evidence = self
.inner
.get_evidence(&req.RuntimeData)
.await
.map_err(|e| {
error!("AA (ttrpc): get evidence failed:\n {e:?}");
error!("AA (ttrpc): get evidence failed: {e:?}");
let mut error_status = ::ttrpc::proto::Status::new();
error_status.set_code(Code::INTERNAL);
error_status
.set_message(format!("[ERROR:{AGENT_NAME}] AA-KBC get evidence failed"));
error_status.set_message(format!("[ERROR:{AGENT_NAME}] AA-KBC get evidence failed"));
::ttrpc::Error::RpcStatus(error_status)
})?;

debug!("AA (ttrpc): Get evidence successfully!");
info!("AA (ttrpc): Successfully retrieved evidence");

let mut reply = GetEvidenceResponse::new();
reply.Evidence = evidence;
Expand All @@ -86,7 +85,7 @@ impl AttestationAgentService for AA {
_ctx: &::ttrpc::r#async::TtrpcContext,
req: ExtendRuntimeMeasurementRequest,
) -> ::ttrpc::Result<ExtendRuntimeMeasurementResponse> {
debug!("AA (ttrpc): extend runtime measurement ...");
info!("AA (ttrpc): Received extend_runtime_measurement request with Domain: {}, Operation: {}, Content: {}", req.Domain, req.Operation, req.Content);

self.inner
.extend_runtime_measurement(
Expand All @@ -97,7 +96,7 @@ impl AttestationAgentService for AA {
)
.await
.map_err(|e| {
error!("AA (ttrpc): extend runtime measurement failed:\n {e:?}");
error!("AA (ttrpc): extend runtime measurement failed: {e:?}");
let mut error_status = ::ttrpc::proto::Status::new();
error_status.set_code(Code::INTERNAL);
error_status.set_message(format!(
Expand All @@ -106,7 +105,7 @@ impl AttestationAgentService for AA {
::ttrpc::Error::RpcStatus(error_status)
})?;

debug!("AA (ttrpc): extend runtime measurement succeeded.");
info!("AA (ttrpc): Successfully extended runtime measurement");
let reply = ExtendRuntimeMeasurementResponse::new();
::ttrpc::Result::Ok(reply)
}
Expand All @@ -116,13 +115,13 @@ impl AttestationAgentService for AA {
_ctx: &::ttrpc::r#async::TtrpcContext,
req: UpdateConfigurationRequest,
) -> ::ttrpc::Result<UpdateConfigurationResponse> {
debug!("AA (ttrpc): update configuration ...");
debug!("AA (ttrpc): Received update_configuration request with config: {}", req.config);

self.inner
.update_configuration(&req.config)
.await
.map_err(|e| {
error!("AA (ttrpc): update configuration failed:\n {e:?}");
error!("AA (ttrpc): update configuration failed: {e:?}");
let mut error_status = ::ttrpc::proto::Status::new();
error_status.set_code(Code::INTERNAL);
error_status.set_message(format!(
Expand All @@ -131,7 +130,7 @@ impl AttestationAgentService for AA {
::ttrpc::Error::RpcStatus(error_status)
})?;

debug!("AA (ttrpc): update configuration succeeded.");
info!("AA (ttrpc): Successfully updated configuration");
let reply = UpdateConfigurationResponse::new();
::ttrpc::Result::Ok(reply)
}
Expand All @@ -141,32 +140,36 @@ impl AttestationAgentService for AA {
_ctx: &::ttrpc::r#async::TtrpcContext,
_req: GetTeeTypeRequest,
) -> ::ttrpc::Result<GetTeeTypeResponse> {
debug!("AA (ttrpc): get tee type ...");
debug!("AA (ttrpc): Received get_tee_type request");

let tee = self.inner.get_tee_type();

let res = serde_json::to_string(&tee)
.map_err(|e| {
error!("AA (ttrpc): get tee type failed:\n {e:?}");
error!("AA (ttrpc): get tee type failed: {e:?}");
let mut error_status = ::ttrpc::proto::Status::new();
error_status.set_code(Code::INTERNAL);
error_status
.set_message(format!("[ERROR:{AGENT_NAME}] AA-KBC get tee type failed"));
error_status.set_message(format!("[ERROR:{AGENT_NAME}] AA-KBC get tee type failed"));
::ttrpc::Error::RpcStatus(error_status)
})?
.trim_end_matches('"')
.trim_start_matches('"')
.to_string();
debug!("AA (ttrpc): get tee type succeeded.");

info!("AA (ttrpc): Successfully retrieved tee type: {}", res);

let mut reply = GetTeeTypeResponse::new();
reply.tee = res;
::ttrpc::Result::Ok(reply)
}
}

pub fn start_ttrpc_service(aa: AttestationAgent) -> Result<HashMap<String, Service>> {
info!("Starting TTRPC service for Attestation Agent");
let service = AA { inner: aa };
let service = Arc::new(service);
let get_resource_service = create_attestation_agent_service(service);
info!("TTRPC service for Attestation Agent started successfully");
Ok(get_resource_service)
}

4 changes: 2 additions & 2 deletions attestation-agent/attestation-agent/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl Default for EventlogConfig {
Self {
eventlog_algorithm: HashAlgorithm::Sha384,
init_pcr: DEFAULT_PCR_INDEX,
enable_eventlog: false,
enable_eventlog: true,
}
}
}
Expand Down Expand Up @@ -94,7 +94,7 @@ impl TryFrom<&str> for Config {
.add_source(config::File::with_name(config_path))
.set_default("eventlog_config.eventlog_algorithm", DEFAULT_EVENTLOG_HASH)?
.set_default("eventlog_config.init_pcr", DEFAULT_PCR_INDEX)?
.set_default("eventlog_config.enable_eventlog", "false")?
.set_default("eventlog_config.enable_eventlog", "true")?
.build()?;

let cfg = c.try_deserialize()?;
Expand Down
Loading