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

Fetch quotes from Marblerun Prometheus REST API endpoint #1159

Merged
merged 40 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
67a5ad7
citadel mods
OverOrion Jan 10, 2023
d74d9de
use ldconfig
OverOrion Jan 11, 2023
9091aca
service: skip check_files if dcap attestation is used
OverOrion Jan 16, 2023
d9a0ccf
worker: move feature check to check_files() to silence unused warning…
OverOrion Jan 16, 2023
a29a0e3
Add function to verify quote from the outside
OverOrion Jan 24, 2023
b493c14
fix invalid extrinsic return parameter
OverOrion Jan 30, 2023
15461be
cleanup
OverOrion Jan 30, 2023
de97b6d
rename fetch_stuff
OverOrion Jan 30, 2023
f6cc3a5
extract timeout
OverOrion Jan 30, 2023
9c3908c
remove comment 2x
OverOrion Jan 30, 2023
192a14f
extract function
OverOrion Jan 30, 2023
129eb76
add flag for prometheus endpoint base url
OverOrion Jan 30, 2023
6090f91
dcap vs ias check_files
OverOrion Jan 30, 2023
cc44202
switch to rest_client
OverOrion Jan 30, 2023
f49978a
fix typo
OverOrion Jan 30, 2023
ec20be4
remove comment by me
OverOrion Jan 30, 2023
1c6bdc2
fetch events every hour
OverOrion Jan 31, 2023
1ef93c9
remove unnecessary comment
OverOrion Jan 31, 2023
072d492
fetch fmspc from dcap_quote
OverOrion Jan 31, 2023
a11e607
fixes
OverOrion Feb 1, 2023
1e87fbe
worker: fetch FMSPC from RA certificate
OverOrion Feb 1, 2023
334c8eb
cleanup2
OverOrion Feb 2, 2023
7974e94
fix typo
OverOrion Feb 2, 2023
68fff49
Placeholder commit for updating pallets/node after .37 polkadot updat…
OverOrion Feb 2, 2023
02de806
Clippy fixes
OverOrion Feb 2, 2023
0b5bb49
add feature flags for dcap, use pallets fork
OverOrion Feb 6, 2023
f189e00
ci: taplo fmt
OverOrion Feb 20, 2023
4da47df
revert accidental Cargo.toml style changes
OverOrion Feb 22, 2023
b03d645
service: add handy derives to PrometheusMarblerRunEvent and Prometheu…
OverOrion Feb 22, 2023
4980f2f
service: add proper reasoning to expect() in register_quotes_from_mar…
OverOrion Feb 22, 2023
43476fd
enclave-runtime/attestation: remove leftover debug output
OverOrion Feb 22, 2023
fa96687
pallets: use updated polkadot branch
OverOrion Feb 22, 2023
174b4e2
rename generate_dcap_ra_extrinsic_internal_with_quote() to generate_d…
OverOrion Feb 22, 2023
2e7c7e2
rename methods to generate_dcap_ra_extrinsic_from_quote{_internal}
OverOrion Feb 22, 2023
00c8b7b
remove obsolete todo
OverOrion Feb 22, 2023
70d859b
fix typo in expect message
OverOrion Feb 22, 2023
f15568b
*.toml: fix accidental formatting
OverOrion Feb 22, 2023
fd2647e
Merge remote-tracking branch 'in/master' into szp/prometheus_pr
OverOrion Feb 22, 2023
a5c9063
service: handle registering marblerun quotes failure with error logging
OverOrion Feb 22, 2023
06e15ff
ffi: remove _internal suffix from generate_dcap_ra_extrinsic_from_quo…
OverOrion Feb 22, 2023
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
172 changes: 88 additions & 84 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions app-libs/stf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ edition = "2021"

