You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@teaclave.apache.org by ms...@apache.org on 2020/01/27 20:06:21 UTC
[incubator-teaclave] branch develop updated: [config] Separate
runtime/build config into two modules
This is an automated email from the ASF dual-hosted git repository.
mssun pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave.git
The following commit(s) were added to refs/heads/develop by this push:
new e219f9c [config] Separate runtime/build config into two modules
e219f9c is described below
commit e219f9c3b44cbf0b3f6d831b3c79a393f51f4cd4
Author: Mingshen Sun <bo...@mssun.me>
AuthorDate: Mon Jan 27 11:59:13 2020 -0800
[config] Separate runtime/build config into two modules
---
config/src/build.rs | 2 +
config/src/lib.rs | 161 ++-------------------
config/src/runtime.rs | 138 ++++++++++++++++++
ipc/src/protos/ecall.rs | 2 +-
services/authentication/app/src/main.rs | 3 +-
services/database/app/src/main.rs | 3 +-
services/execution/app/src/main.rs | 4 +-
.../enclave/src/teaclave_authentication_service.rs | 4 +-
.../app/src/teaclave_config_tests.rs | 3 +-
9 files changed, 159 insertions(+), 161 deletions(-)
diff --git a/config/src/build.rs b/config/src/build.rs
new file mode 100644
index 0000000..517b0af
--- /dev/null
+++ b/config/src/build.rs
@@ -0,0 +1,2 @@
+#![allow(clippy::all)]
+include!(concat!(env!("OUT_DIR"), "/build_config.rs"));
diff --git a/config/src/lib.rs b/config/src/lib.rs
index 91e99e2..6487cde 100644
--- a/config/src/lib.rs
+++ b/config/src/lib.rs
@@ -1,4 +1,3 @@
-// Use sgx_tstd to replace Rust's default std
#![cfg_attr(feature = "mesalock_sgx", no_std)]
#[cfg(feature = "mesalock_sgx")]
#[macro_use]
@@ -6,156 +5,18 @@ extern crate sgx_tstd as std;
#[macro_use]
extern crate log;
-pub use runtime_config::ConfigSource;
+use serde_derive::Deserialize;
+use serde_derive::Serialize;
+use std::path::PathBuf;
-pub mod build_config {
- #![allow(clippy::all)]
- include!(concat!(env!("OUT_DIR"), "/build_config.rs"));
+#[derive(Debug, Serialize, Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub enum ConfigSource {
+ Path(PathBuf),
}
-pub mod runtime_config {
- #[cfg(not(feature = "mesalock_sgx"))]
- use std::fs;
- #[cfg(feature = "mesalock_sgx")]
- use std::prelude::v1::*;
- #[cfg(feature = "mesalock_sgx")]
- use std::untrusted::fs;
+mod build;
+mod runtime;
- use serde_derive::Deserialize;
- use serde_derive::Serialize;
- use std::env;
- use std::net::SocketAddr;
- use std::path::Path;
- use std::path::PathBuf;
- use std::string::String;
- use std::vec::Vec;
- use toml;
-
- #[derive(Debug, Serialize, Deserialize)]
- pub struct RuntimeConfig {
- pub api_endpoints: ApiEndpointsConfig,
- pub internal_endpoints: InternalEndpointsConfig,
- pub audit: AuditConfig,
- pub ias: Option<IasConfig>,
- }
-
- #[derive(Debug, Serialize, Deserialize)]
- pub struct ApiEndpointsConfig {
- pub frontend: EndpointListenConfig,
- pub authentication: EndpointListenConfig,
- }
-
- #[derive(Debug, Serialize, Deserialize)]
- pub struct InternalEndpointsConfig {
- pub dbs: EndpointListenAdvertisedConfig,
- pub execution: EndpointListenAdvertisedConfig,
- }
-
- #[derive(Debug, Serialize, Deserialize)]
- pub struct EndpointListenConfig {
- pub listen_address: SocketAddr,
- }
-
- #[derive(Debug, Serialize, Deserialize)]
- pub struct EndpointListenAdvertisedConfig {
- pub listen_address: SocketAddr,
- pub advertised_address: SocketAddr,
- }
-
- #[derive(Debug, Serialize, Deserialize)]
- pub struct AuditConfig {
- #[serde(rename(serialize = "enclave_info", deserialize = "enclave_info"))]
- enclave_info_source: ConfigSource,
- #[serde(rename(serialize = "auditor_signatures", deserialize = "auditor_signatures"))]
- auditor_signatures_source: Vec<ConfigSource>,
- pub enclave_info_bytes: Option<Vec<u8>>,
- pub auditor_signatures_bytes: Option<Vec<Vec<u8>>>,
- }
-
- #[derive(Debug, Serialize, Deserialize)]
- #[serde(rename_all = "snake_case")]
- pub enum ConfigSource {
- Path(PathBuf),
- }
-
- #[derive(Debug, Serialize, Deserialize)]
- pub struct IasConfig {
- pub ias_spid: String,
- pub ias_key: String,
- }
-
- impl RuntimeConfig {
- pub fn from_toml<T: AsRef<Path>>(path: T) -> Option<Self> {
- use std::prelude::v1::*;
- let contents = match fs::read_to_string(path) {
- Ok(c) => c,
- Err(_) => {
- error!("Something went wrong reading the runtime config file.");
- return None;
- }
- };
- let mut config: RuntimeConfig = match toml::from_str(&contents) {
- Ok(c) => c,
- Err(_) => {
- error!("Something went wrong reading the runtime config file.");
- return None;
- }
- };
-
- config.audit.enclave_info_bytes = match &config.audit.enclave_info_source {
- ConfigSource::Path(ref enclave_info_path) => {
- let content = fs::read(enclave_info_path).unwrap_or_else(|_| {
- panic!("Cannot find enclave info at {:?}.", enclave_info_path)
- });
- Some(content)
- }
- };
-
- let mut signatures: Vec<Vec<u8>> = vec![];
- for source in &config.audit.auditor_signatures_source {
- let signature = match source {
- ConfigSource::Path(ref path) => fs::read(path)
- .unwrap_or_else(|_| panic!("Cannot find signature file {:?}.", path)),
- };
- signatures.push(signature);
- }
- config.audit.auditor_signatures_bytes = Some(signatures);
-
- if !cfg!(sgx_sim) && config.ias.is_none() {
- let ias_spid = match env::var("IAS_SPID") {
- Ok(e) => e.trim().to_string(),
- Err(_) => {
- error!("Cannot find IAS_SPID from config file and environment variables.");
- return None;
- }
- };
- let ias_key = match env::var("IAS_KEY") {
- Ok(e) => e.trim().to_string(),
- Err(_) => {
- error!("Cannot find IAS_KEY from config file and environment variables.");
- return None;
- }
- };
- config.ias = Some(IasConfig { ias_spid, ias_key });
- }
-
- if cfg!(sgx_sim) && config.ias.is_none() {
- config.ias = Some(IasConfig {
- ias_spid: "".to_string(),
- ias_key: "".to_string(),
- });
- }
-
- if !cfg!(sgx_sim)
- && (config.ias.is_none()
- || config.ias.as_ref().unwrap().ias_spid.len() != 32
- || config.ias.as_ref().unwrap().ias_key.len() != 32)
- {
- error!("IAS_SPID or IAS_KEY format error.");
- return None;
- }
-
- Some(config)
- }
- }
-}
+pub use build::BUILD_CONFIG;
+pub use runtime::RuntimeConfig;
diff --git a/config/src/runtime.rs b/config/src/runtime.rs
new file mode 100644
index 0000000..19bee6f
--- /dev/null
+++ b/config/src/runtime.rs
@@ -0,0 +1,138 @@
+use crate::ConfigSource;
+#[cfg(not(feature = "mesalock_sgx"))]
+use std::fs;
+#[cfg(feature = "mesalock_sgx")]
+use std::prelude::v1::*;
+#[cfg(feature = "mesalock_sgx")]
+use std::untrusted::fs;
+
+use serde_derive::Deserialize;
+use serde_derive::Serialize;
+use std::env;
+use std::net::SocketAddr;
+use std::path::Path;
+use std::string::String;
+use std::vec::Vec;
+use toml;
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct RuntimeConfig {
+ pub api_endpoints: ApiEndpointsConfig,
+ pub internal_endpoints: InternalEndpointsConfig,
+ pub audit: AuditConfig,
+ pub ias: Option<IasConfig>,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct ApiEndpointsConfig {
+ pub frontend: EndpointListenConfig,
+ pub authentication: EndpointListenConfig,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct InternalEndpointsConfig {
+ pub dbs: EndpointListenAdvertisedConfig,
+ pub execution: EndpointListenAdvertisedConfig,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct EndpointListenConfig {
+ pub listen_address: SocketAddr,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct EndpointListenAdvertisedConfig {
+ pub listen_address: SocketAddr,
+ pub advertised_address: SocketAddr,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct AuditConfig {
+ #[serde(rename(serialize = "enclave_info", deserialize = "enclave_info"))]
+ enclave_info_source: ConfigSource,
+ #[serde(rename(serialize = "auditor_signatures", deserialize = "auditor_signatures"))]
+ auditor_signatures_source: Vec<ConfigSource>,
+ pub enclave_info_bytes: Option<Vec<u8>>,
+ pub auditor_signatures_bytes: Option<Vec<Vec<u8>>>,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct IasConfig {
+ pub ias_spid: String,
+ pub ias_key: String,
+}
+
+impl RuntimeConfig {
+ pub fn from_toml<T: AsRef<Path>>(path: T) -> Option<Self> {
+ use std::prelude::v1::*;
+ let contents = match fs::read_to_string(path) {
+ Ok(c) => c,
+ Err(_) => {
+ error!("Something went wrong reading the runtime config file.");
+ return None;
+ }
+ };
+ let mut config: RuntimeConfig = match toml::from_str(&contents) {
+ Ok(c) => c,
+ Err(_) => {
+ error!("Something went wrong reading the runtime config file.");
+ return None;
+ }
+ };
+
+ config.audit.enclave_info_bytes = match &config.audit.enclave_info_source {
+ ConfigSource::Path(ref enclave_info_path) => {
+ let content = fs::read(enclave_info_path).unwrap_or_else(|_| {
+ panic!("Cannot find enclave info at {:?}.", enclave_info_path)
+ });
+ Some(content)
+ }
+ };
+
+ let mut signatures: Vec<Vec<u8>> = vec![];
+ for source in &config.audit.auditor_signatures_source {
+ let signature = match source {
+ ConfigSource::Path(ref path) => fs::read(path)
+ .unwrap_or_else(|_| panic!("Cannot find signature file {:?}.", path)),
+ };
+ signatures.push(signature);
+ }
+ config.audit.auditor_signatures_bytes = Some(signatures);
+
+ if !cfg!(sgx_sim) && config.ias.is_none() {
+ let ias_spid = match env::var("IAS_SPID") {
+ Ok(e) => e.trim().to_string(),
+ Err(_) => {
+ error!("Cannot find IAS_SPID from config file and environment variables.");
+ return None;
+ }
+ };
+ let ias_key = match env::var("IAS_KEY") {
+ Ok(e) => e.trim().to_string(),
+ Err(_) => {
+ error!("Cannot find IAS_KEY from config file and environment variables.");
+ return None;
+ }
+ };
+ config.ias = Some(IasConfig { ias_spid, ias_key });
+ }
+
+ if cfg!(sgx_sim) && config.ias.is_none() {
+ config.ias = Some(IasConfig {
+ ias_spid: "".to_string(),
+ ias_key: "".to_string(),
+ });
+ }
+
+ if !cfg!(sgx_sim)
+ && (config.ias.is_none()
+ || config.ias.as_ref().unwrap().ias_spid.len() != 32
+ || config.ias.as_ref().unwrap().ias_key.len() != 32)
+ {
+ error!("IAS_SPID or IAS_KEY format error.");
+ return None;
+ }
+
+ Some(config)
+ }
+}
diff --git a/ipc/src/protos/ecall.rs b/ipc/src/protos/ecall.rs
index 2c499da..a4d88da 100644
--- a/ipc/src/protos/ecall.rs
+++ b/ipc/src/protos/ecall.rs
@@ -21,7 +21,7 @@ use std::os::raw::c_int;
#[derive(Serialize, Deserialize, Debug)]
pub struct StartServiceInput {
pub fd: c_int,
- pub config: teaclave_config::runtime_config::RuntimeConfig,
+ pub config: teaclave_config::RuntimeConfig,
}
#[derive(Clone, Serialize, Deserialize, Debug, Default)]
diff --git a/services/authentication/app/src/main.rs b/services/authentication/app/src/main.rs
index 00620b2..06d27eb 100644
--- a/services/authentication/app/src/main.rs
+++ b/services/authentication/app/src/main.rs
@@ -37,8 +37,7 @@ fn main() -> anyhow::Result<()> {
fn start_enclave_service(tee: &TeeBinder) -> anyhow::Result<()> {
info!("Start enclave service");
- let config =
- teaclave_config::runtime_config::RuntimeConfig::from_toml("runtime.config.toml").unwrap();
+ let config = teaclave_config::RuntimeConfig::from_toml("runtime.config.toml").unwrap();
let listen_address = config.api_endpoints.authentication.listen_address;
let listener = TcpListener::bind(listen_address)?;
let fd = listener.into_raw_fd();
diff --git a/services/database/app/src/main.rs b/services/database/app/src/main.rs
index e14fb52..2cc6866 100644
--- a/services/database/app/src/main.rs
+++ b/services/database/app/src/main.rs
@@ -38,8 +38,7 @@ fn main() -> anyhow::Result<()> {
fn start_enclave_service(tee: &TeeBinder) -> anyhow::Result<()> {
info!("Start enclave service");
- let config =
- teaclave_config::runtime_config::RuntimeConfig::from_toml("runtime.config.toml").unwrap();
+ let config = teaclave_config::RuntimeConfig::from_toml("runtime.config.toml").unwrap();
let listen_address = config.internal_endpoints.dbs.listen_address;
let listener = TcpListener::bind(listen_address)?;
let fd = listener.into_raw_fd();
diff --git a/services/execution/app/src/main.rs b/services/execution/app/src/main.rs
index c5186c2..0506358 100644
--- a/services/execution/app/src/main.rs
+++ b/services/execution/app/src/main.rs
@@ -14,6 +14,7 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
+
#[macro_use]
extern crate log;
@@ -35,8 +36,7 @@ fn main() -> anyhow::Result<()> {
fn start_enclave_service(tee: &TeeBinder) -> anyhow::Result<()> {
info!("Start enclave service");
- let config =
- teaclave_config::runtime_config::RuntimeConfig::from_toml("runtime.config.toml").unwrap();
+ let config = teaclave_config::RuntimeConfig::from_toml("runtime.config.toml").unwrap();
let listen_address = config.internal_endpoints.execution.listen_address;
let listener = TcpListener::bind(listen_address)?;
let fd = listener.into_raw_fd();
diff --git a/tests/functional_tests/enclave/src/teaclave_authentication_service.rs b/tests/functional_tests/enclave/src/teaclave_authentication_service.rs
index 76d4b49..6d05f73 100644
--- a/tests/functional_tests/enclave/src/teaclave_authentication_service.rs
+++ b/tests/functional_tests/enclave/src/teaclave_authentication_service.rs
@@ -1,8 +1,8 @@
use sgx_tunittest::*;
use std::prelude::v1::*;
use teaclave_attestation::verifier;
-use teaclave_config::build_config::BUILD_CONFIG;
-use teaclave_config::runtime_config::RuntimeConfig;
+use teaclave_config::RuntimeConfig;
+use teaclave_config::BUILD_CONFIG;
use teaclave_proto::teaclave_authentication_service::*;
use teaclave_proto::teaclave_common::*;
use teaclave_rpc::config::SgxTrustedTlsClientConfig;
diff --git a/tests/integration_tests/app/src/teaclave_config_tests.rs b/tests/integration_tests/app/src/teaclave_config_tests.rs
index 9515f2b..e149d32 100644
--- a/tests/integration_tests/app/src/teaclave_config_tests.rs
+++ b/tests/integration_tests/app/src/teaclave_config_tests.rs
@@ -6,8 +6,7 @@ pub fn run_tests() {
fn runtime_config() {
let config =
- teaclave_config::runtime_config::RuntimeConfig::from_toml("./fixtures/runtime.config.toml")
- .unwrap();
+ teaclave_config::RuntimeConfig::from_toml("./fixtures/runtime.config.toml").unwrap();
assert_eq!(
config.api_endpoints.authentication.listen_address,
"0.0.0.0:7776".parse().unwrap()
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org