Skip to content

Commit 2f7bda0

Browse files
committed
chore: update enclave image document
1 parent ad65665 commit 2f7bda0

File tree

2 files changed

+107
-15
lines changed

2 files changed

+107
-15
lines changed

README.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,25 @@ Go to the [idempotent-proxy-canister](./src/idempotent-proxy-canister) directory
6060

6161
Run proxy:
6262
```bash
63-
docker run --name redis -d -p 6379:6379 redis:latest
6463
cargo run -p idempotent-proxy-server
6564
```
6665

67-
### Building enclave image for Marlin Oyster
68-
69-
The following steps should be run in AWS Nitro-based instances.
70-
71-
#### Use Nitro Enclaves CLI on AWS Nitro-based instances:
72-
73-
https://docs.aws.amazon.com/enclaves/latest/user/getting-started.html
74-
66+
Make a request:
7567
```bash
76-
sudo nitro-cli build-enclave --docker-uri ghcr.io/ldclabs/idempotent-proxy_enclave_amd64:latest --output-file idempotent-proxy_enclave_amd64.eif
68+
curl -v -X POST \
69+
--url http://YOUR_HOST/eth \
70+
--header 'content-type: application/json' \
71+
--header 'x-forwarded-host: rpc.ankr.com' \
72+
--header 'idempotency-key: key_001' \
73+
--data '{
74+
"id": 1,
75+
"jsonrpc": "2.0",
76+
"method": "eth_getBlockByNumber",
77+
"params": ["latest", false]
78+
}'
7779
```
7880

79-
#### Or spin up a new Docker container based on nitro-cli image:
81+
### Building enclave image for Marlin Oyster
8082

8183
https://docs.marlin.org/user-guides/oyster/instances/quickstart/build
8284

@@ -88,11 +90,16 @@ In a new terminal, run:
8890
```bash
8991
cd /mnt/my-server
9092
sudo docker exec -it nitro-cli sh
91-
docker build -f enclave/amd64.Dockerfile -t enclave_amd64:latest .
92-
nitro-cli build-enclave --docker-uri enclave_amd64:latest --output-file enclave_amd64.eif
93-
# Or: nitro-cli build-enclave --docker-uri ghcr.io/ldclabs/idempotent-proxy_enclave_amd64:latest --output-file idempotent-proxy_enclave_amd64.eif
93+
nitro-cli build-enclave --docker-uri ghcr.io/ldclabs/idempotent-proxy_enclave_amd64:latest --output-file idempotent-proxy_enclave_amd64.eif
9494
```
9595

96+
The image URL to deploy on Marlin Oyster:
97+
```text
98+
https://pub-eea759c16b114748bd3b170eadbb2c30.r2.dev/idempotent-proxy_enclave_amd64.eif
99+
```
100+
101+
Go to the [idempotent-proxy-server](./src/idempotent-proxy-server) directory for more information.
102+
96103
### Running as Cloudflare Worker
97104

98105
Idempotent Proxy can be running as a Cloudflare Worker. In order to use Durable Objects, you must switch to a paid plan.

