diff --git a/benchmark/README.md b/benchmark/README.md index 77170f6..af08560 100644 --- a/benchmark/README.md +++ b/benchmark/README.md @@ -123,14 +123,18 @@ The event contract follows [RADS](../docs/e2e-rads.txt) and [Secure-RADS](../doc | Attestation | — | `unit-ready` → `attested` | | Data retrieval | `artifact-retrieved` → `records-stored-locally` | `attested` → `records-stored-locally` | | Algorithm processing | `records-stored-locally` → `compute-completed` | `records-stored-locally` → `dc-app-completed` | -| Result delivery | `compute-completed` → `result-persisted` | `output-sent` → `result-persisted` | +| Subject access | `compute-completed` → `subject-access-completed` | `dc-app-completed` → `subject-access-completed` | +| Output handoff | — | `subject-access-completed` → `output-received` | +| Result delivery | `subject-access-completed` → `result-persisted` | `output-received` → `result-persisted` | | Total | `run-requested` → `result-persisted` | `run-requested` → `result-persisted` | +Both trees end algorithm processing when the DC app finishes, then measure subject access as its own phase. `output-received` is a host event emitted when the vsock output stream closes, so secure-rads result delivery starts after the enclave has handed off its output and does not include enclave teardown. rads publishes to SQS after subject access, so its result delivery starts at `subject-access-completed`. + `records-fetched` precedes file serialization/writing in both trees. Secure-rads emits `records-decrypted` after decryption and `records-stored-locally` after writing the plaintext file. Its data-retrieval phase includes fetching AWS credentials, fetching records, KMS key unwrapping, record decryption, and writing the file. The CSV includes the individual event timestamps as well as the aggregate phase durations. `executor-launched` records EC2 launch; secure-rads' `enclave-launched` records a successful `nitro-cli run-enclave`. Host and enclave run concurrently, so `enclave-started` can arrive before the host emits `enclave-launched`; enclave boot therefore ends at `enclave-started`. -Existing committed results use the earlier event contract (`data-decrypted` after the file write, and `enclave-launched` for EC2 launch). They remain historical measurements. Re-exporting those runs with the new exporter leaves phases blank where the new events are absent; deploy the aligned services, rebuild the EIFs, ship the rads host tools, and run a fresh sweep for the new contract. +Existing committed results use the earlier event contract (`data-decrypted` after the file write, and `enclave-launched` for EC2 launch) and predate `subject-access-completed` and `output-received`. They remain historical measurements. Re-exporting those runs with the new exporter leaves the subject-access, output-handoff, and secure-rads result-delivery phases blank where the new events are absent; deploy the aligned services, rebuild the EIFs, ship the rads host tools, and run a fresh sweep for the new contract. ## Layout diff --git a/benchmark/src/export.py b/benchmark/src/export.py index be472dd..eba9f4f 100644 --- a/benchmark/src/export.py +++ b/benchmark/src/export.py @@ -27,7 +27,9 @@ "attestation": ("unit-ready", "attested"), "data_retrieval": ("attested", "records-stored-locally"), "algorithm_processing": ("records-stored-locally", "dc-app-completed"), - "result_delivery": ("output-sent", "result-persisted"), + "subject_access": ("dc-app-completed", "subject-access-completed"), + "output_handoff": ("subject-access-completed", "output-received"), + "result_delivery": ("output-received", "result-persisted"), "total": ("run-requested", "result-persisted"), }, "rads": { @@ -38,7 +40,9 @@ "attestation": (None, None), "data_retrieval": ("artifact-retrieved", "records-stored-locally"), "algorithm_processing": ("records-stored-locally", "compute-completed"), - "result_delivery": ("compute-completed", "result-persisted"), + "subject_access": ("compute-completed", "subject-access-completed"), + "output_handoff": (None, None), + "result_delivery": ("subject-access-completed", "result-persisted"), "total": ("run-requested", "result-persisted"), }, } @@ -61,7 +65,9 @@ "records-stored-locally", "dc-app-completed", "compute-completed", + "subject-access-completed", "output-sent", + "output-received", "result-persisted", "executor-finished", ] diff --git a/benchmark/src/plot.py b/benchmark/src/plot.py index 00915bc..760c237 100644 --- a/benchmark/src/plot.py +++ b/benchmark/src/plot.py @@ -28,16 +28,31 @@ "attestation_s": "attestation", "data_retrieval_s": "data retrieval", "algorithm_processing_s": "algorithm processing", + "subject_access_s": "subject access", + "output_handoff_s": "output handoff", "result_delivery_s": "result delivery", } -PHASE_COLORS = ["#1F4E79", "#4C9BE8", "#C0392B", "#6FBF73", "#F2C14E", "#E8873C", "#8E44AD", "#7F8C8D"] +PHASE_COLORS = [ + "#1F4E79", + "#4C9BE8", + "#C0392B", + "#6FBF73", + "#F2C14E", + "#E8873C", + "#8E44AD", + "#56B4E9", + "#D55E00", + "#7F8C8D", +] COST_SERVICES = ["ec2", "dynamodb", "s3", "sqs", "lambda", "apigateway"] COST_COLS = [f"{service}_cost_usd" for service in COST_SERVICES] COST_COLORS = ["#1F4E79", "#4C9BE8", "#C0392B", "#6FBF73", "#F2C14E", "#8E44AD"] NOTE = ( "host provisioning = per-run instance boot + tooling install (size-independent); " "data retrieval is fetch through records.json write (secure-rads includes decrypt).\n" - "rads has no enclave, so enclave boot / sce unit / attestation are blank for it." + "Both trees end algorithm processing at app completion and measure subject access separately; " + "output handoff is the secure-rads enclave-to-host stream. rads has no enclave, so enclave " + "boot / sce unit / attestation / output handoff are blank for it." ) @@ -47,7 +62,8 @@ def load() -> pd.DataFrame: raise SystemExit(1) df = pd.read_csv(PHASE_TIMINGS_CSV) cols = [*PHASES, "total_s"] - df[cols] = df[cols].apply(pd.to_numeric, errors="coerce") + for col in cols: + df[col] = pd.to_numeric(df[col], errors="coerce") if col in df.columns else float("nan") cost_cols = [c for c in [*COST_COLS, "total_cost_usd"] if c in df.columns] if cost_cols: df[cost_cols] = df[cost_cols].apply(pd.to_numeric, errors="coerce") diff --git a/docs/e2e-rads.txt b/docs/e2e-rads.txt index 31d633d..2615e36 100644 --- a/docs/e2e-rads.txt +++ b/docs/e2e-rads.txt @@ -54,11 +54,13 @@ Input: 14 emit records-stored-locally 15 DOCKER-RUN(image, bind ← /data/records.json) 16 emit compute-completed -17 publish result to SQS -18 cost sqs:send // message bytes -19 emit executor-finished -20 cost ec2:instance // captured before the cost POST and terminate request -21 terminate instance +17 SUBJECT-ACCESS-COMPLETED // DSAR POSTs to log-service +18 emit subject-access-completed +19 publish result to SQS +20 cost sqs:send // message bytes +21 emit executor-finished +22 cost ec2:instance // captured before the cost POST and terminate request +23 terminate instance RADS-RESULT-CONSUMER(result) diff --git a/docs/e2e-secure-rads.txt b/docs/e2e-secure-rads.txt index d88fe76..58d9e13 100644 --- a/docs/e2e-secure-rads.txt +++ b/docs/e2e-secure-rads.txt @@ -54,12 +54,13 @@ Input: 8 configure vsock-proxy 9 RUN-ENCLAVE(EIF) 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 the vsock output stream to close +12 emit output-received // direct, auth none +13 publish result to SQS +14 cost sqs:send // message bytes +15 emit executor-finished // direct, auth none +16 cost ec2:instance // captured before the cost POST and terminate request +17 terminate instance // kills the enclave; no describe-enclaves poll SCE-UNIT(a) @@ -87,9 +88,11 @@ 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 SUBJECT-ACCESS-COMPLETED // DSAR POSTs to log-service +24 emit subject-access-completed +25 STREAM output to parent // vsock :5000 +26 emit output-sent +27 // on failure: emit run-failed diff --git a/packages/go-common/log/log.go b/packages/go-common/log/log.go index ab439ca..93ed692 100644 --- a/packages/go-common/log/log.go +++ b/packages/go-common/log/log.go @@ -15,22 +15,23 @@ import ( const requestTimeout = 5 * time.Second const ( - EventImageUploaded = "image-uploaded" - EventBuildStarted = "build-started" - EventAlgorithmRegistered = "algorithm-registered" - EventPCRsRegistered = "pcrs-registered" - EventKMSKeyProvisioned = "kms-key-provisioned" - EventBuildCompleted = "build-completed" - EventBuildFailed = "build-failed" - EventEnclaveStarted = "enclave-started" - EventUnitReady = "unit-ready" - EventAttested = "attested" - EventRecordsFetched = "records-fetched" - EventRecordsDecrypted = "records-decrypted" - EventRecordsStoredLocally = "records-stored-locally" - EventDCAppCompleted = "dc-app-completed" - EventOutputSent = "output-sent" - EventRunFailed = "run-failed" + EventImageUploaded = "image-uploaded" + EventBuildStarted = "build-started" + EventAlgorithmRegistered = "algorithm-registered" + EventPCRsRegistered = "pcrs-registered" + EventKMSKeyProvisioned = "kms-key-provisioned" + EventBuildCompleted = "build-completed" + EventBuildFailed = "build-failed" + EventEnclaveStarted = "enclave-started" + EventUnitReady = "unit-ready" + EventAttested = "attested" + EventRecordsFetched = "records-fetched" + EventRecordsDecrypted = "records-decrypted" + EventRecordsStoredLocally = "records-stored-locally" + EventDCAppCompleted = "dc-app-completed" + EventSubjectAccessCompleted = "subject-access-completed" + EventOutputSent = "output-sent" + EventRunFailed = "run-failed" ) type Client struct { diff --git a/rads/sce/execution-service/README.md b/rads/sce/execution-service/README.md index 0159167..dee8206 100644 --- a/rads/sce/execution-service/README.md +++ b/rads/sce/execution-service/README.md @@ -23,9 +23,11 @@ the stored result. Lifecycle events are posted to log-service `POST /events` (the ingest contract `{algorithmId, runId, event, timestamp, detail?}`): the control plane logs `run-requested` and `executor-launched` / `launch-failed`, and the executor posts `executor-ready`, `artifact-retrieved`, -`records-fetched`, `records-stored-locally`, `compute-completed`, and `executor-finished` over HTTPS. +`records-fetched`, `records-stored-locally`, `compute-completed`, `subject-access-completed`, and `executor-finished` over HTTPS. The fetch helper emits `records-fetched` before serializing/writing the records file; userdata emits -`records-stored-locally` only after that write succeeds. `executor-finished` is timestamped after result publication. +`records-stored-locally` only after that write succeeds. `compute-completed` is emitted as soon as the DC app +exits, before the subject-access POST, so benchmark phases line up with secure-rads. `executor-finished` is +timestamped after result publication. PDM returns a standalone `dataSubjectIds` list aligned with the records. The fetch helper prints those ids on stdout, userdata holds them in a shell variable, and `records.json` stays `{recordId, data}`. After a diff --git a/rads/sce/execution-service/userdata.sh.tmpl b/rads/sce/execution-service/userdata.sh.tmpl index bd82690..45778aa 100644 --- a/rads/sce/execution-service/userdata.sh.tmpl +++ b/rads/sce/execution-service/userdata.sh.tmpl @@ -87,8 +87,9 @@ emit_event records-stored-locally # The app reads /data/records.json and writes /data/result.json; stdout is the diagnostic fallback. # Capped to the secure-rads enclave allocation (1 vCPU / 2048 MiB) so both trees get the same compute. docker run --rm --cpus {{.CPUCount}} --memory {{.MemoryMiB}}m -v "$RUN_DIR:/data" -e RECORDS_PATH=/data/records.json -e RESULT_PATH=/data/result.json "$IMAGE" > "$OUTPUT_FILE" +emit_event compute-completed # DSAR trail: log the data subjects only after the DC app produced a result. Best-effort. if [ -s "$RESULT_FILE" ]; then printf '%s' "$SUBJECT_IDS" | "$TOOLS_BIN" subject-access "https://$LOG_HOST/subject-access" "$ALGORITHM_ID" "$RUN_ID" || true + emit_event subject-access-completed fi -emit_event compute-completed diff --git a/rads/telemetry-service/src/lib/events.ts b/rads/telemetry-service/src/lib/events.ts index 6f6296d..9ad18ed 100644 --- a/rads/telemetry-service/src/lib/events.ts +++ b/rads/telemetry-service/src/lib/events.ts @@ -14,6 +14,7 @@ export const RUN_EVENTS = [ "records-fetched", "records-stored-locally", "compute-completed", + "subject-access-completed", "executor-finished", // Result delivery (result-consumer). "result-persisted", diff --git a/secure/sce-unit/main.go b/secure/sce-unit/main.go index 1dd91e1..06e43c2 100644 --- a/secure/sce-unit/main.go +++ b/secure/sce-unit/main.go @@ -94,6 +94,7 @@ func main() { // DSAR trail: record the data subjects the app used only after it ran successfully, so a run that // never reached the DC app does not show up as an access. accessLog.EmitSubjectAccess(cfg.AlgorithmId, runID, subjectIDs) + timelineLog.EmitEvent(cfg.AlgorithmId, &runID, sharedlog.EventSubjectAccessCompleted, nil) } if readErr != nil || len(output) == 0 { // The enclave console is lost when the host terminates, so deliver the failure and the jailed app's own output. diff --git a/secure/sce/execution-service/README.md b/secure/sce/execution-service/README.md index df4c6ad..6991469 100644 --- a/secure/sce/execution-service/README.md +++ b/secure/sce/execution-service/README.md @@ -6,7 +6,7 @@ Part of the SCE. API Gateway invokes the TypeScript Lambda control plane. Given `GET /run/{runId}?algorithmId={algorithmId}` polls for the result: `{runId, status: "pending"}` until it lands, then the stored result once the consumer has written it. `algorithmId` is required so every poll can be attributed to its run. -The control plane logs `run-requested` and `executor-launched` (or `launch-failed`). The parent posts `executor-ready`, `artifact-retrieved`, `enclave-launched`, and `executor-finished` directly to telemetry-service with `origin: host`. The host holds no credential; telemetry ingest is unauthenticated. The enclave emits `run-failed` before it exits. result-consumer only emits `result-persisted`. SCE-unit and result-consumer emit the remaining events in [the execution flow](../../../docs/e2e-secure-rads.txt). +The control plane logs `run-requested` and `executor-launched` (or `launch-failed`). The parent posts `executor-ready`, `artifact-retrieved`, `enclave-launched`, `output-received`, and `executor-finished` directly to telemetry-service with `origin: host`. `output-received` marks the end of the vsock output stream; the host publishes the result and terminates without polling `nitro-cli describe-enclaves`, since instance termination tears the enclave down. The host holds no credential; telemetry ingest is unauthenticated. The enclave emits `run-failed` before it exits. result-consumer only emits `result-persisted`. SCE-unit and result-consumer emit the remaining events in [the execution flow](../../../docs/e2e-secure-rads.txt). See [../README.md](../README.md) for the full SCE context. diff --git a/secure/sce/execution-service/userdata.sh.tmpl b/secure/sce/execution-service/userdata.sh.tmpl index c56b3a9..751941e 100644 --- a/secure/sce/execution-service/userdata.sh.tmpl +++ b/secure/sce/execution-service/userdata.sh.tmpl @@ -124,13 +124,10 @@ done if [ "$launched" = true ]; then emit_event enclave-launched - # Wait for output first so a transient describe-enclaves miss cannot publish an empty result. + # The listener exits on vsock EOF once the enclave has sent its output. Everything the enclave still does + # after that (teardown) is not part of result delivery, so stop waiting here. wait "$OUTPUT_LISTENER_PID" || exit $? - while true; do - ENCLAVE_COUNT=$(nitro-cli describe-enclaves | python3 -c 'import json, sys; print(sum(e.get("EnclaveCID") == 16 for e in json.load(sys.stdin)))') || exit 1 - [ "$ENCLAVE_COUNT" -eq 0 ] && break - sleep 1 - done + emit_event output-received else kill "$OUTPUT_LISTENER_PID" 2>/dev/null || true wait "$OUTPUT_LISTENER_PID" 2>/dev/null || true diff --git a/secure/telemetry-service/src/lib/events.ts b/secure/telemetry-service/src/lib/events.ts index efb13d3..72307e5 100644 --- a/secure/telemetry-service/src/lib/events.ts +++ b/secure/telemetry-service/src/lib/events.ts @@ -9,13 +9,20 @@ export const ENCLAVE_EVENTS = [ "records-decrypted", "records-stored-locally", "dc-app-completed", + "subject-access-completed", "output-sent", "run-failed", ] as const; // Host-reported events. The EC2 host posts them directly without a token, so they carry origin=host // instead of being presented as enclave claims. -export const HOST_EVENTS = ["executor-ready", "artifact-retrieved", "enclave-launched", "executor-finished"] as const; +export const HOST_EVENTS = [ + "executor-ready", + "artifact-retrieved", + "enclave-launched", + "output-received", + "executor-finished", +] as const; // Control-plane producers: registry-service, execution-service, and result-consumer. export const INTERNAL_EVENTS = [