Skip to content

Commit 08694fa

Browse files
committed
added external templates. Added attestation w/ sdk example
1 parent 526efb9 commit 08694fa

3 files changed

Lines changed: 159 additions & 11 deletions

File tree

README.md

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
**Example applications for [dstack](https://github.com/Dstack-TEE/dstack) - Deploy containerized apps to TEEs with end-to-end security in minutes**
1111

12-
[Use Cases](#use-cases)[Core Patterns](#core-patterns)[Dev Tools](#dev-scaffolding)[Documentation](#documentation)
12+
[Getting Started](#getting-started)[Use Cases](#use-cases)[Core Patterns](#core-patterns)[Dev Tools](#dev-scaffolding)[Other Use Cases](#other-use-cases)
1313

1414
</div>
1515

@@ -19,18 +19,46 @@
1919

2020
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).
2121

22-
## Prerequisites
22+
## Getting Started
2323

24-
- Access to a dstack environment (self-hosted or [Phala Cloud](https://cloud.phala.network))
25-
- Basic understanding of [TEE concepts](https://docs.phala.network/dstack)
26-
- Basic familiarity with Docker Compose
27-
- Git for cloning the repository
24+
### Prerequisites
25+
26+
- Docker and Docker Compose
27+
- Node.js (for Phala CLI)
28+
- Git
29+
30+
### Setup
2831

2932
```bash
33+
# Clone the repo
3034
git clone https://github.com/Dstack-TEE/dstack-examples.git
3135
cd dstack-examples
36+
37+
# Install Phala CLI
38+
npm install -g phala
39+
40+
# Start the local simulator (no TEE hardware needed)
41+
phala simulator start
42+
```
43+
44+
### Run an Example Locally
45+
46+
```bash
47+
cd attestation-with-sdk
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
3258
```
3359

60+
See [Phala Cloud](https://cloud.phala.network) for production TEE deployment.
61+
3462
---
3563

3664
## Use Cases
@@ -52,14 +80,26 @@ Key building blocks for dstack applications.
5280

5381
### Attestation
5482

55-
How to get and verify TEE attestations.
83+
Request TEE attestations via the SDK. Mount `/var/run/dstack.sock` in your compose file to access the TEE.
84+
85+
```javascript
86+
import { DstackClient } from '@phala/dstack-sdk'
87+
const client = new DstackClient()
88+
const info = await client.info() // app_id, instance_id, tcb_info
89+
const quote = await client.getQuote(data) // TDX quote with custom report_data
90+
const key = await client.getKey('/my/path') // deterministic key derivation
91+
```
92+
93+
```yaml
94+
volumes:
95+
- /var/run/dstack.sock:/var/run/dstack.sock
96+
```
5697
5798
| Example | Description | Status |
5899
|---------|-------------|--------|
59-
| [trust-center](./refs/trust-center) | Full attestation verification platform — **start here** for production attestation patterns | Reference |
60-
| [attestation-sdk](./attestation-sdk) | Using Dstack client SDK to fetch attestations | Coming Soon |
61-
| [timelock-nts](./timelock-nts) | Shows raw `/var/run/dstack.sock` usage (what the SDK wraps) | Available |
62-
| [attestation/configid-based](./attestation/configid-based) | ConfigID-based verification (demonstrates current format) | Available |
100+
| [attestation-with-sdk](./attestation-with-sdk) | Complete SDK example with HTTP server | Available |
101+
| [timelock-nts](./timelock-nts) | Raw socket usage (what the SDK wraps) | Available |
102+
| [attestation/configid-based](./attestation/configid-based) | ConfigID-based verification | Available |
63103
64104
### Gateway & Domains
65105
@@ -110,6 +150,27 @@ Interesting demonstrations.
110150

111151
---
112152

153+
## Other Use Cases
154+
155+
External projects and templates worth exploring. These are maintained elsewhere but demonstrate interesting TEE patterns.
156+
157+
| Project | Description | Link |
158+
|---------|-------------|------|
159+
| **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) |
160+
| **VRF Template** | Verifiable Random Function — hardware-backed cryptographic randomness | [Phala-Network/phala-cloud-vrf-template](https://github.com/Phala-Network/phala-cloud-vrf-template) |
161+
| **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) |
162+
| **n8n Automation** | Workflow automation (400+ integrations) with OAuth in TEE | [Marvin-Cypher/phala-n8n-template](https://github.com/Marvin-Cypher/phala-n8n-template) |
163+
| **Primus Attestor** | zkTLS node — TEE + zero-knowledge proofs | [primus-labs/primus-network-startup](https://github.com/primus-labs/primus-network-startup) |
164+
| **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) |
165+
| **Presidio** | Microsoft's PII de-identification running in TEE | [HashWarlock/presidio](https://github.com/HashWarlock/presidio/tree/phala-cloud) |
166+
| **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) |
167+
168+
> **Note**: These templates use pre-built Docker images. For full auditability, review their source repos before deployment.
169+
170+
See the full [Phala Cloud templates](https://github.com/Phala-Network/phala-cloud#templates) for more options.
171+
172+
---
173+
113174
## Details
114175

115176
Implementation details and infrastructure patterns.

attestation-with-sdk/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Attestation SDK Example
2+
3+
Minimal example showing how to use the [Dstack client SDK](https://github.com/Dstack-TEE/dstack/tree/master/sdk) to fetch TEE attestations.
4+
5+
## What it does
6+
7+
```javascript
8+
import { DstackClient } from '@phala/dstack-sdk'
9+
10+
const client = new DstackClient()
11+
const info = await client.info() // App info (app_id, tcb_info, etc)
12+
const quote = await client.getQuote(data) // TDX quote with custom report_data
13+
const key = await client.getKey(path) // Derive deterministic key from path
14+
```
15+
16+
The SDK wraps the raw `/var/run/dstack.sock` API. Results are served at `http://localhost:8080`.
17+
18+
## Local Development
19+
20+
Test locally using the dstack simulator:
21+
22+
```bash
23+
# Start the simulator
24+
phala simulator start
25+
26+
# Run the example (mounts simulator socket)
27+
docker compose run --rm \
28+
-v ~/.phala-cloud/simulator/0.5.3/dstack.sock:/var/run/dstack.sock \
29+
app
30+
```
31+
32+
## Deploy to Phala Cloud
33+
34+
```bash
35+
phala deploy -n attestation-with-sdk -c docker-compose.yaml
36+
```
37+
38+
**Note**: Requires dstack OS 0.5.x+ (uses `/var/run/dstack.sock`). Older 0.3.x images use `/var/run/tappd.sock` which is not compatible with the current SDK.
39+
40+
## Verify with Trust Center
41+
42+
Once deployed, verify your attestation using [trust-center](https://github.com/Phala-Network/trust-center):
43+
44+
1. Get your app's attestation endpoint (e.g., `https://your-app.phala.network/`)
45+
2. Submit to trust-center for verification
46+
3. Trust-center validates: hardware quote → OS integrity → compose hash → domain (if applicable)
47+
48+
## SDK Reference
49+
50+
- **JS/TS**: `npm install @phala/dstack-sdk`[docs](https://github.com/Dstack-TEE/dstack/tree/master/sdk/js)
51+
- **Python**: `pip install dstack-sdk`[docs](https://github.com/Dstack-TEE/dstack/tree/master/sdk/python)
52+
- **Go**: [docs](https://github.com/Dstack-TEE/dstack/tree/master/sdk/go)
53+
- **Rust**: [docs](https://github.com/Dstack-TEE/dstack/tree/master/sdk/rust)
54+
- **Raw curl**: [API docs](https://github.com/Dstack-TEE/dstack/tree/master/sdk/curl)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
services:
2+
app:
3+
build:
4+
context: .
5+
dockerfile_inline: |
6+
FROM node:22-slim
7+
WORKDIR /app
8+
RUN npm init -y && npm install @phala/dstack-sdk
9+
RUN cat > index.mjs <<'SCRIPT'
10+
import { DstackClient } from "@phala/dstack-sdk"
11+
import { createServer } from "http"
12+
const client = new DstackClient()
13+
const [info, quote, key] = await Promise.all([
14+
client.info(),
15+
client.getQuote("example-report-data"),
16+
client.getKey("/example/key/path"),
17+
])
18+
const results = {
19+
info,
20+
quote: { rtmrs: quote.rtmrs, reportData: quote.report_data },
21+
key: { path: "/example/key/path", hex: key.key?.slice(0, 64) + "..." },
22+
}
23+
console.log("Attestation results:", JSON.stringify(results, null, 2))
24+
createServer((req, res) => {
25+
res.writeHead(200, { "Content-Type": "application/json" })
26+
res.end(JSON.stringify(results, null, 2))
27+
}).listen(8080, () => console.log("Serving at http://localhost:8080"))
28+
SCRIPT
29+
CMD ["node", "index.mjs"]
30+
ports:
31+
- "8080:8080"
32+
volumes:
33+
- /var/run/dstack.sock:/var/run/dstack.sock

0 commit comments

Comments
 (0)