[dependencies]
# crates.io
codec = { version = "3.0.0", default-features = false, features = ["derive"], package = "parity-scale-codec" }
codec = { version = "3.0.0", default-features = false, features = [
"derive",
], package = "parity-scale-codec" }
derive_more = { version = "0.99.5" }
log = { version = "0.4", default-features = false }
rlp = { version = "0.5", default-features = false }
Expand All @@ -27,7 +29,11 @@ itp-stf-primitives = { default-features = false, path = "../../core-primitives/s
itp-storage = { default-features = false, path = "../../core-primitives/storage" }
itp-types = { default-features = false, path = "../../core-primitives/types" }
itp-utils = { default-features = false, path = "../../core-primitives/utils" }
sp-io = { default-features = false, features = ["disable_oom", "disable_panic_handler", "disable_allocator"], path = "../../core-primitives/substrate-sgx/sp-io" }
sp-io = { default-features = false, features = [
"disable_oom",
"disable_panic_handler",
"disable_allocator",
], path = "../../core-primitives/substrate-sgx/sp-io" }
clangenb marked this conversation as resolved.
Show resolved Hide resolved

# Substrate dependencies
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
Expand All @@ -49,10 +55,7 @@ sp-keyring = { git = "https://github.com/paritytech/substrate.git", branch = "po
[features]
default = ["std"]
evm = ["ita-sgx-runtime/evm"]
evm_std = [
"evm",
"ita-sgx-runtime/evm_std",
]
evm_std = ["evm", "ita-sgx-runtime/evm_std"]
sgx = [
"sgx_tstd",
"itp-sgx-externalities/sgx",
Expand Down
9 changes: 4 additions & 5 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ base58 = "0.2"
blake2-rfc = { version = "0.2.18" }
chrono = "*"
clap = { version = "3.1.6", features = ["derive"] }
codec = { version = "3.0.0", package = "parity-scale-codec", features = ["derive"] }
codec = { version = "3.0.0", package = "parity-scale-codec", features = [
"derive",
] }
clangenb marked this conversation as resolved.
Show resolved Hide resolved
env_logger = "0.9"
hdrhistogram = "7.5.0"
hex = "0.4.2"
Expand Down Expand Up @@ -51,10 +53,7 @@ itp-utils = { path = "../core-primitives/utils" }

[features]
default = []
evm = [
"ita-stf/evm_std",
"pallet-evm",
]
evm = ["ita-stf/evm_std", "pallet-evm"]
teeracle = []
sidechain = []
offchain-worker = []
Expand Down
22 changes: 22 additions & 0 deletions core-primitives/enclave-api/ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ use sgx_types::{

extern "C" {

pub fn generate_dcap_ra_extrinsic_from_quote_internal(
eid: sgx_enclave_id_t,
retval: *mut sgx_status_t,
w_url: *const u8,
w_url_size: u32,
quote: *const u8,
quote_size: u32,
unchecked_extrinsic: *mut u8,
unchecked_extrinsic_size: u32,
) -> sgx_status_t;

pub fn init(
eid: sgx_enclave_id_t,
retval: *mut sgx_status_t,
Expand Down Expand Up @@ -115,6 +126,16 @@ extern "C" {
quote_size: u32,
) -> sgx_status_t;

pub fn generate_dcap_ra_quote(
eid: sgx_enclave_id_t,
retval: *mut sgx_status_t,
skip_ra: c_int,
quoting_enclave_target_info: &sgx_target_info_t,
quote_size: u32,
dcap_quote_p: *mut u8,
dcap_quote_size: u32,
) -> sgx_status_t;

pub fn generate_register_quoting_enclave_extrinsic(
eid: sgx_enclave_id_t,
retval: *mut sgx_status_t,
Expand Down Expand Up @@ -199,4 +220,5 @@ extern "C" {
shard_size: u32,
skip_ra: c_int,
) -> sgx_status_t;

}
87 changes: 86 additions & 1 deletion core-primitives/enclave-api/src/remote_attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ pub trait RemoteAttestation {
fn generate_ias_ra_extrinsic(&self, w_url: &str, skip_ra: bool) -> EnclaveResult<Vec<u8>>;

fn generate_dcap_ra_extrinsic(&self, w_url: &str, skip_ra: bool) -> EnclaveResult<Vec<u8>>;
fn generate_dcap_ra_extrinsic_from_quote(
&self,
url: String,
quote: &[u8],
) -> EnclaveResult<Vec<u8>>;
fn generate_dcap_ra_quote(&self, skip_ra: bool) -> EnclaveResult<Vec<u8>>;

fn generate_register_quoting_enclave_extrinsic(&self, fmspc: Fmspc) -> EnclaveResult<Vec<u8>>;

Expand Down Expand Up @@ -145,6 +151,60 @@ impl RemoteAttestation for Enclave {

Ok(unchecked_extrinsic)
}
fn generate_dcap_ra_extrinsic_from_quote(
&self,
url: String,
quote: &[u8],
) -> EnclaveResult<Vec<u8>> {
let mut retval = sgx_status_t::SGX_SUCCESS;
let mut unchecked_extrinsic: Vec<u8> = vec![0u8; EXTRINSIC_MAX_SIZE];
let url = url.encode();

let result = unsafe {
ffi::generate_dcap_ra_extrinsic_from_quote_internal(
self.eid,
&mut retval,
url.as_ptr(),
url.len() as u32,
quote.as_ptr(),
quote.len() as u32,
unchecked_extrinsic.as_mut_ptr(),
unchecked_extrinsic.len() as u32,
)
};

ensure!(result == sgx_status_t::SGX_SUCCESS, Error::Sgx(result));
ensure!(retval == sgx_status_t::SGX_SUCCESS, Error::Sgx(retval));

Ok(unchecked_extrinsic.to_vec())
}

fn generate_dcap_ra_quote(&self, skip_ra: bool) -> EnclaveResult<Vec<u8>> {
let mut retval = sgx_status_t::SGX_SUCCESS;
let quoting_enclave_target_info = self.qe_get_target_info()?;
let quote_size = self.qe_get_quote_size()?;

let mut dcap_quote_vec: Vec<u8> = vec![0; quote_size as usize];
let (dcap_quote_p, dcap_quote_size) =
(dcap_quote_vec.as_mut_ptr(), dcap_quote_vec.len() as u32);

let result = unsafe {
ffi::generate_dcap_ra_quote(
self.eid,
&mut retval,
skip_ra.into(),
&quoting_enclave_target_info,
quote_size,
dcap_quote_p,
dcap_quote_size,
)
};

ensure!(result == sgx_status_t::SGX_SUCCESS, Error::Sgx(result));
ensure!(retval == sgx_status_t::SGX_SUCCESS, Error::Sgx(retval));

Ok(dcap_quote_vec)
}

fn generate_dcap_ra_extrinsic(&self, w_url: &str, skip_ra: bool) -> EnclaveResult<Vec<u8>> {
let mut retval = sgx_status_t::SGX_SUCCESS;
Expand Down Expand Up @@ -587,7 +647,32 @@ impl TlsRemoteAttestation for Enclave {
}

fn create_system_path(file_name: &str) -> String {
format!("{}{}{}", OS_SYSTEM_PATH, file_name, C_STRING_ENDING)
info!("create_system_path:: file_name={}", &file_name);
let default_path = format!("{}{}", OS_SYSTEM_PATH, file_name);

let full_path = find_library_by_name(file_name).unwrap_or(default_path);

let c_terminated_path = format!("{}{}", full_path, C_STRING_ENDING);
info!("create_system_path:: created path={}", &c_terminated_path);
c_terminated_path
}
fn find_library_by_name(lib_name: &str) -> Option<String> {
use std::process::Command;
// ldconfig -p | grep libsgx_pce_logic.so.1

let ldconfig_output = Command::new("ldconfig").args(["-p"]).output().ok()?;
let possible_path = String::from_utf8(ldconfig_output.stdout)
.ok()?
.lines()
.filter(|line| line.contains(lib_name))
.map(|lib_name_and_path| {
lib_name_and_path
.rsplit_once("=>")
.map(|(_, lib_path)| lib_path.trim().to_owned())
})
.next()?;

possible_path
}

fn set_ql_path(path_type: sgx_ql_path_type_t, path: &str) -> EnclaveResult<()> {
Expand Down
6 changes: 4 additions & 2 deletions core/rest-client/src/rest_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
#[cfg(all(not(feature = "std"), feature = "sgx"))]
use crate::sgx_reexport_prelude::*;

pub use http_req::{request::Method, response::Headers};
pub use url::Url;

use crate::{
error::Error, http_client::SendHttpRequest, Query, RestDelete, RestGet, RestPatch, RestPath,
RestPost, RestPut,
};
use http_req::{request::Method, response::Headers};

use log::*;
use std::string::{String, ToString};
use url::Url;

/// REST client to make HTTP GET and POST requests.
pub struct RestClient<H> {
Expand Down
16 changes: 8 additions & 8 deletions enclave-runtime/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"
dependencies = [
"getrandom 0.2.3",
"once_cell 1.17.0",
"once_cell 1.17.1",
"version_check",
]

Expand Down Expand Up @@ -2556,7 +2556,7 @@ dependencies = [
"mio",
"sgx_tstd",
"sgx_types",
"slab 0.4.7",
"slab 0.4.8",
]

[[package]]
Expand Down Expand Up @@ -2715,9 +2715,9 @@ dependencies = [

[[package]]
name = "once_cell"
version = "1.17.0"
version = "1.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66"
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"

[[package]]
name = "opaque-debug"
Expand Down Expand Up @@ -2822,7 +2822,7 @@ dependencies = [
[[package]]
name = "pallet-parentchain"
version = "0.9.0"
source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.37#50cac490de02a6484751c193da9f8080477b885c"
source = "git+https://github.com/integritee-network/pallets.git?branch=polkadot-v0.9.37#824c9a50dd8902697bd3e75ab6b5f7c3d663167f"
dependencies = [
"frame-support",
"frame-system",
Expand Down Expand Up @@ -3028,7 +3028,7 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66618389e4ec1c7afe67d51a9bf34ff9236480f8d51e7489b7d5ab0303c13f34"
dependencies = [
"once_cell 1.17.0",
"once_cell 1.17.1",
"toml_edit",
]

Expand Down Expand Up @@ -3838,9 +3838,9 @@ dependencies = [

[[package]]
name = "slab"
version = "0.4.7"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef"
checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d"
dependencies = [
"autocfg 1.1.0",
]
Expand Down
12 changes: 12 additions & 0 deletions enclave-runtime/Enclave.edl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ enclave {
[out, size=unchecked_extrinsic_size] uint8_t* unchecked_extrinsic, uint32_t unchecked_extrinsic_size,
int skip_ra
);
public sgx_status_t generate_dcap_ra_quote(
int skip_ra,
[in] const sgx_target_info_t* quoting_enclave_target_info,
uint32_t quote_size,
[out, size=dcap_quote_size] uint8_t* dcap_quote_p, uint32_t dcap_quote_size
);

public sgx_status_t generate_dcap_ra_extrinsic_from_quote_internal(
clangenb marked this conversation as resolved.
Show resolved Hide resolved
[in, size=w_url_size] uint8_t* w_url, uint32_t w_url_size,
[in, size=quote_size] uint8_t* quote, uint32_t quote_size,
[out, size=unchecked_extrinsic_size] uint8_t* unchecked_extrinsic, uint32_t unchecked_extrinsic_size
);

public sgx_status_t generate_dcap_ra_extrinsic(
[in, size=w_url_size] uint8_t* w_url, uint32_t w_url_size,
Expand Down
Loading