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

CDH | Fix ttrpc memory bug and gRPC lock bug #727

Merged
merged 4 commits into from
Oct 17, 2024
Merged
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
11 changes: 3 additions & 8 deletions .github/workflows/aa_basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ jobs:
include:
- instance: ubuntu-22.04
make_args: ""
cargo_test_opts: "--features openssl,rust-crypto,all-attesters,kbs,coco_as"
cargo_lint_opts: "--workspace"
cargo_test_opts: "--features openssl,rust-crypto,all-attesters,kbs,coco_as,ttrpc,grpc"
- instance: s390x
make_args: "ATTESTER=se-attester TEE_PLATFORM=se"
cargo_test_opts: "--no-default-features --features openssl,passport,se-attester,kbs,coco_as"
cargo_lint_opts: "--no-default-features --features openssl,se-attester,kbs,coco_as -p attestation-agent -p attester -p coco_keyprovider -p kbc -p kbs_protocol -p crypto -p resource_uri"
runs-on: ${{ matrix.instance }}
steps:
- name: Code checkout
Expand Down Expand Up @@ -109,8 +107,5 @@ jobs:
args: --all -- --check

- name: Run rust lint check
uses: actions-rs/cargo@v1
with:
command: clippy
# We are getting error in generated code due to derive_partial_eq_without_eq check, so ignore it for now
args: ${{ matrix.cargo_lint_opts }} -- -D warnings -A clippy::derive-partial-eq-without-eq
run: |
make lint
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ tokio = "1.39"
toml = "0.8.19"
tonic = "0.12"
tonic-build = "0.12"
ttrpc = "0.8.0"
ttrpc = "0.8.2"
ttrpc-codegen = "0.4.2"
url = "2.5.2"
uuid = "1"
Expand Down
28 changes: 0 additions & 28 deletions api-server-rest/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,6 @@ fn main() -> std::io::Result<()> {
];
let protobuf_customized = ProtobufCustomize::default().gen_mod_rs(false);

use std::fs::File;
use std::io::{Read, Write};

fn replace_text_in_file(file_name: &str, from: &str, to: &str) -> Result<(), std::io::Error> {
let mut src = File::open(file_name)?;
let mut contents = String::new();
src.read_to_string(&mut contents).unwrap();
drop(src);

let new_contents = contents.replace(from, to);

let mut dst = File::create(file_name)?;
dst.write_all(new_contents.as_bytes())?;

Ok(())
}

Codegen::new()
.out_dir("src/ttrpc_proto")
.inputs(&protos)
Expand All @@ -118,17 +101,6 @@ fn main() -> std::io::Result<()> {
.run()
.expect("Generate ttrpc protocol code failed.");

// Fix clippy warnings of code generated from ttrpc_codegen
replace_text_in_file(
"src/ttrpc_proto/attestation_agent_ttrpc.rs",
"#![allow(box_pointers)]\n",
"",
)?;
replace_text_in_file(
"src/ttrpc_proto/confidential_data_hub_ttrpc.rs",
"#![allow(box_pointers)]\n",
"",
)?;
generate_openapi_document().expect("Generate restful OpenAPI yaml failed.");

Ok(())
Expand Down
8 changes: 4 additions & 4 deletions api-server-rest/src/ttrpc_proto/attestation_agent_ttrpc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is generated by ttrpc-compiler 0.6.2. Do not edit
// This file is generated by ttrpc-compiler 0.6.3. Do not edit
// @generated

#![cfg_attr(rustfmt, rustfmt_skip)]
Expand Down Expand Up @@ -43,7 +43,7 @@ impl AttestationAgentServiceClient {
}

struct GetEvidenceMethod {
service: Arc<Box<dyn AttestationAgentService + Send + Sync>>,
service: Arc<dyn AttestationAgentService + Send + Sync>,
}

#[async_trait]
Expand All @@ -54,7 +54,7 @@ impl ::ttrpc::r#async::MethodHandler for GetEvidenceMethod {
}

struct GetTokenMethod {
service: Arc<Box<dyn AttestationAgentService + Send + Sync>>,
service: Arc<dyn AttestationAgentService + Send + Sync>,
}

#[async_trait]
Expand All @@ -74,7 +74,7 @@ pub trait AttestationAgentService: Sync {
}
}

pub fn create_attestation_agent_service(service: Arc<Box<dyn AttestationAgentService + Send + Sync>>) -> HashMap<String, ::ttrpc::r#async::Service> {
pub fn create_attestation_agent_service(service: Arc<dyn AttestationAgentService + Send + Sync>) -> HashMap<String, ::ttrpc::r#async::Service> {
let mut ret = HashMap::new();
let mut methods = HashMap::new();
let streams = HashMap::new();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is generated by ttrpc-compiler 0.6.2. Do not edit
// This file is generated by ttrpc-compiler 0.6.3. Do not edit
// @generated

