diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 09a6bd21..38b23011 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,7 @@ jobs: ts_lint: ${{ steps.ts_lint.outputs.changes }} ts_typecheck: ${{ steps.ts_typecheck.outputs.changes }} go: ${{ steps.go.outputs.changes }} + portal: ${{ steps.portal.outputs.changes }} python: ${{ steps.python.outputs.changes }} steps: - uses: actions/checkout@v5 @@ -64,6 +65,10 @@ jobs: - 'secure/cost-service/**' - 'packages/common/**' - '.github/workflows/ci.yml' + 'secure/kms-service': + - 'secure/kms-service/**' + - 'packages/common/**' + - '.github/workflows/ci.yml' 'secure/log-service': - 'secure/log-service/**' - 'packages/common/**' @@ -133,6 +138,10 @@ jobs: - 'secure/cost-service/**' - 'packages/common/**' - '.github/workflows/ci.yml' + 'secure/kms-service': + - 'secure/kms-service/**' + - 'packages/common/**' + - '.github/workflows/ci.yml' 'secure/log-service': - 'secure/log-service/**' - 'packages/common/**' @@ -171,6 +180,23 @@ jobs: - 'secure/sce-unit/**' - 'packages/go-common/**' - '.github/workflows/ci.yml' + 'secure/csav/registry-service': + - 'secure/csav/registry-service/**' + - 'packages/go-common/**' + - '.github/workflows/ci.yml' + 'rads/sce/execution-service/host-tools': + - 'rads/sce/execution-service/host-tools/**' + - '.github/workflows/ci.yml' + - id: portal + uses: dorny/paths-filter@v4 + with: + filters: | + 'rads/transparency-portal': + - 'rads/transparency-portal/**' + - '.github/workflows/ci.yml' + 'secure/transparency-portal': + - 'secure/transparency-portal/**' + - '.github/workflows/ci.yml' - id: python uses: dorny/paths-filter@v4 with: @@ -215,6 +241,24 @@ jobs: - run: bun run typecheck working-directory: ${{ matrix.package }} + build-portal: + needs: changes + if: needs.changes.outputs.portal != '[]' + runs-on: blacksmith-2vcpu-ubuntu-2404 + strategy: + fail-fast: false + matrix: + package: ${{ fromJSON(needs.changes.outputs.portal) }} + steps: + - uses: actions/checkout@v5 + - uses: oven-sh/setup-bun@v2 + with: + bun-version: 1.x + - run: bun install --frozen-lockfile + working-directory: ${{ matrix.package }} + - run: bun run build + working-directory: ${{ matrix.package }} + python: needs: changes if: needs.changes.outputs.python != '[]' @@ -239,8 +283,8 @@ jobs: - uses: actions/checkout@v5 - uses: actions/setup-go@v6 with: - go-version: "1.25" - cache-dependency-path: ${{ matrix.module }}/go.sum + go-version-file: ${{ matrix.module }}/go.mod + cache-dependency-path: ${{ matrix.module }}/go.* - run: test -z "$(gofmt -l .)" working-directory: ${{ matrix.module }} - run: go vet ./... diff --git a/.gitignore b/.gitignore index f0cc3f67..854a1368 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ __pycache__/ !/.aws/credentials.example !/.aws/config.example /.env +/.env.tmp !/.env.example /.ssh/* !/.ssh/README.md @@ -24,3 +25,9 @@ __pycache__/ .opencode/ secure/pdm-service/tls/ + +# CSV exports written by make logs-csv* and cost-csv* +/run-*.csv +/algo-*.csv +/logs-all.csv +/cost-*.csv diff --git a/Makefile b/Makefile index 23489222..48c5c18a 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,7 @@ benchmark-site-deploy: logs: @set -u; \ pids=""; \ - for target in registry-logs; do make $$target & pids="$$pids $$!"; done; \ + for target in registry-logs; do $(MAKE) $$target & pids="$$pids $$!"; done; \ for group in $$(aws logs describe-log-groups --region "$(REGION)" --log-group-name-prefix /aws/lambda/ --query 'logGroups[].logGroupName' --output text); do \ case "$$group" in /aws/lambda/secure-rads-execution-service-dev-*|/aws/lambda/secure-rads-verifier-service-dev-*|/aws/lambda/secure-rads-pdm-service-dev-*|/aws/lambda/secure-rads-kms-service-dev-*|/aws/lambda/secure-rads-log-service-dev-*|/aws/lambda/secure-rads-telemetry-service-dev-*|/aws/lambda/secure-rads-cost-service-dev-*|/aws/lambda/secure-rads-result-consumer-dev-*|/aws/lambda/rads-registry-service-dev-*|/aws/lambda/rads-pdm-service-dev-*|/aws/lambda/rads-log-service-dev-*|/aws/lambda/rads-telemetry-service-dev-*|/aws/lambda/rads-cost-service-dev-*|/aws/lambda/rads-result-consumer-dev-*|/aws/lambda/rads-execution-service-dev-*) aws logs tail "$$group" --region "$(REGION)" --follow & pids="$$pids $$!";; esac; \ done; \ diff --git a/README.md b/README.md index a30860fc..20b1e6f6 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,23 @@ instance. Use a dedicated research account. - [`docs/e2e-rads.txt`](docs/e2e-rads.txt), [`docs/e2e-secure-rads.txt`](docs/e2e-secure-rads.txt) - event-by-event plaintext flows for the build and execution phases. +## Known limitations + +These are accepted as PoC scope and not fixed here. + +- Registry `/upload` is open to anything allowed by the CSAV security group, with no authentication. + Rebuilding an existing `algorithmId` moves its KMS key policy to the new PCRs. +- Execution-service `POST /run` and `GET /run/{runId}` are unauthenticated and have no concurrency cap. +- Log-service subject-access read endpoints and the transparency portal authority view are public. +- Telemetry and cost ingest endpoints are unauthenticated. +- The parent host builds and sends enclave results to SQS without a signature. +- Record encryption uses AES-GCM without associated data (AAD). +- Each deploy re-derives TLS pins from the live endpoints (trust on first use). +- The deploy workflow can be dispatched from any branch, and its OIDC role is broad. +- Executor and enclave hosts have no maximum lifetime. +- Telemetry exports are unpaginated and bounded by the 6 MB Lambda response limit. +- rads DC containers run on the default Docker network. + ## Ongoing work This PoC is under active development until the paper is camera ready. Outstanding work identified diff --git a/benchmark/README.md b/benchmark/README.md index 02fbab64..9e566a7b 100644 --- a/benchmark/README.md +++ b/benchmark/README.md @@ -148,14 +148,14 @@ 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` | +| Result delivery | `compute-completed` → `result-persisted` | `dc-app-completed` → `result-persisted` | | Total | `run-requested` → `result-persisted` | `run-requested` → `result-persisted` | `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. +Result delivery starts when the DC app finishes in both trees, so secure-rads includes the vsock stream to the parent (`dc-app-completed` → `output-sent`). The phases do not cover `run-requested` → `executor-launched` (the `RunInstances` call), so they sum to roughly 1 s less than `total`. ## Layout diff --git a/benchmark/results/phase-timings.csv b/benchmark/results/phase-timings.csv index 2d60fb8f..7e90d89d 100644 --- a/benchmark/results/phase-timings.csv +++ b/benchmark/results/phase-timings.csv @@ -1,31 +1,31 @@ dataset_size,tree,run,status,ec2_cost_usd,dynamodb_cost_usd,s3_cost_usd,sqs_cost_usd,lambda_cost_usd,apigateway_cost_usd,total_cost_usd,host_provisioning_s,algorithm_retrieval_s,enclave_boot_s,sce_unit_s,attestation_s,data_retrieval_s,algorithm_processing_s,result_delivery_s,total_s,run-requested_ts,executor-launched_ts,enclave-launched_ts,executor-ready_ts,artifact-retrieved_ts,enclave-started_ts,unit-ready_ts,attested_ts,records-fetched_ts,records-decrypted_ts,records-stored-locally_ts,dc-app-completed_ts,compute-completed_ts,output-sent_ts,result-persisted_ts,executor-finished_ts 10000,rads,1,exit:0,0.00217067,0.00017684,0.00000088,0.00000120,0.00008493,0.00004773,0.00248224,76.46,4.00,,,,3.87,1.71,1.24,88.28,2026-11-16T02:10:36.940Z,2026-11-16T02:10:37.939Z,,2026-11-16T02:11:54.397142879Z,2026-11-16T02:11:58.401927774Z,,,,2026-11-16T02:12:02.197858598Z,,2026-11-16T02:12:02.27220242Z,,2026-11-16T02:12:03.979990382Z,,2026-11-16T02:12:05.224Z,2026-11-16T02:12:04.630150759Z -10000,secure-rads,1,exit:0,0.00246667,0.00028541,0.00000044,0.00000120,0.00011271,0.00005418,0.00292061,78.37,2.87,5.37,0.04,2.06,5.60,0.80,2.32,100.13,2026-11-16T02:10:36.845Z,2026-11-16T02:10:37.914Z,2026-11-16T02:12:04.606317041Z,2026-11-16T02:11:56.280899727Z,2026-11-16T02:11:59.149262100Z,2026-11-16T02:12:04.516624082Z,2026-11-16T02:12:04.561331757Z,2026-11-16T02:12:06.625278766Z,2026-11-16T02:12:10.96652776Z,2026-11-16T02:12:12.137797494Z,2026-11-16T02:12:12.229541026Z,2026-11-16T02:12:13.034317755Z,,2026-11-16T02:12:14.656063262Z,2026-11-16T02:12:16.977Z,2026-11-16T02:12:16.403498770Z +10000,secure-rads,1,exit:0,0.00246667,0.00028541,0.00000044,0.00000120,0.00011271,0.00005418,0.00292061,78.37,2.87,5.37,0.04,2.06,5.60,0.80,3.94,100.13,2026-11-16T02:10:36.845Z,2026-11-16T02:10:37.914Z,2026-11-16T02:12:04.606317041Z,2026-11-16T02:11:56.280899727Z,2026-11-16T02:11:59.149262100Z,2026-11-16T02:12:04.516624082Z,2026-11-16T02:12:04.561331757Z,2026-11-16T02:12:06.625278766Z,2026-11-16T02:12:10.96652776Z,2026-11-16T02:12:12.137797494Z,2026-11-16T02:12:12.229541026Z,2026-11-16T02:12:13.034317755Z,,2026-11-16T02:12:14.656063262Z,2026-11-16T02:12:16.977Z,2026-11-16T02:12:16.403498770Z 20000,rads,1,exit:0,0.00224467,0.00035126,0.00000088,0.00000120,0.00009532,0.00007482,0.00276814,77.27,4.06,,,,5.81,1.77,0.71,90.57,2026-11-16T02:12:20.490Z,2026-11-16T02:12:21.441Z,,2026-11-16T02:13:38.710368625Z,2026-11-16T02:13:42.769865583Z,,,,2026-11-16T02:13:48.479127982Z,,2026-11-16T02:13:48.583898894Z,,2026-11-16T02:13:50.352004508Z,,2026-11-16T02:13:51.059Z,2026-11-16T02:13:50.988610868Z -20000,secure-rads,1,exit:0,0.00249133,0.00054662,0.00000044,0.00000120,0.00009012,0.00007998,0.00320969,80.17,2.97,5.63,0.03,0.70,5.74,1.16,1.65,100.22,2026-11-16T02:12:19.808Z,2026-11-16T02:12:20.760Z,2026-11-16T02:13:49.428441867Z,2026-11-16T02:13:40.926450181Z,2026-11-16T02:13:43.892077753Z,2026-11-16T02:13:49.517630293Z,2026-11-16T02:13:49.549609993Z,2026-11-16T02:13:50.248531707Z,2026-11-16T02:13:55.125742941Z,2026-11-16T02:13:55.839381176Z,2026-11-16T02:13:55.984300421Z,2026-11-16T02:13:57.143308304Z,,2026-11-16T02:13:58.377585775Z,2026-11-16T02:14:00.030Z,2026-11-16T02:13:59.987268451Z +20000,secure-rads,1,exit:0,0.00249133,0.00054662,0.00000044,0.00000120,0.00009012,0.00007998,0.00320969,80.17,2.97,5.63,0.03,0.70,5.74,1.16,2.89,100.22,2026-11-16T02:12:19.808Z,2026-11-16T02:12:20.760Z,2026-11-16T02:13:49.428441867Z,2026-11-16T02:13:40.926450181Z,2026-11-16T02:13:43.892077753Z,2026-11-16T02:13:49.517630293Z,2026-11-16T02:13:49.549609993Z,2026-11-16T02:13:50.248531707Z,2026-11-16T02:13:55.125742941Z,2026-11-16T02:13:55.839381176Z,2026-11-16T02:13:55.984300421Z,2026-11-16T02:13:57.143308304Z,,2026-11-16T02:13:58.377585775Z,2026-11-16T02:14:00.030Z,2026-11-16T02:13:59.987268451Z 30000,rads,1,exit:0,0.00226933,0.00050722,0.00000088,0.00000120,0.00012567,0.00010062,0.00300493,75.76,3.87,,,,8.61,2.02,0.60,91.84,2026-11-16T02:14:02.379Z,2026-11-16T02:14:03.356Z,,2026-11-16T02:15:19.113722527Z,2026-11-16T02:15:22.98368341Z,,,,2026-11-16T02:15:31.459806257Z,,2026-11-16T02:15:31.593975516Z,,2026-11-16T02:15:33.618103655Z,,2026-11-16T02:15:34.215Z,2026-11-16T02:15:34.205260498Z -30000,secure-rads,1,exit:0,0.00254067,0.00080789,0.00000044,0.00000120,0.00011122,0.00010707,0.00356849,79.56,2.81,5.55,0.04,0.60,8.86,1.46,1.55,103.11,2026-11-16T02:14:01.607Z,2026-11-16T02:14:02.604Z,2026-11-16T02:15:30.411358232Z,2026-11-16T02:15:22.165110799Z,2026-11-16T02:15:24.971121038Z,2026-11-16T02:15:30.516553805Z,2026-11-16T02:15:30.557272721Z,2026-11-16T02:15:31.152475855Z,2026-11-16T02:15:38.465082433Z,2026-11-16T02:15:39.811437138Z,2026-11-16T02:15:40.016558631Z,2026-11-16T02:15:41.476320549Z,,2026-11-16T02:15:43.165682319Z,2026-11-16T02:15:44.714Z,2026-11-16T02:15:44.691586061Z +30000,secure-rads,1,exit:0,0.00254067,0.00080789,0.00000044,0.00000120,0.00011122,0.00010707,0.00356849,79.56,2.81,5.55,0.04,0.60,8.86,1.46,3.24,103.11,2026-11-16T02:14:01.607Z,2026-11-16T02:14:02.604Z,2026-11-16T02:15:30.411358232Z,2026-11-16T02:15:22.165110799Z,2026-11-16T02:15:24.971121038Z,2026-11-16T02:15:30.516553805Z,2026-11-16T02:15:30.557272721Z,2026-11-16T02:15:31.152475855Z,2026-11-16T02:15:38.465082433Z,2026-11-16T02:15:39.811437138Z,2026-11-16T02:15:40.016558631Z,2026-11-16T02:15:41.476320549Z,,2026-11-16T02:15:43.165682319Z,2026-11-16T02:15:44.714Z,2026-11-16T02:15:44.691586061Z 40000,rads,1,exit:0,0.00239267,0.00068157,0.00000088,0.00000120,0.00015095,0.00012771,0.00335497,77.60,3.84,,,,10.99,2.55,0.62,96.63,2026-11-16T02:15:49.700Z,2026-11-16T02:15:50.718Z,,2026-11-16T02:17:08.31905761Z,2026-11-16T02:17:12.162805302Z,,,,2026-11-16T02:17:22.998766525Z,,2026-11-16T02:17:23.15736044Z,,2026-11-16T02:17:25.705896377Z,,2026-11-16T02:17:26.328Z,2026-11-16T02:17:26.314253728Z -40000,secure-rads,1,exit:0,0.00256533,0.00108719,0.00000044,0.00000120,0.00012460,0.00013287,0.00391163,77.80,2.68,5.79,0.06,0.58,11.28,1.99,1.43,104.36,2026-11-16T02:15:49.328Z,2026-11-16T02:15:50.248Z,2026-11-16T02:17:16.290199110Z,2026-11-16T02:17:08.043578606Z,2026-11-16T02:17:10.723621805Z,2026-11-16T02:17:16.518223679Z,2026-11-16T02:17:16.573551359Z,2026-11-16T02:17:17.149047096Z,2026-11-16T02:17:27.24249152Z,2026-11-16T02:17:28.163861537Z,2026-11-16T02:17:28.42775048Z,2026-11-16T02:17:30.417482087Z,,2026-11-16T02:17:32.263818249Z,2026-11-16T02:17:33.691Z,2026-11-16T02:17:33.691618231Z +40000,secure-rads,1,exit:0,0.00256533,0.00108719,0.00000044,0.00000120,0.00012460,0.00013287,0.00391163,77.80,2.68,5.79,0.06,0.58,11.28,1.99,3.27,104.36,2026-11-16T02:15:49.328Z,2026-11-16T02:15:50.248Z,2026-11-16T02:17:16.290199110Z,2026-11-16T02:17:08.043578606Z,2026-11-16T02:17:10.723621805Z,2026-11-16T02:17:16.518223679Z,2026-11-16T02:17:16.573551359Z,2026-11-16T02:17:17.149047096Z,2026-11-16T02:17:27.24249152Z,2026-11-16T02:17:28.163861537Z,2026-11-16T02:17:28.42775048Z,2026-11-16T02:17:30.417482087Z,,2026-11-16T02:17:32.263818249Z,2026-11-16T02:17:33.691Z,2026-11-16T02:17:33.691618231Z 50000,rads,1,exit:0,0.00249133,0.00083761,0.00000088,0.00000120,0.00017383,0.00015480,0.00365965,78.06,3.99,,,,13.82,2.95,0.63,100.42,2026-11-16T02:17:37.514Z,2026-11-16T02:17:38.481Z,,2026-11-16T02:18:56.544318849Z,2026-11-16T02:19:00.532283205Z,,,,2026-11-16T02:19:14.167232238Z,,2026-11-16T02:19:14.354655249Z,,2026-11-16T02:19:17.308467234Z,,2026-11-16T02:19:17.934Z,2026-11-16T02:19:17.943401171Z -50000,secure-rads,1,exit:0,0.00263933,0.00134825,0.00000044,0.00000120,0.00014114,0.00015996,0.00429032,77.81,2.92,5.80,0.04,0.63,13.38,2.31,1.31,106.97,2026-11-16T02:17:37.018Z,2026-11-16T02:17:37.981Z,2026-11-16T02:19:04.200926569Z,2026-11-16T02:18:55.793461209Z,2026-11-16T02:18:58.712830720Z,2026-11-16T02:19:04.516283963Z,2026-11-16T02:19:04.55361353Z,2026-11-16T02:19:05.178878825Z,2026-11-16T02:19:17.215124461Z,2026-11-16T02:19:18.227797378Z,2026-11-16T02:19:18.556638707Z,2026-11-16T02:19:20.862028742Z,,2026-11-16T02:19:22.675156354Z,2026-11-16T02:19:23.988Z,2026-11-16T02:19:23.979694416Z +50000,secure-rads,1,exit:0,0.00263933,0.00134825,0.00000044,0.00000120,0.00014114,0.00015996,0.00429032,77.81,2.92,5.80,0.04,0.63,13.38,2.31,3.13,106.97,2026-11-16T02:17:37.018Z,2026-11-16T02:17:37.981Z,2026-11-16T02:19:04.200926569Z,2026-11-16T02:18:55.793461209Z,2026-11-16T02:18:58.712830720Z,2026-11-16T02:19:04.516283963Z,2026-11-16T02:19:04.55361353Z,2026-11-16T02:19:05.178878825Z,2026-11-16T02:19:17.215124461Z,2026-11-16T02:19:18.227797378Z,2026-11-16T02:19:18.556638707Z,2026-11-16T02:19:20.862028742Z,,2026-11-16T02:19:22.675156354Z,2026-11-16T02:19:23.988Z,2026-11-16T02:19:23.979694416Z 60000,rads,1,exit:0,0.00251600,0.00101203,0.00000088,0.00000120,0.00019928,0.00018060,0.00390999,77.17,3.96,,,,15.79,3.65,0.63,102.11,2026-11-16T02:19:30.026Z,2026-11-16T02:19:30.945Z,,2026-11-16T02:20:48.111105327Z,2026-11-16T02:20:52.068601264Z,,,,2026-11-16T02:21:07.64134785Z,,2026-11-16T02:21:07.854819612Z,,2026-11-16T02:21:11.506719551Z,,2026-11-16T02:21:12.139Z,2026-11-16T02:21:12.128044386Z -60000,secure-rads,1,exit:0,0.00271333,0.00160938,0.00000044,0.00000120,0.00016531,0.00018576,0.00467542,78.42,2.86,5.16,0.05,0.60,15.36,3.04,2.07,110.56,2026-11-16T02:19:29.159Z,2026-11-16T02:19:30.082Z,2026-11-16T02:20:56.888157145Z,2026-11-16T02:20:48.503753978Z,2026-11-16T02:20:51.360966479Z,2026-11-16T02:20:56.517953952Z,2026-11-16T02:20:56.568925718Z,2026-11-16T02:20:57.165171199Z,2026-11-16T02:21:10.98361638Z,2026-11-16T02:21:12.141850454Z,2026-11-16T02:21:12.524940226Z,2026-11-16T02:21:15.56056368Z,,2026-11-16T02:21:17.645257067Z,2026-11-16T02:21:19.716Z,2026-11-16T02:21:19.673962504Z +60000,secure-rads,1,exit:0,0.00271333,0.00160938,0.00000044,0.00000120,0.00016531,0.00018576,0.00467542,78.42,2.86,5.16,0.05,0.60,15.36,3.04,4.16,110.56,2026-11-16T02:19:29.159Z,2026-11-16T02:19:30.082Z,2026-11-16T02:20:56.888157145Z,2026-11-16T02:20:48.503753978Z,2026-11-16T02:20:51.360966479Z,2026-11-16T02:20:56.517953952Z,2026-11-16T02:20:56.568925718Z,2026-11-16T02:20:57.165171199Z,2026-11-16T02:21:10.98361638Z,2026-11-16T02:21:12.141850454Z,2026-11-16T02:21:12.524940226Z,2026-11-16T02:21:15.56056368Z,,2026-11-16T02:21:17.645257067Z,2026-11-16T02:21:19.716Z,2026-11-16T02:21:19.673962504Z 70000,rads,1,exit:0,0.00254067,0.00116800,0.00000088,0.00000120,0.00022011,0.00020640,0.00413725,76.28,3.70,,,,17.70,4.13,0.65,103.40,2026-11-16T02:21:22.321Z,2026-11-16T02:21:23.277Z,,2026-11-16T02:22:39.552222348Z,2026-11-16T02:22:43.249084687Z,,,,2026-11-16T02:23:00.707635223Z,,2026-11-16T02:23:00.949359104Z,,2026-11-16T02:23:05.078762957Z,,2026-11-16T02:23:05.726Z,2026-11-16T02:23:05.661867928Z -70000,secure-rads,1,exit:0,0.00278733,0.00187065,0.00000044,0.00000120,0.00018238,0.00021285,0.00505486,79.04,2.70,5.70,0.04,0.52,17.38,3.28,1.32,113.12,2026-11-16T02:21:22.104Z,2026-11-16T02:21:23.078Z,2026-11-16T02:22:50.101620624Z,2026-11-16T02:22:42.115992710Z,2026-11-16T02:22:44.816351829Z,2026-11-16T02:22:50.515118473Z,2026-11-16T02:22:50.558242338Z,2026-11-16T02:22:51.079734989Z,2026-11-16T02:23:06.862121526Z,2026-11-16T02:23:08.02406216Z,2026-11-16T02:23:08.458530598Z,2026-11-16T02:23:11.738681264Z,,2026-11-16T02:23:13.910173364Z,2026-11-16T02:23:15.226Z,2026-11-16T02:23:15.152206090Z +70000,secure-rads,1,exit:0,0.00278733,0.00187065,0.00000044,0.00000120,0.00018238,0.00021285,0.00505486,79.04,2.70,5.70,0.04,0.52,17.38,3.28,3.49,113.12,2026-11-16T02:21:22.104Z,2026-11-16T02:21:23.078Z,2026-11-16T02:22:50.101620624Z,2026-11-16T02:22:42.115992710Z,2026-11-16T02:22:44.816351829Z,2026-11-16T02:22:50.515118473Z,2026-11-16T02:22:50.558242338Z,2026-11-16T02:22:51.079734989Z,2026-11-16T02:23:06.862121526Z,2026-11-16T02:23:08.02406216Z,2026-11-16T02:23:08.458530598Z,2026-11-16T02:23:11.738681264Z,,2026-11-16T02:23:13.910173364Z,2026-11-16T02:23:15.226Z,2026-11-16T02:23:15.152206090Z 80000,rads,1,exit:0,0.00266400,0.00134242,0.00000088,0.00000120,0.00025053,0.00023349,0.00449251,77.55,4.02,,,,20.09,4.42,0.63,107.66,2026-11-16T02:23:20.558Z,2026-11-16T02:23:21.513Z,,2026-11-16T02:24:39.062988216Z,2026-11-16T02:24:43.081911134Z,,,,2026-11-16T02:25:02.926359062Z,,2026-11-16T02:25:03.168563579Z,,2026-11-16T02:25:07.584844587Z,,2026-11-16T02:25:08.215Z,2026-11-16T02:25:08.192713493Z -80000,secure-rads,1,exit:0,0.00288600,0.00215002,0.00000044,0.00000120,0.00019792,0.00023865,0.00547424,78.29,2.93,5.65,0.05,0.52,20.57,3.79,1.58,116.81,2026-11-16T02:23:19.646Z,2026-11-16T02:23:20.646Z,2026-11-16T02:24:47.390841100Z,2026-11-16T02:24:38.938973863Z,2026-11-16T02:24:41.871527744Z,2026-11-16T02:24:47.517777764Z,2026-11-16T02:24:47.571722248Z,2026-11-16T02:24:48.090075847Z,2026-11-16T02:25:07.081325747Z,2026-11-16T02:25:08.159694196Z,2026-11-16T02:25:08.659557293Z,2026-11-16T02:25:12.445649891Z,,2026-11-16T02:25:14.872084988Z,2026-11-16T02:25:16.451Z,2026-11-16T02:25:16.395565849Z +80000,secure-rads,1,exit:0,0.00288600,0.00215002,0.00000044,0.00000120,0.00019792,0.00023865,0.00547424,78.29,2.93,5.65,0.05,0.52,20.57,3.79,4.01,116.81,2026-11-16T02:23:19.646Z,2026-11-16T02:23:20.646Z,2026-11-16T02:24:47.390841100Z,2026-11-16T02:24:38.938973863Z,2026-11-16T02:24:41.871527744Z,2026-11-16T02:24:47.517777764Z,2026-11-16T02:24:47.571722248Z,2026-11-16T02:24:48.090075847Z,2026-11-16T02:25:07.081325747Z,2026-11-16T02:25:08.159694196Z,2026-11-16T02:25:08.659557293Z,2026-11-16T02:25:12.445649891Z,,2026-11-16T02:25:14.872084988Z,2026-11-16T02:25:16.451Z,2026-11-16T02:25:16.395565849Z 90000,rads,1,exit:0,0.00271333,0.00149845,0.00000088,0.00000120,0.00026609,0.00025929,0.00473925,77.37,4.03,,,,21.89,4.84,0.61,109.68,2026-11-16T02:25:19.757Z,2026-11-16T02:25:20.691Z,,2026-11-16T02:26:38.061747078Z,2026-11-16T02:26:42.090134942Z,,,,2026-11-16T02:27:03.69350784Z,,2026-11-16T02:27:03.983351687Z,,2026-11-16T02:27:08.827231252Z,,2026-11-16T02:27:09.439Z,2026-11-16T02:27:09.440087984Z -90000,secure-rads,1,exit:0,0.00303400,0.00241123,0.00000044,0.00000120,0.00021581,0.00026574,0.00592842,79.64,2.72,5.19,0.04,0.54,21.54,4.25,2.04,122.02,2026-11-16T02:25:18.946Z,2026-11-16T02:25:19.955Z,2026-11-16T02:26:47.861546494Z,2026-11-16T02:26:39.596701945Z,2026-11-16T02:26:42.321219399Z,2026-11-16T02:26:47.515849009Z,2026-11-16T02:26:47.555544549Z,2026-11-16T02:26:48.091903876Z,2026-11-16T02:27:07.790510476Z,2026-11-16T02:27:09.027782031Z,2026-11-16T02:27:09.632553156Z,2026-11-16T02:27:13.881304551Z,,2026-11-16T02:27:18.932151378Z,2026-11-16T02:27:20.971Z,2026-11-16T02:27:20.960308985Z +90000,secure-rads,1,exit:0,0.00303400,0.00241123,0.00000044,0.00000120,0.00021581,0.00026574,0.00592842,79.64,2.72,5.19,0.04,0.54,21.54,4.25,7.09,122.02,2026-11-16T02:25:18.946Z,2026-11-16T02:25:19.955Z,2026-11-16T02:26:47.861546494Z,2026-11-16T02:26:39.596701945Z,2026-11-16T02:26:42.321219399Z,2026-11-16T02:26:47.515849009Z,2026-11-16T02:26:47.555544549Z,2026-11-16T02:26:48.091903876Z,2026-11-16T02:27:07.790510476Z,2026-11-16T02:27:09.027782031Z,2026-11-16T02:27:09.632553156Z,2026-11-16T02:27:13.881304551Z,,2026-11-16T02:27:18.932151378Z,2026-11-16T02:27:20.971Z,2026-11-16T02:27:20.960308985Z 100000,rads,1,exit:0,0.00278733,0.00167287,0.00000088,0.00000120,0.00029720,0.00028638,0.00504587,76.82,3.98,,,,25.35,5.06,0.60,112.78,2026-11-16T02:27:24.624Z,2026-11-16T02:27:25.600Z,,2026-11-16T02:28:42.420278519Z,2026-11-16T02:28:46.39934352Z,,,,2026-11-16T02:29:11.446877892Z,,2026-11-16T02:29:11.751217917Z,,2026-11-16T02:29:16.8085016Z,,2026-11-16T02:29:17.409Z,2026-11-16T02:29:17.418863446Z -100000,secure-rads,1,exit:0,0.00303400,0.00267243,0.00000044,0.00000120,0.00023680,0.00029283,0.00623770,79.36,2.61,5.79,0.05,0.42,23.90,4.69,1.40,122.55,2026-11-16T02:27:23.694Z,2026-11-16T02:27:24.760Z,2026-11-16T02:28:52.267808893Z,2026-11-16T02:28:44.119321861Z,2026-11-16T02:28:46.727411404Z,2026-11-16T02:28:52.515561247Z,2026-11-16T02:28:52.561087269Z,2026-11-16T02:28:52.980370912Z,2026-11-16T02:29:14.809692438Z,2026-11-16T02:29:16.211668895Z,2026-11-16T02:29:16.883466531Z,2026-11-16T02:29:21.571258672Z,,2026-11-16T02:29:24.83533308Z,2026-11-16T02:29:26.240Z,2026-11-16T02:29:26.251125076Z +100000,secure-rads,1,exit:0,0.00303400,0.00267243,0.00000044,0.00000120,0.00023680,0.00029283,0.00623770,79.36,2.61,5.79,0.05,0.42,23.90,4.69,4.67,122.55,2026-11-16T02:27:23.694Z,2026-11-16T02:27:24.760Z,2026-11-16T02:28:52.267808893Z,2026-11-16T02:28:44.119321861Z,2026-11-16T02:28:46.727411404Z,2026-11-16T02:28:52.515561247Z,2026-11-16T02:28:52.561087269Z,2026-11-16T02:28:52.980370912Z,2026-11-16T02:29:14.809692438Z,2026-11-16T02:29:16.211668895Z,2026-11-16T02:29:16.883466531Z,2026-11-16T02:29:21.571258672Z,,2026-11-16T02:29:24.83533308Z,2026-11-16T02:29:26.240Z,2026-11-16T02:29:26.251125076Z 110000,rads,1,exit:0,0.00291067,0.00182891,0.00000088,0.00000120,0.00032180,0.00031347,0.00537693,78.00,4.19,,,,28.57,5.66,0.65,117.98,2026-11-16T02:29:33.555Z,2026-11-16T02:29:34.471Z,,2026-11-16T02:30:52.472977101Z,2026-11-16T02:30:56.660165017Z,,,,2026-11-16T02:31:24.868761914Z,,2026-11-16T02:31:25.22617044Z,,2026-11-16T02:31:30.891080024Z,,2026-11-16T02:31:31.538Z,2026-11-16T02:31:31.53386945Z -110000,secure-rads,1,exit:0,0.00313267,0.00293356,0.00000044,0.00000120,0.00026250,0.00031863,0.00664899,79.33,2.89,5.34,0.04,0.78,26.40,5.09,1.94,126.23,2026-11-16T02:29:32.936Z,2026-11-16T02:29:33.958Z,2026-11-16T02:31:01.788751121Z,2026-11-16T02:30:53.291624745Z,2026-11-16T02:30:56.180463001Z,2026-11-16T02:31:01.519300274Z,2026-11-16T02:31:01.56154473Z,2026-11-16T02:31:02.345049853Z,2026-11-16T02:31:26.548795933Z,2026-11-16T02:31:28.017660899Z,2026-11-16T02:31:28.749707167Z,2026-11-16T02:31:33.843092965Z,,2026-11-16T02:31:37.227757895Z,2026-11-16T02:31:39.167Z,2026-11-16T02:31:39.172755904Z +110000,secure-rads,1,exit:0,0.00313267,0.00293356,0.00000044,0.00000120,0.00026250,0.00031863,0.00664899,79.33,2.89,5.34,0.04,0.78,26.40,5.09,5.32,126.23,2026-11-16T02:29:32.936Z,2026-11-16T02:29:33.958Z,2026-11-16T02:31:01.788751121Z,2026-11-16T02:30:53.291624745Z,2026-11-16T02:30:56.180463001Z,2026-11-16T02:31:01.519300274Z,2026-11-16T02:31:01.56154473Z,2026-11-16T02:31:02.345049853Z,2026-11-16T02:31:26.548795933Z,2026-11-16T02:31:28.017660899Z,2026-11-16T02:31:28.749707167Z,2026-11-16T02:31:33.843092965Z,,2026-11-16T02:31:37.227757895Z,2026-11-16T02:31:39.167Z,2026-11-16T02:31:39.172755904Z 120000,rads,1,exit:0,0.00291067,0.00200326,0.00000088,0.00000120,0.00035031,0.00033927,0.00560558,76.61,3.95,,,,30.70,5.77,0.58,118.64,2026-11-16T02:31:44.971Z,2026-11-16T02:31:45.996Z,,2026-11-16T02:33:02.610647962Z,2026-11-16T02:33:06.564166858Z,,,,2026-11-16T02:33:36.891837632Z,,2026-11-16T02:33:37.26328106Z,,2026-11-16T02:33:43.033464874Z,,2026-11-16T02:33:43.612Z,2026-11-16T02:33:43.607088883Z -120000,secure-rads,1,exit:0,0.00323133,0.00321315,0.00000044,0.00000120,0.00028377,0.00034572,0.00707561,79.38,2.94,4.97,0.04,0.58,30.96,5.52,2.19,131.10,2026-11-16T02:31:44.251Z,2026-11-16T02:31:45.237Z,2026-11-16T02:33:13.016552015Z,2026-11-16T02:33:04.615528979Z,2026-11-16T02:33:07.554171161Z,2026-11-16T02:33:12.519189965Z,2026-11-16T02:33:12.555573325Z,2026-11-16T02:33:13.134151457Z,2026-11-16T02:33:41.561275271Z,2026-11-16T02:33:43.298067047Z,2026-11-16T02:33:44.095686073Z,2026-11-16T02:33:49.614763234Z,,2026-11-16T02:33:53.162659656Z,2026-11-16T02:33:55.351Z,2026-11-16T02:33:55.359206538Z +120000,secure-rads,1,exit:0,0.00323133,0.00321315,0.00000044,0.00000120,0.00028377,0.00034572,0.00707561,79.38,2.94,4.97,0.04,0.58,30.96,5.52,5.74,131.10,2026-11-16T02:31:44.251Z,2026-11-16T02:31:45.237Z,2026-11-16T02:33:13.016552015Z,2026-11-16T02:33:04.615528979Z,2026-11-16T02:33:07.554171161Z,2026-11-16T02:33:12.519189965Z,2026-11-16T02:33:12.555573325Z,2026-11-16T02:33:13.134151457Z,2026-11-16T02:33:41.561275271Z,2026-11-16T02:33:43.298067047Z,2026-11-16T02:33:44.095686073Z,2026-11-16T02:33:49.614763234Z,,2026-11-16T02:33:53.162659656Z,2026-11-16T02:33:55.351Z,2026-11-16T02:33:55.359206538Z 130000,rads,1,exit:0,0.00298467,0.00215923,0.00000088,0.00000120,0.00036300,0.00036507,0.00587404,76.10,3.89,,,,32.63,6.03,0.59,120.23,2026-11-16T02:34:02.717Z,2026-11-16T02:34:03.714Z,,2026-11-16T02:35:19.810175345Z,2026-11-16T02:35:23.696368856Z,,,,2026-11-16T02:35:55.948353111Z,,2026-11-16T02:35:56.329183687Z,,2026-11-16T02:36:02.358488838Z,,2026-11-16T02:36:02.952Z,2026-11-16T02:36:02.925117776Z -130000,secure-rads,1,exit:0,0.00330533,0.00347435,0.00000044,0.00000120,0.00029156,0.00037152,0.00744441,78.97,3.13,5.51,0.04,0.52,32.86,5.80,1.68,133.09,2026-11-16T02:34:01.924Z,2026-11-16T02:34:02.915Z,2026-11-16T02:35:30.543835199Z,2026-11-16T02:35:21.884297672Z,2026-11-16T02:35:25.014143420Z,2026-11-16T02:35:30.521559934Z,2026-11-16T02:35:30.558893751Z,2026-11-16T02:35:31.080583047Z,2026-11-16T02:36:00.931065456Z,2026-11-16T02:36:03.096106117Z,2026-11-16T02:36:03.942184196Z,2026-11-16T02:36:09.74708205Z,,2026-11-16T02:36:13.337216272Z,2026-11-16T02:36:15.014Z,2026-11-16T02:36:15.007614697Z +130000,secure-rads,1,exit:0,0.00330533,0.00347435,0.00000044,0.00000120,0.00029156,0.00037152,0.00744441,78.97,3.13,5.51,0.04,0.52,32.86,5.80,5.27,133.09,2026-11-16T02:34:01.924Z,2026-11-16T02:34:02.915Z,2026-11-16T02:35:30.543835199Z,2026-11-16T02:35:21.884297672Z,2026-11-16T02:35:25.014143420Z,2026-11-16T02:35:30.521559934Z,2026-11-16T02:35:30.558893751Z,2026-11-16T02:35:31.080583047Z,2026-11-16T02:36:00.931065456Z,2026-11-16T02:36:03.096106117Z,2026-11-16T02:36:03.942184196Z,2026-11-16T02:36:09.74708205Z,,2026-11-16T02:36:13.337216272Z,2026-11-16T02:36:15.014Z,2026-11-16T02:36:15.007614697Z 140000,rads,1,exit:0,0.00308333,0.00233350,0.00000088,0.00000120,0.00038908,0.00039216,0.00620016,77.96,4.00,,,,34.29,7.02,0.65,124.95,2026-11-16T02:36:20.130Z,2026-11-16T02:36:21.168Z,,2026-11-16T02:37:39.123138879Z,2026-11-16T02:37:43.120588093Z,,,,2026-11-16T02:38:16.95523965Z,,2026-11-16T02:38:17.41100309Z,,2026-11-16T02:38:24.429912941Z,,2026-11-16T02:38:25.079Z,2026-11-16T02:38:25.093415938Z -140000,secure-rads,1,exit:0,0.00340400,0.00373541,0.00000044,0.00000120,0.00031584,0.00039861,0.00785550,80.58,2.87,5.70,0.04,0.47,35.72,6.30,1.58,138.08,2026-11-16T02:36:19.399Z,2026-11-16T02:36:20.369Z,2026-11-16T02:37:49.382634836Z,2026-11-16T02:37:40.944272911Z,2026-11-16T02:37:43.815787533Z,2026-11-16T02:37:49.518159491Z,2026-11-16T02:37:49.561227158Z,2026-11-16T02:37:50.029732216Z,2026-11-16T02:38:22.808323585Z,2026-11-16T02:38:24.834932451Z,2026-11-16T02:38:25.750922325Z,2026-11-16T02:38:32.04919658Z,,2026-11-16T02:38:35.900330663Z,2026-11-16T02:38:37.480Z,2026-11-16T02:38:37.478596622Z +140000,secure-rads,1,exit:0,0.00340400,0.00373541,0.00000044,0.00000120,0.00031584,0.00039861,0.00785550,80.58,2.87,5.70,0.04,0.47,35.72,6.30,5.43,138.08,2026-11-16T02:36:19.399Z,2026-11-16T02:36:20.369Z,2026-11-16T02:37:49.382634836Z,2026-11-16T02:37:40.944272911Z,2026-11-16T02:37:43.815787533Z,2026-11-16T02:37:49.518159491Z,2026-11-16T02:37:49.561227158Z,2026-11-16T02:37:50.029732216Z,2026-11-16T02:38:22.808323585Z,2026-11-16T02:38:24.834932451Z,2026-11-16T02:38:25.750922325Z,2026-11-16T02:38:32.04919658Z,,2026-11-16T02:38:35.900330663Z,2026-11-16T02:38:37.480Z,2026-11-16T02:38:37.478596622Z 150000,rads,1,exit:0,0.00310800,0.00248391,0.00000088,0.00000120,0.00041374,0.00041796,0.00642569,76.10,4.05,,,,37.85,6.96,0.60,126.55,2026-11-16T02:38:43.109Z,2026-11-16T02:38:44.091Z,,2026-11-16T02:40:00.194155151Z,2026-11-16T02:40:04.241045501Z,,,,2026-11-16T02:40:41.632657196Z,,2026-11-16T02:40:42.091696412Z,,2026-11-16T02:40:49.056082259Z,,2026-11-16T02:40:49.658Z,2026-11-16T02:40:49.669937963Z -150000,secure-rads,1,exit:0,0.00342867,0.00399298,0.00000044,0.00000120,0.00033380,0.00042441,0.00818149,79.75,3.03,5.73,0.05,0.78,37.06,6.66,1.45,139.45,2026-11-16T02:38:42.991Z,2026-11-16T02:38:44.002Z,2026-11-16T02:40:12.265501643Z,2026-11-16T02:40:03.752482688Z,2026-11-16T02:40:06.786060320Z,2026-11-16T02:40:12.517689214Z,2026-11-16T02:40:12.563220004Z,2026-11-16T02:40:13.34715158Z,2026-11-16T02:40:47.525176694Z,2026-11-16T02:40:49.419751772Z,2026-11-16T02:40:50.402271877Z,2026-11-16T02:40:57.063747519Z,,2026-11-16T02:41:00.998855599Z,2026-11-16T02:41:02.445Z,2026-11-16T02:41:02.450126795Z +150000,secure-rads,1,exit:0,0.00342867,0.00399298,0.00000044,0.00000120,0.00033380,0.00042441,0.00818149,79.75,3.03,5.73,0.05,0.78,37.06,6.66,5.38,139.45,2026-11-16T02:38:42.991Z,2026-11-16T02:38:44.002Z,2026-11-16T02:40:12.265501643Z,2026-11-16T02:40:03.752482688Z,2026-11-16T02:40:06.786060320Z,2026-11-16T02:40:12.517689214Z,2026-11-16T02:40:12.563220004Z,2026-11-16T02:40:13.34715158Z,2026-11-16T02:40:47.525176694Z,2026-11-16T02:40:49.419751772Z,2026-11-16T02:40:50.402271877Z,2026-11-16T02:40:57.063747519Z,,2026-11-16T02:41:00.998855599Z,2026-11-16T02:41:02.445Z,2026-11-16T02:41:02.450126795Z diff --git a/benchmark/src/export.py b/benchmark/src/export.py index be472dd7..0ca3d6f1 100644 --- a/benchmark/src/export.py +++ b/benchmark/src/export.py @@ -27,7 +27,7 @@ "attestation": ("unit-ready", "attested"), "data_retrieval": ("attested", "records-stored-locally"), "algorithm_processing": ("records-stored-locally", "dc-app-completed"), - "result_delivery": ("output-sent", "result-persisted"), + "result_delivery": ("dc-app-completed", "result-persisted"), "total": ("run-requested", "result-persisted"), }, "rads": { @@ -127,7 +127,7 @@ def window_seconds(by_event: dict[str, str], window: Window) -> str: def main() -> int: runs = load_runs() if not runs: - logger.error("no sweep rows in {}; run `make execute` first", RAW_DIR) + logger.error("no sweep rows in {}; run `make run` first", RAW_DIR) return 1 try: diff --git a/benchmark/src/grafana_load.py b/benchmark/src/grafana_load.py index 9f1732ad..f24bd65c 100644 --- a/benchmark/src/grafana_load.py +++ b/benchmark/src/grafana_load.py @@ -11,7 +11,8 @@ from paths import PHASE_TIMINGS_CSV -DSN = os.environ.get("BENCH_DB_DSN", "postgresql://bench:bench@127.0.0.1:5432/bench") +DB_PORT = os.environ.get("BENCH_DB_PORT", "5432") +DSN = os.environ.get("BENCH_DB_DSN", f"postgresql://bench:bench@127.0.0.1:{DB_PORT}/bench") INTEGER_COLUMNS = frozenset({"dataset_size", "run"}) TEXT_COLUMNS = frozenset({"tree", "status"}) diff --git a/docs/cost-service.md b/docs/cost-service.md index 166b302e..b421dccb 100644 --- a/docs/cost-service.md +++ b/docs/cost-service.md @@ -50,8 +50,11 @@ rads (`csav/registry-service`, Lambdas): ### Execution phase (both trees) - execution-service `POST /run`: `apigateway:request`, `lambda:invocation`, `lambda:compute`, - `dynamodb:read-capacity` (algorithm lookup and record-count check; actual `ConsumedCapacity.CapacityUnits`). + `dynamodb:read-capacity` (algorithm lookup; actual `ConsumedCapacity.CapacityUnits`). It also stamps the launch epoch into the host user-data. +- pdm-service `GET /count` (only when `POST /run` sets `size`; mTLS host in secure-rads, public PDM URL in rads): + `apigateway:request`, `lambda:invocation`, `lambda:compute`, `dynamodb:read-capacity` (each `Select: COUNT` + `Query` page, stopping once `size` is reached). Keyed by the run through the `x-run-id` header. - execution-service `GET /run/{runId}?algorithmId={algorithmId}` (each poll): `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), diff --git a/docs/deploy.md b/docs/deploy.md index 8184bf49..b2adb9fb 100644 --- a/docs/deploy.md +++ b/docs/deploy.md @@ -77,13 +77,15 @@ so this is close to account admin. Run it in a dedicated account and treat it as ## Repository variables Non-secret configuration. Values left blank fall back to the root `.env` defaults, and regional -certificates are looked up by hostname in ACM. +certificates are looked up by hostname in ACM. `scripts/deploy.sh` then runs `scripts/derive-env.sh`, +which overwrites the AMIs, portal certificates, TLS pins, and `VERIFIER_JWKS_PUBKEY_SHA256` whenever +AWS returns a value, so variables set for those keys only apply when the lookup finds nothing. | Variable | Purpose | | --- | --- | | `AWS_REGION`, `AVAILABILITY_ZONE` | target region and AZ | | `AWS_DEPLOY_ROLE_ARN` | role assumed through OIDC | -| `RADS_EXECUTOR_AMI_ID`, `SCE_ENCLAVE_AMI_ID` | arm64 AL2023 AMIs; derived from SSM when blank | +| `RADS_EXECUTOR_AMI_ID`, `SCE_ENCLAVE_AMI_ID` | arm64 AL2023 AMIs; overwritten from SSM on every run | | `CERT_ARN_RADS`, `CERT_ARN_SECURE_RADS` | us-east-1 certificates for the two portals | | `TRANSPARENCY_DOMAIN_RADS`, `TRANSPARENCY_DOMAIN_SECURE_RADS` | portal hostnames | | `LOG_HOST_RADS`, `LOG_HOST_SECURE_RADS` | log-service hostnames | diff --git a/docs/e2e-rads.txt b/docs/e2e-rads.txt index 31d633df..d232d708 100644 --- a/docs/e2e-rads.txt +++ b/docs/e2e-rads.txt @@ -21,15 +21,18 @@ Input: a ← algorithm id n ← dataset size (# of records) 1 runId ← NEW-ID() -2 emit run-requested -3 cost dynamodb:read-capacity // execution-service: algorithm lookup -4 key ← LOOKUP-S3(a) // S3 location of algorithm's TAR -5 RUN-COUNT-CHECK(n) -6 cost dynamodb:read-capacity // execution-service Query on the PDM table -7 RunInstances(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) -10 return runId +2 cost dynamodb:read-capacity // execution-service: algorithm lookup +3 key ← LOOKUP-S3(a) // S3 location of algorithm's TAR +4 if a is unknown: return 404 // no run-requested event +5 available ← PDM-COUNT(a, n) // pdm-service /count over the public PDM URL, only when n is set +6 cost dynamodb:read-capacity + apigateway:request + lambda // emitted by pdm-service count handler +7 if n > available: return 400 // a count failure skips the check; the executor caps at n anyway +8 emit run-requested +9 RunInstances(userdata ← ⟨a, runId, n, key, launchEpoch⟩) +10 emit executor-launched +11 cost apigateway:request + lambda // per control-plane request/poll (GET /run/{runId}?algorithmId=... too) +12 return runId +13 // on any error after step 1: emit launch-failed, return 500 RADS-EXECUTOR(a, runId, n, key) @@ -53,12 +56,13 @@ Input: 13 write records to records.json 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 +16 if result.json is non-empty: POST subject IDs to log-service /subject-access // DSAR trail, best-effort +17 emit compute-completed +18 publish result to SQS +19 cost sqs:send // message bytes +20 emit executor-finished +21 cost ec2:instance // captured before the cost POST and terminate request +22 terminate instance RADS-RESULT-CONSUMER(result) diff --git a/docs/e2e-secure-rads.txt b/docs/e2e-secure-rads.txt index 75253731..7498a2fa 100644 --- a/docs/e2e-secure-rads.txt +++ b/docs/e2e-secure-rads.txt @@ -27,15 +27,18 @@ Input: a ← algorithm id n ← dataset size (# of records) 1 runId ← NEW-ID() -2 emit run-requested -3 cost dynamodb:read-capacity // execution-service: algorithm lookup -4 key ← LOOKUP-EIF(a) // S3 location of algorithm's EIF -5 RUN-COUNT-CHECK(n) -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) -10 return runId +2 cost dynamodb:read-capacity // execution-service: algorithm lookup +3 key ← LOOKUP-EIF(a) // S3 location of algorithm's EIF +4 if a is unknown: return 404 // no run-requested event +5 available ← PDM-COUNT(a, n) // pdm-service /count over mTLS (pdm-mtls host), only when n is set +6 cost dynamodb:read-capacity + apigateway:request + lambda // emitted by pdm-service count handler +7 if n > available: return 400 // a count failure skips the check; the executor caps at n anyway +8 emit run-requested +9 RunInstances(Nitro parent, userdata ← ⟨a, runId, n, key, launchEpoch⟩) +10 emit executor-launched +11 cost apigateway:request + lambda // per control-plane request/poll (GET /run/{runId}?algorithmId=... too) +12 return runId +13 // on any error after step 1: emit launch-failed, return 500 SECURE-RADS-EXECUTOR(a, runId, n, key) @@ -87,9 +90,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 on success: POST subject IDs to log-service /subject-access // DSAR trail, bearer token from attestation +24 STREAM output to parent // vsock :5000 +25 emit output-sent +26 // on failure: emit run-failed diff --git a/docs/getting-started.md b/docs/getting-started.md index db98dea0..3471be9f 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -67,7 +67,7 @@ cp .env.example .env chmod 600 .env ``` -Fill in `CLOUDFLARE_EMAIL`, `CLOUDFLARE_API_TOKEN`, and optionally `CLOUDFLARE_ZONE` if it is not `secure-rads.org`. Every Makefile and `scripts/*.sh` loads that file itself, from any subdirectory, and stops with a clear message when it is missing. `devbox shell` also exports it on entry, so an existing shell only needs re-sourcing after you edit the file. +Fill in `CLOUDFLARE_EMAIL`, `CLOUDFLARE_API_TOKEN`, and optionally `CLOUDFLARE_ZONE` if it is not `secure-rads.org`. Every Makefile, `scripts/env.sh`, and `scripts/derive-env.sh` load that file themselves, from any subdirectory, and stop with a clear message when it is missing. `scripts/deploy.sh` is the exception: with no `.env` it creates one from `.env.example`, taking any value already set in the environment. `devbox shell` also exports it on entry, so an existing shell only needs re-sourcing after you edit the file. Values the deployment needs, all read from that file: @@ -84,7 +84,7 @@ Values the deployment needs, all read from that file: | `VERIFIER_JWKS_URL`, `VERIFIER_JWKS_PUBKEY_SHA256` | Verifier key location and pin used by the PDM, KMS, and log services. | | `CLOUDFLARE_ZONE`, `CLOUDFLARE_EMAIL`, `CLOUDFLARE_API_TOKEN` | Cloudflare zone and credentials for the DNS helper. | -Commands stop with the variable name when a required value is missing. `make env`, or `scripts/derive-env.sh` directly, fills the values that can be discovered from AWS: both AMIs from SSM, issued certificates from ACM, the TLS pins from the live endpoints, and the verifier key pin from a deployed PDM service. It only reads from AWS and patches those keys in `.env`. +Commands stop with the variable name when a required value is missing. `make env`, or `scripts/derive-env.sh` directly, writes the values that can be discovered from AWS: both AMIs from SSM, issued certificates from ACM, the TLS pins from the live endpoints, and the verifier key pin from a deployed PDM service. It overwrites those keys on every run whenever AWS returns a value, so hand-set AMIs and pins do not survive it; a key is left alone only when the lookup returns nothing. It only reads from AWS. `scripts/deploy.sh` runs it on every deploy. The DNS helper creates DNS-only CNAME records: @@ -117,10 +117,17 @@ Before deployment, prepare the selected region with: - `verifier.sr.secure-rads.org` - `verifier-attest.sr.secure-rads.org` - `pdm.sr.secure-rads.org` + - `pdm-mtls.sr.secure-rads.org` - `kms.sr.secure-rads.org` - `log.sr.secure-rads.org` - - `cost.r.secure-rads.org` + - `telemetry.sr.secure-rads.org` - `cost.sr.secure-rads.org` + - `log.r.secure-rads.org` + - `telemetry.r.secure-rads.org` + - `cost.r.secure-rads.org` + - `pdm.r.secure-rads.org` + - `registry.r.secure-rads.org` + - `execution.r.secure-rads.org` - DNS-only CNAME records in Cloudflare pointing each name to its API Gateway regional domain output after its service is created. The verifier uses mTLS, and secure-rads pins the verifier, PDM, KMS, and log API Gateway certificates; cost-service uses plain TLS and is not pinned. Create the verifier signing key before deploying the verifier service: @@ -128,7 +135,7 @@ Create the verifier signing key before deploying the verifier service: ```sh openssl genpkey -algorithm ML-DSA-87 -out jwt-signing-key.pem aws ssm put-parameter \ - --name /verifier-service/jwt-signing-key \ + --name /secure-rads/verifier-service/jwt-signing-key \ --type SecureString \ --value file://jwt-signing-key.pem rm jwt-signing-key.pem @@ -158,6 +165,8 @@ export KMS_CERT_ARN= export LOG_CERT_ARN= export TELEMETRY_CERT_ARN= export SECURE_COST_CERT_ARN= +export RADS_LOG_CERT_ARN= +export RADS_TELEMETRY_CERT_ARN= export RADS_COST_CERT_ARN= ``` @@ -265,10 +274,10 @@ For the baseline tree, deploy its log, telemetry, and cost services with the `*. ```sh (cd rads/log-service && bun install && bunx serverless deploy \ --param="region=$REGION" \ - --param="domainName=log.r.secure-rads.org" --param="certificateArn=$LOG_CERT_ARN") + --param="domainName=log.r.secure-rads.org" --param="certificateArn=$RADS_LOG_CERT_ARN") (cd rads/telemetry-service && bun install && bunx serverless deploy \ --param="region=$REGION" \ - --param="domainName=telemetry.r.secure-rads.org" --param="certificateArn=$TELEMETRY_CERT_ARN") + --param="domainName=telemetry.r.secure-rads.org" --param="certificateArn=$RADS_TELEMETRY_CERT_ARN") (cd rads/cost-service && bun install && bunx serverless deploy \ --param="region=$REGION" \ --param="domainName=cost.r.secure-rads.org" \ @@ -322,15 +331,12 @@ make -C secure/csav/registry-service ship remote-up REGION="$REGION" \ VERIFIER_HOST_PUBKEY_SHA256="$VERIFIER_ATTEST_PIN" \ PDM_HOST=pdm.sr.secure-rads.org PDM_HOST_PUBKEY_SHA256="$PDM_PIN" \ LOG_HOST=log.sr.secure-rads.org LOG_HOST_PUBKEY_SHA256="$LOG_PIN" \ + TELEMETRY_HOST=telemetry.sr.secure-rads.org TELEMETRY_HOST_PUBKEY_SHA256="$TELEMETRY_PIN" \ KMS_HOST=kms.sr.secure-rads.org KMS_HOST_PUBKEY_SHA256="$KMS_PIN" \ COST_HOST=cost.sr.secure-rads.org ``` -Each algorithm's key policy names the stable kms-service execution role, not the per-deployment enclave-host role. Rebuild and reseed any algorithm built before this change so its policy names kms-service. Once `make secure-rads-run` succeeds through the Lambda API, remove the legacy persistent execution-service EC2 stack: - -```sh -aws cloudformation delete-stack --stack-name execution-service --region "$REGION" -``` +Each algorithm's key policy names the stable kms-service execution role, not the per-deployment enclave-host role. Rebuild and reseed any algorithm built before this change so its policy names kms-service. ## Credential hygiene diff --git a/docs/running.md b/docs/running.md index a73567f0..e4137e4d 100644 --- a/docs/running.md +++ b/docs/running.md @@ -62,6 +62,38 @@ make registry-logs # tail the CSAV registry service make sce-logs # tail the execution-service Lambda make portal-dev # run the secure transparency portal locally make portal-deploy # deploy the secure transparency portal +make csav-key # create the csav-key EC2 key pair into .ssh/csav-key.pem +make csav-deploy # deploy the secure-rads-csav CloudFormation stack +make csav-up # start the CSAV instance +make csav-down # stop the CSAV instance +make csav-status # show the CSAV stack outputs +make csav-ssh # SSH into the CSAV instance +make csav-destroy # delete the CSAV stack +make sce-destroy # remove the secure-rads execution-service stack +``` + +rads targets (no CSAV host; registry and execution are Lambdas, the PDM holds plaintext): + +```sh +make rads # alias for rads-all +make rads-all # build, seed, and run all five samples +make rads-build-all # build and register all samples +make rads-seed # generate and seed all datasets as plaintext +make rads-run-all # run all samples +make rads-status # show the rads stack outputs +make rads-portal-install # install the rads transparency portal deps +make rads-portal-dev # run the rads transparency portal locally +make rads-portal-infra # deploy its S3 bucket and CloudFront distribution +make rads-portal-deploy # build, upload, and invalidate the rads portal +make rads-portal-status # show its bucket, distribution, and domain +``` + +Single rads app (APP is a rads/samples/ dir). `rads-build` presigns an S3 PUT through `/upload`, +uploads the tarball, then calls `/register`: + +```sh +make rads-build APP=health-risk-python ALGORITHM_ID=662fa378-dc53-425d-9225-a187b11ea7dc +make rads-run ALGORITHM_ID=662fa378-dc53-425d-9225-a187b11ea7dc ``` Single app (APP is a secure/samples/ dir, ALGORITHM_ID its fixed id): diff --git a/packages/common/bun.lock b/packages/common/bun.lock index e8593d4e..2453a9c2 100644 --- a/packages/common/bun.lock +++ b/packages/common/bun.lock @@ -5,6 +5,7 @@ "": { "name": "@srads/common", "dependencies": { + "csv-stringify": "^6.8.3", "jose": "^6.2.10", }, "devDependencies": { @@ -35,6 +36,8 @@ "@types/node": ["@types/node@22.20.5", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-U2+DNr+wSjpsTS/wZGYHq7GcwfuSmKiKvoPvK22zwTlRhU91yOniN4qRR5KhIjvif7ysw/dz/hKmfDH0Ris4aA=="], + "csv-stringify": ["csv-stringify@6.9.0", "", {}, "sha512-6b3e29CILFfSQ2nDRuZMRROzQOpPuJ+s8zPB5H7eK5ncXBbFOyVuRLU5Sx/zAUmVri3Ly49GyC8NEme4SVSAbA=="], + "jose": ["jose@6.2.17", "", {}, "sha512-wOuK9V1yujQFH5S0ZWmLcDZN7+IKh9bUCC2ZPCf2HDlol3WWHy+PPyNjEI75FXRLMp3vDKQcupP59xhVU95hcg=="], "typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="], diff --git a/packages/common/package.json b/packages/common/package.json index 556e362a..28ca37f3 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -19,6 +19,26 @@ "./jwt": { "types": "./src/jwt.ts", "import": "./src/jwt.ts" + }, + "./csv": { + "types": "./src/csv.ts", + "import": "./src/csv.ts" + }, + "./cursor": { + "types": "./src/cursor.ts", + "import": "./src/cursor.ts" + }, + "./dynamo": { + "types": "./src/dynamo.ts", + "import": "./src/dynamo.ts" + }, + "./http": { + "types": "./src/http.ts", + "import": "./src/http.ts" + }, + "./ids": { + "types": "./src/ids.ts", + "import": "./src/ids.ts" } }, "scripts": { @@ -32,6 +52,7 @@ "typescript": "^5.7.0" }, "dependencies": { + "csv-stringify": "^6.8.3", "jose": "^6.2.10" } } diff --git a/packages/common/src/csv.ts b/packages/common/src/csv.ts new file mode 100644 index 00000000..b7ea5ce6 --- /dev/null +++ b/packages/common/src/csv.ts @@ -0,0 +1,9 @@ +import { stringify } from "csv-stringify/sync"; + +// detail is an object; flatten it to compact JSON so csv-stringify emits one cell, not [object Object]. +export function toCsv(rows: T[], columns: readonly (keyof T & string)[]): string { + return stringify( + rows.map((row) => ({ ...row, detail: row.detail == null ? "" : JSON.stringify(row.detail) })), + { header: true, columns: [...columns] }, + ); +} diff --git a/rads/cost-service/src/lib/cursor.ts b/packages/common/src/cursor.ts similarity index 79% rename from rads/cost-service/src/lib/cursor.ts rename to packages/common/src/cursor.ts index d9965fcf..0717213d 100644 --- a/rads/cost-service/src/lib/cursor.ts +++ b/packages/common/src/cursor.ts @@ -1,15 +1,13 @@ -export const PAGE_SIZE = 1000; +export function encodeCursor(key: Record): string { + return Buffer.from(JSON.stringify(key)).toString("base64url"); +} export function decodeCursor(cursor: string): Record | undefined { try { const parsed: unknown = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8")); - if (typeof parsed !== "object" || parsed === null) return undefined; + if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return undefined; return parsed as Record; } catch { return undefined; } } - -export function encodeCursor(key: Record): string { - return Buffer.from(JSON.stringify(key)).toString("base64url"); -} diff --git a/packages/common/src/dynamo.ts b/packages/common/src/dynamo.ts new file mode 100644 index 00000000..2f848496 --- /dev/null +++ b/packages/common/src/dynamo.ts @@ -0,0 +1,30 @@ +import { setTimeout as sleep } from "node:timers/promises"; + +const MAX_THROTTLE_ATTEMPTS = 8; +const BACKOFF_BASE_MS = 50; +const BACKOFF_JITTER_MS = 100; + +function hasErrorName(error: unknown, name: string): boolean { + return error instanceof Error && error.name === name; +} + +export async function withThrottleRetry(operation: () => Promise): Promise { + for (let attempt = 1; ; attempt++) { + try { + return await operation(); + } catch (error) { + if (!hasErrorName(error, "ThrottlingException") || attempt >= MAX_THROTTLE_ATTEMPTS) throw error; + await sleep(BACKOFF_BASE_MS * 2 ** attempt + Math.random() * BACKOFF_JITTER_MS); + } + } +} + +// Resolves undefined when the target table does not exist, so callers can answer 404 instead of 500. +export async function ifTableExists(operation: Promise): Promise { + try { + return await operation; + } catch (error) { + if (hasErrorName(error, "ResourceNotFoundException")) return undefined; + throw error; + } +} diff --git a/packages/common/src/http.ts b/packages/common/src/http.ts new file mode 100644 index 00000000..f83c85d6 --- /dev/null +++ b/packages/common/src/http.ts @@ -0,0 +1,3 @@ +export function jsonResponse(statusCode: number, body: unknown) { + return { statusCode, headers: { "content-type": "application/json" }, body: JSON.stringify(body) }; +} diff --git a/packages/common/src/ids.ts b/packages/common/src/ids.ts new file mode 100644 index 00000000..2ae58cbe --- /dev/null +++ b/packages/common/src/ids.ts @@ -0,0 +1,5 @@ +const ALGORITHM_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; + +export function isAlgorithmId(value: string): boolean { + return ALGORITHM_ID.test(value); +} diff --git a/packages/common/src/jwt.ts b/packages/common/src/jwt.ts index f68b861e..0faaa6c9 100644 --- a/packages/common/src/jwt.ts +++ b/packages/common/src/jwt.ts @@ -56,6 +56,10 @@ export function buildVerifierJwksVerifier( return parsed as JsonWebKeySet; })(); jwksCache = fetched; + // A cached rejection would 401 every request for the life of a warm instance; drop it so the next call refetches. + fetched.catch(() => { + if (jwksCache === fetched) jwksCache = undefined; + }); return fetched; } diff --git a/rads/cost-service/README.md b/rads/cost-service/README.md index 81acb1b0..c67dcc5a 100644 --- a/rads/cost-service/README.md +++ b/rads/cost-service/README.md @@ -7,7 +7,7 @@ The table stores **one row per AWS operation**, not per run. Callers (the benchm ## Endpoints - `POST /cost` - a producer posts one event `{algorithmId, runId, eventId, phase, service, operation, quantity, timestamp, detail?}`. `eventId` is a producer-generated UUID; it is part of the sort key so an SQS redelivery overwrites the row instead of double-counting. The handler validates, enqueues, and returns `202` without waiting for DynamoDB. -- `GET /cost/{algorithmId}` - one algorithm's cost rows. `?runId=` narrows to a run; the JSON response also carries `totalUsd` plus `priceRegion`/`priceAsOf` provenance. +- `GET /cost/{algorithmId}` - one algorithm's cost rows. `?runId=` narrows to a run; the JSON response also carries `totalUsd` (the sum over the returned page only, not the whole history; page with `nextCursor` and sum client-side for a full total) plus `priceRegion`/`priceAsOf` provenance. - `GET /cost` - the whole table. Both GET routes page via `?cursor=` (the previous response's `nextCursor`) and return at most one page, so a large history cannot overflow the 10 MB API Gateway response cap. They take `?format=csv` (`text/csv`) or default to JSON; on CSV the next-page token rides the `x-next-cursor` response header. CSV columns: `algorithmId,runId,phase,service,operation,quantity,unit,costUsd,timestamp,receivedAt,detail`. diff --git a/rads/cost-service/bun.lock b/rads/cost-service/bun.lock index 3606fedb..a7c8e200 100644 --- a/rads/cost-service/bun.lock +++ b/rads/cost-service/bun.lock @@ -9,7 +9,6 @@ "@aws-sdk/client-sqs": "^3.1121.0", "@aws-sdk/lib-dynamodb": "^3.700.0", "@srads/common": "file:../../packages/common", - "csv-stringify": "^6.8.3", }, "devDependencies": { "@biomejs/biome": "^2.5.10", @@ -184,7 +183,7 @@ "@smithy/types": ["@smithy/types@4.19.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-r7jh49VJxGerfAcTQA6gXcKc+98zOp/tqRwzYjgOE+iSQsP6cEU1hq2QzbuipmP68QtYdY9wKEhiCQZIzHgZ4Q=="], - "@srads/common": ["@srads/common@file:../../packages/common", { "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], + "@srads/common": ["@srads/common@file:../../packages/common", { "dependencies": { "csv-stringify": "^6.8.3", "jose": "^6.2.10" }, "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], "@tybys/wasm-util": ["@tybys/wasm-util@0.10.4", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-W3c4gRigFS0T/Ma4qIYF3GDAc5AQdHb1yL5znJT1Zv1YaD9Kitx656wBjvr19qbiosmZT8lWDM5BEMynUqX65A=="], @@ -206,6 +205,8 @@ "jiti": ["jiti@2.7.0", "", { "bin": { "jiti": "lib/jiti-cli.mjs" } }, "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ=="], + "jose": ["jose@6.2.17", "", {}, "sha512-wOuK9V1yujQFH5S0ZWmLcDZN7+IKh9bUCC2ZPCf2HDlol3WWHy+PPyNjEI75FXRLMp3vDKQcupP59xhVU95hcg=="], + "knip": ["knip@6.40.0", "", { "dependencies": { "fdir": "^6.5.0", "formatly": "^0.7.0", "get-tsconfig": "4.14.3", "jiti": "^2.7.0", "oxc-parser": "^0.150.0", "oxc-resolver": "11.24.2", "picomatch": "^4.0.7", "smol-toml": "^1.8.0", "strip-json-comments": "5.0.3", "tinyglobby": "^0.2.17", "unbash": "^4.0.11", "yaml": "^2.9.1", "zod": "^4.4.3" }, "bin": { "knip": "bin/knip.js", "knip-bun": "bin/knip-bun.js" } }, "sha512-5Lp/ANJu3AkW5f+J+2QG14z7xKZGi/ybb5MU1EWjeGdt6MpuIaLpLFiyBi0ZKryTiuTHiJqo/WKJRaWYimvavw=="], "mnemonist": ["mnemonist@0.38.3", "", { "dependencies": { "obliterator": "^1.6.1" } }, "sha512-2K9QYubXx/NAjv4VLq1d1Ly8pWNC5L3BrixtdkyTegXWJIqY+zLNDhhX/A+ZwWt70tB1S8H4BE8FLYEFyNoOBw=="], diff --git a/rads/cost-service/package.json b/rads/cost-service/package.json index 27bd8123..069ddd52 100644 --- a/rads/cost-service/package.json +++ b/rads/cost-service/package.json @@ -23,7 +23,6 @@ "@aws-sdk/client-dynamodb": "^3.700.0", "@aws-sdk/client-sqs": "^3.1121.0", "@aws-sdk/lib-dynamodb": "^3.700.0", - "@srads/common": "file:../../packages/common", - "csv-stringify": "^6.8.3" + "@srads/common": "file:../../packages/common" } } diff --git a/rads/cost-service/src/handlers/all.ts b/rads/cost-service/src/handlers/all.ts index 17d7e14d..4a558c11 100644 --- a/rads/cost-service/src/handlers/all.ts +++ b/rads/cost-service/src/handlers/all.ts @@ -1,29 +1,16 @@ import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient, ScanCommand } from "@aws-sdk/lib-dynamodb"; +import { toCsv } from "@srads/common/csv"; +import { decodeCursor, encodeCursor } from "@srads/common/cursor"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; -import { type CostRow, csvHeaders, toCsv } from "../lib/csv.js"; -import { decodeCursor, encodeCursor, PAGE_SIZE } from "../lib/cursor.js"; +import { COST_COLUMNS, csvHeaders, toRow } from "../lib/csv.js"; +import { PAGE_SIZE } from "../lib/paging.js"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); const table = requiredEnv("COST_TABLE"); -function toRow(item: Record): CostRow { - return { - algorithmId: item.AlgorithmId as string, - runId: item.RunId as string, - phase: item.Phase as string, - service: item.Service as string, - operation: item.Operation as string, - quantity: item.Quantity as number, - unit: item.Unit as string, - costUsd: item.CostUsd as number, - timestamp: item.Timestamp as string, - receivedAt: item.ReceivedAt as string, - detail: item.Detail ?? null, - }; -} - // Cursor paging keeps full-table exports below API Gateway's response-size limit. export const handler: APIGatewayProxyHandlerV2 = async (event) => { const format = event.queryStringParameters?.format; @@ -33,11 +20,7 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => { if (cursor) { exclusiveStartKey = decodeCursor(cursor); if (!exclusiveStartKey) { - return { - statusCode: 400, - headers: { "content-type": "application/json" }, - body: JSON.stringify({ error: "invalid cursor" }), - }; + return jsonResponse(400, { error: "invalid cursor" }); } } @@ -48,11 +31,7 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => { const nextCursor = result.LastEvaluatedKey ? encodeCursor(result.LastEvaluatedKey) : null; if (format === "csv") { - return { statusCode: 200, headers: csvHeaders(nextCursor), body: toCsv(rows) }; + return { statusCode: 200, headers: csvHeaders(nextCursor), body: toCsv(rows, COST_COLUMNS) }; } - return { - statusCode: 200, - headers: { "content-type": "application/json" }, - body: JSON.stringify({ events: rows, nextCursor }), - }; + return jsonResponse(200, { events: rows, nextCursor }); }; diff --git a/rads/cost-service/src/handlers/byAlgorithm.ts b/rads/cost-service/src/handlers/byAlgorithm.ts index 7a308ffa..8cefdf88 100644 --- a/rads/cost-service/src/handlers/byAlgorithm.ts +++ b/rads/cost-service/src/handlers/byAlgorithm.ts @@ -1,39 +1,22 @@ import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient, QueryCommand } from "@aws-sdk/lib-dynamodb"; +import { toCsv } from "@srads/common/csv"; +import { decodeCursor, encodeCursor } from "@srads/common/cursor"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; -import { type CostRow, csvHeaders, toCsv } from "../lib/csv.js"; -import { decodeCursor, encodeCursor, PAGE_SIZE } from "../lib/cursor.js"; +import { COST_COLUMNS, csvHeaders, toRow } from "../lib/csv.js"; +import { PAGE_SIZE } from "../lib/paging.js"; import { PRICE_AS_OF, PRICE_REGION } from "../lib/prices.js"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); const table = requiredEnv("COST_TABLE"); -function toRow(item: Record): CostRow { - return { - algorithmId: item.AlgorithmId as string, - runId: item.RunId as string, - phase: item.Phase as string, - service: item.Service as string, - operation: item.Operation as string, - quantity: item.Quantity as number, - unit: item.Unit as string, - costUsd: item.CostUsd as number, - timestamp: item.Timestamp as string, - receivedAt: item.ReceivedAt as string, - detail: item.Detail ?? null, - }; -} - // Cursor paging keeps large algorithm histories below API Gateway's response-size limit. export const handler: APIGatewayProxyHandlerV2 = async (event) => { const algorithmId = event.pathParameters?.algorithmId; if (!algorithmId) { - return { - statusCode: 400, - headers: { "content-type": "application/json" }, - body: JSON.stringify({ error: "missing algorithmId" }), - }; + return jsonResponse(400, { error: "missing algorithmId" }); } const runId = event.queryStringParameters?.runId; const format = event.queryStringParameters?.format; @@ -43,11 +26,7 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => { if (cursor) { exclusiveStartKey = decodeCursor(cursor); if (!exclusiveStartKey) { - return { - statusCode: 400, - headers: { "content-type": "application/json" }, - body: JSON.stringify({ error: "invalid cursor" }), - }; + return jsonResponse(400, { error: "invalid cursor" }); } } @@ -64,21 +43,17 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => { const nextCursor = result.LastEvaluatedKey ? encodeCursor(result.LastEvaluatedKey) : null; if (format === "csv") { - return { statusCode: 200, headers: csvHeaders(nextCursor), body: toCsv(rows) }; + return { statusCode: 200, headers: csvHeaders(nextCursor), body: toCsv(rows, COST_COLUMNS) }; } const totalUsd = rows.reduce((sum, row) => sum + row.costUsd, 0); - return { - statusCode: 200, - headers: { "content-type": "application/json" }, - body: JSON.stringify({ - algorithmId, - runId: runId ?? null, - priceRegion: PRICE_REGION, - priceAsOf: PRICE_AS_OF, - totalUsd, - events: rows, - nextCursor, - }), - }; + return jsonResponse(200, { + algorithmId, + runId: runId ?? null, + priceRegion: PRICE_REGION, + priceAsOf: PRICE_AS_OF, + totalUsd, + events: rows, + nextCursor, + }); }; diff --git a/rads/cost-service/src/handlers/cost.ts b/rads/cost-service/src/handlers/cost.ts index e1198afb..fd1d96d8 100644 --- a/rads/cost-service/src/handlers/cost.ts +++ b/rads/cost-service/src/handlers/cost.ts @@ -1,15 +1,12 @@ import { SendMessageCommand, SQSClient } from "@aws-sdk/client-sqs"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; import { parseCostBody } from "../lib/ingest.js"; const sqs = new SQSClient({}); const queueUrl = requiredEnv("COST_QUEUE_URL"); -function jsonResponse(statusCode: number, body: unknown) { - return { statusCode, headers: { "content-type": "application/json" }, body: JSON.stringify(body) }; -} - export const handler: APIGatewayProxyHandlerV2 = async (event) => { let body: unknown; try { diff --git a/rads/cost-service/src/lib/csv.ts b/rads/cost-service/src/lib/csv.ts index 280da1f9..d44c0d1e 100644 --- a/rads/cost-service/src/lib/csv.ts +++ b/rads/cost-service/src/lib/csv.ts @@ -1,5 +1,3 @@ -import { stringify } from "csv-stringify/sync"; - export interface CostRow { algorithmId: string; runId: string; @@ -14,7 +12,7 @@ export interface CostRow { detail: unknown; } -const COLUMNS = [ +export const COST_COLUMNS = [ "algorithmId", "runId", "phase", @@ -26,17 +24,25 @@ const COLUMNS = [ "timestamp", "receivedAt", "detail", -]; +] as const satisfies readonly (keyof CostRow)[]; + +export function toRow(item: Record): CostRow { + return { + algorithmId: item.AlgorithmId as string, + runId: item.RunId as string, + phase: item.Phase as string, + service: item.Service as string, + operation: item.Operation as string, + quantity: item.Quantity as number, + unit: item.Unit as string, + costUsd: item.CostUsd as number, + timestamp: item.Timestamp as string, + receivedAt: item.ReceivedAt as string, + detail: item.Detail ?? null, + }; +} // CSV can't carry a cursor in the body, so the next-page token rides on a response header for clients that page. export function csvHeaders(nextCursor: string | null): Record { return nextCursor ? { "content-type": "text/csv", "x-next-cursor": nextCursor } : { "content-type": "text/csv" }; } - -export function toCsv(rows: CostRow[]): string { - // Serialize detail objects as JSON so csv-stringify emits one cell instead of [object Object]. - return stringify( - rows.map((row) => ({ ...row, detail: row.detail == null ? "" : JSON.stringify(row.detail) })), - { header: true, columns: COLUMNS }, - ); -} diff --git a/rads/cost-service/src/lib/paging.ts b/rads/cost-service/src/lib/paging.ts new file mode 100644 index 00000000..df69ad1d --- /dev/null +++ b/rads/cost-service/src/lib/paging.ts @@ -0,0 +1 @@ +export const PAGE_SIZE = 1000; diff --git a/rads/csav/registry-service/bun.lock b/rads/csav/registry-service/bun.lock index 24c1018a..cd3ccb5e 100644 --- a/rads/csav/registry-service/bun.lock +++ b/rads/csav/registry-service/bun.lock @@ -189,7 +189,7 @@ "@smithy/types": ["@smithy/types@4.18.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-CgB6HHWer/vrKps24ulRIbpcpb7K4xAU7SkZ7YHzBPlwHsvsrCJFEXK421s+cJzX+ZrqtA/TuU5w1HzI7k9N8A=="], - "@srads/common": ["@srads/common@file:../../../packages/common", { "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], + "@srads/common": ["@srads/common@file:../../../packages/common", { "dependencies": { "csv-stringify": "^6.8.3", "jose": "^6.2.10" }, "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], "@tybys/wasm-util": ["@tybys/wasm-util@0.10.3", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-F3fo1MYrRJYL3zER0OUOmkutjr1Vp23m7OsSgp7nq4SP6OqX6C/56XFIPAl5bt3zaBRjmW7SGz3u/6LwFpYcOg=="], @@ -199,6 +199,8 @@ "bowser": ["bowser@2.14.1", "", {}, "sha512-tzPjzCxygAKWFOJP011oxFHs57HzIhOEracIgAePE4pqB3LikALKnSzUyU4MGs9/iCEUuHlAJTjTc5M+u7YEGg=="], + "csv-stringify": ["csv-stringify@6.9.0", "", {}, "sha512-6b3e29CILFfSQ2nDRuZMRROzQOpPuJ+s8zPB5H7eK5ncXBbFOyVuRLU5Sx/zAUmVri3Ly49GyC8NEme4SVSAbA=="], + "fd-package-json": ["fd-package-json@2.0.0", "", { "dependencies": { "walk-up-path": "^4.0.0" } }, "sha512-jKmm9YtsNXN789RS/0mSzOC1NUq9mkVd65vbSSVsKdjGvYXBuE4oWe2QOEoFeRmJg+lPuZxpmrfFclNhoRMneQ=="], "fdir": ["fdir@6.5.0", "", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg=="], @@ -209,6 +211,8 @@ "jiti": ["jiti@2.7.0", "", { "bin": { "jiti": "lib/jiti-cli.mjs" } }, "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ=="], + "jose": ["jose@6.2.17", "", {}, "sha512-wOuK9V1yujQFH5S0ZWmLcDZN7+IKh9bUCC2ZPCf2HDlol3WWHy+PPyNjEI75FXRLMp3vDKQcupP59xhVU95hcg=="], + "knip": ["knip@6.35.1", "", { "dependencies": { "fdir": "^6.5.0", "formatly": "^0.7.0", "get-tsconfig": "4.14.3", "jiti": "^2.7.0", "oxc-parser": "^0.148.0", "oxc-resolver": "11.24.2", "picomatch": "^4.0.7", "smol-toml": "^1.8.0", "strip-json-comments": "5.0.3", "tinyglobby": "^0.2.17", "unbash": "^4.0.11", "yaml": "^2.9.0", "zod": "^4.4.3" }, "bin": { "knip": "bin/knip.js", "knip-bun": "bin/knip-bun.js" } }, "sha512-22wnEnv4do2fvoeJsxpFCG/MBxReNxoCVBccaCl7suUJsG+F0UvxI9ycxZ9YgtLHSSjrZl5tOas0JZ/R1vJ93g=="], "mnemonist": ["mnemonist@0.38.3", "", { "dependencies": { "obliterator": "^1.6.1" } }, "sha512-2K9QYubXx/NAjv4VLq1d1Ly8pWNC5L3BrixtdkyTegXWJIqY+zLNDhhX/A+ZwWt70tB1S8H4BE8FLYEFyNoOBw=="], diff --git a/rads/csav/registry-service/src/handlers/register.ts b/rads/csav/registry-service/src/handlers/register.ts index 288ea734..bc409cb5 100644 --- a/rads/csav/registry-service/src/handlers/register.ts +++ b/rads/csav/registry-service/src/handlers/register.ts @@ -3,10 +3,11 @@ import { HeadObjectCommand, NotFound, S3Client } from "@aws-sdk/client-s3"; import { DynamoDBDocumentClient, PutCommand } from "@aws-sdk/lib-dynamodb"; import { CostPhase, costEvent, recordRequest } from "@srads/common/cost"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import { emitEvent } from "@srads/common/log"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; import { RegistryEvent } from "../lib/events.js"; -import { jsonResponse, parseBody } from "../lib/http.js"; +import { parseBody } from "../lib/http.js"; import { algorithmRequestSchema } from "../lib/schema.js"; const s3 = new S3Client({}); diff --git a/rads/csav/registry-service/src/handlers/upload.ts b/rads/csav/registry-service/src/handlers/upload.ts index 336665bb..6de6a214 100644 --- a/rads/csav/registry-service/src/handlers/upload.ts +++ b/rads/csav/registry-service/src/handlers/upload.ts @@ -2,8 +2,9 @@ import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3"; import { getSignedUrl } from "@aws-sdk/s3-request-presigner"; import { CostPhase, recordRequest } from "@srads/common/cost"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; -import { jsonResponse, parseBody } from "../lib/http.js"; +import { parseBody } from "../lib/http.js"; import { algorithmRequestSchema } from "../lib/schema.js"; const s3 = new S3Client({}); diff --git a/rads/csav/registry-service/src/lib/events.ts b/rads/csav/registry-service/src/lib/events.ts index 40c4253f..839d8c12 100644 --- a/rads/csav/registry-service/src/lib/events.ts +++ b/rads/csav/registry-service/src/lib/events.ts @@ -1,4 +1,4 @@ -// Keep these build events in sync with log-service/src/lib/events.ts, which validates them at ingest. +// Keep these build events in sync with telemetry-service/src/lib/events.ts, which validates them at ingest. export const RegistryEvent = { ImageUploaded: "image-uploaded", AlgorithmRegistered: "algorithm-registered", diff --git a/rads/csav/registry-service/src/lib/http.ts b/rads/csav/registry-service/src/lib/http.ts index ae63d998..47fc5348 100644 --- a/rads/csav/registry-service/src/lib/http.ts +++ b/rads/csav/registry-service/src/lib/http.ts @@ -1,7 +1,3 @@ -export function jsonResponse(statusCode: number, body: unknown) { - return { statusCode, headers: { "content-type": "application/json" }, body: JSON.stringify(body) }; -} - export function parseBody(body: string | undefined): unknown { try { return JSON.parse(body ?? ""); diff --git a/rads/log-service/bun.lock b/rads/log-service/bun.lock index 401a7bdd..285fde28 100644 --- a/rads/log-service/bun.lock +++ b/rads/log-service/bun.lock @@ -6,10 +6,8 @@ "name": "rads-log-service", "dependencies": { "@aws-sdk/client-dynamodb": "^3.700.0", - "@aws-sdk/client-sqs": "^3.1121.0", "@aws-sdk/lib-dynamodb": "^3.700.0", "@srads/common": "file:../../packages/common", - "csv-stringify": "^6.8.3", "ts-retry": "^7.0.3", "zod": "^4.6.5", }, @@ -26,8 +24,6 @@ "packages": { "@aws-sdk/client-dynamodb": ["@aws-sdk/client-dynamodb@3.1128.0", "", { "dependencies": { "@aws-sdk/core": "^3.977.9", "@aws-sdk/credential-provider-node": "^3.972.82", "@aws-sdk/dynamodb-codec": "^3.973.44", "@aws-sdk/middleware-endpoint-discovery": "^3.972.30", "@aws-sdk/types": "^3.974.5", "@smithy/core": "^3.33.3", "@smithy/fetch-http-handler": "^5.7.2", "@smithy/node-http-handler": "^4.11.3", "@smithy/types": "^4.17.2", "tslib": "^2.6.2" } }, "sha512-l8cr5ydjj0H9jK8MtTL337CbI+s9azwgWl/MLlBkGQqsAJ6BT6v72APDiv7GFGJVI7JmNItdifjbTqve2HQnJA=="], - "@aws-sdk/client-sqs": ["@aws-sdk/client-sqs@3.1128.0", "", { "dependencies": { "@aws-sdk/core": "^3.977.9", "@aws-sdk/credential-provider-node": "^3.972.82", "@aws-sdk/middleware-sdk-sqs": "^3.972.42", "@aws-sdk/types": "^3.974.5", "@smithy/core": "^3.33.3", "@smithy/fetch-http-handler": "^5.7.2", "@smithy/node-http-handler": "^4.11.3", "@smithy/types": "^4.17.2", "tslib": "^2.6.2" } }, "sha512-KQNQJsw+D291Js/VgcFLl5vhUpB3HeZ49+kKDLcmApARPjbCcJxLspwgikeVt45f+VtYcR4oFgkD/tJeIE/FNg=="], - "@aws-sdk/core": ["@aws-sdk/core@3.977.9", "", { "dependencies": { "@aws-sdk/types": "^3.974.5", "@aws-sdk/xml-builder": "^3.972.40", "@aws/lambda-invoke-store": "^0.3.0", "@smithy/core": "^3.33.3", "@smithy/signature-v4": "^5.6.12", "@smithy/types": "^4.17.2", "bowser": "^2.11.0", "tslib": "^2.6.2" } }, "sha512-reqPFEQrZxDZpeGj4PFMepBeR5LGYHRqq/L0motTzgFkCRBA4rFdaVXDSLYyGHhxVz7sT2PDnPN9CluGSfgyJA=="], "@aws-sdk/credential-provider-env": ["@aws-sdk/credential-provider-env@3.972.70", "", { "dependencies": { "@aws-sdk/core": "^3.977.9", "@aws-sdk/types": "^3.974.5", "@smithy/core": "^3.33.3", "@smithy/types": "^4.17.2", "tslib": "^2.6.2" } }, "sha512-H404B7dJl2mCrBqahDEYsanB0xhdDp6tXnXcTUnXmmpy2Q3J0Ho0bUajZ2jr/RdwzCyS59Gi8xXIFwPLGBl6Uw=="], @@ -54,8 +50,6 @@ "@aws-sdk/middleware-endpoint-discovery": ["@aws-sdk/middleware-endpoint-discovery@3.972.30", "", { "dependencies": { "@aws-sdk/endpoint-cache": "^3.972.11", "@aws-sdk/types": "^3.974.5", "@smithy/core": "^3.33.3", "@smithy/types": "^4.17.2", "tslib": "^2.6.2" } }, "sha512-0hmD7/NG2NoVOVHvUb6rtY5POQYr+/9gdHvrYhIBA1zmCqKOBd5Gz3dL+iZ15FHOJbs/5kLplGoePc8PHTlzYA=="], - "@aws-sdk/middleware-sdk-sqs": ["@aws-sdk/middleware-sdk-sqs@3.972.42", "", { "dependencies": { "@aws-sdk/types": "^3.974.5", "@smithy/core": "^3.33.3", "@smithy/types": "^4.17.2", "tslib": "^2.6.2" } }, "sha512-D/O6iHAqlm0b430vIGewanSsr5RzaWbSDFlHYdKLWlZb4kaMKBmb44ReNHAFEKj5tNRY8pysw0qfciosB/VcJg=="], - "@aws-sdk/nested-clients": ["@aws-sdk/nested-clients@3.997.44", "", { "dependencies": { "@aws-sdk/core": "^3.977.9", "@aws-sdk/signature-v4-multi-region": "^3.996.46", "@aws-sdk/types": "^3.974.5", "@smithy/core": "^3.33.3", "@smithy/fetch-http-handler": "^5.7.2", "@smithy/node-http-handler": "^4.11.3", "@smithy/types": "^4.17.2", "tslib": "^2.6.2" } }, "sha512-NhEgryjlBF9w38ZXqGymQV28IhkYa1mKhlbYnqIis57AYwWGVYfUPgg/qC2rLRqOUfblxx++irvju10kVTa8Vw=="], "@aws-sdk/signature-v4-multi-region": ["@aws-sdk/signature-v4-multi-region@3.996.46", "", { "dependencies": { "@aws-sdk/types": "^3.974.5", "@smithy/signature-v4": "^5.6.12", "@smithy/types": "^4.17.2", "tslib": "^2.6.2" } }, "sha512-L+2xZTye/2T96f3lwCws0Zw6GG2JHZW9e8FpVgGBeeExSKyeoZ6CWRpBml/7DNiK/O26jrgPM9F+Ay8VkgzUWQ=="], @@ -186,7 +180,7 @@ "@smithy/types": ["@smithy/types@4.18.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-CgB6HHWer/vrKps24ulRIbpcpb7K4xAU7SkZ7YHzBPlwHsvsrCJFEXK421s+cJzX+ZrqtA/TuU5w1HzI7k9N8A=="], - "@srads/common": ["@srads/common@file:../../packages/common", { "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], + "@srads/common": ["@srads/common@file:../../packages/common", { "dependencies": { "csv-stringify": "^6.8.3", "jose": "^6.2.10" }, "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], "@tybys/wasm-util": ["@tybys/wasm-util@0.10.3", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-F3fo1MYrRJYL3zER0OUOmkutjr1Vp23m7OsSgp7nq4SP6OqX6C/56XFIPAl5bt3zaBRjmW7SGz3u/6LwFpYcOg=="], @@ -208,6 +202,8 @@ "jiti": ["jiti@2.7.0", "", { "bin": { "jiti": "lib/jiti-cli.mjs" } }, "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ=="], + "jose": ["jose@6.2.17", "", {}, "sha512-wOuK9V1yujQFH5S0ZWmLcDZN7+IKh9bUCC2ZPCf2HDlol3WWHy+PPyNjEI75FXRLMp3vDKQcupP59xhVU95hcg=="], + "knip": ["knip@6.35.1", "", { "dependencies": { "fdir": "^6.5.0", "formatly": "^0.7.0", "get-tsconfig": "4.14.3", "jiti": "^2.7.0", "oxc-parser": "^0.148.0", "oxc-resolver": "11.24.2", "picomatch": "^4.0.7", "smol-toml": "^1.8.0", "strip-json-comments": "5.0.3", "tinyglobby": "^0.2.17", "unbash": "^4.0.11", "yaml": "^2.9.0", "zod": "^4.4.3" }, "bin": { "knip": "bin/knip.js", "knip-bun": "bin/knip-bun.js" } }, "sha512-22wnEnv4do2fvoeJsxpFCG/MBxReNxoCVBccaCl7suUJsG+F0UvxI9ycxZ9YgtLHSSjrZl5tOas0JZ/R1vJ93g=="], "mnemonist": ["mnemonist@0.38.3", "", { "dependencies": { "obliterator": "^1.6.1" } }, "sha512-2K9QYubXx/NAjv4VLq1d1Ly8pWNC5L3BrixtdkyTegXWJIqY+zLNDhhX/A+ZwWt70tB1S8H4BE8FLYEFyNoOBw=="], diff --git a/rads/log-service/package.json b/rads/log-service/package.json index c38c4c4f..c4c34722 100644 --- a/rads/log-service/package.json +++ b/rads/log-service/package.json @@ -21,10 +21,8 @@ }, "dependencies": { "@aws-sdk/client-dynamodb": "^3.700.0", - "@aws-sdk/client-sqs": "^3.1121.0", "@aws-sdk/lib-dynamodb": "^3.700.0", "@srads/common": "file:../../packages/common", - "csv-stringify": "^6.8.3", "ts-retry": "^7.0.3", "zod": "^4.6.5" } diff --git a/rads/log-service/src/handlers/subjectAccessAll.ts b/rads/log-service/src/handlers/subjectAccessAll.ts index 54004848..83a29d52 100644 --- a/rads/log-service/src/handlers/subjectAccessAll.ts +++ b/rads/log-service/src/handlers/subjectAccessAll.ts @@ -1,6 +1,8 @@ import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb"; +import { decodeCursor } from "@srads/common/cursor"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; import { scanAccesses } from "../lib/subjectAccessRows.js"; @@ -9,19 +11,17 @@ const table = requiredEnv("SUBJECT_ACCESS_TABLE"); const DEFAULT_LIMIT = 500; const MAX_LIMIT = 1_000; -function jsonResponse(statusCode: number, body: unknown) { - return { statusCode, headers: { "content-type": "application/json" }, body: JSON.stringify(body) }; -} - // Service-authority view: one page of access events plus an opaque cursor for the next page. export const handler: APIGatewayProxyHandlerV2 = async (event) => { const parsed = Number(event.queryStringParameters?.limit ?? DEFAULT_LIMIT); const limit = Number.isInteger(parsed) && parsed > 0 ? Math.min(parsed, MAX_LIMIT) : DEFAULT_LIMIT; - try { - const { rows, nextCursor } = await scanAccesses(ddb, table, limit, event.queryStringParameters?.cursor); - return jsonResponse(200, { dataSubjectId: null, accesses: rows, nextCursor }); - } catch { + const cursor = event.queryStringParameters?.cursor; + const exclusiveStartKey = cursor ? decodeCursor(cursor) : undefined; + if (cursor && !exclusiveStartKey) { return jsonResponse(400, { error: "invalid cursor" }); } + + const { rows, nextCursor } = await scanAccesses(ddb, table, limit, exclusiveStartKey); + return jsonResponse(200, { dataSubjectId: null, accesses: rows, nextCursor }); }; diff --git a/rads/log-service/src/handlers/subjectAccessBySubject.ts b/rads/log-service/src/handlers/subjectAccessBySubject.ts index 6e8f252c..1c18cd39 100644 --- a/rads/log-service/src/handlers/subjectAccessBySubject.ts +++ b/rads/log-service/src/handlers/subjectAccessBySubject.ts @@ -1,16 +1,13 @@ import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; import { queryAccesses } from "../lib/subjectAccessRows.js"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); const table = requiredEnv("SUBJECT_ACCESS_TABLE"); -function jsonResponse(statusCode: number, body: unknown) { - return { statusCode, headers: { "content-type": "application/json" }, body: JSON.stringify(body) }; -} - // Data-subject view: a single subject's access trail, queried by their UUID (the PDM DSAR proxy relays here). export const handler: APIGatewayProxyHandlerV2 = async (event) => { const dataSubjectId = event.pathParameters?.dataSubjectId; diff --git a/rads/log-service/src/handlers/subjectAccessIngest.ts b/rads/log-service/src/handlers/subjectAccessIngest.ts index 00839c71..f532076a 100644 --- a/rads/log-service/src/handlers/subjectAccessIngest.ts +++ b/rads/log-service/src/handlers/subjectAccessIngest.ts @@ -1,6 +1,7 @@ import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { BatchWriteCommand, DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; import { retryAsync } from "ts-retry"; import { parseSubjectAccessBody, toItem } from "../lib/subjectAccess.js"; @@ -13,10 +14,6 @@ const table = requiredEnv("SUBJECT_ACCESS_TABLE"); const CHUNK = 25; const MAX_TRY = 4; -function jsonResponse(statusCode: number, body: unknown) { - return { statusCode, headers: { "content-type": "application/json" }, body: JSON.stringify(body) }; -} - function chunk(rows: T[], size: number): T[][] { const out: T[][] = []; for (let i = 0; i < rows.length; i += size) out.push(rows.slice(i, i + size)); diff --git a/rads/log-service/src/lib/subjectAccess.ts b/rads/log-service/src/lib/subjectAccess.ts index 8f0a578c..64e28c57 100644 --- a/rads/log-service/src/lib/subjectAccess.ts +++ b/rads/log-service/src/lib/subjectAccess.ts @@ -33,10 +33,9 @@ export function parseSubjectAccessBody(body: unknown): SubjectAccessIngest | { e return { ...result.data, receivedAt: new Date().toISOString() }; } -// The sort key is (timestamp, algorithmId, runId). That tuple is unique per item: a data subject's record -// lives on exactly one PDM page, so it is read once per run by exactly one algorithm. Dropping the old -// random nonce makes writes idempotent - a redelivered ingest overwrites an identical row instead of -// appending a duplicate. +// The sort key is (timestamp, algorithmId, runId), unique per item: a data subject's record lives on exactly one +// PDM page, so it is read once per run by exactly one algorithm. A chunk retried inside one ingest overwrites an +// identical row; a repeat ingest for the same run is rejected with 409 before any write. export function toItem(row: SubjectAccessRow): Record { return { DataSubjectId: row.dataSubjectId, diff --git a/rads/log-service/src/lib/subjectAccessRows.ts b/rads/log-service/src/lib/subjectAccessRows.ts index bafe0180..c921c89b 100644 --- a/rads/log-service/src/lib/subjectAccessRows.ts +++ b/rads/log-service/src/lib/subjectAccessRows.ts @@ -1,5 +1,6 @@ import type { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb"; import { paginateQuery, ScanCommand } from "@aws-sdk/lib-dynamodb"; +import { encodeCursor } from "@srads/common/cursor"; import { type SubjectAccessRow, toRow } from "./subjectAccess.js"; export async function queryAccesses( @@ -27,31 +28,19 @@ export interface AccessPage { nextCursor: string | null; } -function encodeCursor(key: Record): string { - return Buffer.from(JSON.stringify(key)).toString("base64url"); -} - -function decodeCursor(cursor: string): Record { - const parsed: unknown = JSON.parse(Buffer.from(cursor, "base64url").toString()); - if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) { - throw new Error("cursor must encode an object"); - } - return parsed as Record; -} - // The access table can hold tens of millions of rows, so a single Lambda cannot scan it. Return one page // and an opaque cursor for the next; the caller pages until nextCursor is null. export async function scanAccesses( ddb: DynamoDBDocumentClient, table: string, limit: number, - cursor?: string, + exclusiveStartKey?: Record, ): Promise { const result = await ddb.send( new ScanCommand({ TableName: table, Limit: limit, - ExclusiveStartKey: cursor ? decodeCursor(cursor) : undefined, + ExclusiveStartKey: exclusiveStartKey, }), ); return { diff --git a/rads/pdm-service/bun.lock b/rads/pdm-service/bun.lock index d6a34771..8d4ec0e4 100644 --- a/rads/pdm-service/bun.lock +++ b/rads/pdm-service/bun.lock @@ -178,7 +178,7 @@ "@smithy/types": ["@smithy/types@4.18.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-CgB6HHWer/vrKps24ulRIbpcpb7K4xAU7SkZ7YHzBPlwHsvsrCJFEXK421s+cJzX+ZrqtA/TuU5w1HzI7k9N8A=="], - "@srads/common": ["@srads/common@file:../../packages/common", { "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], + "@srads/common": ["@srads/common@file:../../packages/common", { "dependencies": { "csv-stringify": "^6.8.3", "jose": "^6.2.10" }, "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], "@tybys/wasm-util": ["@tybys/wasm-util@0.10.3", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-F3fo1MYrRJYL3zER0OUOmkutjr1Vp23m7OsSgp7nq4SP6OqX6C/56XFIPAl5bt3zaBRjmW7SGz3u/6LwFpYcOg=="], @@ -188,6 +188,8 @@ "bowser": ["bowser@2.14.1", "", {}, "sha512-tzPjzCxygAKWFOJP011oxFHs57HzIhOEracIgAePE4pqB3LikALKnSzUyU4MGs9/iCEUuHlAJTjTc5M+u7YEGg=="], + "csv-stringify": ["csv-stringify@6.9.0", "", {}, "sha512-6b3e29CILFfSQ2nDRuZMRROzQOpPuJ+s8zPB5H7eK5ncXBbFOyVuRLU5Sx/zAUmVri3Ly49GyC8NEme4SVSAbA=="], + "fd-package-json": ["fd-package-json@2.0.0", "", { "dependencies": { "walk-up-path": "^4.0.0" } }, "sha512-jKmm9YtsNXN789RS/0mSzOC1NUq9mkVd65vbSSVsKdjGvYXBuE4oWe2QOEoFeRmJg+lPuZxpmrfFclNhoRMneQ=="], "fdir": ["fdir@6.5.0", "", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg=="], @@ -198,6 +200,8 @@ "jiti": ["jiti@2.7.0", "", { "bin": { "jiti": "lib/jiti-cli.mjs" } }, "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ=="], + "jose": ["jose@6.2.17", "", {}, "sha512-wOuK9V1yujQFH5S0ZWmLcDZN7+IKh9bUCC2ZPCf2HDlol3WWHy+PPyNjEI75FXRLMp3vDKQcupP59xhVU95hcg=="], + "knip": ["knip@6.35.1", "", { "dependencies": { "fdir": "^6.5.0", "formatly": "^0.7.0", "get-tsconfig": "4.14.3", "jiti": "^2.7.0", "oxc-parser": "^0.148.0", "oxc-resolver": "11.24.2", "picomatch": "^4.0.7", "smol-toml": "^1.8.0", "strip-json-comments": "5.0.3", "tinyglobby": "^0.2.17", "unbash": "^4.0.11", "yaml": "^2.9.0", "zod": "^4.4.3" }, "bin": { "knip": "bin/knip.js", "knip-bun": "bin/knip-bun.js" } }, "sha512-22wnEnv4do2fvoeJsxpFCG/MBxReNxoCVBccaCl7suUJsG+F0UvxI9ycxZ9YgtLHSSjrZl5tOas0JZ/R1vJ93g=="], "mnemonist": ["mnemonist@0.38.3", "", { "dependencies": { "obliterator": "^1.6.1" } }, "sha512-2K9QYubXx/NAjv4VLq1d1Ly8pWNC5L3BrixtdkyTegXWJIqY+zLNDhhX/A+ZwWt70tB1S8H4BE8FLYEFyNoOBw=="], diff --git a/rads/pdm-service/src/handlers/count.ts b/rads/pdm-service/src/handlers/count.ts index 23205e10..8083e8ed 100644 --- a/rads/pdm-service/src/handlers/count.ts +++ b/rads/pdm-service/src/handlers/count.ts @@ -1,31 +1,38 @@ import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient, QueryCommand } from "@aws-sdk/lib-dynamodb"; import { CostPhase, costEvent, recordRequest } from "@srads/common/cost"; +import { ifTableExists, withThrottleRetry } from "@srads/common/dynamo"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; +import { isAlgorithmId } from "@srads/common/ids"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); const tablePrefix = requiredEnv("PDM_TABLE_PREFIX"); -const ALGORITHM_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; -const MAX_QUERY_ATTEMPTS = 8; - -async function queryWithRetry(command: QueryCommand) { - for (let attempt = 1; ; attempt++) { - try { - return await ddb.send(command); - } catch (error) { - if (!(error instanceof Error) || error.name !== "ThrottlingException" || attempt >= MAX_QUERY_ATTEMPTS) { - throw error; - } - const backoffMs = 50 * 2 ** attempt + Math.random() * 100; - await new Promise((resolve) => setTimeout(resolve, backoffMs)); - } - } -} - -function jsonResponse(statusCode: number, body: unknown) { - return { statusCode, headers: { "content-type": "application/json" }, body: JSON.stringify(body) }; +async function countRecords(algorithmId: string, atLeast: number | undefined) { + let count = 0; + let readCapacityUnits = 0; + let exclusiveStartKey: Record | undefined; + do { + const page = await withThrottleRetry(() => + ddb.send( + new QueryCommand({ + TableName: `${tablePrefix}-${algorithmId}`, + KeyConditionExpression: "AlgorithmId = :a", + ExpressionAttributeValues: { ":a": algorithmId }, + Select: "COUNT", + ExclusiveStartKey: exclusiveStartKey, + ReturnConsumedCapacity: "TOTAL", + }), + ), + ); + count += page.Count ?? 0; + readCapacityUnits += page.ConsumedCapacity?.CapacityUnits ?? 0; + if (atLeast !== undefined && count >= atLeast) break; + exclusiveStartKey = page.LastEvaluatedKey as Record | undefined; + } while (exclusiveStartKey); + return { count, readCapacityUnits }; } // Metadata-only count used by execution-service's size check. When `size` is set the count may stop early and @@ -36,7 +43,7 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => { if (!algorithmId) { return jsonResponse(400, { error: "missing algorithmId" }); } - if (!ALGORITHM_ID.test(algorithmId)) { + if (!isAlgorithmId(algorithmId)) { return jsonResponse(400, { error: "invalid algorithmId" }); } @@ -51,27 +58,12 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => { } const runId = event.headers["x-run-id"] ?? ""; - let count = 0; - let readCapacityUnits = 0; - let exclusiveStartKey: Record | undefined; - do { - const page = await queryWithRetry( - new QueryCommand({ - TableName: `${tablePrefix}-${algorithmId}`, - KeyConditionExpression: "AlgorithmId = :a", - ExpressionAttributeValues: { ":a": algorithmId }, - Select: "COUNT", - ExclusiveStartKey: exclusiveStartKey, - ReturnConsumedCapacity: "TOTAL", - }), - ); - count += page.Count ?? 0; - readCapacityUnits += page.ConsumedCapacity?.CapacityUnits ?? 0; - if (atLeast !== undefined && count >= atLeast) break; - exclusiveStartKey = page.LastEvaluatedKey as Record | undefined; - } while (exclusiveStartKey); + const counted = await ifTableExists(countRecords(algorithmId, atLeast)); + if (!counted) { + return jsonResponse(404, { error: "algorithm not found" }); + } - await costEvent(algorithmId, runId, CostPhase.Execution, "dynamodb", "read-capacity", readCapacityUnits); + await costEvent(algorithmId, runId, CostPhase.Execution, "dynamodb", "read-capacity", counted.readCapacityUnits); await recordRequest(algorithmId, runId, CostPhase.Execution, startedAt); - return jsonResponse(200, { algorithmId, count }); + return jsonResponse(200, { algorithmId, count: counted.count }); }; diff --git a/rads/pdm-service/src/handlers/records.ts b/rads/pdm-service/src/handlers/records.ts index 908ad252..bbe5a4ab 100644 --- a/rads/pdm-service/src/handlers/records.ts +++ b/rads/pdm-service/src/handlers/records.ts @@ -1,43 +1,17 @@ import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient, QueryCommand } from "@aws-sdk/lib-dynamodb"; import { CostPhase, costEvent, recordRequest } from "@srads/common/cost"; +import { decodeCursor, encodeCursor } from "@srads/common/cursor"; +import { ifTableExists, withThrottleRetry } from "@srads/common/dynamo"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; +import { isAlgorithmId } from "@srads/common/ids"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); const tablePrefix = requiredEnv("PDM_TABLE_PREFIX"); -const ALGORITHM_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; const PAGE_SIZE = 500; -const MAX_QUERY_ATTEMPTS = 8; - -async function queryWithRetry(command: QueryCommand) { - for (let attempt = 1; ; attempt++) { - try { - return await ddb.send(command); - } catch (error) { - if (!(error instanceof Error) || error.name !== "ThrottlingException" || attempt >= MAX_QUERY_ATTEMPTS) { - throw error; - } - const backoffMs = 50 * 2 ** attempt + Math.random() * 100; - await new Promise((resolve) => setTimeout(resolve, backoffMs)); - } - } -} - -function jsonResponse(statusCode: number, body: unknown) { - return { statusCode, headers: { "content-type": "application/json" }, body: JSON.stringify(body) }; -} - -function decodeCursor(cursor: string): Record | undefined { - try { - const parsed: unknown = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8")); - if (typeof parsed !== "object" || parsed === null) return undefined; - return parsed as Record; - } catch { - return undefined; - } -} export const handler: APIGatewayProxyHandlerV2 = async (event) => { const startedAt = process.hrtime.bigint(); @@ -45,7 +19,7 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => { if (!algorithmId) { return jsonResponse(400, { error: "missing algorithmId" }); } - if (!ALGORITHM_ID.test(algorithmId)) { + if (!isAlgorithmId(algorithmId)) { return jsonResponse(400, { error: "invalid algorithmId" }); } const runId = event.headers["x-run-id"] ?? ""; @@ -59,16 +33,23 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => { } } - const result = await queryWithRetry( - new QueryCommand({ - TableName: `${tablePrefix}-${algorithmId}`, - KeyConditionExpression: "AlgorithmId = :a", - ExpressionAttributeValues: { ":a": algorithmId }, - Limit: PAGE_SIZE, - ExclusiveStartKey: exclusiveStartKey, - ReturnConsumedCapacity: "TOTAL", - }), + const result = await ifTableExists( + withThrottleRetry(() => + ddb.send( + new QueryCommand({ + TableName: `${tablePrefix}-${algorithmId}`, + KeyConditionExpression: "AlgorithmId = :a", + ExpressionAttributeValues: { ":a": algorithmId }, + Limit: PAGE_SIZE, + ExclusiveStartKey: exclusiveStartKey, + ReturnConsumedCapacity: "TOTAL", + }), + ), + ), ); + if (!result) { + return jsonResponse(404, { error: "algorithm not found" }); + } await costEvent( algorithmId, runId, @@ -83,9 +64,7 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => { const items = result.Items ?? []; const records = items.map((item) => ({ recordId: item.RecordId, data: item.Data })); const dataSubjectIds = items.map((item) => (typeof item.DataSubjectId === "string" ? item.DataSubjectId : "")); - const nextCursor = result.LastEvaluatedKey - ? Buffer.from(JSON.stringify(result.LastEvaluatedKey)).toString("base64url") - : null; + const nextCursor = result.LastEvaluatedKey ? encodeCursor(result.LastEvaluatedKey) : null; await recordRequest(algorithmId, runId, CostPhase.Execution, startedAt); return jsonResponse(200, { algorithmId, records, dataSubjectIds, nextCursor }); diff --git a/rads/pdm-service/src/handlers/subject.ts b/rads/pdm-service/src/handlers/subject.ts index b1047885..6863875f 100644 --- a/rads/pdm-service/src/handlers/subject.ts +++ b/rads/pdm-service/src/handlers/subject.ts @@ -1,12 +1,9 @@ import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; const logHost = requiredEnv("LOG_HOST"); -function jsonResponse(statusCode: number, body: unknown) { - return { statusCode, headers: { "content-type": "application/json" }, body: JSON.stringify(body) }; -} - // Public DSAR lookup: the data subject presents only an opaque UUID, PDM relays the query to log-service. export const handler: APIGatewayProxyHandlerV2 = async (event) => { const dataSubjectId = event.pathParameters?.dataSubjectId; diff --git a/rads/result-consumer/bun.lock b/rads/result-consumer/bun.lock index 9ec70b29..e4667c88 100644 --- a/rads/result-consumer/bun.lock +++ b/rads/result-consumer/bun.lock @@ -178,7 +178,7 @@ "@smithy/types": ["@smithy/types@4.18.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-CgB6HHWer/vrKps24ulRIbpcpb7K4xAU7SkZ7YHzBPlwHsvsrCJFEXK421s+cJzX+ZrqtA/TuU5w1HzI7k9N8A=="], - "@srads/common": ["@srads/common@file:../../packages/common", { "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], + "@srads/common": ["@srads/common@file:../../packages/common", { "dependencies": { "csv-stringify": "^6.8.3", "jose": "^6.2.10" }, "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], "@tybys/wasm-util": ["@tybys/wasm-util@0.10.3", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-F3fo1MYrRJYL3zER0OUOmkutjr1Vp23m7OsSgp7nq4SP6OqX6C/56XFIPAl5bt3zaBRjmW7SGz3u/6LwFpYcOg=="], @@ -188,6 +188,8 @@ "bowser": ["bowser@2.14.1", "", {}, "sha512-tzPjzCxygAKWFOJP011oxFHs57HzIhOEracIgAePE4pqB3LikALKnSzUyU4MGs9/iCEUuHlAJTjTc5M+u7YEGg=="], + "csv-stringify": ["csv-stringify@6.9.0", "", {}, "sha512-6b3e29CILFfSQ2nDRuZMRROzQOpPuJ+s8zPB5H7eK5ncXBbFOyVuRLU5Sx/zAUmVri3Ly49GyC8NEme4SVSAbA=="], + "fd-package-json": ["fd-package-json@2.0.0", "", { "dependencies": { "walk-up-path": "^4.0.0" } }, "sha512-jKmm9YtsNXN789RS/0mSzOC1NUq9mkVd65vbSSVsKdjGvYXBuE4oWe2QOEoFeRmJg+lPuZxpmrfFclNhoRMneQ=="], "fdir": ["fdir@6.5.0", "", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg=="], @@ -198,6 +200,8 @@ "jiti": ["jiti@2.7.0", "", { "bin": { "jiti": "lib/jiti-cli.mjs" } }, "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ=="], + "jose": ["jose@6.2.17", "", {}, "sha512-wOuK9V1yujQFH5S0ZWmLcDZN7+IKh9bUCC2ZPCf2HDlol3WWHy+PPyNjEI75FXRLMp3vDKQcupP59xhVU95hcg=="], + "knip": ["knip@6.35.1", "", { "dependencies": { "fdir": "^6.5.0", "formatly": "^0.7.0", "get-tsconfig": "4.14.3", "jiti": "^2.7.0", "oxc-parser": "^0.148.0", "oxc-resolver": "11.24.2", "picomatch": "^4.0.7", "smol-toml": "^1.8.0", "strip-json-comments": "5.0.3", "tinyglobby": "^0.2.17", "unbash": "^4.0.11", "yaml": "^2.9.0", "zod": "^4.4.3" }, "bin": { "knip": "bin/knip.js", "knip-bun": "bin/knip-bun.js" } }, "sha512-22wnEnv4do2fvoeJsxpFCG/MBxReNxoCVBccaCl7suUJsG+F0UvxI9ycxZ9YgtLHSSjrZl5tOas0JZ/R1vJ93g=="], "mnemonist": ["mnemonist@0.38.3", "", { "dependencies": { "obliterator": "^1.6.1" } }, "sha512-2K9QYubXx/NAjv4VLq1d1Ly8pWNC5L3BrixtdkyTegXWJIqY+zLNDhhX/A+ZwWt70tB1S8H4BE8FLYEFyNoOBw=="], diff --git a/rads/result-consumer/src/handlers/consume.ts b/rads/result-consumer/src/handlers/consume.ts index 8be9253f..3b7c4986 100644 --- a/rads/result-consumer/src/handlers/consume.ts +++ b/rads/result-consumer/src/handlers/consume.ts @@ -32,17 +32,10 @@ function messageId(record: SQSRecord): { algorithmId: string; runId: string } | // Consumes executor run-result messages off RunResultsQueue and persists them to the RunResults table, // where execution-service's GET /run/{runId} reads them back. The batch's records are handled concurrently. async function persist(record: SQSRecord): Promise { - let message: RunResultMessage; - try { - message = JSON.parse(record.body) as RunResultMessage; - } catch { - // A malformed message shouldn't poison the batch and block good ones - skip it, let it age to the DLQ. - console.error("skipping message with unparsable body", record.messageId); - return; - } + // Malformed messages throw so SQS redelivers them up to maxReceiveCount, then moves them to the DLQ. + const message: RunResultMessage = JSON.parse(record.body); if (typeof message.runId !== "string") { - console.error("skipping message with missing/invalid runId", record.messageId); - return; + throw new Error(`run-result message ${record.messageId} has a missing or invalid runId`); } const item = { diff --git a/rads/samples/audience-segments-rust/Cargo.lock b/rads/samples/audience-segments-rust/Cargo.lock index e315eaee..6422c5e2 100644 --- a/rads/samples/audience-segments-rust/Cargo.lock +++ b/rads/samples/audience-segments-rust/Cargo.lock @@ -2,202 +2,12 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "adler2" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" - [[package]] name = "audience-segments" version = "0.1.0" dependencies = [ "serde", "serde_json", - "ureq", -] - -[[package]] -name = "base64" -version = "0.22.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" - -[[package]] -name = "cc" -version = "1.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "005ec2760ca554fae18df7a11195552ec576cd665632a881bc011d5bb2fd4d80" -dependencies = [ - "find-msvc-tools", - "shlex", -] - -[[package]] -name = "cfg-if" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" - -[[package]] -name = "crc32fast" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8498c871161e1742aaa9d52551b2d6ebdd4c3d45a3be423e3728f33b955be550" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "displaydoc" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" -dependencies = [ - "proc-macro2", - "quote", - "syn 3.0.5", -] - -[[package]] -name = "find-msvc-tools" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e0f1c7c3a72c66fd80abe965175f7523475c0489a87d3ff9d6e8c87d87a9d2d" - -[[package]] -name = "flate2" -version = "1.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e634e2e0ebac1ee034020da1ca582e17ffe4e0f5e985823721e168928136dcb" -dependencies = [ - "crc32fast", - "miniz_oxide", - "zlib-rs", -] - -[[package]] -name = "form_urlencoded" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "getrandom" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "icu_collections" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa68d21081c4a05d5a901a1c62add574c77048b6a1c67be3b50ce0b60d4ca513" -dependencies = [ - "displaydoc", - "potential_utf", - "utf8_iter", - "yoke", - "zerofrom", - "zerovec", -] - -[[package]] -name = "icu_locale_core" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d56e28588da92eee5c3201a6eff33fabdd49b62269c8938d4ff050ce4d900deb" -dependencies = [ - "displaydoc", - "litemap", - "tinystr", - "writeable", - "zerovec", -] - -[[package]] -name = "icu_normalizer" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12f9cf5f235641ed274641dd81c3f28d870e276763d0797aeeab72317b1c646f" -dependencies = [ - "icu_collections", - "icu_normalizer_data", - "icu_properties", - "icu_provider", - "smallvec", - "zerovec", -] - -[[package]] -name = "icu_normalizer_data" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1563da1ed3e0b3bf3d74c9b85917ac9c56464d2f57242270c09c9e752f8021a0" - -[[package]] -name = "icu_properties" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e7ca276ad3145661a65914e6daf131ca5120cd3dcee8f8f3214b8875184a148" -dependencies = [ - "displaydoc", - "icu_collections", - "icu_locale_core", - "icu_properties_data", - "icu_provider", - "zerotrie", - "zerovec", -] - -[[package]] -name = "icu_properties_data" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e590f038c1464a96894fd6d10127e90a8be4509f56ff7ecef851b15cee0b7caa" - -[[package]] -name = "icu_provider" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d27bbb9d3abbefac45d55f647c9de1d44aafcd1186eb91879afef17c396c3e73" -dependencies = [ - "displaydoc", - "icu_locale_core", - "writeable", - "yoke", - "zerofrom", - "zerotrie", - "zerovec", -] - -[[package]] -name = "idna" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" -dependencies = [ - "idna_adapter", - "smallvec", - "utf8_iter", -] - -[[package]] -name = "idna_adapter" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" -dependencies = [ - "icu_normalizer", - "icu_properties", ] [[package]] @@ -206,61 +16,12 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" -[[package]] -name = "libc" -version = "0.2.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" - -[[package]] -name = "litemap" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" - -[[package]] -name = "log" -version = "0.4.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" - [[package]] name = "memchr" version = "2.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" -[[package]] -name = "miniz_oxide" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c" -dependencies = [ - "adler2", - "simd-adler32", -] - -[[package]] -name = "once_cell" -version = "1.21.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" - -[[package]] -name = "percent-encoding" -version = "2.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" - -[[package]] -name = "potential_utf" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" -dependencies = [ - "zerovec", -] - [[package]] name = "proc-macro2" version = "1.0.107" @@ -279,55 +40,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "ring" -version = "0.17.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" -dependencies = [ - "cc", - "cfg-if", - "getrandom", - "libc", - "untrusted", - "windows-sys", -] - -[[package]] -name = "rustls" -version = "0.23.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6725596c3f2c3a0aef021139e145d4eafe314a6623e4680ca83852b2c67ab2ba" -dependencies = [ - "log", - "once_cell", - "ring", - "rustls-pki-types", - "rustls-webpki", - "subtle", - "zeroize", -] - -[[package]] -name = "rustls-pki-types" -version = "1.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96" -dependencies = [ - "zeroize", -] - -[[package]] -name = "rustls-webpki" -version = "0.103.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2" -dependencies = [ - "ring", - "rustls-pki-types", - "untrusted", -] - [[package]] name = "serde" version = "1.0.229" @@ -355,7 +67,7 @@ checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" dependencies = [ "proc-macro2", "quote", - "syn 3.0.5", + "syn", ] [[package]] @@ -371,47 +83,6 @@ dependencies = [ "zmij", ] -[[package]] -name = "shlex" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" - -[[package]] -name = "simd-adler32" -version = "0.3.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea" - -[[package]] -name = "smallvec" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9be42f50aa861c555654aa3a37f52f4b1074bacf4e48fe0ef7fa584e80f1f0f" - -[[package]] -name = "stable_deref_trait" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" - -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - -[[package]] -name = "syn" -version = "2.0.119" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - [[package]] name = "syn" version = "3.0.5" @@ -423,265 +94,12 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "synstructure" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.119", -] - -[[package]] -name = "tinystr" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1e27c91459209c2986af3dcf603a5a74a4368754ce37414f59acc971167f643" -dependencies = [ - "displaydoc", - "zerovec", -] - [[package]] name = "unicode-ident" version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" -[[package]] -name = "untrusted" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" - -[[package]] -name = "ureq" -version = "2.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02d1a66277ed75f640d608235660df48c8e3c19f3b4edb6a263315626cc3c01d" -dependencies = [ - "base64", - "flate2", - "log", - "once_cell", - "rustls", - "rustls-pki-types", - "url", - "webpki-roots 0.26.11", -] - -[[package]] -name = "url" -version = "2.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", - "serde", -] - -[[package]] -name = "utf8_iter" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" - -[[package]] -name = "wasi" -version = "0.11.1+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" - -[[package]] -name = "webpki-roots" -version = "0.26.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9" -dependencies = [ - "webpki-roots 1.0.9", -] - -[[package]] -name = "webpki-roots" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a" -dependencies = [ - "rustls-pki-types", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" - -[[package]] -name = "writeable" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" - -[[package]] -name = "yoke" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5" -dependencies = [ - "stable_deref_trait", - "yoke-derive", - "zerofrom", -] - -[[package]] -name = "yoke-derive" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.119", - "synstructure", -] - -[[package]] -name = "zerofrom" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" -dependencies = [ - "zerofrom-derive", -] - -[[package]] -name = "zerofrom-derive" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.119", - "synstructure", -] - -[[package]] -name = "zeroize" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" - -[[package]] -name = "zerotrie" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f" -dependencies = [ - "displaydoc", - "yoke", - "zerofrom", -] - -[[package]] -name = "zerovec" -version = "0.11.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0464e17806c1d976d5cba29399c7f08e516e279e2ba493f63123b5fca67dd8" -dependencies = [ - "yoke", - "zerofrom", - "zerovec-derive", -] - -[[package]] -name = "zerovec-derive" -version = "0.11.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34df6fc39dbd26ddc9c10e6a2984476e13acce22e64e4487636ef494369225da" -dependencies = [ - "proc-macro2", - "quote", - "syn 3.0.5", -] - -[[package]] -name = "zlib-rs" -version = "0.6.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34b31d188d9d685a4f9c7b46d6e36631b07058d2cfe190267adce54dc230bf12" - [[package]] name = "zmij" version = "1.0.23" diff --git a/rads/samples/audience-segments-rust/Cargo.toml b/rads/samples/audience-segments-rust/Cargo.toml index 6d980634..68704f85 100644 --- a/rads/samples/audience-segments-rust/Cargo.toml +++ b/rads/samples/audience-segments-rust/Cargo.toml @@ -6,4 +6,3 @@ edition = "2021" [dependencies] serde = { version = "1", features = ["derive"] } serde_json = "1" -ureq = "2" \ No newline at end of file diff --git a/rads/samples/audience-segments-rust/Dockerfile b/rads/samples/audience-segments-rust/Dockerfile index d2eb5775..a1399988 100644 --- a/rads/samples/audience-segments-rust/Dockerfile +++ b/rads/samples/audience-segments-rust/Dockerfile @@ -1,13 +1,12 @@ FROM rust:1-alpine AS build WORKDIR /src -RUN apk add --no-cache musl-dev ca-certificates +RUN apk add --no-cache musl-dev COPY Cargo.toml Cargo.lock ./ COPY src ./src RUN cargo build --release --locked && cp target/release/audience-segments /audience-segments FROM scratch COPY --from=build /audience-segments /audience-segments -COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt ENV PATH="/" -ENTRYPOINT ["/audience-segments"] \ No newline at end of file +ENTRYPOINT ["/audience-segments"] diff --git a/rads/samples/audience-segments-rust/README.md b/rads/samples/audience-segments-rust/README.md new file mode 100644 index 00000000..8ff327c1 --- /dev/null +++ b/rads/samples/audience-segments-rust/README.md @@ -0,0 +1,23 @@ +# audience-segments-rust + +Sample rads Data Controller app (Rust, serde_json only). Reads the social-media records file +the runner downloaded at `RECORDS_PATH` and writes an ad-audience segmentation to +`RESULT_PATH`: top 10 interests by user count with mean weekly active minutes, engagement +tiers by mean weekly minutes (low < 30, medium 30-120, high > 120), and mean connection +count. PII fields are ignored. Same file contract as secure-rads (`RECORDS_PATH` / +`RESULT_PATH`); the runner fetches plaintext from PDM instead of sce-unit decrypting inside +the enclave. Progress lines go to stderr so the result holds exactly one JSON object. + +```json +{"algorithmId": "a1", "userCount": 1, "segments": [{"interest": "music", "users": 1, "avgWeeklyMinutes": 45.5}], "engagementTiers": {"low": 0, "medium": 1, "high": 0}, "avgConnections": 2.0} +``` + +Build and run (writing the same `{"algorithmId", "records"}` file the runner produces): + +```sh +docker build -t audience-segments-rust . +docker run --rm -v /tmp/rads-run:/data \ + -e RECORDS_PATH=/data/records.json \ + -e RESULT_PATH=/data/result.json \ + audience-segments-rust +``` diff --git a/rads/samples/spend-analysis-go/Dockerfile b/rads/samples/spend-analysis-go/Dockerfile index 30d31102..3dccd8a1 100644 --- a/rads/samples/spend-analysis-go/Dockerfile +++ b/rads/samples/spend-analysis-go/Dockerfile @@ -2,11 +2,9 @@ FROM golang:1.24-alpine AS build WORKDIR /src COPY go.mod main.go ./ RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /spend-analysis . -RUN apk add --no-cache ca-certificates FROM scratch COPY --from=build /spend-analysis /spend-analysis -COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt ENV PATH="/" -ENTRYPOINT ["/spend-analysis"] \ No newline at end of file +ENTRYPOINT ["/spend-analysis"] diff --git a/rads/sce/execution-service/bun.lock b/rads/sce/execution-service/bun.lock index 642daabe..75c25075 100644 --- a/rads/sce/execution-service/bun.lock +++ b/rads/sce/execution-service/bun.lock @@ -183,7 +183,7 @@ "@smithy/types": ["@smithy/types@4.18.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-CgB6HHWer/vrKps24ulRIbpcpb7K4xAU7SkZ7YHzBPlwHsvsrCJFEXK421s+cJzX+ZrqtA/TuU5w1HzI7k9N8A=="], - "@srads/common": ["@srads/common@file:../../../packages/common", { "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], + "@srads/common": ["@srads/common@file:../../../packages/common", { "dependencies": { "csv-stringify": "^6.8.3", "jose": "^6.2.10" }, "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], "@tybys/wasm-util": ["@tybys/wasm-util@0.10.3", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-F3fo1MYrRJYL3zER0OUOmkutjr1Vp23m7OsSgp7nq4SP6OqX6C/56XFIPAl5bt3zaBRjmW7SGz3u/6LwFpYcOg=="], @@ -193,6 +193,8 @@ "bowser": ["bowser@2.14.1", "", {}, "sha512-tzPjzCxygAKWFOJP011oxFHs57HzIhOEracIgAePE4pqB3LikALKnSzUyU4MGs9/iCEUuHlAJTjTc5M+u7YEGg=="], + "csv-stringify": ["csv-stringify@6.9.0", "", {}, "sha512-6b3e29CILFfSQ2nDRuZMRROzQOpPuJ+s8zPB5H7eK5ncXBbFOyVuRLU5Sx/zAUmVri3Ly49GyC8NEme4SVSAbA=="], + "fd-package-json": ["fd-package-json@2.0.0", "", { "dependencies": { "walk-up-path": "^4.0.0" } }, "sha512-jKmm9YtsNXN789RS/0mSzOC1NUq9mkVd65vbSSVsKdjGvYXBuE4oWe2QOEoFeRmJg+lPuZxpmrfFclNhoRMneQ=="], "fdir": ["fdir@6.5.0", "", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg=="], @@ -203,6 +205,8 @@ "jiti": ["jiti@2.7.0", "", { "bin": { "jiti": "lib/jiti-cli.mjs" } }, "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ=="], + "jose": ["jose@6.2.17", "", {}, "sha512-wOuK9V1yujQFH5S0ZWmLcDZN7+IKh9bUCC2ZPCf2HDlol3WWHy+PPyNjEI75FXRLMp3vDKQcupP59xhVU95hcg=="], + "knip": ["knip@6.35.1", "", { "dependencies": { "fdir": "^6.5.0", "formatly": "^0.7.0", "get-tsconfig": "4.14.3", "jiti": "^2.7.0", "oxc-parser": "^0.148.0", "oxc-resolver": "11.24.2", "picomatch": "^4.0.7", "smol-toml": "^1.8.0", "strip-json-comments": "5.0.3", "tinyglobby": "^0.2.17", "unbash": "^4.0.11", "yaml": "^2.9.0", "zod": "^4.4.3" }, "bin": { "knip": "bin/knip.js", "knip-bun": "bin/knip-bun.js" } }, "sha512-22wnEnv4do2fvoeJsxpFCG/MBxReNxoCVBccaCl7suUJsG+F0UvxI9ycxZ9YgtLHSSjrZl5tOas0JZ/R1vJ93g=="], "mnemonist": ["mnemonist@0.38.3", "", { "dependencies": { "obliterator": "^1.6.1" } }, "sha512-2K9QYubXx/NAjv4VLq1d1Ly8pWNC5L3BrixtdkyTegXWJIqY+zLNDhhX/A+ZwWt70tB1S8H4BE8FLYEFyNoOBw=="], diff --git a/rads/sce/execution-service/src/handlers/run.ts b/rads/sce/execution-service/src/handlers/run.ts index d2d2bf0f..a0bc74c9 100644 --- a/rads/sce/execution-service/src/handlers/run.ts +++ b/rads/sce/execution-service/src/handlers/run.ts @@ -4,6 +4,7 @@ import { EC2Client, RunInstancesCommand, type RunInstancesCommandInput } from "@ import { DynamoDBDocumentClient, GetCommand } from "@aws-sdk/lib-dynamodb"; import { CostPhase, costEvent, recordRequest } from "@srads/common/cost"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import { emitEvent } from "@srads/common/log"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; import { fetchAlgorithmRecordCount } from "../lib/pdmCount.js"; @@ -33,7 +34,6 @@ interface RunRequest { interface AlgorithmRecord { Bucket?: string; Key?: string; - RecordCount?: number; } interface RunResult { @@ -46,10 +46,6 @@ interface RunResult { Status?: string; } -function jsonResponse(statusCode: number, body: unknown) { - return { statusCode, headers: { "content-type": "application/json" }, body: JSON.stringify(body) }; -} - function parseRunRequest(body: string | undefined): RunRequest | undefined { try { const parsed: unknown = JSON.parse(body ?? ""); @@ -94,26 +90,17 @@ export const create: APIGatewayProxyHandlerV2 = async (event) => { } if (request.size !== undefined) { - if (record.RecordCount !== undefined) { - if (request.size > record.RecordCount) { + try { + const available = await fetchAlgorithmRecordCount(pdmUrl, request.algorithmId, request.size, runId); + if (request.size > available) { await recordRequest(request.algorithmId, runId, CostPhase.Execution, startedAt); return jsonResponse(400, { - error: `size ${request.size} exceeds seeded dataset (${record.RecordCount} records)`, + error: `size ${request.size} exceeds seeded dataset (${available} records)`, }); } - } else { - try { - const available = await fetchAlgorithmRecordCount(pdmUrl, request.algorithmId, request.size, runId); - if (request.size > available) { - await recordRequest(request.algorithmId, runId, CostPhase.Execution, startedAt); - return jsonResponse(400, { - error: `size ${request.size} exceeds seeded dataset (${available} records)`, - }); - } - } catch (error) { - // The executor caps at size anyway, so a count outage should not block runs. - console.warn("record count failed; skipping size validation", error); - } + } catch (error) { + // The executor caps at size anyway, so a count outage should not block runs. + console.warn("record count failed; skipping size validation", error); } } diff --git a/rads/telemetry-service/bun.lock b/rads/telemetry-service/bun.lock index 401a7bdd..1f4927ea 100644 --- a/rads/telemetry-service/bun.lock +++ b/rads/telemetry-service/bun.lock @@ -9,9 +9,6 @@ "@aws-sdk/client-sqs": "^3.1121.0", "@aws-sdk/lib-dynamodb": "^3.700.0", "@srads/common": "file:../../packages/common", - "csv-stringify": "^6.8.3", - "ts-retry": "^7.0.3", - "zod": "^4.6.5", }, "devDependencies": { "@biomejs/biome": "^2.5.10", @@ -186,7 +183,7 @@ "@smithy/types": ["@smithy/types@4.18.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-CgB6HHWer/vrKps24ulRIbpcpb7K4xAU7SkZ7YHzBPlwHsvsrCJFEXK421s+cJzX+ZrqtA/TuU5w1HzI7k9N8A=="], - "@srads/common": ["@srads/common@file:../../packages/common", { "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], + "@srads/common": ["@srads/common@file:../../packages/common", { "dependencies": { "csv-stringify": "^6.8.3", "jose": "^6.2.10" }, "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], "@tybys/wasm-util": ["@tybys/wasm-util@0.10.3", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-F3fo1MYrRJYL3zER0OUOmkutjr1Vp23m7OsSgp7nq4SP6OqX6C/56XFIPAl5bt3zaBRjmW7SGz3u/6LwFpYcOg=="], @@ -208,6 +205,8 @@ "jiti": ["jiti@2.7.0", "", { "bin": { "jiti": "lib/jiti-cli.mjs" } }, "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ=="], + "jose": ["jose@6.2.17", "", {}, "sha512-wOuK9V1yujQFH5S0ZWmLcDZN7+IKh9bUCC2ZPCf2HDlol3WWHy+PPyNjEI75FXRLMp3vDKQcupP59xhVU95hcg=="], + "knip": ["knip@6.35.1", "", { "dependencies": { "fdir": "^6.5.0", "formatly": "^0.7.0", "get-tsconfig": "4.14.3", "jiti": "^2.7.0", "oxc-parser": "^0.148.0", "oxc-resolver": "11.24.2", "picomatch": "^4.0.7", "smol-toml": "^1.8.0", "strip-json-comments": "5.0.3", "tinyglobby": "^0.2.17", "unbash": "^4.0.11", "yaml": "^2.9.0", "zod": "^4.4.3" }, "bin": { "knip": "bin/knip.js", "knip-bun": "bin/knip-bun.js" } }, "sha512-22wnEnv4do2fvoeJsxpFCG/MBxReNxoCVBccaCl7suUJsG+F0UvxI9ycxZ9YgtLHSSjrZl5tOas0JZ/R1vJ93g=="], "mnemonist": ["mnemonist@0.38.3", "", { "dependencies": { "obliterator": "^1.6.1" } }, "sha512-2K9QYubXx/NAjv4VLq1d1Ly8pWNC5L3BrixtdkyTegXWJIqY+zLNDhhX/A+ZwWt70tB1S8H4BE8FLYEFyNoOBw=="], @@ -232,8 +231,6 @@ "tinyglobby": ["tinyglobby@0.2.17", "", { "dependencies": { "fdir": "^6.5.0", "picomatch": "^4.0.4" } }, "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g=="], - "ts-retry": ["ts-retry@7.0.3", "", {}, "sha512-sEaLD4RaKmEDvLeki2qQsJgqc50cdmBhQJ90I6V0ur/g1iO6P9PxU2dP52SF87dHEtb1jwb/BJWH5gCx6IfqgQ=="], - "tslib": ["tslib@2.8.1", "", {}, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="], "typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="], @@ -248,8 +245,6 @@ "yaml": ["yaml@2.9.0", "", { "bin": { "yaml": "bin.mjs" } }, "sha512-2AvhNX3mb8zd6Zy7INTtSpl1F15HW6Wnqj0srWlkKLcpYl/gMIMJiyuGq2KeI2YFxUPjdlB+3Lc10seMLtL4cA=="], - "zod": ["zod@4.6.5", "", {}, "sha512-v5l/aFXZQeai4awLbOpSoHecE9UiMrnfx75tEXLjNonXVARxQ5mOeipTjROUchszUNCqnE+hqAMujRsRHsut2Q=="], - - "knip/zod": ["zod@4.5.4", "", {}, "sha512-sC95tT5iHHH9gtpj6A81kh+NEaRAUFN+qlUPDUbRfOMvNf5QCBqsb3WgvnpVtK5Y+4UfA6KqufotuTvMGiTlsA=="], + "zod": ["zod@4.5.4", "", {}, "sha512-sC95tT5iHHH9gtpj6A81kh+NEaRAUFN+qlUPDUbRfOMvNf5QCBqsb3WgvnpVtK5Y+4UfA6KqufotuTvMGiTlsA=="], } } diff --git a/rads/telemetry-service/package.json b/rads/telemetry-service/package.json index 6bb28055..e3ca5252 100644 --- a/rads/telemetry-service/package.json +++ b/rads/telemetry-service/package.json @@ -23,9 +23,6 @@ "@aws-sdk/client-dynamodb": "^3.700.0", "@aws-sdk/client-sqs": "^3.1121.0", "@aws-sdk/lib-dynamodb": "^3.700.0", - "@srads/common": "file:../../packages/common", - "csv-stringify": "^6.8.3", - "ts-retry": "^7.0.3", - "zod": "^4.6.5" + "@srads/common": "file:../../packages/common" } } diff --git a/rads/telemetry-service/src/handlers/all.ts b/rads/telemetry-service/src/handlers/all.ts index 6c39492f..b6dd5255 100644 --- a/rads/telemetry-service/src/handlers/all.ts +++ b/rads/telemetry-service/src/handlers/all.ts @@ -1,23 +1,14 @@ import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient, ScanCommand } from "@aws-sdk/lib-dynamodb"; +import { toCsv } from "@srads/common/csv"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; -import { type EventRow, toCsv } from "../lib/csv.js"; +import { EVENT_COLUMNS, type EventRow, toRow } from "../lib/csv.js"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); const table = requiredEnv("RUN_LOG_TABLE"); -function toRow(item: Record): EventRow { - return { - algorithmId: item.AlgorithmId as string, - runId: item.RunId as string, - event: item.Event as string, - timestamp: item.Timestamp as string, - receivedAt: item.ReceivedAt as string, - detail: item.Detail ?? null, - }; -} - // Exports the whole table across all algorithms. Pages through every scan page so a benchmarking export is // never silently truncated. export const handler: APIGatewayProxyHandlerV2 = async (event) => { @@ -34,7 +25,7 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => { } while (exclusiveStartKey); if (format === "csv") { - return { statusCode: 200, headers: { "content-type": "text/csv" }, body: toCsv(rows) }; + return { statusCode: 200, headers: { "content-type": "text/csv" }, body: toCsv(rows, EVENT_COLUMNS) }; } - return { statusCode: 200, headers: { "content-type": "application/json" }, body: JSON.stringify(rows) }; + return jsonResponse(200, rows); }; diff --git a/rads/telemetry-service/src/handlers/byAlgorithm.ts b/rads/telemetry-service/src/handlers/byAlgorithm.ts index a9993216..66848de0 100644 --- a/rads/telemetry-service/src/handlers/byAlgorithm.ts +++ b/rads/telemetry-service/src/handlers/byAlgorithm.ts @@ -1,33 +1,20 @@ import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient, QueryCommand } from "@aws-sdk/lib-dynamodb"; +import { toCsv } from "@srads/common/csv"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; -import { type EventRow, toCsv } from "../lib/csv.js"; +import { EVENT_COLUMNS, type EventRow, toRow } from "../lib/csv.js"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); const table = requiredEnv("RUN_LOG_TABLE"); -function toRow(item: Record): EventRow { - return { - algorithmId: item.AlgorithmId as string, - runId: item.RunId as string, - event: item.Event as string, - timestamp: item.Timestamp as string, - receivedAt: item.ReceivedAt as string, - detail: item.Detail ?? null, - }; -} - // Exports one algorithm's timeline, optionally narrowed to a single run. Pages through every result so an // export is never silently truncated; the SK gives a chronological (runId, timestamp) sort for free. export const handler: APIGatewayProxyHandlerV2 = async (event) => { const algorithmId = event.pathParameters?.algorithmId; if (!algorithmId) { - return { - statusCode: 400, - headers: { "content-type": "application/json" }, - body: JSON.stringify({ error: "missing algorithmId" }), - }; + return jsonResponse(400, { error: "missing algorithmId" }); } const runId = event.queryStringParameters?.runId; const format = event.queryStringParameters?.format; @@ -50,7 +37,7 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => { } while (exclusiveStartKey); if (format === "csv") { - return { statusCode: 200, headers: { "content-type": "text/csv" }, body: toCsv(rows) }; + return { statusCode: 200, headers: { "content-type": "text/csv" }, body: toCsv(rows, EVENT_COLUMNS) }; } - return { statusCode: 200, headers: { "content-type": "application/json" }, body: JSON.stringify(rows) }; + return jsonResponse(200, rows); }; diff --git a/rads/telemetry-service/src/handlers/events.ts b/rads/telemetry-service/src/handlers/events.ts index 0924a407..41133917 100644 --- a/rads/telemetry-service/src/handlers/events.ts +++ b/rads/telemetry-service/src/handlers/events.ts @@ -1,5 +1,6 @@ import { SendMessageCommand, SQSClient } from "@aws-sdk/client-sqs"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; import { parseIngestBody } from "../lib/ingest.js"; import { runEventExists } from "../lib/lookup.js"; @@ -7,10 +8,6 @@ import { runEventExists } from "../lib/lookup.js"; const sqs = new SQSClient({}); const queueUrl = requiredEnv("EVENT_QUEUE_URL"); -function jsonResponse(statusCode: number, body: unknown) { - return { statusCode, headers: { "content-type": "application/json" }, body: JSON.stringify(body) }; -} - export const handler: APIGatewayProxyHandlerV2 = async (event) => { let body: unknown; try { diff --git a/rads/telemetry-service/src/lib/csv.ts b/rads/telemetry-service/src/lib/csv.ts index 1c8bff9b..e860a011 100644 --- a/rads/telemetry-service/src/lib/csv.ts +++ b/rads/telemetry-service/src/lib/csv.ts @@ -1,5 +1,3 @@ -import { stringify } from "csv-stringify/sync"; - export interface EventRow { algorithmId: string; runId: string; @@ -9,12 +7,22 @@ export interface EventRow { detail: unknown; } -const COLUMNS = ["algorithmId", "runId", "event", "timestamp", "receivedAt", "detail"]; +export const EVENT_COLUMNS = [ + "algorithmId", + "runId", + "event", + "timestamp", + "receivedAt", + "detail", +] as const satisfies readonly (keyof EventRow)[]; -export function toCsv(rows: EventRow[]): string { - // detail is an object; flatten it to compact JSON so csv-stringify emits one cell, not [object Object]. - return stringify( - rows.map((row) => ({ ...row, detail: row.detail == null ? "" : JSON.stringify(row.detail) })), - { header: true, columns: COLUMNS }, - ); +export function toRow(item: Record): EventRow { + return { + algorithmId: item.AlgorithmId as string, + runId: item.RunId as string, + event: item.Event as string, + timestamp: item.Timestamp as string, + receivedAt: item.ReceivedAt as string, + detail: item.Detail ?? null, + }; } diff --git a/rads/telemetry-service/src/lib/events.ts b/rads/telemetry-service/src/lib/events.ts index 6f6296db..60b25e6c 100644 --- a/rads/telemetry-service/src/lib/events.ts +++ b/rads/telemetry-service/src/lib/events.ts @@ -1,5 +1,5 @@ -// Canonical rads run-timeline event names. Every producer emits one of these; log-service rejects anything else -// at ingest. Producers (registry, execution control plane, the EC2 executor) mirror this list - keep them in sync. +// Canonical rads run-timeline event names. Every producer emits one of these; ingest rejects anything else. +// Producers (registry, execution control plane, the EC2 executor) mirror this list - keep them in sync. export const RUN_EVENTS = [ // Build phase (registry-service); no runId (the build records the algorithm). "image-uploaded", diff --git a/rads/transparency-portal/README.md b/rads/transparency-portal/README.md index 7340d1e3..9de8e3a8 100644 --- a/rads/transparency-portal/README.md +++ b/rads/transparency-portal/README.md @@ -14,7 +14,7 @@ browser -> GET https://pdm.r.secure-rads.org/subject/{dataSubjectId} -> GET https://log.r.secure-rads.org/subject-access/{dataSubjectId} ``` -The authority view reads `log.r.secure-rads.org` directly (`/logs`, `/subject-access`). Both APIs send permissive CORS headers (`httpApi.cors: true` in each `serverless.yml`). +The authority view reads `telemetry.r.secure-rads.org` for run timelines (`/logs`) and `log.r.secure-rads.org` for the subject-access trail (`/subject-access`). Both APIs send permissive CORS headers (`httpApi.cors: true` in each `serverless.yml`). The rads host records a subject-access entry (algorithm, run, timestamp, data subject) after a successful DC app run, using the data subject ids PDM returned for that run, so the trail reflects runs that actually reached the application. @@ -25,6 +25,7 @@ Build-time Vite variables, defaulting to the deployed domains if unset: | Variable | Default | | --- | --- | | `VITE_LOG_SERVICE_URL` | `https://log.r.secure-rads.org` | +| `VITE_TELEMETRY_SERVICE_URL` | `https://telemetry.r.secure-rads.org` | | `VITE_PDM_URL` | `https://pdm.r.secure-rads.org` | ## Develop diff --git a/rads/transparency-portal/bun.lock b/rads/transparency-portal/bun.lock index f98e2107..d36db12d 100644 --- a/rads/transparency-portal/bun.lock +++ b/rads/transparency-portal/bun.lock @@ -3,7 +3,7 @@ "configVersion": 1, "workspaces": { "": { - "name": "transparency-portal", + "name": "rads-transparency-portal", "dependencies": { "@base-ui/react": "^1.8.0", "@fontsource-variable/geist": "^5.3.0", @@ -15,7 +15,6 @@ "react": "^19.2.8", "react-dom": "^19.2.8", "react-router-dom": "^7.18.3", - "shadcn": "^4.21.0", "tw-animate-css": "^1.4.0", }, "devDependencies": { @@ -25,6 +24,7 @@ "@types/react-dom": "^19.2.7", "@vitejs/plugin-react": "^6.1.1", "oxlint": "^1.81.0", + "shadcn": "^4.21.0", "tailwindcss": "^4.3.3", "typescript": "~6.0.2", "vite": "^8.3.0", diff --git a/rads/transparency-portal/package.json b/rads/transparency-portal/package.json index e6150a73..6041be37 100644 --- a/rads/transparency-portal/package.json +++ b/rads/transparency-portal/package.json @@ -20,7 +20,6 @@ "react": "^19.2.8", "react-dom": "^19.2.8", "react-router-dom": "^7.18.3", - "shadcn": "^4.21.0", "tw-animate-css": "^1.4.0" }, "devDependencies": { @@ -30,6 +29,7 @@ "@types/react-dom": "^19.2.7", "@vitejs/plugin-react": "^6.1.1", "oxlint": "^1.81.0", + "shadcn": "^4.21.0", "tailwindcss": "^4.3.3", "typescript": "~6.0.2", "vite": "^8.3.0" diff --git a/rads/transparency-portal/src/components/site-header.tsx b/rads/transparency-portal/src/components/site-header.tsx index 0ee3d578..33689d5d 100644 --- a/rads/transparency-portal/src/components/site-header.tsx +++ b/rads/transparency-portal/src/components/site-header.tsx @@ -1,6 +1,6 @@ import { Link, NavLink } from "react-router-dom"; import { ShieldCheckIcon } from "lucide-react"; -import { cn } from "@/lib/utils"; +import { cn } from "cn"; const LINKS = [ { to: "/", label: "Home" }, diff --git a/secure/cost-service/README.md b/secure/cost-service/README.md index ce459cbb..b5a7ae06 100644 --- a/secure/cost-service/README.md +++ b/secure/cost-service/README.md @@ -7,7 +7,7 @@ The table stores **one row per AWS operation**, not per run. Callers (the benchm ## Endpoints - `POST /cost` - a producer posts one event `{algorithmId, runId, eventId, phase, service, operation, quantity, timestamp, detail?}`. `eventId` is a producer-generated UUID; it is part of the sort key so an SQS redelivery overwrites the row instead of double-counting. The handler validates, enqueues, and returns `202` without waiting for DynamoDB. -- `GET /cost/{algorithmId}` - one algorithm's cost rows. `?runId=` narrows to a run; the JSON response also carries `totalUsd` plus `priceRegion`/`priceAsOf` provenance. +- `GET /cost/{algorithmId}` - one algorithm's cost rows. `?runId=` narrows to a run; the JSON response also carries `totalUsd` (the sum over the returned page only, not the whole history; page with `nextCursor` and sum client-side for a full total) plus `priceRegion`/`priceAsOf` provenance. - `GET /cost` - the whole table. Both GET routes page via `?cursor=` (the previous response's `nextCursor`) and return at most one page, so a large history cannot overflow the 10 MB API Gateway response cap. They take `?format=csv` (`text/csv`) or default to JSON; on CSV the next-page token rides the `x-next-cursor` response header. CSV columns: `algorithmId,runId,phase,service,operation,quantity,unit,costUsd,timestamp,receivedAt,detail`. diff --git a/secure/cost-service/bun.lock b/secure/cost-service/bun.lock index 3606fedb..a7c8e200 100644 --- a/secure/cost-service/bun.lock +++ b/secure/cost-service/bun.lock @@ -9,7 +9,6 @@ "@aws-sdk/client-sqs": "^3.1121.0", "@aws-sdk/lib-dynamodb": "^3.700.0", "@srads/common": "file:../../packages/common", - "csv-stringify": "^6.8.3", }, "devDependencies": { "@biomejs/biome": "^2.5.10", @@ -184,7 +183,7 @@ "@smithy/types": ["@smithy/types@4.19.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-r7jh49VJxGerfAcTQA6gXcKc+98zOp/tqRwzYjgOE+iSQsP6cEU1hq2QzbuipmP68QtYdY9wKEhiCQZIzHgZ4Q=="], - "@srads/common": ["@srads/common@file:../../packages/common", { "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], + "@srads/common": ["@srads/common@file:../../packages/common", { "dependencies": { "csv-stringify": "^6.8.3", "jose": "^6.2.10" }, "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], "@tybys/wasm-util": ["@tybys/wasm-util@0.10.4", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-W3c4gRigFS0T/Ma4qIYF3GDAc5AQdHb1yL5znJT1Zv1YaD9Kitx656wBjvr19qbiosmZT8lWDM5BEMynUqX65A=="], @@ -206,6 +205,8 @@ "jiti": ["jiti@2.7.0", "", { "bin": { "jiti": "lib/jiti-cli.mjs" } }, "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ=="], + "jose": ["jose@6.2.17", "", {}, "sha512-wOuK9V1yujQFH5S0ZWmLcDZN7+IKh9bUCC2ZPCf2HDlol3WWHy+PPyNjEI75FXRLMp3vDKQcupP59xhVU95hcg=="], + "knip": ["knip@6.40.0", "", { "dependencies": { "fdir": "^6.5.0", "formatly": "^0.7.0", "get-tsconfig": "4.14.3", "jiti": "^2.7.0", "oxc-parser": "^0.150.0", "oxc-resolver": "11.24.2", "picomatch": "^4.0.7", "smol-toml": "^1.8.0", "strip-json-comments": "5.0.3", "tinyglobby": "^0.2.17", "unbash": "^4.0.11", "yaml": "^2.9.1", "zod": "^4.4.3" }, "bin": { "knip": "bin/knip.js", "knip-bun": "bin/knip-bun.js" } }, "sha512-5Lp/ANJu3AkW5f+J+2QG14z7xKZGi/ybb5MU1EWjeGdt6MpuIaLpLFiyBi0ZKryTiuTHiJqo/WKJRaWYimvavw=="], "mnemonist": ["mnemonist@0.38.3", "", { "dependencies": { "obliterator": "^1.6.1" } }, "sha512-2K9QYubXx/NAjv4VLq1d1Ly8pWNC5L3BrixtdkyTegXWJIqY+zLNDhhX/A+ZwWt70tB1S8H4BE8FLYEFyNoOBw=="], diff --git a/secure/cost-service/package.json b/secure/cost-service/package.json index 6b607fba..d156f2e8 100644 --- a/secure/cost-service/package.json +++ b/secure/cost-service/package.json @@ -23,7 +23,6 @@ "@aws-sdk/client-dynamodb": "^3.700.0", "@aws-sdk/client-sqs": "^3.1121.0", "@aws-sdk/lib-dynamodb": "^3.700.0", - "@srads/common": "file:../../packages/common", - "csv-stringify": "^6.8.3" + "@srads/common": "file:../../packages/common" } } diff --git a/secure/cost-service/src/handlers/all.ts b/secure/cost-service/src/handlers/all.ts index 17d7e14d..4a558c11 100644 --- a/secure/cost-service/src/handlers/all.ts +++ b/secure/cost-service/src/handlers/all.ts @@ -1,29 +1,16 @@ import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient, ScanCommand } from "@aws-sdk/lib-dynamodb"; +import { toCsv } from "@srads/common/csv"; +import { decodeCursor, encodeCursor } from "@srads/common/cursor"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; -import { type CostRow, csvHeaders, toCsv } from "../lib/csv.js"; -import { decodeCursor, encodeCursor, PAGE_SIZE } from "../lib/cursor.js"; +import { COST_COLUMNS, csvHeaders, toRow } from "../lib/csv.js"; +import { PAGE_SIZE } from "../lib/paging.js"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); const table = requiredEnv("COST_TABLE"); -function toRow(item: Record): CostRow { - return { - algorithmId: item.AlgorithmId as string, - runId: item.RunId as string, - phase: item.Phase as string, - service: item.Service as string, - operation: item.Operation as string, - quantity: item.Quantity as number, - unit: item.Unit as string, - costUsd: item.CostUsd as number, - timestamp: item.Timestamp as string, - receivedAt: item.ReceivedAt as string, - detail: item.Detail ?? null, - }; -} - // Cursor paging keeps full-table exports below API Gateway's response-size limit. export const handler: APIGatewayProxyHandlerV2 = async (event) => { const format = event.queryStringParameters?.format; @@ -33,11 +20,7 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => { if (cursor) { exclusiveStartKey = decodeCursor(cursor); if (!exclusiveStartKey) { - return { - statusCode: 400, - headers: { "content-type": "application/json" }, - body: JSON.stringify({ error: "invalid cursor" }), - }; + return jsonResponse(400, { error: "invalid cursor" }); } } @@ -48,11 +31,7 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => { const nextCursor = result.LastEvaluatedKey ? encodeCursor(result.LastEvaluatedKey) : null; if (format === "csv") { - return { statusCode: 200, headers: csvHeaders(nextCursor), body: toCsv(rows) }; + return { statusCode: 200, headers: csvHeaders(nextCursor), body: toCsv(rows, COST_COLUMNS) }; } - return { - statusCode: 200, - headers: { "content-type": "application/json" }, - body: JSON.stringify({ events: rows, nextCursor }), - }; + return jsonResponse(200, { events: rows, nextCursor }); }; diff --git a/secure/cost-service/src/handlers/byAlgorithm.ts b/secure/cost-service/src/handlers/byAlgorithm.ts index 7a308ffa..8cefdf88 100644 --- a/secure/cost-service/src/handlers/byAlgorithm.ts +++ b/secure/cost-service/src/handlers/byAlgorithm.ts @@ -1,39 +1,22 @@ import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient, QueryCommand } from "@aws-sdk/lib-dynamodb"; +import { toCsv } from "@srads/common/csv"; +import { decodeCursor, encodeCursor } from "@srads/common/cursor"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; -import { type CostRow, csvHeaders, toCsv } from "../lib/csv.js"; -import { decodeCursor, encodeCursor, PAGE_SIZE } from "../lib/cursor.js"; +import { COST_COLUMNS, csvHeaders, toRow } from "../lib/csv.js"; +import { PAGE_SIZE } from "../lib/paging.js"; import { PRICE_AS_OF, PRICE_REGION } from "../lib/prices.js"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); const table = requiredEnv("COST_TABLE"); -function toRow(item: Record): CostRow { - return { - algorithmId: item.AlgorithmId as string, - runId: item.RunId as string, - phase: item.Phase as string, - service: item.Service as string, - operation: item.Operation as string, - quantity: item.Quantity as number, - unit: item.Unit as string, - costUsd: item.CostUsd as number, - timestamp: item.Timestamp as string, - receivedAt: item.ReceivedAt as string, - detail: item.Detail ?? null, - }; -} - // Cursor paging keeps large algorithm histories below API Gateway's response-size limit. export const handler: APIGatewayProxyHandlerV2 = async (event) => { const algorithmId = event.pathParameters?.algorithmId; if (!algorithmId) { - return { - statusCode: 400, - headers: { "content-type": "application/json" }, - body: JSON.stringify({ error: "missing algorithmId" }), - }; + return jsonResponse(400, { error: "missing algorithmId" }); } const runId = event.queryStringParameters?.runId; const format = event.queryStringParameters?.format; @@ -43,11 +26,7 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => { if (cursor) { exclusiveStartKey = decodeCursor(cursor); if (!exclusiveStartKey) { - return { - statusCode: 400, - headers: { "content-type": "application/json" }, - body: JSON.stringify({ error: "invalid cursor" }), - }; + return jsonResponse(400, { error: "invalid cursor" }); } } @@ -64,21 +43,17 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => { const nextCursor = result.LastEvaluatedKey ? encodeCursor(result.LastEvaluatedKey) : null; if (format === "csv") { - return { statusCode: 200, headers: csvHeaders(nextCursor), body: toCsv(rows) }; + return { statusCode: 200, headers: csvHeaders(nextCursor), body: toCsv(rows, COST_COLUMNS) }; } const totalUsd = rows.reduce((sum, row) => sum + row.costUsd, 0); - return { - statusCode: 200, - headers: { "content-type": "application/json" }, - body: JSON.stringify({ - algorithmId, - runId: runId ?? null, - priceRegion: PRICE_REGION, - priceAsOf: PRICE_AS_OF, - totalUsd, - events: rows, - nextCursor, - }), - }; + return jsonResponse(200, { + algorithmId, + runId: runId ?? null, + priceRegion: PRICE_REGION, + priceAsOf: PRICE_AS_OF, + totalUsd, + events: rows, + nextCursor, + }); }; diff --git a/secure/cost-service/src/handlers/cost.ts b/secure/cost-service/src/handlers/cost.ts index e1198afb..fd1d96d8 100644 --- a/secure/cost-service/src/handlers/cost.ts +++ b/secure/cost-service/src/handlers/cost.ts @@ -1,15 +1,12 @@ import { SendMessageCommand, SQSClient } from "@aws-sdk/client-sqs"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; import { parseCostBody } from "../lib/ingest.js"; const sqs = new SQSClient({}); const queueUrl = requiredEnv("COST_QUEUE_URL"); -function jsonResponse(statusCode: number, body: unknown) { - return { statusCode, headers: { "content-type": "application/json" }, body: JSON.stringify(body) }; -} - export const handler: APIGatewayProxyHandlerV2 = async (event) => { let body: unknown; try { diff --git a/secure/cost-service/src/lib/csv.ts b/secure/cost-service/src/lib/csv.ts index 280da1f9..d44c0d1e 100644 --- a/secure/cost-service/src/lib/csv.ts +++ b/secure/cost-service/src/lib/csv.ts @@ -1,5 +1,3 @@ -import { stringify } from "csv-stringify/sync"; - export interface CostRow { algorithmId: string; runId: string; @@ -14,7 +12,7 @@ export interface CostRow { detail: unknown; } -const COLUMNS = [ +export const COST_COLUMNS = [ "algorithmId", "runId", "phase", @@ -26,17 +24,25 @@ const COLUMNS = [ "timestamp", "receivedAt", "detail", -]; +] as const satisfies readonly (keyof CostRow)[]; + +export function toRow(item: Record): CostRow { + return { + algorithmId: item.AlgorithmId as string, + runId: item.RunId as string, + phase: item.Phase as string, + service: item.Service as string, + operation: item.Operation as string, + quantity: item.Quantity as number, + unit: item.Unit as string, + costUsd: item.CostUsd as number, + timestamp: item.Timestamp as string, + receivedAt: item.ReceivedAt as string, + detail: item.Detail ?? null, + }; +} // CSV can't carry a cursor in the body, so the next-page token rides on a response header for clients that page. export function csvHeaders(nextCursor: string | null): Record { return nextCursor ? { "content-type": "text/csv", "x-next-cursor": nextCursor } : { "content-type": "text/csv" }; } - -export function toCsv(rows: CostRow[]): string { - // Serialize detail objects as JSON so csv-stringify emits one cell instead of [object Object]. - return stringify( - rows.map((row) => ({ ...row, detail: row.detail == null ? "" : JSON.stringify(row.detail) })), - { header: true, columns: COLUMNS }, - ); -} diff --git a/secure/cost-service/src/lib/cursor.ts b/secure/cost-service/src/lib/cursor.ts deleted file mode 100644 index d9965fcf..00000000 --- a/secure/cost-service/src/lib/cursor.ts +++ /dev/null @@ -1,15 +0,0 @@ -export const PAGE_SIZE = 1000; - -export function decodeCursor(cursor: string): Record | undefined { - try { - const parsed: unknown = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8")); - if (typeof parsed !== "object" || parsed === null) return undefined; - return parsed as Record; - } catch { - return undefined; - } -} - -export function encodeCursor(key: Record): string { - return Buffer.from(JSON.stringify(key)).toString("base64url"); -} diff --git a/secure/cost-service/src/lib/paging.ts b/secure/cost-service/src/lib/paging.ts new file mode 100644 index 00000000..df69ad1d --- /dev/null +++ b/secure/cost-service/src/lib/paging.ts @@ -0,0 +1 @@ +export const PAGE_SIZE = 1000; diff --git a/secure/csav/registry-service/Makefile b/secure/csav/registry-service/Makefile index 2c182624..de5bbbeb 100644 --- a/secure/csav/registry-service/Makefile +++ b/secure/csav/registry-service/Makefile @@ -49,7 +49,7 @@ test: go test ./... run: - AWS_REGION=$(REGION) ARTIFACT_BUCKET=$(ARTIFACT_BUCKET) go run . + AWS_REGION=$(REGION) ARTIFACT_BUCKET=$(ARTIFACT_BUCKET) DYNAMO_TABLE=$(DYNAMO_TABLE) go run . clean: rm -f /tmp/registry-service diff --git a/secure/csav/registry-service/go.mod b/secure/csav/registry-service/go.mod index c024592e..a0dd2bea 100644 --- a/secure/csav/registry-service/go.mod +++ b/secure/csav/registry-service/go.mod @@ -11,7 +11,6 @@ require ( github.com/aws/aws-sdk-go-v2/service/dynamodb v1.63.1 github.com/aws/aws-sdk-go-v2/service/kms v1.56.0 github.com/aws/aws-sdk-go-v2/service/s3 v1.107.0 - github.com/aws/aws-sdk-go-v2/service/ssm v1.60.0 github.com/aws/aws-sdk-go-v2/service/sts v1.45.4 github.com/gin-gonic/gin v1.12.0 github.com/google/uuid v1.6.0 diff --git a/secure/csav/registry-service/go.sum b/secure/csav/registry-service/go.sum index 2d4eabe8..0bf8d81f 100644 --- a/secure/csav/registry-service/go.sum +++ b/secure/csav/registry-service/go.sum @@ -38,8 +38,6 @@ github.com/aws/aws-sdk-go-v2/service/s3 v1.107.0 h1:OkYV+1171za+ab9otU1tGxMXhx6u github.com/aws/aws-sdk-go-v2/service/s3 v1.107.0/go.mod h1:5FTZoQxhmLEiCAtYVk6V+t0iS/B5yGZVLZ3Wq5FDJZI= github.com/aws/aws-sdk-go-v2/service/signin v1.5.4 h1:cOJELVNrq5Q3Udry2GLuHUM7MhwpeaQRdYaoa6GI/yI= github.com/aws/aws-sdk-go-v2/service/signin v1.5.4/go.mod h1:f4LxzKBtaTxD7xh3PiVg3CE1tchQemfmghaJr+NbK2c= -github.com/aws/aws-sdk-go-v2/service/ssm v1.60.0 h1:YuMspnzt8uHda7a6A/29WCbjMJygyiyTvq480lnsScQ= -github.com/aws/aws-sdk-go-v2/service/ssm v1.60.0/go.mod h1:IyVabkWrs8SNdOEZLyFFcW9bUltV4G6OQS0s6H20PHg= github.com/aws/aws-sdk-go-v2/service/sso v1.33.4 h1:AMW7a7S8iQaHjBYZdU3PCq4GKRPijTPRAc7e6XtEThY= github.com/aws/aws-sdk-go-v2/service/sso v1.33.4/go.mod h1:QQNsFV1DVXoXcZt18FS8lI8rtUrlDyAuWZLQ5shunv4= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.38.4 h1:AsbZcJAQPRmHDJG8K1N0pof/1zPWjVT8TFlTWuGLSvo= diff --git a/secure/csav/registry-service/verifier.go b/secure/csav/registry-service/verifier.go index 42112931..25bed70b 100644 --- a/secure/csav/registry-service/verifier.go +++ b/secure/csav/registry-service/verifier.go @@ -43,10 +43,7 @@ type registerPCRsRequest struct { PCR2 string `json:"pcr2"` } -// registerPCRs hands PCR measurements to verifier-service over mTLS, pinning -// its leaf cert's public key on top of normal chain verification - trust -// material (client cert/key, pinned pubkey hash) is baked in at build time, -// not configurable at runtime. +// registerPCRs hands PCR measurements to verifier-service over mTLS, trusting its leaf only by the pubkey pin from the env. func registerPCRs(ctx context.Context, algorithmId string, pcrs pcrMeasurements) error { pinnedPubKeySHA256 := os.Getenv(verifierPinnedPubKeyEnv) if verifierURL == "" || pinnedPubKeySHA256 == "" { diff --git a/secure/kms-service/bun.lock b/secure/kms-service/bun.lock index 28ed20f0..74fed5b8 100644 --- a/secure/kms-service/bun.lock +++ b/secure/kms-service/bun.lock @@ -9,7 +9,6 @@ "@aws-sdk/client-kms": "^3.700.0", "@aws-sdk/lib-dynamodb": "^3.700.0", "@srads/common": "file:../../packages/common", - "jose": "^6.2.10", }, "devDependencies": { "@biomejs/biome": "2.5.10", @@ -182,7 +181,7 @@ "@smithy/types": ["@smithy/types@4.20.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-lCA6QG22dPk9ecHbv91jDQZsmtPUjdS1aE2Il6NNPqe7DrYc0dZQi6DhcESk2KYXH2sp5xbAcGdYMZDFnuzA2A=="], - "@srads/common": ["@srads/common@file:../../packages/common", { "dependencies": { "jose": "^6.2.10" }, "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], + "@srads/common": ["@srads/common@file:../../packages/common", { "dependencies": { "csv-stringify": "^6.8.3", "jose": "^6.2.10" }, "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], "@tybys/wasm-util": ["@tybys/wasm-util@0.10.4", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-W3c4gRigFS0T/Ma4qIYF3GDAc5AQdHb1yL5znJT1Zv1YaD9Kitx656wBjvr19qbiosmZT8lWDM5BEMynUqX65A=="], @@ -192,6 +191,8 @@ "bowser": ["bowser@2.15.0", "", {}, "sha512-xic6KSZglg/I4ymp45fdM4GWfYpBK79Fxd/TOvJktlaPgQqqDxvmGwOPZl2V0dyeS3Lj5c180bLhXF43iyAjZQ=="], + "csv-stringify": ["csv-stringify@6.9.0", "", {}, "sha512-6b3e29CILFfSQ2nDRuZMRROzQOpPuJ+s8zPB5H7eK5ncXBbFOyVuRLU5Sx/zAUmVri3Ly49GyC8NEme4SVSAbA=="], + "fd-package-json": ["fd-package-json@2.0.0", "", { "dependencies": { "walk-up-path": "^4.0.0" } }, "sha512-jKmm9YtsNXN789RS/0mSzOC1NUq9mkVd65vbSSVsKdjGvYXBuE4oWe2QOEoFeRmJg+lPuZxpmrfFclNhoRMneQ=="], "fdir": ["fdir@6.5.0", "", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg=="], diff --git a/secure/kms-service/knip.json b/secure/kms-service/knip.json index f7bc9985..7db903ed 100644 --- a/secure/kms-service/knip.json +++ b/secure/kms-service/knip.json @@ -5,8 +5,5 @@ ], "project": [ "src/**/*.ts" - ], - "ignoreDependencies": [ - "jose" ] } diff --git a/secure/kms-service/package.json b/secure/kms-service/package.json index 0a58b435..72a910b7 100644 --- a/secure/kms-service/package.json +++ b/secure/kms-service/package.json @@ -23,7 +23,6 @@ "@aws-sdk/client-dynamodb": "^3.700.0", "@aws-sdk/client-kms": "^3.700.0", "@aws-sdk/lib-dynamodb": "^3.700.0", - "@srads/common": "file:../../packages/common", - "jose": "^6.2.10" + "@srads/common": "file:../../packages/common" } } diff --git a/secure/kms-service/src/handlers/decrypt.ts b/secure/kms-service/src/handlers/decrypt.ts index b3e45b0c..28d06b28 100644 --- a/secure/kms-service/src/handlers/decrypt.ts +++ b/secure/kms-service/src/handlers/decrypt.ts @@ -3,6 +3,7 @@ import { DecryptCommand, KMSClient } from "@aws-sdk/client-kms"; import { DynamoDBDocumentClient, GetCommand } from "@aws-sdk/lib-dynamodb"; import { CostPhase, costEvent, recordRequest } from "@srads/common/cost"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; import { verifyAccessToken } from "../lib/jwt.js"; @@ -18,10 +19,6 @@ interface AlgorithmRecord { KmsKeyArn?: string; } -function jsonResponse(statusCode: number, body: unknown) { - return { statusCode, headers: { "content-type": "application/json" }, body: JSON.stringify(body) }; -} - function bearerToken(event: Parameters[0]): string | undefined { const authorization = event.headers.authorization; return authorization?.startsWith("Bearer ") ? authorization.slice("Bearer ".length) : undefined; diff --git a/secure/log-service/README.md b/secure/log-service/README.md index 52ba1d75..c81bb0df 100644 --- a/secure/log-service/README.md +++ b/secure/log-service/README.md @@ -14,7 +14,7 @@ The public domain carries the subject-access write and read paths: ## Authentication -When `VERIFIER_JWKS_URL` is set, `POST /subject-access` verifies the ML-DSA-87 access token that verifier-service mints only after a successful Nitro attestation (`src/lib/jwt.ts` on the shared `@srads/common/jwt` verifier, with SPKI-pinned TLS on the JWKS fetch and `aud=log-service`). The token's `sub` must match the request's `algorithmId`, and the request's `runId` must match the token's `run_id`, so the trail cannot be written for another algorithm or run. The read paths are open, matching the PDM DSAR relay. +`POST /subject-access` verifies the ML-DSA-87 access token that verifier-service mints only after a successful Nitro attestation (`src/lib/jwt.ts` on the shared `@srads/common/jwt` verifier, with SPKI-pinned TLS on the JWKS fetch and `aud=log-service`; `VERIFIER_JWKS_URL` and `VERIFIER_JWKS_PUBKEY_SHA256` are required at startup). The token's `sub` must match the request's `algorithmId`, and the request's `runId` must match the token's `run_id`, so the trail cannot be written for another algorithm or run. The read paths are open, matching the PDM DSAR relay. The `rads` baseline has no verifier, so its log-service accepts subject-access writes without a token. diff --git a/secure/log-service/bun.lock b/secure/log-service/bun.lock index 9eae41ca..c245bfa5 100644 --- a/secure/log-service/bun.lock +++ b/secure/log-service/bun.lock @@ -6,11 +6,8 @@ "name": "log-service", "dependencies": { "@aws-sdk/client-dynamodb": "^3.700.0", - "@aws-sdk/client-sqs": "^3.1121.0", "@aws-sdk/lib-dynamodb": "^3.700.0", "@srads/common": "file:../../packages/common", - "csv-stringify": "^6.8.3", - "jose": "^6.2.10", "ts-retry": "^7.0.3", "zod": "^4.6.5", }, @@ -27,10 +24,6 @@ "packages": { "@aws-sdk/client-dynamodb": ["@aws-sdk/client-dynamodb@3.1169.0", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/credential-provider-node": "^3.972.97", "@aws-sdk/dynamodb-codec": "^3.973.58", "@aws-sdk/middleware-endpoint-discovery": "^3.972.39", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/fetch-http-handler": "^5.8.1", "@smithy/node-http-handler": "^4.14.2", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-FqvqV/l5gJCluCLxE37sNxd9UFunnZFwc/yQCizLYN368rlbFbcJ3SiHqYvJEmZZFFV3sWs9kyn3D3HiGxjumA=="], - "@aws-sdk/client-sqs": ["@aws-sdk/client-sqs@3.1169.0", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/credential-provider-node": "^3.972.97", "@aws-sdk/middleware-sdk-sqs": "^3.972.50", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/fetch-http-handler": "^5.8.1", "@smithy/node-http-handler": "^4.14.2", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-7bX9EB7CH/L/CuYv/4l3/LlBofBfyjZqFHbsLHJ/Wki08fMsq6g/RCsCKU29UmCINLdX13Un9YtWu5Gv8pHxCA=="], - - "@aws-sdk/client-ssm": ["@aws-sdk/client-ssm@3.1169.0", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/credential-provider-node": "^3.972.97", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/fetch-http-handler": "^5.8.1", "@smithy/node-http-handler": "^4.14.2", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-EAqUE22l8bOeCPMNxnahMhKrWW2n7siZjVL1rNWWaD9prTTwDbMf2xeaAOqVx5lLOz+3sSuicM6OMY5yYTR1Eg=="], - "@aws-sdk/core": ["@aws-sdk/core@3.981.0", "", { "dependencies": { "@aws-sdk/types": "^3.975.1", "@aws-sdk/xml-builder": "^3.972.43", "@aws/lambda-invoke-store": "^0.3.0", "@smithy/core": "^3.40.0", "@smithy/signature-v4": "^5.7.5", "@smithy/types": "^4.20.0", "bowser": "^2.11.0", "tslib": "^2.6.2" } }, "sha512-Mnu7gaDrC5UCdyH8uLxLfB2eWbjE/HbjKX1U1J2VQxG3TTATUDObW2wU3I8iH3e9YH5NN2CY6w1mlAIe2XJ3jg=="], "@aws-sdk/credential-provider-env": ["@aws-sdk/credential-provider-env@3.972.84", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-akZJetiMVeLRHsKzYh3LamDCo74ZUCeo0XoyRKMEMZT5qP7ReM6LhpioBCyuqKP5Vav5gEOeCmaQV0VVQr1Meg=="], @@ -57,8 +50,6 @@ "@aws-sdk/middleware-endpoint-discovery": ["@aws-sdk/middleware-endpoint-discovery@3.972.39", "", { "dependencies": { "@aws-sdk/endpoint-cache": "^3.972.11", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-AtZS+UK7CciPbdiszPoG08A23kUojFxFnWIv155uPieSPcHR9D9Sovtp19U0j5qmD2DzHpG9OI7mb0Kiyvf3mA=="], - "@aws-sdk/middleware-sdk-sqs": ["@aws-sdk/middleware-sdk-sqs@3.972.50", "", { "dependencies": { "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-iSxF2dJT3+At+RT9eeyq0qFKVLEPto27TAQxn2zH2bw5syXj4+/H4VReFqcQAe3n0IdGlt+0T6flnPMb71FOHA=="], - "@aws-sdk/nested-clients": ["@aws-sdk/nested-clients@3.998.3", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/signature-v4-multi-region": "^3.996.52", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/fetch-http-handler": "^5.8.1", "@smithy/node-http-handler": "^4.14.2", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-acHTTzMB13CU6dU4sxABYExMI3PQM2zStWH2MiUwJp/7QKTrLg2f7mbzSXoegW2kYOk2tdqQYagsZrWB8Xv7eA=="], "@aws-sdk/signature-v4-multi-region": ["@aws-sdk/signature-v4-multi-region@3.996.52", "", { "dependencies": { "@aws-sdk/types": "^3.975.1", "@smithy/signature-v4": "^5.7.5", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-6W6SjGc8OXUhMzNxU1X922ghD+PP1XvzmCk5Scui0jaYsLezycMYR1RaLp5xTIOUrhTXyb4DnAbPr3fBgmdnzg=="], @@ -193,7 +184,7 @@ "@smithy/types": ["@smithy/types@4.20.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-lCA6QG22dPk9ecHbv91jDQZsmtPUjdS1aE2Il6NNPqe7DrYc0dZQi6DhcESk2KYXH2sp5xbAcGdYMZDFnuzA2A=="], - "@srads/common": ["@srads/common@file:../../packages/common", { "dependencies": { "@aws-sdk/client-ssm": "^3.700.0", "jose": "^6.2.10" }, "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], + "@srads/common": ["@srads/common@file:../../packages/common", { "dependencies": { "csv-stringify": "^6.8.3", "jose": "^6.2.10" }, "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], "@tybys/wasm-util": ["@tybys/wasm-util@0.10.4", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-W3c4gRigFS0T/Ma4qIYF3GDAc5AQdHb1yL5znJT1Zv1YaD9Kitx656wBjvr19qbiosmZT8lWDM5BEMynUqX65A=="], diff --git a/secure/log-service/knip.json b/secure/log-service/knip.json index f7bc9985..7db903ed 100644 --- a/secure/log-service/knip.json +++ b/secure/log-service/knip.json @@ -5,8 +5,5 @@ ], "project": [ "src/**/*.ts" - ], - "ignoreDependencies": [ - "jose" ] } diff --git a/secure/log-service/package.json b/secure/log-service/package.json index a1f30d84..6c83839d 100644 --- a/secure/log-service/package.json +++ b/secure/log-service/package.json @@ -21,12 +21,9 @@ }, "dependencies": { "@aws-sdk/client-dynamodb": "^3.700.0", - "@aws-sdk/client-sqs": "^3.1121.0", "@aws-sdk/lib-dynamodb": "^3.700.0", "@srads/common": "file:../../packages/common", - "csv-stringify": "^6.8.3", "ts-retry": "^7.0.3", - "zod": "^4.6.5", - "jose": "^6.2.10" + "zod": "^4.6.5" } } diff --git a/secure/log-service/src/handlers/subjectAccessAll.ts b/secure/log-service/src/handlers/subjectAccessAll.ts index 54004848..83a29d52 100644 --- a/secure/log-service/src/handlers/subjectAccessAll.ts +++ b/secure/log-service/src/handlers/subjectAccessAll.ts @@ -1,6 +1,8 @@ import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb"; +import { decodeCursor } from "@srads/common/cursor"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; import { scanAccesses } from "../lib/subjectAccessRows.js"; @@ -9,19 +11,17 @@ const table = requiredEnv("SUBJECT_ACCESS_TABLE"); const DEFAULT_LIMIT = 500; const MAX_LIMIT = 1_000; -function jsonResponse(statusCode: number, body: unknown) { - return { statusCode, headers: { "content-type": "application/json" }, body: JSON.stringify(body) }; -} - // Service-authority view: one page of access events plus an opaque cursor for the next page. export const handler: APIGatewayProxyHandlerV2 = async (event) => { const parsed = Number(event.queryStringParameters?.limit ?? DEFAULT_LIMIT); const limit = Number.isInteger(parsed) && parsed > 0 ? Math.min(parsed, MAX_LIMIT) : DEFAULT_LIMIT; - try { - const { rows, nextCursor } = await scanAccesses(ddb, table, limit, event.queryStringParameters?.cursor); - return jsonResponse(200, { dataSubjectId: null, accesses: rows, nextCursor }); - } catch { + const cursor = event.queryStringParameters?.cursor; + const exclusiveStartKey = cursor ? decodeCursor(cursor) : undefined; + if (cursor && !exclusiveStartKey) { return jsonResponse(400, { error: "invalid cursor" }); } + + const { rows, nextCursor } = await scanAccesses(ddb, table, limit, exclusiveStartKey); + return jsonResponse(200, { dataSubjectId: null, accesses: rows, nextCursor }); }; diff --git a/secure/log-service/src/handlers/subjectAccessBySubject.ts b/secure/log-service/src/handlers/subjectAccessBySubject.ts index 6e8f252c..1c18cd39 100644 --- a/secure/log-service/src/handlers/subjectAccessBySubject.ts +++ b/secure/log-service/src/handlers/subjectAccessBySubject.ts @@ -1,16 +1,13 @@ import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; import { queryAccesses } from "../lib/subjectAccessRows.js"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); const table = requiredEnv("SUBJECT_ACCESS_TABLE"); -function jsonResponse(statusCode: number, body: unknown) { - return { statusCode, headers: { "content-type": "application/json" }, body: JSON.stringify(body) }; -} - // Data-subject view: a single subject's access trail, queried by their UUID (the PDM DSAR proxy relays here). export const handler: APIGatewayProxyHandlerV2 = async (event) => { const dataSubjectId = event.pathParameters?.dataSubjectId; diff --git a/secure/log-service/src/handlers/subjectAccessIngest.ts b/secure/log-service/src/handlers/subjectAccessIngest.ts index b6e118c4..76c0bc3c 100644 --- a/secure/log-service/src/handlers/subjectAccessIngest.ts +++ b/secure/log-service/src/handlers/subjectAccessIngest.ts @@ -1,6 +1,7 @@ import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { BatchWriteCommand, DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; import { retryAsync } from "ts-retry"; import { requireEnclaveToken } from "../lib/auth.js"; @@ -14,10 +15,6 @@ const table = requiredEnv("SUBJECT_ACCESS_TABLE"); const CHUNK = 25; const MAX_TRY = 4; -function jsonResponse(statusCode: number, body: unknown) { - return { statusCode, headers: { "content-type": "application/json" }, body: JSON.stringify(body) }; -} - function chunk(rows: T[], size: number): T[][] { const out: T[][] = []; for (let i = 0; i < rows.length; i += size) out.push(rows.slice(i, i + size)); diff --git a/secure/log-service/src/lib/auth.ts b/secure/log-service/src/lib/auth.ts index af0cab3b..a9c5bac5 100644 --- a/secure/log-service/src/lib/auth.ts +++ b/secure/log-service/src/lib/auth.ts @@ -1,13 +1,11 @@ -import { jwtEnforced, verifyAccessToken } from "./jwt.js"; +import { verifyAccessToken } from "./jwt.js"; -// Returns null when the caller may proceed, otherwise the error to report. When jwtEnforced is false the -// baseline has no verifier, so no token is required. +// Returns null when the caller may proceed, otherwise the error to report. export async function requireEnclaveToken( authorization: string | undefined, algorithmId: string, runId?: string | null, ): Promise { - if (!jwtEnforced) return null; if (!authorization?.startsWith("Bearer ")) return "missing bearer token"; const validation = await verifyAccessToken(authorization.slice("Bearer ".length)); diff --git a/secure/log-service/src/lib/jwt.ts b/secure/log-service/src/lib/jwt.ts index 5dbe3f38..07069599 100644 --- a/secure/log-service/src/lib/jwt.ts +++ b/secure/log-service/src/lib/jwt.ts @@ -1,20 +1,9 @@ import { requiredEnv } from "@srads/common/env"; import { buildVerifierJwksVerifier } from "@srads/common/jwt"; -const jwksUrl = process.env.VERIFIER_JWKS_URL; - -// Baseline deployments have no verifier and leave these unset, so ingest stays open. secure-rads sets them -// and every post-attestation enclave request must then carry an attested access token. -export const jwtEnforced = Boolean(jwksUrl); - -const verifyWithVerifier = jwksUrl - ? buildVerifierJwksVerifier({ - audience: "log-service", - pubkeySha256: requiredEnv("VERIFIER_JWKS_PUBKEY_SHA256"), - url: new URL(jwksUrl), - }) - : undefined; - -export function verifyAccessToken(token: string) { - return verifyWithVerifier ? verifyWithVerifier(token) : Promise.resolve(null); -} +// Every post-attestation enclave request must carry an attested access token minted for log-service. +export const verifyAccessToken = buildVerifierJwksVerifier({ + audience: "log-service", + pubkeySha256: requiredEnv("VERIFIER_JWKS_PUBKEY_SHA256"), + url: new URL(requiredEnv("VERIFIER_JWKS_URL")), +}); diff --git a/secure/log-service/src/lib/subjectAccess.ts b/secure/log-service/src/lib/subjectAccess.ts index 8f0a578c..64e28c57 100644 --- a/secure/log-service/src/lib/subjectAccess.ts +++ b/secure/log-service/src/lib/subjectAccess.ts @@ -33,10 +33,9 @@ export function parseSubjectAccessBody(body: unknown): SubjectAccessIngest | { e return { ...result.data, receivedAt: new Date().toISOString() }; } -// The sort key is (timestamp, algorithmId, runId). That tuple is unique per item: a data subject's record -// lives on exactly one PDM page, so it is read once per run by exactly one algorithm. Dropping the old -// random nonce makes writes idempotent - a redelivered ingest overwrites an identical row instead of -// appending a duplicate. +// The sort key is (timestamp, algorithmId, runId), unique per item: a data subject's record lives on exactly one +// PDM page, so it is read once per run by exactly one algorithm. A chunk retried inside one ingest overwrites an +// identical row; a repeat ingest for the same run is rejected with 409 before any write. export function toItem(row: SubjectAccessRow): Record { return { DataSubjectId: row.dataSubjectId, diff --git a/secure/log-service/src/lib/subjectAccessRows.ts b/secure/log-service/src/lib/subjectAccessRows.ts index bafe0180..c921c89b 100644 --- a/secure/log-service/src/lib/subjectAccessRows.ts +++ b/secure/log-service/src/lib/subjectAccessRows.ts @@ -1,5 +1,6 @@ import type { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb"; import { paginateQuery, ScanCommand } from "@aws-sdk/lib-dynamodb"; +import { encodeCursor } from "@srads/common/cursor"; import { type SubjectAccessRow, toRow } from "./subjectAccess.js"; export async function queryAccesses( @@ -27,31 +28,19 @@ export interface AccessPage { nextCursor: string | null; } -function encodeCursor(key: Record): string { - return Buffer.from(JSON.stringify(key)).toString("base64url"); -} - -function decodeCursor(cursor: string): Record { - const parsed: unknown = JSON.parse(Buffer.from(cursor, "base64url").toString()); - if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) { - throw new Error("cursor must encode an object"); - } - return parsed as Record; -} - // The access table can hold tens of millions of rows, so a single Lambda cannot scan it. Return one page // and an opaque cursor for the next; the caller pages until nextCursor is null. export async function scanAccesses( ddb: DynamoDBDocumentClient, table: string, limit: number, - cursor?: string, + exclusiveStartKey?: Record, ): Promise { const result = await ddb.send( new ScanCommand({ TableName: table, Limit: limit, - ExclusiveStartKey: cursor ? decodeCursor(cursor) : undefined, + ExclusiveStartKey: exclusiveStartKey, }), ); return { diff --git a/secure/pdm-service/README.md b/secure/pdm-service/README.md index ee43b3a5..5440f95f 100644 --- a/secure/pdm-service/README.md +++ b/secure/pdm-service/README.md @@ -18,7 +18,7 @@ Bun is used as the local dev/bundle tool only (`bun install`) - the Lambda itsel - A second domain name (`pdm-mtls.sr.secure-rads.org`) + ACM certificate for the mTLS count API, passed as `mtlsDomainName`/`mtlsCertificateArn`. The wildcard `*.sr.secure-rads.org` certificate covers it. - The execution-service client certificate public cert in the stack's `TruststoreBucket`, and the matching cert/key in SSM at `/secure-rads/pdm-service/client-cert` and `/secure-rads/pdm-service/client-key`. - verifier-service's public (attest) domain TLS leaf cert pubkey SHA-256, passed as the `verifierJwksPubkeySha256` param - pinned on JWKS fetches on top of normal CA verification. Without the pin, a MITM could swap in its own JWKS and mint tokens that verify locally. -- verifier-service deployed with its ML-DSA-87 signing key at SSM `/verifier-service/jwt-signing-key` (see secure/verifier-service/README.md). +- verifier-service deployed with its ML-DSA-87 signing key at SSM `/secure-rads/verifier-service/jwt-signing-key` (see secure/verifier-service/README.md). ## Deploy diff --git a/secure/pdm-service/bun.lock b/secure/pdm-service/bun.lock index 228cd522..4ca6f9df 100644 --- a/secure/pdm-service/bun.lock +++ b/secure/pdm-service/bun.lock @@ -6,10 +6,8 @@ "name": "pdm-service", "dependencies": { "@aws-sdk/client-dynamodb": "^3.700.0", - "@aws-sdk/client-ssm": "^3.700.0", "@aws-sdk/lib-dynamodb": "^3.700.0", "@srads/common": "file:../../packages/common", - "jose": "^6.2.10", }, "devDependencies": { "@biomejs/biome": "^2.5.10", @@ -24,8 +22,6 @@ "packages": { "@aws-sdk/client-dynamodb": ["@aws-sdk/client-dynamodb@3.1118.0", "", { "dependencies": { "@aws-sdk/core": "^3.977.9", "@aws-sdk/credential-provider-node": "^3.972.81", "@aws-sdk/dynamodb-codec": "^3.973.44", "@aws-sdk/middleware-endpoint-discovery": "^3.972.30", "@aws-sdk/types": "^3.974.5", "@smithy/core": "^3.33.3", "@smithy/fetch-http-handler": "^5.7.2", "@smithy/node-http-handler": "^4.11.3", "@smithy/types": "^4.17.2", "tslib": "^2.6.2" } }, "sha512-svEO204aN18SV433vZ1+VRCdRrMhQto52pTDOJwkwO5FcydmZa+Ld+lWu0k6OC50Ft4qJb1WrG2lsEno/++lGg=="], - "@aws-sdk/client-ssm": ["@aws-sdk/client-ssm@3.1169.0", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/credential-provider-node": "^3.972.97", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/fetch-http-handler": "^5.8.1", "@smithy/node-http-handler": "^4.14.2", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-EAqUE22l8bOeCPMNxnahMhKrWW2n7siZjVL1rNWWaD9prTTwDbMf2xeaAOqVx5lLOz+3sSuicM6OMY5yYTR1Eg=="], - "@aws-sdk/core": ["@aws-sdk/core@3.977.9", "", { "dependencies": { "@aws-sdk/types": "^3.974.5", "@aws-sdk/xml-builder": "^3.972.40", "@aws/lambda-invoke-store": "^0.3.0", "@smithy/core": "^3.33.3", "@smithy/signature-v4": "^5.6.12", "@smithy/types": "^4.17.2", "bowser": "^2.11.0", "tslib": "^2.6.2" } }, "sha512-reqPFEQrZxDZpeGj4PFMepBeR5LGYHRqq/L0motTzgFkCRBA4rFdaVXDSLYyGHhxVz7sT2PDnPN9CluGSfgyJA=="], "@aws-sdk/credential-provider-env": ["@aws-sdk/credential-provider-env@3.972.70", "", { "dependencies": { "@aws-sdk/core": "^3.977.9", "@aws-sdk/types": "^3.974.5", "@smithy/core": "^3.33.3", "@smithy/types": "^4.17.2", "tslib": "^2.6.2" } }, "sha512-H404B7dJl2mCrBqahDEYsanB0xhdDp6tXnXcTUnXmmpy2Q3J0Ho0bUajZ2jr/RdwzCyS59Gi8xXIFwPLGBl6Uw=="], @@ -182,7 +178,7 @@ "@smithy/types": ["@smithy/types@4.17.2", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-FOKpVZob9MPTn2znRzGrnsMHv7BOsKVw3XiP/cOyYLDVZ9qKp4nifIiSCuUU/fIj5Vu0UOAxCFr+qRAtG0NUkA=="], - "@srads/common": ["@srads/common@file:../../packages/common", { "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], + "@srads/common": ["@srads/common@file:../../packages/common", { "dependencies": { "csv-stringify": "^6.8.3", "jose": "^6.2.10" }, "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], "@tybys/wasm-util": ["@tybys/wasm-util@0.10.3", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-F3fo1MYrRJYL3zER0OUOmkutjr1Vp23m7OsSgp7nq4SP6OqX6C/56XFIPAl5bt3zaBRjmW7SGz3u/6LwFpYcOg=="], @@ -192,6 +188,8 @@ "bowser": ["bowser@2.14.1", "", {}, "sha512-tzPjzCxygAKWFOJP011oxFHs57HzIhOEracIgAePE4pqB3LikALKnSzUyU4MGs9/iCEUuHlAJTjTc5M+u7YEGg=="], + "csv-stringify": ["csv-stringify@6.9.0", "", {}, "sha512-6b3e29CILFfSQ2nDRuZMRROzQOpPuJ+s8zPB5H7eK5ncXBbFOyVuRLU5Sx/zAUmVri3Ly49GyC8NEme4SVSAbA=="], + "fd-package-json": ["fd-package-json@2.0.0", "", { "dependencies": { "walk-up-path": "^4.0.0" } }, "sha512-jKmm9YtsNXN789RS/0mSzOC1NUq9mkVd65vbSSVsKdjGvYXBuE4oWe2QOEoFeRmJg+lPuZxpmrfFclNhoRMneQ=="], "fdir": ["fdir@6.5.0", "", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg=="], @@ -241,57 +239,5 @@ "yaml": ["yaml@2.9.0", "", { "bin": { "yaml": "bin.mjs" } }, "sha512-2AvhNX3mb8zd6Zy7INTtSpl1F15HW6Wnqj0srWlkKLcpYl/gMIMJiyuGq2KeI2YFxUPjdlB+3Lc10seMLtL4cA=="], "zod": ["zod@4.4.3", "", {}, "sha512-ytENFjIJFl2UwYglde2jchW2Hwm4GJFLDiSXWdTrJQBIN9Fcyp7n4DhxJEiWNAJMV1/BqWfW/kkg71UDcHJyTQ=="], - - "@aws-sdk/client-ssm/@aws-sdk/core": ["@aws-sdk/core@3.981.0", "", { "dependencies": { "@aws-sdk/types": "^3.975.1", "@aws-sdk/xml-builder": "^3.972.43", "@aws/lambda-invoke-store": "^0.3.0", "@smithy/core": "^3.40.0", "@smithy/signature-v4": "^5.7.5", "@smithy/types": "^4.20.0", "bowser": "^2.11.0", "tslib": "^2.6.2" } }, "sha512-Mnu7gaDrC5UCdyH8uLxLfB2eWbjE/HbjKX1U1J2VQxG3TTATUDObW2wU3I8iH3e9YH5NN2CY6w1mlAIe2XJ3jg=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node": ["@aws-sdk/credential-provider-node@3.972.97", "", { "dependencies": { "@aws-sdk/credential-provider-env": "^3.972.84", "@aws-sdk/credential-provider-http": "^3.972.86", "@aws-sdk/credential-provider-ini": "^3.973.30", "@aws-sdk/credential-provider-process": "^3.972.84", "@aws-sdk/credential-provider-sso": "^3.973.28", "@aws-sdk/credential-provider-web-identity": "^3.972.90", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/credential-provider-imds": "^4.5.2", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-E4a0IXXJVsIdo/K9roX4JAEfI0JJr7KTPymkbKgETRDqEcLygE4ZlLTe24+7Qkh8Dl5YpnPd+Tt0DOPJDFXIwA=="], - - "@aws-sdk/client-ssm/@aws-sdk/types": ["@aws-sdk/types@3.975.1", "", { "dependencies": { "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-7rGxUkCB2QPoQOeJmonmAICTN2zrH+fpmi1p4Iwu72lnxNaMhOgqcbpyddifnM1DBb19TWQ1u6z/XjkaFNEDWw=="], - - "@aws-sdk/client-ssm/@smithy/core": ["@smithy/core@3.40.0", "", { "dependencies": { "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-DssGno52pzZ5m6RlDtyKuBIpZNPg9pqgs0CnNDKz9IatxCsmvNmJNn5Zn6rf77MthZo9wf89OvZFhTY/RwxhxQ=="], - - "@aws-sdk/client-ssm/@smithy/fetch-http-handler": ["@smithy/fetch-http-handler@5.8.1", "", { "dependencies": { "@smithy/core": "^3.39.0", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-h8BdMUrUBhMhMaeK7QqAdINRZezCGuYOCpcOZZ1ewxbHST9rdTd09xwNpvLTYfzDRehxQiReK4SKbdYZxBA+ew=="], - - "@aws-sdk/client-ssm/@smithy/node-http-handler": ["@smithy/node-http-handler@4.14.2", "", { "dependencies": { "@smithy/core": "^3.39.0", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-i1uORV1v3qBqP43ayRKzIdm1q5x14tf8N4Dd06/QUX1Szm6VxHMrTsu20X5E63UFsaNZCRjI4SXG0jDmqYa+3w=="], - - "@aws-sdk/client-ssm/@smithy/types": ["@smithy/types@4.20.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-lCA6QG22dPk9ecHbv91jDQZsmtPUjdS1aE2Il6NNPqe7DrYc0dZQi6DhcESk2KYXH2sp5xbAcGdYMZDFnuzA2A=="], - - "@aws-sdk/client-ssm/@aws-sdk/core/@aws-sdk/xml-builder": ["@aws-sdk/xml-builder@3.972.43", "", { "dependencies": { "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-rG8QVx4DOrJWptsogu1Aq+CDsnPKaBrAlJpKLxrJrIDXAq1ElnW0yQjjBnlWSXll0cDakCG6UDvaqwz0A9d9Og=="], - - "@aws-sdk/client-ssm/@aws-sdk/core/@smithy/signature-v4": ["@smithy/signature-v4@5.7.5", "", { "dependencies": { "@smithy/core": "^3.38.0", "@smithy/types": "^4.19.0", "tslib": "^2.6.2" } }, "sha512-WPjdr5oWOk1LArpI4pavu+fSo+/evi0Re1olxGvqwuZopd4gYR1UGCi+Soyn/IjmafqbWs+ZC+3AKxJS3ZpwUg=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-env": ["@aws-sdk/credential-provider-env@3.972.84", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-akZJetiMVeLRHsKzYh3LamDCo74ZUCeo0XoyRKMEMZT5qP7ReM6LhpioBCyuqKP5Vav5gEOeCmaQV0VVQr1Meg=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-http": ["@aws-sdk/credential-provider-http@3.972.86", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/fetch-http-handler": "^5.8.1", "@smithy/node-http-handler": "^4.14.2", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-U4mHaDRPWAn63yhl7FXIzbppNmW1F+4dSLeuiUpej2v3Xb6rGwvayEJ8SdlrdMV+/mZtd+GStTEP2HqurEzXtw=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-ini": ["@aws-sdk/credential-provider-ini@3.973.30", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/credential-provider-env": "^3.972.84", "@aws-sdk/credential-provider-http": "^3.972.86", "@aws-sdk/credential-provider-login": "^3.972.92", "@aws-sdk/credential-provider-process": "^3.972.84", "@aws-sdk/credential-provider-sso": "^3.973.28", "@aws-sdk/credential-provider-web-identity": "^3.972.90", "@aws-sdk/nested-clients": "^3.998.3", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/credential-provider-imds": "^4.5.2", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-r6r6499GWoGN943NA5YEhBEQ6TEOGTf7tTOBhHd/zw0UbNvSzd1/zPCNcDkPmRarA+e24X7KgxutqxjoWcskBg=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-process": ["@aws-sdk/credential-provider-process@3.972.84", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-199C6OpNejd0nq9GFAkEFIKids1FL0R6LJtL9c1OTiDOXki7S1OduuPxW4+hE0LwndcYJ7YHOuYTlqScfpCocA=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-sso": ["@aws-sdk/credential-provider-sso@3.973.28", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/nested-clients": "^3.998.3", "@aws-sdk/token-providers": "3.1166.0", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-bGg7wH8wVDJQIcJggO9lg1ZYbG7l+PbLwHuM3Bi/e1TlCZhU712JS1W3tdRpyptdJD1UGyhBNGO/YrhrQCHKbg=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-web-identity": ["@aws-sdk/credential-provider-web-identity@3.972.90", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/nested-clients": "^3.998.3", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-duLeE3xlf0viHeH+1RM4z5duR3b32BCZTWVMu+MbxFPjQBxy7hmIGEqt5hekuFPRuXoyhMovjNl+PNNsb5oiGQ=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-ini/@aws-sdk/credential-provider-login": ["@aws-sdk/credential-provider-login@3.972.92", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/nested-clients": "^3.998.3", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-96bcp9Pe/Xd60OEwncZ+kAQTQSu+fJnpUGz1qE6ghF5jnETmrk8XMU86mIP3lolvnCgR61XbZ+Ht6hdBjiQOmQ=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-ini/@aws-sdk/nested-clients": ["@aws-sdk/nested-clients@3.998.3", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/signature-v4-multi-region": "^3.996.52", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/fetch-http-handler": "^5.8.1", "@smithy/node-http-handler": "^4.14.2", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-acHTTzMB13CU6dU4sxABYExMI3PQM2zStWH2MiUwJp/7QKTrLg2f7mbzSXoegW2kYOk2tdqQYagsZrWB8Xv7eA=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-sso/@aws-sdk/nested-clients": ["@aws-sdk/nested-clients@3.998.3", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/signature-v4-multi-region": "^3.996.52", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/fetch-http-handler": "^5.8.1", "@smithy/node-http-handler": "^4.14.2", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-acHTTzMB13CU6dU4sxABYExMI3PQM2zStWH2MiUwJp/7QKTrLg2f7mbzSXoegW2kYOk2tdqQYagsZrWB8Xv7eA=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-sso/@aws-sdk/token-providers": ["@aws-sdk/token-providers@3.1166.0", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/nested-clients": "^3.998.3", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-ngJ8mxXqtQ9mnp7QV6TWKJCxkpjVfPWxKQSc2FYhCyCfOVFIGdFv7P+/RqVffFrJAorwBPpktnv32gNlcEgF4g=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-web-identity/@aws-sdk/nested-clients": ["@aws-sdk/nested-clients@3.998.3", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/signature-v4-multi-region": "^3.996.52", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/fetch-http-handler": "^5.8.1", "@smithy/node-http-handler": "^4.14.2", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-acHTTzMB13CU6dU4sxABYExMI3PQM2zStWH2MiUwJp/7QKTrLg2f7mbzSXoegW2kYOk2tdqQYagsZrWB8Xv7eA=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-ini/@aws-sdk/nested-clients/@aws-sdk/signature-v4-multi-region": ["@aws-sdk/signature-v4-multi-region@3.996.52", "", { "dependencies": { "@aws-sdk/types": "^3.975.1", "@smithy/signature-v4": "^5.7.5", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-6W6SjGc8OXUhMzNxU1X922ghD+PP1XvzmCk5Scui0jaYsLezycMYR1RaLp5xTIOUrhTXyb4DnAbPr3fBgmdnzg=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-sso/@aws-sdk/nested-clients/@aws-sdk/signature-v4-multi-region": ["@aws-sdk/signature-v4-multi-region@3.996.52", "", { "dependencies": { "@aws-sdk/types": "^3.975.1", "@smithy/signature-v4": "^5.7.5", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-6W6SjGc8OXUhMzNxU1X922ghD+PP1XvzmCk5Scui0jaYsLezycMYR1RaLp5xTIOUrhTXyb4DnAbPr3fBgmdnzg=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-web-identity/@aws-sdk/nested-clients/@aws-sdk/signature-v4-multi-region": ["@aws-sdk/signature-v4-multi-region@3.996.52", "", { "dependencies": { "@aws-sdk/types": "^3.975.1", "@smithy/signature-v4": "^5.7.5", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-6W6SjGc8OXUhMzNxU1X922ghD+PP1XvzmCk5Scui0jaYsLezycMYR1RaLp5xTIOUrhTXyb4DnAbPr3fBgmdnzg=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-ini/@aws-sdk/nested-clients/@aws-sdk/signature-v4-multi-region/@smithy/signature-v4": ["@smithy/signature-v4@5.7.5", "", { "dependencies": { "@smithy/core": "^3.38.0", "@smithy/types": "^4.19.0", "tslib": "^2.6.2" } }, "sha512-WPjdr5oWOk1LArpI4pavu+fSo+/evi0Re1olxGvqwuZopd4gYR1UGCi+Soyn/IjmafqbWs+ZC+3AKxJS3ZpwUg=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-sso/@aws-sdk/nested-clients/@aws-sdk/signature-v4-multi-region/@smithy/signature-v4": ["@smithy/signature-v4@5.7.5", "", { "dependencies": { "@smithy/core": "^3.38.0", "@smithy/types": "^4.19.0", "tslib": "^2.6.2" } }, "sha512-WPjdr5oWOk1LArpI4pavu+fSo+/evi0Re1olxGvqwuZopd4gYR1UGCi+Soyn/IjmafqbWs+ZC+3AKxJS3ZpwUg=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-web-identity/@aws-sdk/nested-clients/@aws-sdk/signature-v4-multi-region/@smithy/signature-v4": ["@smithy/signature-v4@5.7.5", "", { "dependencies": { "@smithy/core": "^3.38.0", "@smithy/types": "^4.19.0", "tslib": "^2.6.2" } }, "sha512-WPjdr5oWOk1LArpI4pavu+fSo+/evi0Re1olxGvqwuZopd4gYR1UGCi+Soyn/IjmafqbWs+ZC+3AKxJS3ZpwUg=="], } } diff --git a/secure/pdm-service/knip.json b/secure/pdm-service/knip.json index 78914330..7db903ed 100644 --- a/secure/pdm-service/knip.json +++ b/secure/pdm-service/knip.json @@ -5,9 +5,5 @@ ], "project": [ "src/**/*.ts" - ], - "ignoreDependencies": [ - "jose", - "@aws-sdk/client-ssm" ] } diff --git a/secure/pdm-service/package.json b/secure/pdm-service/package.json index 9491d0a3..38e98764 100644 --- a/secure/pdm-service/package.json +++ b/secure/pdm-service/package.json @@ -22,8 +22,6 @@ "dependencies": { "@aws-sdk/client-dynamodb": "^3.700.0", "@aws-sdk/lib-dynamodb": "^3.700.0", - "@srads/common": "file:../../packages/common", - "jose": "^6.2.10", - "@aws-sdk/client-ssm": "^3.700.0" + "@srads/common": "file:../../packages/common" } } diff --git a/secure/pdm-service/src/handlers/count.ts b/secure/pdm-service/src/handlers/count.ts index 23205e10..8083e8ed 100644 --- a/secure/pdm-service/src/handlers/count.ts +++ b/secure/pdm-service/src/handlers/count.ts @@ -1,31 +1,38 @@ import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient, QueryCommand } from "@aws-sdk/lib-dynamodb"; import { CostPhase, costEvent, recordRequest } from "@srads/common/cost"; +import { ifTableExists, withThrottleRetry } from "@srads/common/dynamo"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; +import { isAlgorithmId } from "@srads/common/ids"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); const tablePrefix = requiredEnv("PDM_TABLE_PREFIX"); -const ALGORITHM_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; -const MAX_QUERY_ATTEMPTS = 8; - -async function queryWithRetry(command: QueryCommand) { - for (let attempt = 1; ; attempt++) { - try { - return await ddb.send(command); - } catch (error) { - if (!(error instanceof Error) || error.name !== "ThrottlingException" || attempt >= MAX_QUERY_ATTEMPTS) { - throw error; - } - const backoffMs = 50 * 2 ** attempt + Math.random() * 100; - await new Promise((resolve) => setTimeout(resolve, backoffMs)); - } - } -} - -function jsonResponse(statusCode: number, body: unknown) { - return { statusCode, headers: { "content-type": "application/json" }, body: JSON.stringify(body) }; +async function countRecords(algorithmId: string, atLeast: number | undefined) { + let count = 0; + let readCapacityUnits = 0; + let exclusiveStartKey: Record | undefined; + do { + const page = await withThrottleRetry(() => + ddb.send( + new QueryCommand({ + TableName: `${tablePrefix}-${algorithmId}`, + KeyConditionExpression: "AlgorithmId = :a", + ExpressionAttributeValues: { ":a": algorithmId }, + Select: "COUNT", + ExclusiveStartKey: exclusiveStartKey, + ReturnConsumedCapacity: "TOTAL", + }), + ), + ); + count += page.Count ?? 0; + readCapacityUnits += page.ConsumedCapacity?.CapacityUnits ?? 0; + if (atLeast !== undefined && count >= atLeast) break; + exclusiveStartKey = page.LastEvaluatedKey as Record | undefined; + } while (exclusiveStartKey); + return { count, readCapacityUnits }; } // Metadata-only count used by execution-service's size check. When `size` is set the count may stop early and @@ -36,7 +43,7 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => { if (!algorithmId) { return jsonResponse(400, { error: "missing algorithmId" }); } - if (!ALGORITHM_ID.test(algorithmId)) { + if (!isAlgorithmId(algorithmId)) { return jsonResponse(400, { error: "invalid algorithmId" }); } @@ -51,27 +58,12 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => { } const runId = event.headers["x-run-id"] ?? ""; - let count = 0; - let readCapacityUnits = 0; - let exclusiveStartKey: Record | undefined; - do { - const page = await queryWithRetry( - new QueryCommand({ - TableName: `${tablePrefix}-${algorithmId}`, - KeyConditionExpression: "AlgorithmId = :a", - ExpressionAttributeValues: { ":a": algorithmId }, - Select: "COUNT", - ExclusiveStartKey: exclusiveStartKey, - ReturnConsumedCapacity: "TOTAL", - }), - ); - count += page.Count ?? 0; - readCapacityUnits += page.ConsumedCapacity?.CapacityUnits ?? 0; - if (atLeast !== undefined && count >= atLeast) break; - exclusiveStartKey = page.LastEvaluatedKey as Record | undefined; - } while (exclusiveStartKey); + const counted = await ifTableExists(countRecords(algorithmId, atLeast)); + if (!counted) { + return jsonResponse(404, { error: "algorithm not found" }); + } - await costEvent(algorithmId, runId, CostPhase.Execution, "dynamodb", "read-capacity", readCapacityUnits); + await costEvent(algorithmId, runId, CostPhase.Execution, "dynamodb", "read-capacity", counted.readCapacityUnits); await recordRequest(algorithmId, runId, CostPhase.Execution, startedAt); - return jsonResponse(200, { algorithmId, count }); + return jsonResponse(200, { algorithmId, count: counted.count }); }; diff --git a/secure/pdm-service/src/handlers/records.ts b/secure/pdm-service/src/handlers/records.ts index 35245e2d..170f85aa 100644 --- a/secure/pdm-service/src/handlers/records.ts +++ b/secure/pdm-service/src/handlers/records.ts @@ -1,44 +1,18 @@ import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient, QueryCommand } from "@aws-sdk/lib-dynamodb"; import { CostPhase, costEvent, recordRequest } from "@srads/common/cost"; +import { decodeCursor, encodeCursor } from "@srads/common/cursor"; +import { ifTableExists, withThrottleRetry } from "@srads/common/dynamo"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; +import { isAlgorithmId } from "@srads/common/ids"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; import { verifyAccessToken } from "../lib/jwt.js"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); const tablePrefix = requiredEnv("PDM_TABLE_PREFIX"); -const ALGORITHM_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; const PAGE_SIZE = 500; -const MAX_QUERY_ATTEMPTS = 8; - -async function queryWithRetry(command: QueryCommand) { - for (let attempt = 1; ; attempt++) { - try { - return await ddb.send(command); - } catch (error) { - if (!(error instanceof Error) || error.name !== "ThrottlingException" || attempt >= MAX_QUERY_ATTEMPTS) { - throw error; - } - const backoffMs = 50 * 2 ** attempt + Math.random() * 100; - await new Promise((resolve) => setTimeout(resolve, backoffMs)); - } - } -} - -function jsonResponse(statusCode: number, body: unknown) { - return { statusCode, headers: { "content-type": "application/json" }, body: JSON.stringify(body) }; -} - -function decodeCursor(cursor: string): Record | undefined { - try { - const parsed: unknown = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8")); - if (typeof parsed !== "object" || parsed === null) return undefined; - return parsed as Record; - } catch { - return undefined; - } -} export const handler: APIGatewayProxyHandlerV2 = async (event) => { const startedAt = process.hrtime.bigint(); @@ -52,7 +26,7 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => { if (!validation) { return jsonResponse(401, { error: "invalid token" }); } - if (!ALGORITHM_ID.test(validation.algorithmId)) { + if (!isAlgorithmId(validation.algorithmId)) { return jsonResponse(401, { error: "invalid token" }); } const runId = validation.runId; @@ -66,16 +40,23 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => { } } - const result = await queryWithRetry( - new QueryCommand({ - TableName: `${tablePrefix}-${validation.algorithmId}`, - KeyConditionExpression: "AlgorithmId = :a", - ExpressionAttributeValues: { ":a": validation.algorithmId }, - Limit: PAGE_SIZE, - ExclusiveStartKey: exclusiveStartKey, - ReturnConsumedCapacity: "TOTAL", - }), + const result = await ifTableExists( + withThrottleRetry(() => + ddb.send( + new QueryCommand({ + TableName: `${tablePrefix}-${validation.algorithmId}`, + KeyConditionExpression: "AlgorithmId = :a", + ExpressionAttributeValues: { ":a": validation.algorithmId }, + Limit: PAGE_SIZE, + ExclusiveStartKey: exclusiveStartKey, + ReturnConsumedCapacity: "TOTAL", + }), + ), + ), ); + if (!result) { + return jsonResponse(404, { error: "algorithm not found" }); + } await costEvent( validation.algorithmId, runId, @@ -90,9 +71,7 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => { const items = result.Items ?? []; const records = items.map((item) => ({ recordId: item.RecordId, data: item.Data })); const dataSubjectIds = items.map((item) => (typeof item.DataSubjectId === "string" ? item.DataSubjectId : "")); - const nextCursor = result.LastEvaluatedKey - ? Buffer.from(JSON.stringify(result.LastEvaluatedKey)).toString("base64url") - : null; + const nextCursor = result.LastEvaluatedKey ? encodeCursor(result.LastEvaluatedKey) : null; await recordRequest(validation.algorithmId, runId, CostPhase.Execution, startedAt); return jsonResponse(200, { algorithmId: validation.algorithmId, records, dataSubjectIds, nextCursor }); diff --git a/secure/pdm-service/src/handlers/subject.ts b/secure/pdm-service/src/handlers/subject.ts index b1047885..6863875f 100644 --- a/secure/pdm-service/src/handlers/subject.ts +++ b/secure/pdm-service/src/handlers/subject.ts @@ -1,12 +1,9 @@ import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; const logHost = requiredEnv("LOG_HOST"); -function jsonResponse(statusCode: number, body: unknown) { - return { statusCode, headers: { "content-type": "application/json" }, body: JSON.stringify(body) }; -} - // Public DSAR lookup: the data subject presents only an opaque UUID, PDM relays the query to log-service. export const handler: APIGatewayProxyHandlerV2 = async (event) => { const dataSubjectId = event.pathParameters?.dataSubjectId; diff --git a/secure/result-consumer/bun.lock b/secure/result-consumer/bun.lock index b45126fd..cee90159 100644 --- a/secure/result-consumer/bun.lock +++ b/secure/result-consumer/bun.lock @@ -6,7 +6,6 @@ "name": "result-consumer", "dependencies": { "@aws-sdk/client-dynamodb": "^3.700.0", - "@aws-sdk/client-ssm": "^3.700.0", "@aws-sdk/lib-dynamodb": "^3.700.0", "@srads/common": "file:../../packages/common", }, @@ -23,8 +22,6 @@ "packages": { "@aws-sdk/client-dynamodb": ["@aws-sdk/client-dynamodb@3.1118.0", "", { "dependencies": { "@aws-sdk/core": "^3.977.9", "@aws-sdk/credential-provider-node": "^3.972.81", "@aws-sdk/dynamodb-codec": "^3.973.44", "@aws-sdk/middleware-endpoint-discovery": "^3.972.30", "@aws-sdk/types": "^3.974.5", "@smithy/core": "^3.33.3", "@smithy/fetch-http-handler": "^5.7.2", "@smithy/node-http-handler": "^4.11.3", "@smithy/types": "^4.17.2", "tslib": "^2.6.2" } }, "sha512-svEO204aN18SV433vZ1+VRCdRrMhQto52pTDOJwkwO5FcydmZa+Ld+lWu0k6OC50Ft4qJb1WrG2lsEno/++lGg=="], - "@aws-sdk/client-ssm": ["@aws-sdk/client-ssm@3.1169.0", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/credential-provider-node": "^3.972.97", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/fetch-http-handler": "^5.8.1", "@smithy/node-http-handler": "^4.14.2", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-EAqUE22l8bOeCPMNxnahMhKrWW2n7siZjVL1rNWWaD9prTTwDbMf2xeaAOqVx5lLOz+3sSuicM6OMY5yYTR1Eg=="], - "@aws-sdk/core": ["@aws-sdk/core@3.977.9", "", { "dependencies": { "@aws-sdk/types": "^3.974.5", "@aws-sdk/xml-builder": "^3.972.40", "@aws/lambda-invoke-store": "^0.3.0", "@smithy/core": "^3.33.3", "@smithy/signature-v4": "^5.6.12", "@smithy/types": "^4.17.2", "bowser": "^2.11.0", "tslib": "^2.6.2" } }, "sha512-reqPFEQrZxDZpeGj4PFMepBeR5LGYHRqq/L0motTzgFkCRBA4rFdaVXDSLYyGHhxVz7sT2PDnPN9CluGSfgyJA=="], "@aws-sdk/credential-provider-env": ["@aws-sdk/credential-provider-env@3.972.70", "", { "dependencies": { "@aws-sdk/core": "^3.977.9", "@aws-sdk/types": "^3.974.5", "@smithy/core": "^3.33.3", "@smithy/types": "^4.17.2", "tslib": "^2.6.2" } }, "sha512-H404B7dJl2mCrBqahDEYsanB0xhdDp6tXnXcTUnXmmpy2Q3J0Ho0bUajZ2jr/RdwzCyS59Gi8xXIFwPLGBl6Uw=="], @@ -181,7 +178,7 @@ "@smithy/types": ["@smithy/types@4.17.2", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-FOKpVZob9MPTn2znRzGrnsMHv7BOsKVw3XiP/cOyYLDVZ9qKp4nifIiSCuUU/fIj5Vu0UOAxCFr+qRAtG0NUkA=="], - "@srads/common": ["@srads/common@file:../../packages/common", { "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], + "@srads/common": ["@srads/common@file:../../packages/common", { "dependencies": { "csv-stringify": "^6.8.3", "jose": "^6.2.10" }, "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], "@tybys/wasm-util": ["@tybys/wasm-util@0.10.3", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-F3fo1MYrRJYL3zER0OUOmkutjr1Vp23m7OsSgp7nq4SP6OqX6C/56XFIPAl5bt3zaBRjmW7SGz3u/6LwFpYcOg=="], @@ -191,6 +188,8 @@ "bowser": ["bowser@2.14.1", "", {}, "sha512-tzPjzCxygAKWFOJP011oxFHs57HzIhOEracIgAePE4pqB3LikALKnSzUyU4MGs9/iCEUuHlAJTjTc5M+u7YEGg=="], + "csv-stringify": ["csv-stringify@6.9.0", "", {}, "sha512-6b3e29CILFfSQ2nDRuZMRROzQOpPuJ+s8zPB5H7eK5ncXBbFOyVuRLU5Sx/zAUmVri3Ly49GyC8NEme4SVSAbA=="], + "fd-package-json": ["fd-package-json@2.0.0", "", { "dependencies": { "walk-up-path": "^4.0.0" } }, "sha512-jKmm9YtsNXN789RS/0mSzOC1NUq9mkVd65vbSSVsKdjGvYXBuE4oWe2QOEoFeRmJg+lPuZxpmrfFclNhoRMneQ=="], "fdir": ["fdir@6.5.0", "", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg=="], @@ -201,6 +200,8 @@ "jiti": ["jiti@2.7.0", "", { "bin": { "jiti": "lib/jiti-cli.mjs" } }, "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ=="], + "jose": ["jose@6.2.17", "", {}, "sha512-wOuK9V1yujQFH5S0ZWmLcDZN7+IKh9bUCC2ZPCf2HDlol3WWHy+PPyNjEI75FXRLMp3vDKQcupP59xhVU95hcg=="], + "knip": ["knip@6.32.3", "", { "dependencies": { "fdir": "^6.5.0", "formatly": "^0.3.0", "get-tsconfig": "4.14.1", "jiti": "^2.7.0", "oxc-parser": "^0.143.0", "oxc-resolver": "11.24.2", "picomatch": "^4.0.5", "smol-toml": "^1.7.1", "strip-json-comments": "5.0.3", "tinyglobby": "^0.2.17", "unbash": "^4.0.9", "yaml": "^2.9.0", "zod": "^4.4.3" }, "bin": { "knip": "bin/knip.js", "knip-bun": "bin/knip-bun.js" } }, "sha512-wOJ1Av8PwKqFO0wU7F64vzIcUjxhrieA3Tc2lmeK9C9prpxq+TeG2ewNH5tCaBVZwXNPp6lJkrr+IhZ20iqkMA=="], "mnemonist": ["mnemonist@0.38.3", "", { "dependencies": { "obliterator": "^1.6.1" } }, "sha512-2K9QYubXx/NAjv4VLq1d1Ly8pWNC5L3BrixtdkyTegXWJIqY+zLNDhhX/A+ZwWt70tB1S8H4BE8FLYEFyNoOBw=="], @@ -238,57 +239,5 @@ "yaml": ["yaml@2.9.0", "", { "bin": { "yaml": "bin.mjs" } }, "sha512-2AvhNX3mb8zd6Zy7INTtSpl1F15HW6Wnqj0srWlkKLcpYl/gMIMJiyuGq2KeI2YFxUPjdlB+3Lc10seMLtL4cA=="], "zod": ["zod@4.4.3", "", {}, "sha512-ytENFjIJFl2UwYglde2jchW2Hwm4GJFLDiSXWdTrJQBIN9Fcyp7n4DhxJEiWNAJMV1/BqWfW/kkg71UDcHJyTQ=="], - - "@aws-sdk/client-ssm/@aws-sdk/core": ["@aws-sdk/core@3.981.0", "", { "dependencies": { "@aws-sdk/types": "^3.975.1", "@aws-sdk/xml-builder": "^3.972.43", "@aws/lambda-invoke-store": "^0.3.0", "@smithy/core": "^3.40.0", "@smithy/signature-v4": "^5.7.5", "@smithy/types": "^4.20.0", "bowser": "^2.11.0", "tslib": "^2.6.2" } }, "sha512-Mnu7gaDrC5UCdyH8uLxLfB2eWbjE/HbjKX1U1J2VQxG3TTATUDObW2wU3I8iH3e9YH5NN2CY6w1mlAIe2XJ3jg=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node": ["@aws-sdk/credential-provider-node@3.972.97", "", { "dependencies": { "@aws-sdk/credential-provider-env": "^3.972.84", "@aws-sdk/credential-provider-http": "^3.972.86", "@aws-sdk/credential-provider-ini": "^3.973.30", "@aws-sdk/credential-provider-process": "^3.972.84", "@aws-sdk/credential-provider-sso": "^3.973.28", "@aws-sdk/credential-provider-web-identity": "^3.972.90", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/credential-provider-imds": "^4.5.2", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-E4a0IXXJVsIdo/K9roX4JAEfI0JJr7KTPymkbKgETRDqEcLygE4ZlLTe24+7Qkh8Dl5YpnPd+Tt0DOPJDFXIwA=="], - - "@aws-sdk/client-ssm/@aws-sdk/types": ["@aws-sdk/types@3.975.1", "", { "dependencies": { "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-7rGxUkCB2QPoQOeJmonmAICTN2zrH+fpmi1p4Iwu72lnxNaMhOgqcbpyddifnM1DBb19TWQ1u6z/XjkaFNEDWw=="], - - "@aws-sdk/client-ssm/@smithy/core": ["@smithy/core@3.40.0", "", { "dependencies": { "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-DssGno52pzZ5m6RlDtyKuBIpZNPg9pqgs0CnNDKz9IatxCsmvNmJNn5Zn6rf77MthZo9wf89OvZFhTY/RwxhxQ=="], - - "@aws-sdk/client-ssm/@smithy/fetch-http-handler": ["@smithy/fetch-http-handler@5.8.1", "", { "dependencies": { "@smithy/core": "^3.39.0", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-h8BdMUrUBhMhMaeK7QqAdINRZezCGuYOCpcOZZ1ewxbHST9rdTd09xwNpvLTYfzDRehxQiReK4SKbdYZxBA+ew=="], - - "@aws-sdk/client-ssm/@smithy/node-http-handler": ["@smithy/node-http-handler@4.14.2", "", { "dependencies": { "@smithy/core": "^3.39.0", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-i1uORV1v3qBqP43ayRKzIdm1q5x14tf8N4Dd06/QUX1Szm6VxHMrTsu20X5E63UFsaNZCRjI4SXG0jDmqYa+3w=="], - - "@aws-sdk/client-ssm/@smithy/types": ["@smithy/types@4.20.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-lCA6QG22dPk9ecHbv91jDQZsmtPUjdS1aE2Il6NNPqe7DrYc0dZQi6DhcESk2KYXH2sp5xbAcGdYMZDFnuzA2A=="], - - "@aws-sdk/client-ssm/@aws-sdk/core/@aws-sdk/xml-builder": ["@aws-sdk/xml-builder@3.972.43", "", { "dependencies": { "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-rG8QVx4DOrJWptsogu1Aq+CDsnPKaBrAlJpKLxrJrIDXAq1ElnW0yQjjBnlWSXll0cDakCG6UDvaqwz0A9d9Og=="], - - "@aws-sdk/client-ssm/@aws-sdk/core/@smithy/signature-v4": ["@smithy/signature-v4@5.7.5", "", { "dependencies": { "@smithy/core": "^3.38.0", "@smithy/types": "^4.19.0", "tslib": "^2.6.2" } }, "sha512-WPjdr5oWOk1LArpI4pavu+fSo+/evi0Re1olxGvqwuZopd4gYR1UGCi+Soyn/IjmafqbWs+ZC+3AKxJS3ZpwUg=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-env": ["@aws-sdk/credential-provider-env@3.972.84", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-akZJetiMVeLRHsKzYh3LamDCo74ZUCeo0XoyRKMEMZT5qP7ReM6LhpioBCyuqKP5Vav5gEOeCmaQV0VVQr1Meg=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-http": ["@aws-sdk/credential-provider-http@3.972.86", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/fetch-http-handler": "^5.8.1", "@smithy/node-http-handler": "^4.14.2", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-U4mHaDRPWAn63yhl7FXIzbppNmW1F+4dSLeuiUpej2v3Xb6rGwvayEJ8SdlrdMV+/mZtd+GStTEP2HqurEzXtw=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-ini": ["@aws-sdk/credential-provider-ini@3.973.30", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/credential-provider-env": "^3.972.84", "@aws-sdk/credential-provider-http": "^3.972.86", "@aws-sdk/credential-provider-login": "^3.972.92", "@aws-sdk/credential-provider-process": "^3.972.84", "@aws-sdk/credential-provider-sso": "^3.973.28", "@aws-sdk/credential-provider-web-identity": "^3.972.90", "@aws-sdk/nested-clients": "^3.998.3", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/credential-provider-imds": "^4.5.2", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-r6r6499GWoGN943NA5YEhBEQ6TEOGTf7tTOBhHd/zw0UbNvSzd1/zPCNcDkPmRarA+e24X7KgxutqxjoWcskBg=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-process": ["@aws-sdk/credential-provider-process@3.972.84", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-199C6OpNejd0nq9GFAkEFIKids1FL0R6LJtL9c1OTiDOXki7S1OduuPxW4+hE0LwndcYJ7YHOuYTlqScfpCocA=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-sso": ["@aws-sdk/credential-provider-sso@3.973.28", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/nested-clients": "^3.998.3", "@aws-sdk/token-providers": "3.1166.0", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-bGg7wH8wVDJQIcJggO9lg1ZYbG7l+PbLwHuM3Bi/e1TlCZhU712JS1W3tdRpyptdJD1UGyhBNGO/YrhrQCHKbg=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-web-identity": ["@aws-sdk/credential-provider-web-identity@3.972.90", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/nested-clients": "^3.998.3", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-duLeE3xlf0viHeH+1RM4z5duR3b32BCZTWVMu+MbxFPjQBxy7hmIGEqt5hekuFPRuXoyhMovjNl+PNNsb5oiGQ=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-ini/@aws-sdk/credential-provider-login": ["@aws-sdk/credential-provider-login@3.972.92", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/nested-clients": "^3.998.3", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-96bcp9Pe/Xd60OEwncZ+kAQTQSu+fJnpUGz1qE6ghF5jnETmrk8XMU86mIP3lolvnCgR61XbZ+Ht6hdBjiQOmQ=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-ini/@aws-sdk/nested-clients": ["@aws-sdk/nested-clients@3.998.3", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/signature-v4-multi-region": "^3.996.52", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/fetch-http-handler": "^5.8.1", "@smithy/node-http-handler": "^4.14.2", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-acHTTzMB13CU6dU4sxABYExMI3PQM2zStWH2MiUwJp/7QKTrLg2f7mbzSXoegW2kYOk2tdqQYagsZrWB8Xv7eA=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-sso/@aws-sdk/nested-clients": ["@aws-sdk/nested-clients@3.998.3", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/signature-v4-multi-region": "^3.996.52", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/fetch-http-handler": "^5.8.1", "@smithy/node-http-handler": "^4.14.2", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-acHTTzMB13CU6dU4sxABYExMI3PQM2zStWH2MiUwJp/7QKTrLg2f7mbzSXoegW2kYOk2tdqQYagsZrWB8Xv7eA=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-sso/@aws-sdk/token-providers": ["@aws-sdk/token-providers@3.1166.0", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/nested-clients": "^3.998.3", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-ngJ8mxXqtQ9mnp7QV6TWKJCxkpjVfPWxKQSc2FYhCyCfOVFIGdFv7P+/RqVffFrJAorwBPpktnv32gNlcEgF4g=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-web-identity/@aws-sdk/nested-clients": ["@aws-sdk/nested-clients@3.998.3", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/signature-v4-multi-region": "^3.996.52", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/fetch-http-handler": "^5.8.1", "@smithy/node-http-handler": "^4.14.2", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-acHTTzMB13CU6dU4sxABYExMI3PQM2zStWH2MiUwJp/7QKTrLg2f7mbzSXoegW2kYOk2tdqQYagsZrWB8Xv7eA=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-ini/@aws-sdk/nested-clients/@aws-sdk/signature-v4-multi-region": ["@aws-sdk/signature-v4-multi-region@3.996.52", "", { "dependencies": { "@aws-sdk/types": "^3.975.1", "@smithy/signature-v4": "^5.7.5", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-6W6SjGc8OXUhMzNxU1X922ghD+PP1XvzmCk5Scui0jaYsLezycMYR1RaLp5xTIOUrhTXyb4DnAbPr3fBgmdnzg=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-sso/@aws-sdk/nested-clients/@aws-sdk/signature-v4-multi-region": ["@aws-sdk/signature-v4-multi-region@3.996.52", "", { "dependencies": { "@aws-sdk/types": "^3.975.1", "@smithy/signature-v4": "^5.7.5", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-6W6SjGc8OXUhMzNxU1X922ghD+PP1XvzmCk5Scui0jaYsLezycMYR1RaLp5xTIOUrhTXyb4DnAbPr3fBgmdnzg=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-web-identity/@aws-sdk/nested-clients/@aws-sdk/signature-v4-multi-region": ["@aws-sdk/signature-v4-multi-region@3.996.52", "", { "dependencies": { "@aws-sdk/types": "^3.975.1", "@smithy/signature-v4": "^5.7.5", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-6W6SjGc8OXUhMzNxU1X922ghD+PP1XvzmCk5Scui0jaYsLezycMYR1RaLp5xTIOUrhTXyb4DnAbPr3fBgmdnzg=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-ini/@aws-sdk/nested-clients/@aws-sdk/signature-v4-multi-region/@smithy/signature-v4": ["@smithy/signature-v4@5.7.5", "", { "dependencies": { "@smithy/core": "^3.38.0", "@smithy/types": "^4.19.0", "tslib": "^2.6.2" } }, "sha512-WPjdr5oWOk1LArpI4pavu+fSo+/evi0Re1olxGvqwuZopd4gYR1UGCi+Soyn/IjmafqbWs+ZC+3AKxJS3ZpwUg=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-sso/@aws-sdk/nested-clients/@aws-sdk/signature-v4-multi-region/@smithy/signature-v4": ["@smithy/signature-v4@5.7.5", "", { "dependencies": { "@smithy/core": "^3.38.0", "@smithy/types": "^4.19.0", "tslib": "^2.6.2" } }, "sha512-WPjdr5oWOk1LArpI4pavu+fSo+/evi0Re1olxGvqwuZopd4gYR1UGCi+Soyn/IjmafqbWs+ZC+3AKxJS3ZpwUg=="], - - "@aws-sdk/client-ssm/@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-web-identity/@aws-sdk/nested-clients/@aws-sdk/signature-v4-multi-region/@smithy/signature-v4": ["@smithy/signature-v4@5.7.5", "", { "dependencies": { "@smithy/core": "^3.38.0", "@smithy/types": "^4.19.0", "tslib": "^2.6.2" } }, "sha512-WPjdr5oWOk1LArpI4pavu+fSo+/evi0Re1olxGvqwuZopd4gYR1UGCi+Soyn/IjmafqbWs+ZC+3AKxJS3ZpwUg=="], } } diff --git a/secure/result-consumer/knip.json b/secure/result-consumer/knip.json index 0fbf4f39..7db903ed 100644 --- a/secure/result-consumer/knip.json +++ b/secure/result-consumer/knip.json @@ -5,8 +5,5 @@ ], "project": [ "src/**/*.ts" - ], - "ignoreDependencies": [ - "@aws-sdk/client-ssm" ] } diff --git a/secure/result-consumer/package.json b/secure/result-consumer/package.json index c6f11583..27320951 100644 --- a/secure/result-consumer/package.json +++ b/secure/result-consumer/package.json @@ -22,7 +22,6 @@ "dependencies": { "@aws-sdk/client-dynamodb": "^3.700.0", "@aws-sdk/lib-dynamodb": "^3.700.0", - "@srads/common": "file:../../packages/common", - "@aws-sdk/client-ssm": "^3.700.0" + "@srads/common": "file:../../packages/common" } } diff --git a/secure/result-consumer/src/handlers/consume.ts b/secure/result-consumer/src/handlers/consume.ts index 71d467eb..709e61bf 100644 --- a/secure/result-consumer/src/handlers/consume.ts +++ b/secure/result-consumer/src/handlers/consume.ts @@ -32,11 +32,10 @@ function messageId(record: SQSRecord): { algorithmId: string; runId: string } | // Consumes enclave run-result messages off RunResultsQueue and persists them to the RunResults table, // where execution-service's GET /run/{runId} reads them back. The batch's records are handled concurrently. async function persist(record: SQSRecord): Promise { + // Malformed messages throw so SQS redelivers them up to maxReceiveCount, then moves them to the DLQ. const message: RunResultMessage = JSON.parse(record.body); - // A malformed message shouldn't poison the batch and block good ones - skip it, let it age to the DLQ. if (typeof message.runId !== "string") { - console.error("skipping message with missing/invalid runId", record.messageId); - return; + throw new Error(`run-result message ${record.messageId} has a missing or invalid runId`); } const item = { diff --git a/secure/samples/product-trends-node/package.json b/secure/samples/product-trends-node/package.json index 779da8ad..bb1ef973 100644 --- a/secure/samples/product-trends-node/package.json +++ b/secure/samples/product-trends-node/package.json @@ -2,7 +2,6 @@ "name": "product-trends-node", "version": "0.1.0", "private": true, - "type": "module", "scripts": { "start": "node main.js" } diff --git a/secure/sce-unit/crypto.go b/secure/sce-unit/crypto.go index f9c9a879..9e824bf8 100644 --- a/secure/sce-unit/crypto.go +++ b/secure/sce-unit/crypto.go @@ -39,6 +39,9 @@ func decryptRecord(dek []byte, blob json.RawMessage) (json.RawMessage, error) { if err != nil { return nil, err } + if len(nonce) != gcm.NonceSize() { + return nil, fmt.Errorf("nonce is %d bytes, want %d", len(nonce), gcm.NonceSize()) + } if len(body) < gcm.Overhead() { return nil, fmt.Errorf("ciphertext too short") } diff --git a/secure/sce-unit/vsock_transport.go b/secure/sce-unit/vsock_transport.go index 89d0076d..5a2c5e99 100644 --- a/secure/sce-unit/vsock_transport.go +++ b/secure/sce-unit/vsock_transport.go @@ -39,7 +39,7 @@ func (e pinnedEndpoint) client() *http.Client { return pinnedVsockHTTPClient(e.host, e.pubKeySHA, e.proxyPort) } -// verifier and pdm pair each service's baked-in host/pin with its fixed proxy port. +// Each endpoint pairs a service's baked-in host/pin with its fixed proxy port. func (c runConfig) verifier() pinnedEndpoint { return pinnedEndpoint{c.VerifierHost, c.VerifierPubKeySHA256, verifierProxyPort} } @@ -95,8 +95,7 @@ func pinnedVsockHTTPClient(host, pinSHA256 string, proxyPort uint32) *http.Clien } } -// net.FileConn doesn't recognize AF_VSOCK (returns "protocol not supported"), so this needs a real vsock-aware -// net.Conn rather than the raw-fd wrapping used elsewhere in this file. +// net.FileConn doesn't recognize AF_VSOCK (returns "protocol not supported"), so raw-fd wrapping won't work here. func dialVsock(ctx context.Context, cid, port uint32) (net.Conn, error) { type result struct { conn net.Conn diff --git a/secure/sce/execution-service/bun.lock b/secure/sce/execution-service/bun.lock index b45c5ef6..cbb9a8c0 100644 --- a/secure/sce/execution-service/bun.lock +++ b/secure/sce/execution-service/bun.lock @@ -186,7 +186,7 @@ "@smithy/types": ["@smithy/types@4.18.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-CgB6HHWer/vrKps24ulRIbpcpb7K4xAU7SkZ7YHzBPlwHsvsrCJFEXK421s+cJzX+ZrqtA/TuU5w1HzI7k9N8A=="], - "@srads/common": ["@srads/common@file:../../../packages/common", { "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], + "@srads/common": ["@srads/common@file:../../../packages/common", { "dependencies": { "csv-stringify": "^6.8.3", "jose": "^6.2.10" }, "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], "@tybys/wasm-util": ["@tybys/wasm-util@0.10.3", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-F3fo1MYrRJYL3zER0OUOmkutjr1Vp23m7OsSgp7nq4SP6OqX6C/56XFIPAl5bt3zaBRjmW7SGz3u/6LwFpYcOg=="], @@ -196,6 +196,8 @@ "bowser": ["bowser@2.14.1", "", {}, "sha512-tzPjzCxygAKWFOJP011oxFHs57HzIhOEracIgAePE4pqB3LikALKnSzUyU4MGs9/iCEUuHlAJTjTc5M+u7YEGg=="], + "csv-stringify": ["csv-stringify@6.9.0", "", {}, "sha512-6b3e29CILFfSQ2nDRuZMRROzQOpPuJ+s8zPB5H7eK5ncXBbFOyVuRLU5Sx/zAUmVri3Ly49GyC8NEme4SVSAbA=="], + "fd-package-json": ["fd-package-json@2.0.0", "", { "dependencies": { "walk-up-path": "^4.0.0" } }, "sha512-jKmm9YtsNXN789RS/0mSzOC1NUq9mkVd65vbSSVsKdjGvYXBuE4oWe2QOEoFeRmJg+lPuZxpmrfFclNhoRMneQ=="], "fdir": ["fdir@6.5.0", "", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg=="], @@ -206,6 +208,8 @@ "jiti": ["jiti@2.7.0", "", { "bin": { "jiti": "lib/jiti-cli.mjs" } }, "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ=="], + "jose": ["jose@6.2.17", "", {}, "sha512-wOuK9V1yujQFH5S0ZWmLcDZN7+IKh9bUCC2ZPCf2HDlol3WWHy+PPyNjEI75FXRLMp3vDKQcupP59xhVU95hcg=="], + "knip": ["knip@6.34.0", "", { "dependencies": { "fdir": "^6.5.0", "formatly": "^0.7.0", "get-tsconfig": "4.14.3", "jiti": "^2.7.0", "oxc-parser": "^0.147.0", "oxc-resolver": "11.24.2", "picomatch": "^4.0.7", "smol-toml": "^1.8.0", "strip-json-comments": "5.0.3", "tinyglobby": "^0.2.17", "unbash": "^4.0.10", "yaml": "^2.9.0", "zod": "^4.4.3" }, "bin": { "knip": "bin/knip.js", "knip-bun": "bin/knip-bun.js" } }, "sha512-bbHIrnGspYwe4EBPjjx+lvkUor0F2qfKQc5BPzPI4SOAImYA+k2ueVpIcF7d/W1LEVT7XoJUPt6zELeGZhXBgA=="], "mnemonist": ["mnemonist@0.38.3", "", { "dependencies": { "obliterator": "^1.6.1" } }, "sha512-2K9QYubXx/NAjv4VLq1d1Ly8pWNC5L3BrixtdkyTegXWJIqY+zLNDhhX/A+ZwWt70tB1S8H4BE8FLYEFyNoOBw=="], diff --git a/secure/sce/execution-service/knip.json b/secure/sce/execution-service/knip.json index 0fbf4f39..7db903ed 100644 --- a/secure/sce/execution-service/knip.json +++ b/secure/sce/execution-service/knip.json @@ -5,8 +5,5 @@ ], "project": [ "src/**/*.ts" - ], - "ignoreDependencies": [ - "@aws-sdk/client-ssm" ] } diff --git a/secure/sce/execution-service/src/handlers/run.ts b/secure/sce/execution-service/src/handlers/run.ts index f9808746..c07a6e71 100644 --- a/secure/sce/execution-service/src/handlers/run.ts +++ b/secure/sce/execution-service/src/handlers/run.ts @@ -4,6 +4,7 @@ import { EC2Client, RunInstancesCommand, type RunInstancesCommandInput } from "@ import { DynamoDBDocumentClient, GetCommand } from "@aws-sdk/lib-dynamodb"; import { CostPhase, costEvent, recordRequest } from "@srads/common/cost"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import { emitEvent } from "@srads/common/log"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; import { fetchAlgorithmRecordCount } from "../lib/pdmCount.js"; @@ -36,7 +37,6 @@ interface RunRequest { interface AlgorithmRecord { S3Bucket?: string; S3Key?: string; - RecordCount?: number; } interface RunResult { @@ -49,10 +49,6 @@ interface RunResult { Status?: string; } -function jsonResponse(statusCode: number, body: unknown) { - return { statusCode, headers: { "content-type": "application/json" }, body: JSON.stringify(body) }; -} - function parseRunRequest(body: string | undefined): RunRequest | undefined { try { const parsed: unknown = JSON.parse(body ?? ""); @@ -97,26 +93,17 @@ export const create: APIGatewayProxyHandlerV2 = async (event) => { } if (request.size !== undefined) { - if (record.RecordCount !== undefined) { - if (request.size > record.RecordCount) { + try { + const available = await fetchAlgorithmRecordCount(pdmMtlsHost, request.algorithmId, request.size, runId); + if (request.size > available) { await recordRequest(request.algorithmId, runId, CostPhase.Execution, startedAt); return jsonResponse(400, { - error: `size ${request.size} exceeds seeded dataset (${record.RecordCount} records)`, + error: `size ${request.size} exceeds seeded dataset (${available} records)`, }); } - } else { - try { - const available = await fetchAlgorithmRecordCount(pdmMtlsHost, request.algorithmId, request.size, runId); - if (request.size > available) { - await recordRequest(request.algorithmId, runId, CostPhase.Execution, startedAt); - return jsonResponse(400, { - error: `size ${request.size} exceeds seeded dataset (${available} records)`, - }); - } - } catch (error) { - // The executor caps at size anyway, so a count outage should not block runs. - console.warn("record count failed; skipping size validation", error); - } + } catch (error) { + // The executor caps at size anyway, so a count outage should not block runs. + console.warn("record count failed; skipping size validation", error); } } diff --git a/secure/sce/execution-service/src/lib/pdmCount.ts b/secure/sce/execution-service/src/lib/pdmCount.ts index 792403b0..323bc475 100644 --- a/secure/sce/execution-service/src/lib/pdmCount.ts +++ b/secure/sce/execution-service/src/lib/pdmCount.ts @@ -1,7 +1,10 @@ import { request as httpsRequest } from "node:https"; import { GetParameterCommand, SSMClient } from "@aws-sdk/client-ssm"; +import { requiredEnv } from "@srads/common/env"; const ssm = new SSMClient({}); +const certParam = requiredEnv("PDM_MTLS_CERT_PARAM"); +const keyParam = requiredEnv("PDM_MTLS_KEY_PARAM"); const COUNT_TIMEOUT_MS = 5000; interface ClientMaterial { @@ -21,11 +24,6 @@ async function getParameter(name: string): Promise { } function loadClientMaterial(): Promise { - const certParam = process.env.PDM_MTLS_CERT_PARAM; - const keyParam = process.env.PDM_MTLS_KEY_PARAM; - if (!certParam || !keyParam) { - throw new Error("PDM mTLS parameter names are not configured"); - } material ??= Promise.all([getParameter(certParam), getParameter(keyParam)]).then(([cert, key]) => ({ cert, key, diff --git a/secure/telemetry-service/bun.lock b/secure/telemetry-service/bun.lock index c0d8eff2..7d5513a3 100644 --- a/secure/telemetry-service/bun.lock +++ b/secure/telemetry-service/bun.lock @@ -9,9 +9,6 @@ "@aws-sdk/client-sqs": "^3.1121.0", "@aws-sdk/lib-dynamodb": "^3.700.0", "@srads/common": "file:../../packages/common", - "csv-stringify": "^6.8.3", - "ts-retry": "^7.0.3", - "zod": "^4.6.5", }, "devDependencies": { "@biomejs/biome": "^2.5.10", @@ -28,8 +25,6 @@ "@aws-sdk/client-sqs": ["@aws-sdk/client-sqs@3.1169.0", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/credential-provider-node": "^3.972.97", "@aws-sdk/middleware-sdk-sqs": "^3.972.50", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/fetch-http-handler": "^5.8.1", "@smithy/node-http-handler": "^4.14.2", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-7bX9EB7CH/L/CuYv/4l3/LlBofBfyjZqFHbsLHJ/Wki08fMsq6g/RCsCKU29UmCINLdX13Un9YtWu5Gv8pHxCA=="], - "@aws-sdk/client-ssm": ["@aws-sdk/client-ssm@3.1169.0", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/credential-provider-node": "^3.972.97", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/fetch-http-handler": "^5.8.1", "@smithy/node-http-handler": "^4.14.2", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-EAqUE22l8bOeCPMNxnahMhKrWW2n7siZjVL1rNWWaD9prTTwDbMf2xeaAOqVx5lLOz+3sSuicM6OMY5yYTR1Eg=="], - "@aws-sdk/core": ["@aws-sdk/core@3.981.0", "", { "dependencies": { "@aws-sdk/types": "^3.975.1", "@aws-sdk/xml-builder": "^3.972.43", "@aws/lambda-invoke-store": "^0.3.0", "@smithy/core": "^3.40.0", "@smithy/signature-v4": "^5.7.5", "@smithy/types": "^4.20.0", "bowser": "^2.11.0", "tslib": "^2.6.2" } }, "sha512-Mnu7gaDrC5UCdyH8uLxLfB2eWbjE/HbjKX1U1J2VQxG3TTATUDObW2wU3I8iH3e9YH5NN2CY6w1mlAIe2XJ3jg=="], "@aws-sdk/credential-provider-env": ["@aws-sdk/credential-provider-env@3.972.84", "", { "dependencies": { "@aws-sdk/core": "^3.981.0", "@aws-sdk/types": "^3.975.1", "@smithy/core": "^3.40.0", "@smithy/types": "^4.20.0", "tslib": "^2.6.2" } }, "sha512-akZJetiMVeLRHsKzYh3LamDCo74ZUCeo0XoyRKMEMZT5qP7ReM6LhpioBCyuqKP5Vav5gEOeCmaQV0VVQr1Meg=="], @@ -192,7 +187,7 @@ "@smithy/types": ["@smithy/types@4.20.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-lCA6QG22dPk9ecHbv91jDQZsmtPUjdS1aE2Il6NNPqe7DrYc0dZQi6DhcESk2KYXH2sp5xbAcGdYMZDFnuzA2A=="], - "@srads/common": ["@srads/common@file:../../packages/common", { "dependencies": { "@aws-sdk/client-ssm": "^3.700.0", "jose": "^6.2.10" }, "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], + "@srads/common": ["@srads/common@file:../../packages/common", { "dependencies": { "csv-stringify": "^6.8.3", "jose": "^6.2.10" }, "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], "@tybys/wasm-util": ["@tybys/wasm-util@0.10.4", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-W3c4gRigFS0T/Ma4qIYF3GDAc5AQdHb1yL5znJT1Zv1YaD9Kitx656wBjvr19qbiosmZT8lWDM5BEMynUqX65A=="], @@ -240,8 +235,6 @@ "tinyglobby": ["tinyglobby@0.2.17", "", { "dependencies": { "fdir": "^6.5.0", "picomatch": "^4.0.4" } }, "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g=="], - "ts-retry": ["ts-retry@7.0.3", "", {}, "sha512-sEaLD4RaKmEDvLeki2qQsJgqc50cdmBhQJ90I6V0ur/g1iO6P9PxU2dP52SF87dHEtb1jwb/BJWH5gCx6IfqgQ=="], - "tslib": ["tslib@2.9.1", "", {}, "sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA=="], "typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="], @@ -255,7 +248,5 @@ "walk-up-path": ["walk-up-path@4.0.0", "", {}, "sha512-3hu+tD8YzSLGuFYtPRb48vdhKMi0KQV5sn+uWr8+7dMEq/2G/dtLrdDinkLjqq5TIbIBjYJ4Ax/n3YiaW7QM8A=="], "yaml": ["yaml@2.9.1", "", { "bin": { "yaml": "bin.mjs" } }, "sha512-3NxN8+78OdzbT7C/WjGsyfPAtJaN3FNDsWxv7Y7mcDsT/oOmgW8BpyQQFFBnvZE3j9Y2Sdz1ULFLezL7Eb2yFw=="], - - "zod": ["zod@4.6.7", "", {}, "sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg=="], } } diff --git a/secure/telemetry-service/knip.json b/secure/telemetry-service/knip.json index 41f49502..7db903ed 100644 --- a/secure/telemetry-service/knip.json +++ b/secure/telemetry-service/knip.json @@ -5,6 +5,5 @@ ], "project": [ "src/**/*.ts" - ], - "ignoreDependencies": [] + ] } diff --git a/secure/telemetry-service/package.json b/secure/telemetry-service/package.json index 12169e86..9ed71636 100644 --- a/secure/telemetry-service/package.json +++ b/secure/telemetry-service/package.json @@ -23,9 +23,6 @@ "@aws-sdk/client-dynamodb": "^3.700.0", "@aws-sdk/client-sqs": "^3.1121.0", "@aws-sdk/lib-dynamodb": "^3.700.0", - "@srads/common": "file:../../packages/common", - "csv-stringify": "^6.8.3", - "ts-retry": "^7.0.3", - "zod": "^4.6.5" + "@srads/common": "file:../../packages/common" } } diff --git a/secure/telemetry-service/src/handlers/all.ts b/secure/telemetry-service/src/handlers/all.ts index 98ce40b3..b6dd5255 100644 --- a/secure/telemetry-service/src/handlers/all.ts +++ b/secure/telemetry-service/src/handlers/all.ts @@ -1,24 +1,14 @@ import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient, ScanCommand } from "@aws-sdk/lib-dynamodb"; +import { toCsv } from "@srads/common/csv"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; -import { type EventRow, toCsv } from "../lib/csv.js"; +import { EVENT_COLUMNS, type EventRow, toRow } from "../lib/csv.js"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); const table = requiredEnv("RUN_LOG_TABLE"); -function toRow(item: Record): EventRow { - return { - algorithmId: item.AlgorithmId as string, - runId: item.RunId as string, - event: item.Event as string, - timestamp: item.Timestamp as string, - receivedAt: item.ReceivedAt as string, - detail: item.Detail ?? null, - origin: (item.Origin as string | undefined) ?? "service", - }; -} - // Exports the whole table across all algorithms. Pages through every scan page so a benchmarking export is // never silently truncated. export const handler: APIGatewayProxyHandlerV2 = async (event) => { @@ -35,7 +25,7 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => { } while (exclusiveStartKey); if (format === "csv") { - return { statusCode: 200, headers: { "content-type": "text/csv" }, body: toCsv(rows) }; + return { statusCode: 200, headers: { "content-type": "text/csv" }, body: toCsv(rows, EVENT_COLUMNS) }; } - return { statusCode: 200, headers: { "content-type": "application/json" }, body: JSON.stringify(rows) }; + return jsonResponse(200, rows); }; diff --git a/secure/telemetry-service/src/handlers/byAlgorithm.ts b/secure/telemetry-service/src/handlers/byAlgorithm.ts index ccb8ff88..66848de0 100644 --- a/secure/telemetry-service/src/handlers/byAlgorithm.ts +++ b/secure/telemetry-service/src/handlers/byAlgorithm.ts @@ -1,34 +1,20 @@ import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient, QueryCommand } from "@aws-sdk/lib-dynamodb"; +import { toCsv } from "@srads/common/csv"; import { requiredEnv } from "@srads/common/env"; +import { jsonResponse } from "@srads/common/http"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; -import { type EventRow, toCsv } from "../lib/csv.js"; +import { EVENT_COLUMNS, type EventRow, toRow } from "../lib/csv.js"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); const table = requiredEnv("RUN_LOG_TABLE"); -function toRow(item: Record): EventRow { - return { - algorithmId: item.AlgorithmId as string, - runId: item.RunId as string, - event: item.Event as string, - timestamp: item.Timestamp as string, - receivedAt: item.ReceivedAt as string, - detail: item.Detail ?? null, - origin: (item.Origin as string | undefined) ?? "service", - }; -} - // Exports one algorithm's timeline, optionally narrowed to a single run. Pages through every result so an // export is never silently truncated; the SK gives a chronological (runId, timestamp) sort for free. export const handler: APIGatewayProxyHandlerV2 = async (event) => { const algorithmId = event.pathParameters?.algorithmId; if (!algorithmId) { - return { - statusCode: 400, - headers: { "content-type": "application/json" }, - body: JSON.stringify({ error: "missing algorithmId" }), - }; + return jsonResponse(400, { error: "missing algorithmId" }); } const runId = event.queryStringParameters?.runId; const format = event.queryStringParameters?.format; @@ -51,7 +37,7 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => { } while (exclusiveStartKey); if (format === "csv") { - return { statusCode: 200, headers: { "content-type": "text/csv" }, body: toCsv(rows) }; + return { statusCode: 200, headers: { "content-type": "text/csv" }, body: toCsv(rows, EVENT_COLUMNS) }; } - return { statusCode: 200, headers: { "content-type": "application/json" }, body: JSON.stringify(rows) }; + return jsonResponse(200, rows); }; diff --git a/secure/telemetry-service/src/handlers/events.ts b/secure/telemetry-service/src/handlers/events.ts index c0484950..60045724 100644 --- a/secure/telemetry-service/src/handlers/events.ts +++ b/secure/telemetry-service/src/handlers/events.ts @@ -1,12 +1,9 @@ +import { jsonResponse } from "@srads/common/http"; import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; import { parseIngestBody } from "../lib/ingest.js"; import { runEventExists } from "../lib/lookup.js"; import { enqueueEvent } from "../lib/queue.js"; -function jsonResponse(statusCode: number, body: unknown) { - return { statusCode, headers: { "content-type": "application/json" }, body: JSON.stringify(body) }; -} - // Diagnostic telemetry: performance, test, and debug events. There is no authentication, so any producer // that can reach the endpoint may append to the timeline. export const handler: APIGatewayProxyHandlerV2 = async (event) => { diff --git a/secure/telemetry-service/src/lib/csv.ts b/secure/telemetry-service/src/lib/csv.ts index 94d766f4..c9eac483 100644 --- a/secure/telemetry-service/src/lib/csv.ts +++ b/secure/telemetry-service/src/lib/csv.ts @@ -1,21 +1,31 @@ -import { stringify } from "csv-stringify/sync"; - export interface EventRow { algorithmId: string; runId: string; event: string; timestamp: string; receivedAt: string; - detail: unknown; origin: string; + detail: unknown; } -const COLUMNS = ["algorithmId", "runId", "event", "timestamp", "receivedAt", "origin", "detail"]; +export const EVENT_COLUMNS = [ + "algorithmId", + "runId", + "event", + "timestamp", + "receivedAt", + "origin", + "detail", +] as const satisfies readonly (keyof EventRow)[]; -export function toCsv(rows: EventRow[]): string { - // detail is an object; flatten it to compact JSON so csv-stringify emits one cell, not [object Object]. - return stringify( - rows.map((row) => ({ ...row, detail: row.detail == null ? "" : JSON.stringify(row.detail) })), - { header: true, columns: COLUMNS }, - ); +export function toRow(item: Record): EventRow { + return { + algorithmId: item.AlgorithmId as string, + runId: item.RunId as string, + event: item.Event as string, + timestamp: item.Timestamp as string, + receivedAt: item.ReceivedAt as string, + detail: item.Detail ?? null, + origin: (item.Origin as string | undefined) ?? "service", + }; } diff --git a/secure/telemetry-service/src/lib/events.ts b/secure/telemetry-service/src/lib/events.ts index efb13d3d..d70e27b5 100644 --- a/secure/telemetry-service/src/lib/events.ts +++ b/secure/telemetry-service/src/lib/events.ts @@ -1,9 +1,9 @@ // Keep producer event enums in sync with this ingest allowlist. // Emitted before attestation. Telemetry accepts them without a token. -export const PRE_ATTESTATION_EVENTS = ["enclave-started", "unit-ready"] as const; +const PRE_ATTESTATION_EVENTS = ["enclave-started", "unit-ready"] as const; // Emitted after attestation. Telemetry does not verify the enclave token; it stores the timeline only. -export const ENCLAVE_EVENTS = [ +const ENCLAVE_EVENTS = [ "attested", "records-fetched", "records-decrypted", @@ -42,14 +42,6 @@ export function isRunEvent(value: unknown): value is RunEvent { return typeof value === "string" && RUN_EVENTS.includes(value); } -export function isEnclaveEvent(value: unknown): value is (typeof ENCLAVE_EVENTS)[number] { - return typeof value === "string" && (ENCLAVE_EVENTS as readonly string[]).includes(value); -} - -export function isPreAttestationEvent(value: unknown): value is (typeof PRE_ATTESTATION_EVENTS)[number] { - return typeof value === "string" && (PRE_ATTESTATION_EVENTS as readonly string[]).includes(value); -} - export function isHostEvent(value: unknown): value is (typeof HOST_EVENTS)[number] { return typeof value === "string" && (HOST_EVENTS as readonly string[]).includes(value); } diff --git a/secure/telemetry-service/src/lib/ingest.ts b/secure/telemetry-service/src/lib/ingest.ts index 7272b569..afc2c754 100644 --- a/secure/telemetry-service/src/lib/ingest.ts +++ b/secure/telemetry-service/src/lib/ingest.ts @@ -1,4 +1,4 @@ -import { isHostEvent, isRunEvent, RUN_EVENTS } from "./events.js"; +import { isHostEvent, isInternalEvent, isRunEvent, RUN_EVENTS } from "./events.js"; type EventOrigin = "enclave" | "host" | "service"; @@ -14,6 +14,11 @@ export interface ParsedEvent { export type IngestedEvent = ParsedEvent; +function eventOrigin(name: string): EventOrigin { + if (isHostEvent(name)) return "host"; + return isInternalEvent(name) ? "service" : "enclave"; +} + export function parseIngestBody(body: unknown): ParsedEvent | { error: string } { if (typeof body !== "object" || body === null) { return { error: "body must be a JSON object" }; @@ -50,6 +55,6 @@ export function parseIngestBody(body: unknown): ParsedEvent | { error: string } timestamp: timestamp as string, detail: (detail as Record | undefined) ?? null, receivedAt: new Date().toISOString(), - origin: isHostEvent(name) ? "host" : "enclave", + origin: eventOrigin(name), }; } diff --git a/secure/transparency-portal/bun.lock b/secure/transparency-portal/bun.lock index f98e2107..d023f636 100644 --- a/secure/transparency-portal/bun.lock +++ b/secure/transparency-portal/bun.lock @@ -15,7 +15,6 @@ "react": "^19.2.8", "react-dom": "^19.2.8", "react-router-dom": "^7.18.3", - "shadcn": "^4.21.0", "tw-animate-css": "^1.4.0", }, "devDependencies": { @@ -25,6 +24,7 @@ "@types/react-dom": "^19.2.7", "@vitejs/plugin-react": "^6.1.1", "oxlint": "^1.81.0", + "shadcn": "^4.21.0", "tailwindcss": "^4.3.3", "typescript": "~6.0.2", "vite": "^8.3.0", diff --git a/secure/transparency-portal/package.json b/secure/transparency-portal/package.json index 3d3dbd94..df7659fa 100644 --- a/secure/transparency-portal/package.json +++ b/secure/transparency-portal/package.json @@ -20,7 +20,6 @@ "react": "^19.2.8", "react-dom": "^19.2.8", "react-router-dom": "^7.18.3", - "shadcn": "^4.21.0", "tw-animate-css": "^1.4.0" }, "devDependencies": { @@ -30,6 +29,7 @@ "@types/react-dom": "^19.2.7", "@vitejs/plugin-react": "^6.1.1", "oxlint": "^1.81.0", + "shadcn": "^4.21.0", "tailwindcss": "^4.3.3", "typescript": "~6.0.2", "vite": "^8.3.0" diff --git a/secure/transparency-portal/src/components/site-header.tsx b/secure/transparency-portal/src/components/site-header.tsx index 95b749a2..a07bd774 100644 --- a/secure/transparency-portal/src/components/site-header.tsx +++ b/secure/transparency-portal/src/components/site-header.tsx @@ -1,6 +1,6 @@ import { Link, NavLink } from "react-router-dom"; import { ShieldCheckIcon } from "lucide-react"; -import { cn } from "@/lib/utils"; +import { cn } from "cn"; const LINKS = [ { to: "/", label: "Home" }, diff --git a/secure/verifier-service/README.md b/secure/verifier-service/README.md index 51907c61..fd1570b0 100644 --- a/secure/verifier-service/README.md +++ b/secure/verifier-service/README.md @@ -24,7 +24,7 @@ Downstream services (pdm-service, kms-service, log-service) verify the JWT local | `jti` | random 32 hex chars | unique per minted token, even within one refresh session | | `run_id` | run ID from `/attest` | the only source of `runId` pdm-service and kms-service trust for cost and DSAR attribution; a token without it is rejected | -Expiry behavior: access tokens live **2 hours** (`ACCESS_TOKEN_TTL_SECONDS` in `src/lib/tokens.ts`). sce-unit refreshes 30 s before expiry via `/refresh`; the refresh token itself is opaque, lives **4 hours** (it must outlive the access token), and is stored SHA-256-hashed with a `Revoked` flag in `AttestationSessionTable` - revoking a session row stops refreshes immediately, and already-minted access JWTs die within at most 2 hours. Signing key: an ML-DSA-87 (FIPS 204) private key in SSM SecureString `/verifier-service/jwt-signing-key`, whose `kid` is the RFC 7638 thumbprint of its public JWK. +Expiry behavior: access tokens live **2 hours** (`ACCESS_TOKEN_TTL_SECONDS` in `src/lib/tokens.ts`). sce-unit refreshes 30 s before expiry via `/refresh`; the refresh token itself is opaque, lives **4 hours** (it must outlive the access token), and is stored SHA-256-hashed with a `Revoked` flag in `AttestationSessionTable` - revoking a session row stops refreshes immediately, and already-minted access JWTs die within at most 2 hours. Signing key: an ML-DSA-87 (FIPS 204) private key in SSM SecureString `/secure-rads/verifier-service/jwt-signing-key`, whose `kid` is the RFC 7638 thumbprint of its public JWK. `/attest`, `/challenge`, and `/refresh` are deliberately not behind mTLS: a static client cert baked into the EIF would be extractable by anyone who can pull the artifact from S3 and decompose it, and would be redundant anyway - the attestation document itself (PCR0/1/2) is the real identity proof. So they (plus the JWKS endpoint) live on a second `AWS::ApiGatewayV2::Api` with a plain-TLS custom domain, pinned by callers to its leaf pubkey instead (same scheme registry-service already uses against the mTLS domain). @@ -36,12 +36,12 @@ Bun is used as the local dev/bundle tool only (`bun install`) - the Lambda itsel - Two domain names + ACM certificates already provisioned, one per custom domain - `serverless.yml` takes these as `domainName`/`certificateArn` (mTLS) and `publicDomainName`/`publicCertificateArn` (plain TLS) params, it does not create them. - The truststore PEM in `TruststoreBucket` bundles the mTLS client cert: registry-service's (`secure/csav/registry-service/tls/client.crt`, from `make gen-client-cert` there). `TruststoreBucket` is versioned per AWS's guidance for safe truststore rollovers. -- Once deployed, each custom domain's TLS leaf cert pubkey SHA-256 needs to be read back and pinned on the other side: the mTLS domain's into registry-service's `VERIFIER_PUBKEY_SHA256` (`secure/csav/registry-service/verifier.go`), the public domain's into registry-service's `VERIFIER_HOST`/pubkey used to bake `sce-unit`'s run config (`secure/csav/registry-service/rootfs.go`), into execution-service's `VERIFIER_HOST` (`secure/sce/execution-service/Makefile`), and into pdm-service's `verifierJwksPubkeySha256` (pinned on JWKS fetches). Manual bootstrap step since both sides pin each other. -- An ML-DSA-87 (FIPS 204) JWT signing key, stored as an SSM SecureString at `/verifier-service/jwt-signing-key`: +- Once deployed, each custom domain's TLS leaf cert pubkey SHA-256 needs to be read back and pinned on the other side: the mTLS domain's into registry-service's `VERIFIER_PUBKEY_SHA256` (`secure/csav/registry-service/verifier.go`), the public domain's into registry-service's `VERIFIER_HOST`/pubkey used to bake `sce-unit`'s run config (`secure/csav/registry-service/rootfs.go`), into execution-service's `VERIFIER_HOST` (`VERIFIER_ATTEST_HOST` in `secure/sce/Makefile`), and into pdm-service's `verifierJwksPubkeySha256` (pinned on JWKS fetches). Manual bootstrap step since both sides pin each other. +- An ML-DSA-87 (FIPS 204) JWT signing key, stored as an SSM SecureString at `/secure-rads/verifier-service/jwt-signing-key`: ```sh openssl genpkey -algorithm ML-DSA-87 -out jwt-signing-key.pem -aws ssm put-parameter --name /verifier-service/jwt-signing-key --type SecureString --value file://jwt-signing-key.pem +aws ssm put-parameter --name /secure-rads/verifier-service/jwt-signing-key --type SecureString --value file://jwt-signing-key.pem ``` (The key must be PKCS#8 "BEGIN PRIVATE KEY" PEM - `genpkey` emits this by default. ML-DSA generation needs OpenSSL 3.5+.) diff --git a/secure/verifier-service/bun.lock b/secure/verifier-service/bun.lock index cb731053..4d5370fd 100644 --- a/secure/verifier-service/bun.lock +++ b/secure/verifier-service/bun.lock @@ -187,7 +187,7 @@ "@smithy/types": ["@smithy/types@4.16.1", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-0JFs3V2y2M9tKW5na/qxe69Zv+uxLMO7QBbhxF/FHu/Gp2NFZAAL9tWl9PU02xxo07pb3G9FTyjNc6D5uZrJIg=="], - "@srads/common": ["@srads/common@file:../../packages/common", { "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], + "@srads/common": ["@srads/common@file:../../packages/common", { "dependencies": { "csv-stringify": "^6.8.3", "jose": "^6.2.10" }, "devDependencies": { "@biomejs/biome": "^2.5.10", "@types/node": "^22.0.0", "typescript": "^5.7.0" } }], "@tybys/wasm-util": ["@tybys/wasm-util@0.10.3", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-F3fo1MYrRJYL3zER0OUOmkutjr1Vp23m7OsSgp7nq4SP6OqX6C/56XFIPAl5bt3zaBRjmW7SGz3u/6LwFpYcOg=="], @@ -213,6 +213,8 @@ "cross-spawn": ["cross-spawn@7.0.6", "", { "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", "which": "^2.0.1" } }, "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA=="], + "csv-stringify": ["csv-stringify@6.9.0", "", {}, "sha512-6b3e29CILFfSQ2nDRuZMRROzQOpPuJ+s8zPB5H7eK5ncXBbFOyVuRLU5Sx/zAUmVri3Ly49GyC8NEme4SVSAbA=="], + "eastasianwidth": ["eastasianwidth@0.2.0", "", {}, "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA=="], "emoji-regex": ["emoji-regex@9.2.2", "", {}, "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg=="], diff --git a/secure/verifier-service/serverless.yml b/secure/verifier-service/serverless.yml index 8fb37967..df83054c 100644 --- a/secure/verifier-service/serverless.yml +++ b/secure/verifier-service/serverless.yml @@ -25,9 +25,7 @@ provider: Action: dynamodb:GetItem Resource: !GetAtt AlgorithmPCRTable.Arn - Effect: Allow - Action: - - dynamodb:PutItem - - dynamodb:UpdateItem + Action: dynamodb:PutItem Resource: !GetAtt AttestationSessionTable.Arn - Effect: Allow Action: dynamodb:Query diff --git a/seeding/bun.lock b/seeding/bun.lock index 4a494bf1..22b5145e 100644 --- a/seeding/bun.lock +++ b/seeding/bun.lock @@ -8,6 +8,7 @@ "@aws-sdk/client-dynamodb": "^3.1141.0", "@aws-sdk/client-kms": "^3.1119.0", "@aws-sdk/lib-dynamodb": "^3.700.0", + "@smithy/node-http-handler": "^4.12.1", "p-map": "^7.0.6", "uuid": "^14.0.2", }, diff --git a/seeding/lib/dynamo.ts b/seeding/lib/dynamo.ts index 465177f4..e7659ea5 100644 --- a/seeding/lib/dynamo.ts +++ b/seeding/lib/dynamo.ts @@ -26,7 +26,6 @@ export function documentClient(region: string): DynamoDBDocumentClient { export async function writeAll( client: DynamoDBDocumentClient, table: string, - _name: string, batches: Record[][], ): Promise { const counts = await pMap( diff --git a/seeding/package.json b/seeding/package.json index 2f4b9156..30b723a4 100644 --- a/seeding/package.json +++ b/seeding/package.json @@ -22,6 +22,7 @@ "@aws-sdk/client-dynamodb": "^3.1141.0", "@aws-sdk/client-kms": "^3.1119.0", "@aws-sdk/lib-dynamodb": "^3.700.0", + "@smithy/node-http-handler": "^4.12.1", "p-map": "^7.0.6", "uuid": "^14.0.2" }, diff --git a/seeding/seed-rads.ts b/seeding/seed-rads.ts index 26e14556..012cfc91 100644 --- a/seeding/seed-rads.ts +++ b/seeding/seed-rads.ts @@ -29,7 +29,7 @@ for (const name of resolveSeedNames()) { const inflight: Promise[] = []; const enqueue = async (chunk: Record[][]) => { - const written = await writeAll(client, table, meta.name, chunk); + const written = await writeAll(client, table, chunk); progress.written += written; console.log(`${meta.name}: ${progress.written}/${progress.total ?? "?"}`); }; diff --git a/seeding/seed-secure-rads.ts b/seeding/seed-secure-rads.ts index e77cbe49..e67a4e99 100644 --- a/seeding/seed-secure-rads.ts +++ b/seeding/seed-secure-rads.ts @@ -1,5 +1,5 @@ import { createCipheriv, randomBytes } from "node:crypto"; -import { existsSync, readFileSync, writeFileSync } from "node:fs"; +import { chmodSync, existsSync, readFileSync, writeFileSync } from "node:fs"; import { CreateKeyCommand, GenerateDataKeyCommand, KMSClient } from "@aws-sdk/client-kms"; import { GetCommand, PutCommand, UpdateCommand } from "@aws-sdk/lib-dynamodb"; import { readDatasetMeta, resolveSeedNames, streamDatasetRecords } from "./lib/datasets"; @@ -51,7 +51,8 @@ async function loadOrCreateDek(algorithmId: string, kmsKeyArn: string): Promise< }), ); const dek = Buffer.from(dk.Plaintext); - writeFileSync(cache, dek); + writeFileSync(cache, dek, { mode: 0o600 }); + chmodSync(cache, 0o600); return dek; } @@ -107,7 +108,7 @@ for (const name of resolveSeedNames()) { const inflight: Promise[] = []; const enqueue = async (chunk: Record[][]) => { - const written = await writeAll(client, table, meta.name, chunk); + const written = await writeAll(client, table, chunk); progress.written += written; console.log(`${meta.name}: ${progress.written}/${progress.total ?? "?"}`); };