src/idempotent-proxy-server/README.md

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,95 @@ This service can be used to proxy [HTTPS outcalls](https://internetcomputer.org/
2626

2727
Run proxy:
2828
```bash
29-
docker run --name redis -d -p 6379:6379 redis:latest
29+
# docker run --name redis -d -p 6379:6379 redis:latest # optional redis
3030
cargo run -p idempotent-proxy-server
3131
```
3232

33+
### Building and running AWS Nitro Enclave image
34+
35+
#### Setup host machine
36+
37+
https://docs.marlin.org/learn/oyster/core-concepts/networking/outgoing
38+
39+
```bash
40+
wget -O vsock-to-ip-transparent http://public.artifacts.marlin.pro/projects/enclaves/vsock-to-ip-transparent_v1.0.0_linux_amd64
41+
chmod +x vsock-to-ip-transparent
42+
./vsock-to-ip-transparent --vsock-addr 3:1200
43+
```
44+
45+
https://docs.marlin.org/learn/oyster/core-concepts/networking/incoming
46+
47+
iptables rules:
48+
```bash
49+
# route incoming packets on port 80 to the transparent proxy
50+
iptables -A PREROUTING -t nat -p tcp --dport 80 -i ens5 -j REDIRECT --to-port 1200
51+
# route incoming packets on port 443 to the transparent proxy
52+
iptables -A PREROUTING -t nat -p tcp --dport 443 -i ens5 -j REDIRECT --to-port 1200
53+
# route incoming packets on port 1025:65535 to the transparent proxy
54+
iptables -A PREROUTING -t nat -p tcp --dport 1025:65535 -i ens5 -j REDIRECT --to-port 1200
55+
```
56+
57+
```bash
58+
wget -O port-to-vsock-transparent http://public.artifacts.marlin.pro/projects/enclaves/port-to-vsock-transparent_v1.0.0_linux_amd64
59+
chmod +x port-to-vsock-transparent
60+
./port-to-vsock-transparent --vsock 88 --ip-addr 0.0.0.0:1200
61+
```
62+
63+
#### Build and run enclave
64+
65+
The following steps should be run in AWS Nitro-based instances.
66+
67+
https://docs.aws.amazon.com/enclaves/latest/user/getting-started.html
68+
69+
```bash
70+
sudo nitro-cli build-enclave --docker-uri ghcr.io/ldclabs/idempotent-proxy_enclave_amd64:latest --output-file idempotent-proxy_enclave_amd64.eif
71+
# Start building the Enclave Image...
72+
# Using the locally available Docker image...
73+
# Enclave Image successfully created.
74+
# {
75+
# "Measurements": {
76+
# "HashAlgorithm": "Sha384 { ... }",
77+
# "PCR0": "bbfe317cdaba604e1364fbd254150ce25516d83e31a87f8b3d8acb163286f57f51d8b3f6b2a482ac209b758334d996d9",
78+
# "PCR1": "4b4d5b3661b3efc12920900c80e126e4ce783c522de6c02a2a5bf7af3a2b9327b86776f188e4be1c1c404a129dbda493",
79+
# "PCR2": "9ea2080d6e6bd61f03a62357a1cbbae278b070db5df6b1fe5c57821ff249b77add0f95dab0a5beec7aa6ef6735f27b14"
80+
# }
81+
# }
82+
sudo nitro-cli run-enclave --cpu-count 2 --memory 512 --enclave-cid 88 --eif-path idempotent-proxy_enclave_amd64.eif --debug-mode
83+
# Started enclave with enclave-cid: 88, memory: 512 MiB, cpu-ids: [1, 3]
84+
# {
85+
# "EnclaveName": "idempotent-proxy_enclave_amd64",
86+
# "EnclaveID": "i-056e1ab9a31cd77a0-enc190ca7263013fd3",
87+
# "ProcessID": 21493,
88+
# "EnclaveCID": 88,
89+
# "NumberOfCPUs": 2,
90+
# "CPUIDs": [
91+
# 1,
92+
# 3
93+
# ],
94+
# "MemoryMiB": 512
95+
# }
96+
sudo nitro-cli describe-enclaves
97+
sudo nitro-cli console --enclave-id i-056e1ab9a31cd77a0-enc190ca7263013fd3
98+
sudo nitro-cli terminate-enclave --enclave-id i-056e1ab9a31cd77a0-enc190ca7263013fd3
99+
```
100+
101+
102+
#### Make a request
103+
104+
```bash
105+
curl -v -X POST \
106+
--url http://YOUR_HOST/ \
107+
--header 'content-type: application/json' \
108+
--header 'x-forwarded-host: cloudflare-eth.com' \
109+
--header 'idempotency-key: key_001' \
110+
--data '{
111+
"id": 1,
112+
"jsonrpc": "2.0",
113+
"method": "eth_getBlockByNumber",
114+
"params": ["latest", false]
115+
}'
116+
```
117+
33118
## License
34119
Copyright © 2024 [LDC Labs](https://github.com/ldclabs).
35120

0 commit comments

Comments
 (0)