#![cfg_attr(rustfmt, rustfmt_skip)]
Expand Down Expand Up @@ -38,7 +38,7 @@ impl GetResourceServiceClient {
}

struct GetResourceMethod {
service: Arc<Box<dyn GetResourceService + Send + Sync>>,
service: Arc<dyn GetResourceService + Send + Sync>,
}

#[async_trait]
Expand All @@ -55,7 +55,7 @@ pub trait GetResourceService: Sync {
}
}

pub fn create_get_resource_service(service: Arc<Box<dyn GetResourceService + Send + Sync>>) -> HashMap<String, ::ttrpc::r#async::Service> {
pub fn create_get_resource_service(service: Arc<dyn GetResourceService + Send + Sync>) -> HashMap<String, ::ttrpc::r#async::Service> {
let mut ret = HashMap::new();
let mut methods = HashMap::new();
let streams = HashMap::new();
Expand Down
14 changes: 14 additions & 0 deletions attestation-agent/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,26 @@ else
features := $(features),rust-crypto
endif

ifeq ($(ARCH), s390x)
LINT_OPTION = lint-s390x
else
LINT_OPTION = lint-default
endif

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

TARGET := $(TARGET_DIR)/$(BIN_NAME)

lint: $(LINT_OPTION)

lint-default:
cd attestation-agent && cargo clippy --features kbs,coco_as,bin,grpc,ttrpc,all-attesters

lint-s390x:
cd attestation-agent && cargo clippy --no-default-features --features openssl,kbs,coco_as,bin,grpc,ttrpc

install:
install -D -m0755 $(TARGET) $(DESTDIR)/$(BIN_NAME)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ impl AttestationAgentService for AA {
}

pub fn start_ttrpc_service(aa: AttestationAgent) -> Result<HashMap<String, Service>> {
let service = Box::new(AA { inner: aa }) as Box<dyn AttestationAgentService + Send + Sync>;

let service = AA { inner: aa };
let service = Arc::new(service);
let get_resource_service = create_attestation_agent_service(service);
Ok(get_resource_service)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is generated by rust-protobuf 3.5.0. Do not edit
// This file is generated by rust-protobuf 3.5.1. Do not edit
// .proto file is parsed by pure
// @generated

Expand All @@ -9,7 +9,6 @@
#![allow(unused_attributes)]
#![cfg_attr(rustfmt, rustfmt::skip)]

#![allow(box_pointers)]
#![allow(dead_code)]
Xynnn007 marked this conversation as resolved.
Show resolved Hide resolved
#![allow(missing_docs)]
#![allow(non_camel_case_types)]
Expand All @@ -23,7 +22,7 @@
/// Generated files are compatible only with the same version
/// of protobuf runtime.
const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_3_5_0;
const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_3_5_1;

// @@protoc_insertion_point(message:attestation_agent.GetEvidenceRequest)
#[derive(PartialEq,Clone,Default,Debug)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// This file is generated by ttrpc-compiler 0.6.2. Do not edit
// This file is generated by ttrpc-compiler 0.6.3. Do not edit
// @generated

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unknown_lints)]
#![allow(clipto_camel_casepy)]
#![allow(box_pointers)]
#![allow(dead_code)]
#![allow(missing_docs)]
#![allow(non_camel_case_types)]
Expand Down Expand Up @@ -64,7 +63,7 @@ impl AttestationAgentServiceClient {
}

struct GetEvidenceMethod {
service: Arc<Box<dyn AttestationAgentService + Send + Sync>>,
service: Arc<dyn AttestationAgentService + Send + Sync>,
}

#[async_trait]
Expand All @@ -75,7 +74,7 @@ impl ::ttrpc::r#async::MethodHandler for GetEvidenceMethod {
}

struct GetTokenMethod {
service: Arc<Box<dyn AttestationAgentService + Send + Sync>>,
service: Arc<dyn AttestationAgentService + Send + Sync>,
}

#[async_trait]
Expand All @@ -86,7 +85,7 @@ impl ::ttrpc::r#async::MethodHandler for GetTokenMethod {
}

struct ExtendRuntimeMeasurementMethod {
service: Arc<Box<dyn AttestationAgentService + Send + Sync>>,
service: Arc<dyn AttestationAgentService + Send + Sync>,
}

#[async_trait]
Expand All @@ -97,7 +96,7 @@ impl ::ttrpc::r#async::MethodHandler for ExtendRuntimeMeasurementMethod {
}

struct CheckInitDataMethod {
service: Arc<Box<dyn AttestationAgentService + Send + Sync>>,
service: Arc<dyn AttestationAgentService + Send + Sync>,
}

#[async_trait]
Expand All @@ -108,7 +107,7 @@ impl ::ttrpc::r#async::MethodHandler for CheckInitDataMethod {
}

