Phala TEE Deployment Toolkit
A Rust library for deploying Docker Compose applications to the Phala TEE (Trusted Execution Environment) Cloud with secure environment variable handling.
Overview
Phala TEE Cloud runs applications in hardware-enforced isolated enclaves, providing enhanced security guarantees. This toolkit simplifies deployments to the Phala Cloud with:
- Environment Variable Encryption - Secure handling of sensitive data
- Docker Compose Support - Deploy multi-container applications
- Flexible Deployment Patterns - From simple one-step to advanced privilege separation
Getting Started
Prerequisites
- Phala Cloud account with API access
- A TEE pod ID from your Phala account
- Docker Compose configuration for your application
Environment Setup
Create a .env file with:
PHALA_CLOUD_API_KEY=your-api-key
PHALA_CLOUD_API_ENDPOINT=https://cloud-api.phala.network/api/v1
PHALA_TEEPOD_ID=your-teepod-id
PHALA_APP_ID=your-app-id # For updating existing deployments
Deployment Patterns
Pattern 1: Simple Deployment
Deploy with a single function call. Best for straightforward applications where simplicity is key:
let config = new;
let client = new?;
let deployment = client.deploy.await?;
println!;
Pattern 2: Step-by-Step Deployment
For when you need full control over the deployment process:
// 1. Initialize client
let client = new?;
// 2. Get available TEEPods
let teepods = client.get_available_teepods.await?;
let teepod_id = teepods.as_u64?;
let image = teepods.as_str?;
// 3. Prepare VM configuration
let vm_config = json!;
// 4. Get encryption keys
let pubkey_response = client.get_pubkey_for_config.await?;
// 5. Deploy with environment variables
let deployment = client.deploy_with_config_do_encrypt.await?;
Pattern 3: Privilege Separation
Security-focused approach where operators handle infrastructure while users manage secrets:
// OPERATOR: Has API access, doesn't see secrets
// 1. Get available TEEPods
let teepods = client.get_available_teepods.await?;
// 2. Prepare VM configuration
let vm_config = json!;
// 3. Get encryption key
let pubkey = client.get_pubkey_for_config.await?;
// 4. Send pubkey to user through secure channel
send_to_user;
// 5. Receive encrypted variables from user
let encrypted_env = receive_from_user;
// 6. Deploy with encrypted environment
client.deploy_with_config_encrypted_env.await?;
// USER: Has secrets, doesn't need API access
// 1. Receives pubkey from operator
// 2. Encrypts environment variables
let encrypted = encrypt_env_vars?;
// 3. Sends encrypted data to operator
send_to_operator;
Pattern 4: Updating Deployments
Update existing deployments with new configurations or environment variables:
// 1. Get current configuration
let compose = client.get_compose.await?;
// 2. Modify configuration and environment variables
let mut compose_file = compose.compose_file;
compose_file = json!;
// 3. Apply update
client.update_compose.await?;
API Reference
DeploymentConfig- Core configuration for deploymentsTeeClient- API client with methods for deployment operationsEncryptor- Handles secure encryption of environment variables
Examples
See the examples/ directory for full working examples:
typescript_equivalent.rs- Step-by-step deployment matching TypeScript workflowpubkey_workflow.rs- Public key encryption workflowoperator_user_flow.rs- Privilege separation patternupdate_deployment.rs- Updating existing deployments
License
MIT License