|
9 | 9 |
|
10 | 10 | **Example applications for [dstack](https://github.com/Dstack-TEE/dstack) - Deploy containerized apps to TEEs with end-to-end security in minutes** |
11 | 11 |
|
12 | | -[Getting Started](#getting-started) • [Examples](#examples) • [Contributing](CONTRIBUTING.md) • [Documentation](#documentation) • [Community](#community) |
| 12 | +[Getting Started](#getting-started) • [Use Cases](#use-cases) • [Core Patterns](#core-patterns) • [Dev Tools](#dev-scaffolding) • [Starter Packs](#starter-packs) • [Other Use Cases](#other-use-cases) |
13 | 13 |
|
14 | 14 | </div> |
15 | 15 |
|
|
19 | 19 |
|
20 | 20 | This repository contains ready-to-deploy examples demonstrating how to build and run applications on [dstack](https://github.com/Dstack-TEE/dstack), the developer-friendly SDK for deploying containerized apps in Trusted Execution Environments (TEE). |
21 | 21 |
|
22 | | -### What You'll Find Here |
| 22 | +## Getting Started |
23 | 23 |
|
24 | | -- **Security Features** - Remote attestation, verification, and privacy-preserving apps |
25 | | -- **Secret Management** - Secure handling of credentials and sensitive data in TEE environments |
26 | | -- **Networking Patterns** - HTTPS termination, custom domains, port forwarding in the cloud |
27 | | -- **Best Practices** - Production-ready implementations following TEE security principles |
| 24 | +### Prerequisites |
28 | 25 |
|
29 | | -## Prerequisites |
| 26 | +- Docker and Docker Compose |
| 27 | +- Node.js (for Phala CLI) |
| 28 | +- Git |
30 | 29 |
|
31 | | -Before you begin, ensure you have: |
| 30 | +### Setup |
32 | 31 |
|
33 | | -- Access to a dstack environment |
34 | | -- Basic understanding of [TEE concepts](https://docs.phala.network/dstack) |
35 | | -- Basic familiarity with Docker Compose configuration files |
36 | | -- Git for cloning the repository |
| 32 | +```bash |
| 33 | +# Clone the repo |
| 34 | +git clone https://github.com/Dstack-TEE/dstack-examples.git |
| 35 | +cd dstack-examples |
37 | 36 |
|
38 | | -You can deploy dstack on your own server, or use [Phala Cloud](https://cloud.phala.network). |
| 37 | +# Install Phala CLI |
| 38 | +npm install -g phala |
39 | 39 |
|
40 | | -## Getting Started |
| 40 | +# Start the local simulator (no TEE hardware needed) |
| 41 | +phala simulator start |
| 42 | +``` |
41 | 43 |
|
42 | | -### Quick Start |
| 44 | +### Run an Example Locally |
43 | 45 |
|
44 | 46 | ```bash |
45 | | -# Clone the repository |
46 | | -git clone https://github.com/Dstack-TEE/dstack-examples.git |
47 | | -cd dstack-examples |
| 47 | +cd tutorial/01-attestation-oracle |
| 48 | +docker compose run --rm \ |
| 49 | + -v ~/.phala-cloud/simulator/0.5.3/dstack.sock:/var/run/dstack.sock \ |
| 50 | + app |
| 51 | +``` |
| 52 | + |
| 53 | +### Deploy to Phala Cloud |
| 54 | + |
| 55 | +```bash |
| 56 | +phala auth login |
| 57 | +phala deploy -n my-app -c docker-compose.yaml |
| 58 | +``` |
| 59 | + |
| 60 | +See [Phala Cloud](https://cloud.phala.network) for production TEE deployment. |
| 61 | + |
| 62 | +--- |
| 63 | + |
| 64 | +## Tutorials |
| 65 | + |
| 66 | +Step-by-step guides covering core dstack concepts. |
| 67 | + |
| 68 | +| Tutorial | Description | |
| 69 | +|----------|-------------| |
| 70 | +| [01-attestation-oracle](./tutorial/01-attestation-oracle) | Use the guest SDK to work with attestations directly — build an oracle, bind data to TDX quotes via `report_data`, verify with local scripts | |
| 71 | +| [02-persistence-and-kms](./tutorial/02-persistence-and-kms) | Use `getKey()` for deterministic key derivation from a KMS — persistent wallets, same key across restarts | |
| 72 | +| [03-gateway-and-ingress](./tutorial/03-gateway-and-ingress) | Custom domains with automatic SSL, certificate evidence chain | |
| 73 | +| [04-upgrades](./tutorial/04-upgrades) | Extend `AppAuth.sol` with custom authorization logic — NFT-gated clusters, on-chain governance | |
| 74 | + |
| 75 | +--- |
48 | 76 |
|
49 | | -# Choose an example |
50 | | -cd attestation/configid-based |
| 77 | +## Use Cases |
51 | 78 |
|
52 | | -# Copy the docker-compose.yaml content to your dstack deployment |
53 | | -# Follow the example-specific README for deployment instructions |
| 79 | +Real-world applications you can build with dstack. |
| 80 | + |
| 81 | +| Example | Description | Status | |
| 82 | +|---------|-------------|--------| |
| 83 | +| [8004-agent](./8004-agent) | Trustless AI agent with on-chain attestation and LLM access | Coming Soon | |
| 84 | +| [oracle](./oracle) | TEE oracle returning JSON + signature + attestation bundle | Coming Soon | |
| 85 | +| [mcp-server](./mcp-server) | Attested MCP tool server behind gateway | Coming Soon | |
| 86 | +| [telegram-agent](./telegram-agent) | Telegram bot with TEE wallet and verified execution | Coming Soon | |
| 87 | + |
| 88 | +--- |
| 89 | + |
| 90 | +## Core Patterns |
| 91 | + |
| 92 | +Key building blocks for dstack applications. |
| 93 | + |
| 94 | +### Attestation |
| 95 | + |
| 96 | +Request TEE attestations via the SDK. Mount `/var/run/dstack.sock` in your compose file to access the TEE. |
| 97 | + |
| 98 | +```javascript |
| 99 | +import { DstackClient } from '@phala/dstack-sdk' |
| 100 | +const client = new DstackClient() |
| 101 | +const info = await client.info() // app_id, instance_id, tcb_info |
| 102 | +const quote = await client.getQuote(data) // TDX quote with custom report_data |
| 103 | +const key = await client.getKey('/my/path') // deterministic key derivation |
54 | 104 | ``` |
55 | 105 |
|
56 | | -## Examples |
| 106 | +```yaml |
| 107 | +volumes: |
| 108 | + - /var/run/dstack.sock:/var/run/dstack.sock |
| 109 | +``` |
| 110 | +
|
| 111 | +| Example | Description | Status | |
| 112 | +|---------|-------------|--------| |
| 113 | +| [timelock-nts](./timelock-nts) | Raw socket usage (what the SDK wraps) | Available | |
| 114 | +| [attestation/configid-based](./attestation/configid-based) | ConfigID-based verification | Available | |
| 115 | +
|
| 116 | +### Gateway & Domains |
| 117 | +
|
| 118 | +TLS termination, custom domains, external connectivity. |
57 | 119 |
|
58 | | -### Security & Attestation |
59 | 120 | | Example | Description | |
60 | 121 | |---------|-------------| |
61 | | -| [attestation/configid-based](./attestation/configid-based) | ConfigID-based remote attestation verification | |
62 | | -| [attestation/rtmr3-based](./attestation/rtmr3-based) | RTMR3-based attestation (legacy) | |
| 122 | +| [dstack-ingress](./custom-domain/dstack-ingress) | **Complete ingress solution** — auto SSL via Let's Encrypt, multi-domain, DNS validation, evidence generation with TDX quote chain | |
| 123 | +| [custom-domain](./custom-domain/custom-domain) | Simpler custom domain setup via zt-https | |
| 124 | +
|
| 125 | +### Keys & Persistence |
| 126 | +
|
| 127 | +Persistent keys across deployments via KMS. |
| 128 | +
|
| 129 | +| Example | Description | Status | |
| 130 | +|---------|-------------|--------| |
| 131 | +| [get-key-basic](./get-key-basic) | `dstack.get_key()` — same key identity across machines | Coming Soon | |
| 132 | + |
| 133 | +### On-Chain Interaction |
| 134 | + |
| 135 | +Light client for reading chain state, anchoring outputs. |
63 | 136 |
|
64 | | -### Networking & Domains |
65 | 137 | | Example | Description | |
66 | 138 | |---------|-------------| |
67 | | -| [custom-domain](./custom-domain) | Set up custom domain with automatic TLS certificate management via zt-https | |
| 139 | +| [lightclient](./lightclient) | Ethereum light client (Helios) running in enclave | |
| 140 | + |
| 141 | +--- |
| 142 | + |
| 143 | +## Dev Scaffolding |
| 144 | + |
| 145 | +Development and debugging tools. **Not for production.** |
| 146 | + |
| 147 | +| Example | Description | |
| 148 | +|---------|-------------| |
| 149 | +| [webshell](./webshell) | Web-based shell access for debugging | |
68 | 150 | | [ssh-over-gateway](./ssh-over-gateway) | SSH tunneling through dstack gateway | |
69 | 151 | | [tcp-port-forwarding](./tcp-port-forwarding) | Arbitrary TCP port forwarding | |
70 | | -| [tor-hidden-service](./tor-hidden-service) | Run Tor hidden services in TEEs | |
71 | 152 |
|
72 | | -### Development Tools |
| 153 | +--- |
| 154 | + |
| 155 | +## Tech Demos |
| 156 | + |
| 157 | +Interesting demonstrations. |
| 158 | + |
73 | 159 | | Example | Description | |
74 | 160 | |---------|-------------| |
75 | | -| [launcher](./launcher) | Generic launcher pattern for Docker Compose apps | |
76 | | -| [webshell](./webshell) | Web-based shell access for debugging | |
77 | | -| [prelaunch-script](./prelaunch-script) | Pre-launch script patterns used by Phala Cloud | |
| 161 | +| [tor-hidden-service](./tor-hidden-service) | Run Tor hidden services in TEEs | |
| 162 | + |
| 163 | +--- |
| 164 | + |
| 165 | +## Starter Packs |
| 166 | + |
| 167 | +Full-stack templates with SDK integration. These demonstrate attestation, key derivation, and wallet generation. |
| 168 | + |
| 169 | +| Template | Stack | Link | |
| 170 | +|----------|-------|------| |
| 171 | +| **Next.js Starter** | Next.js + TypeScript | [phala-cloud-nextjs-starter](https://github.com/Phala-Network/phala-cloud-nextjs-starter) | |
| 172 | +| **Python Starter** | FastAPI + Python | [phala-cloud-python-starter](https://github.com/Phala-Network/phala-cloud-python-starter) | |
| 173 | +| **Bun Starter** | Bun + TypeScript | [phala-cloud-bun-starter](https://github.com/Phala-Network/phala-cloud-bun-starter) | |
| 174 | +| **Node.js Starter** | Express + TypeScript | [phala-cloud-node-starter](https://github.com/Gldywn/phala-cloud-node-starter) | |
| 175 | + |
| 176 | +Features: `/api/tdx_quote` (attestation), `/api/eth_account` (derived wallet), `/api/info` (TCB info) |
| 177 | + |
| 178 | +--- |
| 179 | + |
| 180 | +## Other Use Cases |
| 181 | + |
| 182 | +External projects and templates worth exploring. These are maintained elsewhere but demonstrate interesting TEE patterns. |
| 183 | + |
| 184 | +| Project | Description | Link | |
| 185 | +|---------|-------------|------| |
| 186 | +| **Oracle Template** | Price aggregator with verifiable networking (hardened TLS) and multi-source validation | [Gldywn/phala-cloud-oracle-template](https://github.com/Gldywn/phala-cloud-oracle-template) | |
| 187 | +| **VRF Template** | Verifiable Random Function — hardware-backed cryptographic randomness | [Phala-Network/phala-cloud-vrf-template](https://github.com/Phala-Network/phala-cloud-vrf-template) | |
| 188 | +| **Open WebUI** | Self-hosted AI chat interface in TEE | [phala-cloud/templates/openwebui](https://github.com/Phala-Network/phala-cloud/tree/main/templates/prebuilt/openwebui) | |
| 189 | +| **n8n Automation** | Workflow automation (400+ integrations) with OAuth in TEE | [Marvin-Cypher/phala-n8n-template](https://github.com/Marvin-Cypher/phala-n8n-template) | |
| 190 | +| **Primus Attestor** | zkTLS node — TEE + zero-knowledge proofs | [primus-labs/primus-network-startup](https://github.com/primus-labs/primus-network-startup) | |
| 191 | +| **NEAR Shade Agent** | Blockchain oracle/agent for NEAR with TEE attestation | [phala-cloud/templates/near-shade-agent](https://github.com/Phala-Network/phala-cloud/tree/main/templates/prebuilt/near-shade-agent) | |
| 192 | +| **Presidio** | Microsoft's PII de-identification running in TEE | [HashWarlock/presidio](https://github.com/HashWarlock/presidio/tree/phala-cloud) | |
| 193 | +| **ByteBot** | AI desktop agent — computer control in isolated TEE sandbox | [phala-cloud/templates/bytebot](https://github.com/Phala-Network/phala-cloud/tree/main/templates/prebuilt/bytebot) | |
| 194 | + |
| 195 | +> **Note**: These templates use pre-built Docker images. For full auditability, review their source repos before deployment. |
| 196 | + |
| 197 | +See the full [Phala Cloud templates](https://github.com/Phala-Network/phala-cloud#templates) for more options. |
| 198 | + |
| 199 | +--- |
| 200 | + |
| 201 | +## Details |
| 202 | + |
| 203 | +Implementation details and infrastructure patterns. |
78 | 204 |
|
79 | | -### Advanced Use Cases |
80 | 205 | | Example | Description | |
81 | 206 | |---------|-------------| |
82 | | -| [lightclient](./lightclient) | Blockchain light client integration | |
83 | | -| [timelock-nts](./timelock-nts) | Timelock decryption with NTS | |
| 207 | +| [launcher](./launcher) | Generic launcher pattern for Docker Compose apps | |
| 208 | +| [prelaunch-script](./prelaunch-script) | Pre-launch script patterns (Phala Cloud) | |
84 | 209 | | [private-docker-image-deployment](./private-docker-image-deployment) | Using private Docker registries | |
| 210 | +| [attestation/rtmr3-based](./attestation/rtmr3-based) | RTMR3-based attestation (legacy) | |
| 211 | + |
| 212 | +--- |
85 | 213 |
|
86 | 214 | ## Documentation |
87 | 215 |
|
88 | 216 | - **[dstack Documentation](https://docs.phala.network/dstack)** - Official platform documentation |
89 | 217 | - **[Main Repository](https://github.com/Dstack-TEE/dstack)** - Core dstack framework |
90 | | -- **[Security Guide](SECURITY.md)** - Security best practices |
91 | 218 | - **[Contributing Guide](CONTRIBUTING.md)** - How to contribute |
92 | 219 |
|
93 | 220 | ## Development |
94 | 221 |
|
95 | | -Use the `dev.sh` script for validation and development tasks: |
96 | | - |
97 | 222 | ```bash |
98 | 223 | ./dev.sh help # Show available commands |
99 | 224 | ./dev.sh validate <example> # Validate a specific example |
100 | 225 | ./dev.sh validate-all # Validate all examples |
101 | | -./dev.sh security # Run security checks |
102 | | -./dev.sh lint # Run linting checks |
103 | | -./dev.sh check-all # Run all checks |
104 | 226 | ``` |
105 | 227 |
|
106 | | -## Contributing |
107 | | - |
108 | | -We welcome contributions! Please see our [Contributing Guidelines](CONTRIBUTING.md) for details. |
109 | | - |
110 | 228 | ## Community |
111 | 229 |
|
112 | | -### Getting Help |
113 | | - |
114 | 230 | - **Telegram**: [Join our community](https://t.me/+UO4bS4jflr45YmUx) |
115 | 231 | - **Issues**: [GitHub Issues](https://github.com/Dstack-TEE/dstack-examples/issues) |
116 | 232 |
|
117 | | -### Reporting Issues |
118 | | - |
119 | | -When reporting issues, please include: |
120 | | - |
121 | | -1. Example name and version |
122 | | -2. Steps to reproduce |
123 | | -3. Expected vs actual behavior |
124 | | -4. Relevant logs and error messages |
125 | | - |
126 | 233 | ## License |
127 | 234 |
|
128 | | -This project is licensed under the Apache 2.0 License - see the [LICENSE](LICENSE) file for details. |
| 235 | +Apache 2.0 — see [LICENSE](LICENSE). |
129 | 236 |
|
130 | 237 | --- |
131 | 238 |
|
|
0 commit comments