struct UpdateConfigurationMethod {
service: Arc<Box<dyn AttestationAgentService + Send + Sync>>,
service: Arc<dyn AttestationAgentService + Send + Sync>,
}

#[async_trait]
Expand All @@ -119,7 +118,7 @@ impl ::ttrpc::r#async::MethodHandler for UpdateConfigurationMethod {
}

struct GetTeeTypeMethod {
service: Arc<Box<dyn AttestationAgentService + Send + Sync>>,
service: Arc<dyn AttestationAgentService + Send + Sync>,
}

#[async_trait]
Expand Down Expand Up @@ -151,7 +150,7 @@ pub trait AttestationAgentService: Sync {
}
}

pub fn create_attestation_agent_service(service: Arc<Box<dyn AttestationAgentService + Send + Sync>>) -> HashMap<String, ::ttrpc::r#async::Service> {
pub fn create_attestation_agent_service(service: Arc<dyn AttestationAgentService + Send + Sync>) -> HashMap<String, ::ttrpc::r#async::Service> {
let mut ret = HashMap::new();
let mut methods = HashMap::new();
let streams = HashMap::new();
Expand Down
5 changes: 0 additions & 5 deletions attestation-agent/kbs_protocol/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"client: client",
"client",
)?;
replace_text_in_file(
"src/token_provider/aa/attestation_agent_ttrpc.rs",
"#![allow(box_pointers)]\n",
"",
)?;
}

Ok(())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is generated by ttrpc-compiler 0.6.2. Do not edit
// This file is generated by ttrpc-compiler 0.6.3. Do not edit
// @generated

#![cfg_attr(rustfmt, rustfmt_skip)]
Expand Down Expand Up @@ -63,7 +63,7 @@ impl AttestationAgentServiceClient {
}

struct GetEvidenceMethod {
service: Arc<Box<dyn AttestationAgentService + Send + Sync>>,
service: Arc<dyn AttestationAgentService + Send + Sync>,
}

#[async_trait]
Expand All @@ -74,7 +74,7 @@ impl ::ttrpc::r#async::MethodHandler for GetEvidenceMethod {
}

struct GetTokenMethod {
service: Arc<Box<dyn AttestationAgentService + Send + Sync>>,
service: Arc<dyn AttestationAgentService + Send + Sync>,
}

#[async_trait]
Expand All @@ -85,7 +85,7 @@ impl ::ttrpc::r#async::MethodHandler for GetTokenMethod {
}

struct ExtendRuntimeMeasurementMethod {
service: Arc<Box<dyn AttestationAgentService + Send + Sync>>,
service: Arc<dyn AttestationAgentService + Send + Sync>,
}

#[async_trait]
Expand All @@ -96,7 +96,7 @@ impl ::ttrpc::r#async::MethodHandler for ExtendRuntimeMeasurementMethod {
}

struct CheckInitDataMethod {
service: Arc<Box<dyn AttestationAgentService + Send + Sync>>,
service: Arc<dyn AttestationAgentService + Send + Sync>,
}

#[async_trait]
Expand All @@ -107,7 +107,7 @@ impl ::ttrpc::r#async::MethodHandler for CheckInitDataMethod {
}

struct UpdateConfigurationMethod {
service: Arc<Box<dyn AttestationAgentService + Send + Sync>>,
service: Arc<dyn AttestationAgentService + Send + Sync>,
}

#[async_trait]
Expand All @@ -118,7 +118,7 @@ impl ::ttrpc::r#async::MethodHandler for UpdateConfigurationMethod {
}

struct GetTeeTypeMethod {
service: Arc<Box<dyn AttestationAgentService + Send + Sync>>,
service: Arc<dyn AttestationAgentService + Send + Sync>,
}

#[async_trait]
Expand Down Expand Up @@ -150,7 +150,7 @@ pub trait AttestationAgentService: Sync {
}
}

pub fn create_attestation_agent_service(service: Arc<Box<dyn AttestationAgentService + Send + Sync>>) -> HashMap<String, ::ttrpc::r#async::Service> {
pub fn create_attestation_agent_service(service: Arc<dyn AttestationAgentService + Send + Sync>) -> HashMap<String, ::ttrpc::r#async::Service> {
let mut ret = HashMap::new();
let mut methods = HashMap::new();
let streams = HashMap::new();
Expand Down
10 changes: 0 additions & 10 deletions confidential-data-hub/hub/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ fn main() {

// Fix clippy warnings of code generated from ttrpc_codegen
replace_text_in_file("src/bin/protos/api_ttrpc.rs", "client: client", "client");
replace_text_in_file(
"src/bin/protos/api_ttrpc.rs",
"#![allow(box_pointers)]\n",
"",
);
replace_text_in_file(
"src/bin/protos/keyprovider_ttrpc.rs",
"#![allow(box_pointers)]\n",
"",
);
}

#[cfg(feature = "bin")]
Expand Down
Loading
Loading