Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ TRANSPARENCY_DOMAIN_RADS=transparency.r.secure-rads.org
TRANSPARENCY_DOMAIN_SECURE_RADS=transparency.sr.secure-rads.org
LOG_HOST_RADS=log.r.secure-rads.org
LOG_HOST_SECURE_RADS=log.sr.secure-rads.org
# mTLS domain for internal producers (registry, execution-service, result-consumer).
# mTLS domain for internal producers (registry, execution-service).
TELEMETRY_HOST_RADS=telemetry.r.secure-rads.org
TELEMETRY_HOST_SECURE_RADS=telemetry.sr.secure-rads.org
COST_HOST_RADS=cost.r.secure-rads.org
Expand Down
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The human user is the technical lead. The agent is a supporting engineer that he

## Project Context

This repo is a PoC of the Secure Computing Environment (SCE), running on AWS Nitro Enclaves. It covers the end-to-end workflow: a build phase (Registry Service, part of the CSAV, turns a Data Controller's OCI image into a single EIF, layering the SCE Unit and nsjail on top, stores the artifact in S3, records `AlgorithmId` -> S3 path in DynamoDB) and an execution phase (enclave provisioning, remote attestation against the Verifier Service, data fetch from the Personal Data Management Service and KMS, computation over decrypted records files inside the enclave (`RECORDS_PATH` / `RESULT_PATH`, same contract as rads), async result delivery through SQS and a result-consumer Lambda, polled via `GET /run/{runId}`). See the architecture section in `README.md` and the docs it links before making assumptions about scope or design.
This repo is a PoC of the Secure Computing Environment (SCE), running on AWS Nitro Enclaves. It covers the end-to-end workflow: a build phase (Registry Service, part of the CSAV, turns a Data Controller's OCI image into a single EIF, layering the SCE Unit and nsjail on top, stores the artifact in S3, records `AlgorithmId` -> S3 path in DynamoDB) and an execution phase (enclave provisioning, remote attestation against the Verifier Service, data fetch from the Personal Data Management Service and KMS, computation over decrypted records files inside the enclave (`RECORDS_PATH` / `RESULT_PATH`, same contract as rads), async result delivery by signed webhook to a per-run URL, with result-consumer as the store-backed receiver, verifiable via verifier-service). See the architecture section in `README.md` and the docs it links before making assumptions about scope or design.

## Operating Rules

Expand Down
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ instance_ip = $(shell aws ec2 describe-instances --region $(REGION) --instance-i
CSAV_IP = $(call instance_ip,secure-rads-csav,CsavInstanceId)
EXECUTION_API_URL = $(shell aws cloudformation describe-stacks --stack-name secure-rads-execution-service-dev --region $(REGION) \
--query "Stacks[0].Outputs[?OutputKey=='ExecutionApiUrl'].OutputValue" --output text)
RESULT_WEBHOOK_URL = $(shell aws cloudformation describe-stacks --stack-name secure-rads-result-consumer-dev --region $(REGION) \
--query "Stacks[0].Outputs[?OutputKey=='ResultWebhookUrl'].OutputValue" --output text)
PDM_TABLE_PREFIX = $(shell aws cloudformation describe-stacks --stack-name secure-rads-pdm-service-dev --region $(REGION) \
--query "Stacks[0].Outputs[?OutputKey=='PdmTablePrefix'].OutputValue" --output text)
DATA_KEY_TABLE = $(shell aws cloudformation describe-stacks --stack-name secure-rads-pdm-service-dev --region $(REGION) \
Expand Down Expand Up @@ -219,14 +221,16 @@ secure-rads-build-all:
$(MAKE) secure-rads-build APP=$$app ALGORITHM_ID=$$id || exit 1; \
done

# Execution phase (one run): make secure-rads-run ALGORITHM_ID=<id>.
# Fires /run (202 + runId), then polls GET /run/{runId} until the enclave reports back.
# Execution phase (one run): make secure-rads-run ALGORITHM_ID=<id> WEBHOOK_URL=<url>.
# Fires /run with the required webhook. When the webhook is result-consumer, GET /run/{runId} is polled.
secure-rads-run:
@test -n "$(ALGORITHM_ID)" || { echo "ALGORITHM_ID is required"; exit 1; }
@test -n "$(WEBHOOK_URL)" || { echo "WEBHOOK_URL is required"; exit 1; }
@api=$(EXECUTION_API_URL); \
runId=$$(curl -sS -X POST "$$api/run" -H 'Content-Type: application/json' \
-d '{"algorithmId":"$(ALGORITHM_ID)"}' | python3 -c 'import sys,json; print(json.load(sys.stdin)["runId"])'); \
-d '{"algorithmId":"$(ALGORITHM_ID)","webhookUrl":"$(WEBHOOK_URL)"}' | python3 -c 'import sys,json; print(json.load(sys.stdin)["runId"])'); \
echo "runId=$$runId"; \
if [ "$(WEBHOOK_URL)" != "$(RESULT_WEBHOOK_URL)" ]; then echo "webhook run; result goes to $(WEBHOOK_URL)"; exit 0; fi; \
for i in $$(seq 1 132); do \
res=$$(curl -sS "$$api/run/$$runId?algorithmId=$(ALGORITHM_ID)"); \
status=$$(echo "$$res" | python3 -c 'import sys,json; print(json.load(sys.stdin).get("status",""))'); \
Expand All @@ -241,14 +245,16 @@ secure-rads-run:

# Fire and poll every sample app in turn (sequential - each spins up its own enclave).
secure-rads-run-all:
@test -n "$(WEBHOOK_URL)" || { echo "WEBHOOK_URL is required"; exit 1; }
@for pair in $(SAMPLE_APPS); do \
app=$${pair%%:*}; id=$${pair##*:}; \
$(MAKE) secure-rads-run ALGORITHM_ID=$$id || exit 1; \
$(MAKE) secure-rads-run ALGORITHM_ID=$$id WEBHOOK_URL="$(WEBHOOK_URL)" || exit 1; \
done

# Start the existing hosts, then build, seed, and run the whole fleet. Build comes first because it
# provisions the per-algorithm KMS keys used by seeding.
secure-rads-all:
@test -n "$(WEBHOOK_URL)" || { echo "WEBHOOK_URL is required"; exit 1; }
$(MAKE) secure-rads-ready
$(MAKE) secure-rads-build-all
$(MAKE) secure-rads-seed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Every rads AWS resource is prefixed `rads-`; every secure-rads resource is prefi

**Build phase (CSAV).** A Data Controller uploads an OCI image and assigns it an `algorithmId`. registry-service unpacks the image (daemonless: skopeo + umoci), layers the SCE Unit and nsjail on top, and builds a single Nitro Enclave Image File (EIF). It registers the EIF's PCR measurements against that `algorithmId` with the Verifier Service (over mTLS) and stores the EIF in S3, recording `algorithmId -> S3 path` in DynamoDB.

**Execution phase (SCE).** A caller POSTs an `algorithmId` to the API Gateway and Lambda execution-service control plane, which launches a per-run Nitro Enclave parent EC2 instance. Inside, the SCE Unit seeds enclave entropy from the NSM, attests to the Verifier Service, and - once attestation passes - fetches that algorithm's records from the PDM Service, gets the data key unwrapped by the KMS Service, decrypts them, and writes `records.json` for the jailed Data Controller app (`RECORDS_PATH` / `RESULT_PATH`, same file contract as rads). Results come back asynchronously: `/run` returns a `runId` immediately, the enclave host publishes the result to SQS, a consumer Lambda persists it, and the caller polls `GET /run/{runId}`.
**Execution phase (SCE).** A caller POSTs an `algorithmId` to the API Gateway and Lambda execution-service control plane, which launches a per-run Nitro Enclave parent EC2 instance. Inside, the SCE Unit seeds enclave entropy from the NSM, attests to the Verifier Service, and - once attestation passes - fetches that algorithm's records from the PDM Service, gets the data key unwrapped by the KMS Service, decrypts them, and writes `records.json` for the jailed Data Controller app (`RECORDS_PATH` / `RESULT_PATH`, same file contract as rads). Results come back asynchronously: `/run` returns a `runId` immediately, the enclave signs the result with its attested key and POSTs it to a per-run webhook; when that webhook is result-consumer, it verifies the signature and `GET /run/{runId}` reads the stored result.

Throughout both phases every component posts timestamped events to the telemetry-service, so a run's full timeline - build to execution - can be exported for benchmarking. The log-service records only the subject-access trail. Components also report selected, attributable AWS operations to the cost-service, keyed by the same `(AlgorithmId, runId)`, so their estimated costs can be summed per AWS service ([`docs/cost-service.md`](docs/cost-service.md)). Event-by-event plaintext flows: [`docs/e2e-rads.txt`](docs/e2e-rads.txt), [`docs/e2e-secure-rads.txt`](docs/e2e-secure-rads.txt).

Expand Down
6 changes: 6 additions & 0 deletions benchmark/src/lib/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class ApiGatewayService(BaseModel):
has_url: bool = True
# Env var holding the caller-facing hostname, for stacks whose URL is a custom domain.
host_env: str | None = None
# Stack output that holds the URL, when it is not HttpApiUrl.
url_output: str = "HttpApiUrl"


class Ec2HttpService(BaseModel):
Expand Down Expand Up @@ -61,6 +63,10 @@ class Ec2HttpService(BaseModel):
),
"pdm": ApiGatewayService(stack="secure-rads-pdm-service-dev"),
"execution": ApiGatewayService(stack="secure-rads-execution-service-dev"),
"result_consumer": ApiGatewayService(
stack="secure-rads-result-consumer-dev",
url_output="ResultWebhookUrl",
),
"log": ApiGatewayService(
stack="secure-rads-log-service-dev",
host_env="LOG_HOST_SECURE_RADS",
Expand Down
8 changes: 4 additions & 4 deletions benchmark/src/lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ def stack_outputs(stack: str) -> dict[str, str]:
return outputs


def _api_gateway_url(outputs: dict[str, str], host_env: str | None) -> str:
def _api_gateway_url(outputs: dict[str, str], host_env: str | None, url_output: str) -> str:
if host_env:
host = os.environ.get(host_env)
if not host:
msg = f"{host_env} is required to resolve the service URL"
raise RuntimeError(msg)
return f"https://{host}"
if url := outputs.get("HttpApiUrl"):
if url := outputs.get(url_output):
return url
domain = outputs.get("ApiRegionalDomainName")
if not domain:
msg = "stack outputs missing HttpApiUrl and ApiRegionalDomainName"
msg = f"stack outputs missing {url_output} and ApiRegionalDomainName"
raise RuntimeError(msg)
return f"https://{domain}"

Expand Down Expand Up @@ -91,7 +91,7 @@ def _ec2_http_url(service: Ec2HttpService, outputs: dict[str, str]) -> str:

def _service_url(service: ApiGatewayService | Ec2HttpService, outputs: dict[str, str]) -> str:
if service.kind is ServiceKind.API_GATEWAY:
return _api_gateway_url(outputs, service.host_env)
return _api_gateway_url(outputs, service.host_env, service.url_output)
if service.kind is ServiceKind.EC2_HTTP:
return _ec2_http_url(service, outputs)
msg = f"unknown service kind {service.kind!r}"
Expand Down
2 changes: 1 addition & 1 deletion benchmark/src/lib/trees/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ def harness_for(tree: Tree, endpoints: dict[str, str]) -> TreeHarness:
if tree is Tree.RADS:
return RadsHarness(endpoints["registry"], endpoints["execution"])
if tree is Tree.SECURE_RADS:
return SecureRadsHarness(endpoints["registry"], endpoints["execution"])
return SecureRadsHarness(endpoints["registry"], endpoints["execution"], endpoints["result_consumer"])
msg = f"unknown tree {tree!r}"
raise ValueError(msg)
28 changes: 28 additions & 0 deletions benchmark/src/lib/trees/secure_rads.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,34 @@ class SecureRadsHarness(TreeHarness):

name: ClassVar[Tree] = Tree.SECURE_RADS

def __init__(self, registry_url: str, execution_url: str, result_webhook_url: str) -> None:
super().__init__(registry_url, execution_url)
self._webhook = result_webhook_url

async def execute(self, client: httpx.AsyncClient, algorithm_id: str, size: int) -> tuple[str, str, str]:
status, body = await http.arequest(
client,
"POST",
f"{self._execution}/run",
json={"algorithmId": algorithm_id, "size": size, "webhookUrl": self._webhook},
)
http.require(status, http.HTTP_ACCEPTED, "/run", body)

run_id = http.parse_json(body)["runId"]
deadline = asyncio.get_running_loop().time() + http.POLL_TIMEOUT_SECONDS
while asyncio.get_running_loop().time() < deadline:
status, result_body = await http.arequest(
client, "GET", f"{self._execution}/run/{run_id}?algorithmId={algorithm_id}"
)
http.require(status, http.HTTP_OK, f"/run/{run_id}", result_body)
result = http.parse_json(result_body)
if result.get("status") != "pending":
return run_id, result.get("status", ""), result.get("output", "") or ""
await asyncio.sleep(http.POLL_INTERVAL_SECONDS)

msg = f"timed out after {http.POLL_TIMEOUT_SECONDS:.0f}s waiting for runId={run_id}"
raise http.FlowError(msg)

async def upload(self, client: httpx.AsyncClient, algorithm_id: str) -> None:
tar_path = await asyncio.to_thread(self.build_sample_tar, self.name)
content = await asyncio.to_thread(tar_path.read_bytes)
Expand Down
10 changes: 6 additions & 4 deletions docs/cost-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,19 @@ rads (`csav/registry-service`, Lambdas):
- execution-service `POST /run`: `apigateway:request`, `lambda:invocation`, `lambda:compute`,
`dynamodb:read-capacity` (algorithm lookup and record-count check; actual `ConsumedCapacity.CapacityUnits`).
It also stamps the launch epoch into the host user-data.
- execution-service `GET /run/{runId}?algorithmId={algorithmId}` (each poll): `apigateway:request`, `lambda:invocation`,
- execution-service `GET /run/{runId}?algorithmId={algorithmId}` (both trees; secure-rads webhook runs stored by result-consumer): `apigateway:request`, `lambda:invocation`,
`lambda:compute`, `dynamodb:read-capacity`. `algorithmId` is required so pending-run polls can be attributed.
- executor host (user-data, both trees): `s3:get` (artifact; rads also the host tools), `sqs:send` (result),
- executor host (user-data): `s3:get` (artifact; rads also the host tools), `sqs:send` (rads result only),
`ec2:instance` (seconds from launch to the terminate call).
- pdm-service `/records`: `apigateway:request`, `lambda:invocation`, `lambda:compute`, `dynamodb:read-capacity`
(each records `Query` page).
- kms-service `/decrypt` (secure-rads): `apigateway:request`, `lambda:invocation`, `lambda:compute`,
`dynamodb:read-capacity` (algorithm and data-key `GetItem`s).
- result-consumer (`batchSize` 1, so each run's receive + invoke lands on that run): `sqs:receive` (message
- rads result-consumer (`batchSize` 1, so each run's receive + invoke lands on that run): `sqs:receive` (message
bytes), `sqs:delete` (one request when the handler succeeds; Lambda performs the deletion),
`dynamodb:write-capacity`, `lambda:invocation`, `lambda:compute`.
- secure-rads result-consumer (`POST /results`): `apigateway:request`, `lambda:invocation`, `lambda:compute`,
`dynamodb:write-capacity` for each verified webhook result.
- verifier-service (secure-rads): `/challenge`, `/attest` and `/refresh` (the enclave's challenge, attestation and
token refresh, keyed by the run) and `/algorithms` (build-time PCR registration, keyed by `algorithmId`): `dynamodb:read-capacity` and
`dynamodb:write-capacity` where attributable, plus `apigateway:request`, `lambda:invocation`, `lambda:compute`.
Expand Down Expand Up @@ -103,7 +105,7 @@ per-run against Cost Explorer.
- log-service, telemetry-service, and cost-service self-cost (ingest API Gateway/Lambda/queue/DynamoDB).
- Ongoing storage (S3 EIF/artifact objects, DynamoDB table storage), CloudWatch Logs ingestion/storage, CloudWatch
alarms, the persistent CSAV host, and data transfer (internet egress, cross-AZ).
- SQS queue-cost of result delivery is metered as `sqs:send`, `sqs:receive`, and `sqs:delete`. Receive requests
- rads result delivery SQS cost is metered as `sqs:send`, `sqs:receive`, and `sqs:delete`. Receive requests
that invoke the handler with an attributable result are counted, including redeliveries; idle polling, empty
receives, and messages without parseable run identifiers cannot be attributed to a run.
- Attributed DynamoDB events use each response's `ConsumedCapacity.CapacityUnits`; an invalid verifier refresh lookup
Expand Down
36 changes: 17 additions & 19 deletions docs/e2e-secure-rads.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Input:
6 cost dynamodb:read-capacity // execution-service Query on the PDM table
7 RunInstances(Nitro parent, userdata ← ⟨a, runId, n, key, launchEpoch⟩)
8 emit executor-launched
9 cost apigateway:request + lambda // per control-plane request/poll (GET /run/{runId}?algorithmId=... too)
9 cost apigateway:request + lambda // per control-plane request
10 return runId


Expand All @@ -50,23 +50,21 @@ Input:
4 cost s3:get // EIF pull
5 EIF ← GET-S3(key)
6 emit artifact-retrieved // direct, auth none
7 start vsock listeners // output :5000, runInfo :5001
7 start vsock listeners // runInfo :5001, webhook :8006
8 configure vsock-proxy
9 RUN-ENCLAVE(EIF)
9 RUN-ENCLAVE(EIF) // on failure: emit enclave-launch-failed {runEnclave log tail}, go to 12
10 emit enclave-launched // direct, auth none
11 wait for enclave exit
12 publish result to SQS
13 cost sqs:send // message bytes
14 emit executor-finished // direct, auth none
15 cost ec2:instance // captured before the cost POST and terminate request
16 terminate instance
11 wait for enclave exit // absent from describe-enclaves for 5 consecutive polls
12 emit executor-finished // direct, auth none
13 cost ec2:instance // captured before the cost POST and terminate request
14 terminate instance


SCE-UNIT(a)
Input:
a ← algorithm id
1 cfg ← LOAD-RUN-CONFIG()
2 ⟨runId, n⟩ ← READ-RUNINFO(:5001)
2 ⟨runId, n, webhookUrl⟩ ← READ-RUNINFO(:5001)
3 emit enclave-started // no token yet, auth none
4 SEED-ENTROPY from NSM // no AWS cost
5 emit unit-ready // no token yet, auth none
Expand All @@ -87,9 +85,10 @@ Input:
20 wait for nsjail exit
21 output ← read /data/result.json
22 emit dc-app-completed // on success, else run-failed
23 STREAM output to parent // vsock :5000
24 emit output-sent
25 // on failure: emit run-failed
23 SIGN result // signature key registered at attestation
24 SEND signed envelope to webhook // CA-verified TLS via vsock :8006; retry transport/429/5xx only
25 emit output-sent
26 // on failure: emit run-failed; before attestation no signed result is sent



Expand All @@ -109,9 +108,8 @@ Input:

SECURE-RADS-RESULT-CONSUMER(result)
Input:
result ← processing result returned by the SCE-UNIT
1 SQS delivers result batch; invoke Lambda // receive is billed before the handler runs
2 persist result to DynamoDB
3 cost dynamodb:write-capacity; emit result-persisted
4 cost sqs:receive + lambda:invocation + lambda:compute // reported by handler after processing
5 cost sqs:delete // reported on success; Lambda deletes after return
result ← signed envelope POSTed by the SCE-UNIT webhook
1 key ← GET-VERIFIER-RUN-ATTESTATION(result.runId) // verifier GET /runs/{runId}
2 if not VERIFY-SIGNATURE(key, result) then reject
3 persist verified result to DynamoDB
4 cost dynamodb:write-capacity; emit result-persisted
14 changes: 7 additions & 7 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,7 @@ export SECURE_COST_CERT_ARN=<cost.sr-acm-certificate-arn>
export RADS_COST_CERT_ARN=<cost.r-acm-certificate-arn>
```

Deploy the result consumer first because the execution-service stack needs its queue and table:

```sh
(cd secure/result-consumer && bun install && bunx serverless deploy --param="region=$REGION")
```

Generate the mTLS client certificate, then deploy verifier-service once to create its truststore bucket:
Generate the mTLS client certificate, then deploy verifier-service once to create its truststore bucket and run-attestation table:

```sh
make -C secure/csav/registry-service gen-client-cert
Expand All @@ -179,6 +173,12 @@ make -C secure/csav/registry-service gen-client-cert
--param="publicCertificateArn=$VERIFIER_ATTEST_CERT_ARN")
```

Deploy the result consumer next so the execution-service stack can use its receiver URL and results table:

```sh
(cd secure/result-consumer && bun install && bunx serverless deploy --param="region=$REGION")
```

Upload the truststore, then deploy verifier-service again with its immutable S3 object version:

```sh
Expand Down
Loading
Loading