use crate::attestation::report::AttestationReport;
use crate::config::{RuntimeLifecyclePolicy, TeeProvider};
use crate::errors::TeeError;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TeeDeployRequest {
pub image: String,
#[serde(default)]
pub env: BTreeMap<String, String>,
#[serde(default)]
pub resources: BTreeMap<String, String>,
pub preferred_provider: Option<TeeProvider>,
#[serde(default)]
pub extra_ports: Vec<u16>,
}
impl TeeDeployRequest {
pub fn new(image: impl Into<String>) -> Self {
Self {
image: image.into(),
env: BTreeMap::new(),
resources: BTreeMap::new(),
preferred_provider: None,
extra_ports: Vec::new(),
}
}
pub fn with_env(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.env.insert(key.into(), value.into());
self
}
pub fn with_provider(mut self, provider: TeeProvider) -> Self {
self.preferred_provider = Some(provider);
self
}
pub fn with_extra_ports(mut self, ports: impl IntoIterator<Item = u16>) -> Self {
self.extra_ports.extend(ports);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TeePublicKey {
pub key: Vec<u8>,
pub key_type: String,
pub fingerprint: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TeeDeploymentHandle {
pub id: String,
pub provider: TeeProvider,
#[serde(default)]
pub metadata: BTreeMap<String, String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub cached_attestation: Option<AttestationReport>,
#[serde(default)]
pub port_mapping: BTreeMap<u16, u16>,
#[serde(default = "default_lifecycle_policy")]
pub lifecycle_policy: RuntimeLifecyclePolicy,
}
fn default_lifecycle_policy() -> RuntimeLifecyclePolicy {
RuntimeLifecyclePolicy::CloudManaged
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum TeeDeploymentStatus {
Provisioning,
Running,
Stopping,
Stopped,
Failed,
}
pub trait TeeRuntimeBackend: Send + Sync {
fn deploy(
&self,
req: TeeDeployRequest,
) -> impl core::future::Future<Output = Result<TeeDeploymentHandle, TeeError>> + Send;
fn get_attestation(
&self,
handle: &TeeDeploymentHandle,
) -> impl core::future::Future<Output = Result<AttestationReport, TeeError>> + Send;
fn cached_attestation(
&self,
handle: &TeeDeploymentHandle,
) -> impl core::future::Future<Output = Result<Option<AttestationReport>, TeeError>> + Send;
fn derive_public_key(
&self,
handle: &TeeDeploymentHandle,
) -> impl core::future::Future<Output = Result<TeePublicKey, TeeError>> + Send;
fn status(
&self,
handle: &TeeDeploymentHandle,
) -> impl core::future::Future<Output = Result<TeeDeploymentStatus, TeeError>> + Send;
fn stop(
&self,
handle: &TeeDeploymentHandle,
) -> impl core::future::Future<Output = Result<(), TeeError>> + Send;
fn destroy(
&self,
handle: &TeeDeploymentHandle,
) -> impl core::future::Future<Output = Result<(), TeeError>> + Send;
}