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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/e2e-secure-rads.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Input:
4 SEED-ENTROPY from NSM // no AWS cost
5 emit unit-ready // no token yet, auth none
6 challenge ← REQUEST-CHALLENGE(Verifier, a, runId) // single-use nonce, verifier API GW/Lambda and DynamoDB metered
7 token ← ATTEST(Verifier, runId, challenge) // NSM nonce ← challenge; verifier API GW/Lambda and DynamoDB metered
7 token ← ATTEST(Verifier, runId, challenge) // NSM nonce ← challenge; claims the run so only one attestation succeeds; verifier API GW/Lambda and DynamoDB metered
8 emit attested
9 records ← FETCH-PDM(a, token, limit ← n)
10 cost apigateway:request + lambda:invocation + lambda:compute + dynamodb:read-capacity // PDM /records
Expand Down
2 changes: 1 addition & 1 deletion secure/verifier-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Serverless Framework v4, TypeScript. Receives `AlgorithmId` + PCR values from re

- `POST /algorithms` (mTLS domain) - registry-service registers `AlgorithmId` -> PCR0/1/2 at build time.
- `POST /challenge` (public domain) - sce-unit asks for a single-use nonce before attesting. The row is stored hashed in `AttestationChallengeTable` with a 60 s TTL and is bound to the `algorithmId` and `runId` in the request.
- `POST /attest` (public domain) - sce-unit submits a real Nitro attestation document (base64 COSE_Sign1 bytes) + `algorithmId` + `runId` + the `challenge` it was issued. The document's `nonce` must equal the challenge, and the challenge is consumed atomically before the PCR check, so a captured document cannot be replayed. Verified against the pinned AWS Nitro root cert chain and the registered PCRs; on success, issues a signed access JWT + opaque refresh token (persisted in `AttestationSessionTable`, including `RunId`).
- `POST /attest` (public domain) - sce-unit submits a real Nitro attestation document (base64 COSE_Sign1 bytes) + `algorithmId` + `runId` + the `challenge` it was issued. The document's `nonce` must equal the challenge, and the challenge is consumed atomically before the PCR check, so a captured document cannot be replayed. After the PCR check, the run is claimed in `RunAttestationTable` with a conditional put, so only the first attestation for a `runId` succeeds; later ones get 409. Verified against the pinned AWS Nitro root cert chain and the registered PCRs; on success, issues a signed access JWT + opaque refresh token (persisted in `AttestationSessionTable`, including `RunId`).
- `POST /refresh` (public domain) - exchanges a still-valid refresh token plus its `runId` for a new access JWT, without requiring a fresh attestation document. The `runId` must match the one stored on the session.
- `GET /.well-known/jwks.json` (public domain) - the ML-DSA-87 public key downstream services use to verify access JWTs locally. Public by definition, no auth.

Expand Down
17 changes: 17 additions & 0 deletions secure/verifier-service/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ provider:
- dynamodb:PutItem
- dynamodb:UpdateItem
Resource: !GetAtt AttestationChallengeTable.Arn
- Effect: Allow
Action: dynamodb:PutItem
Resource: !GetAtt RunAttestationTable.Arn
- Effect: Allow
Action: ssm:GetParameter
Resource: !Sub "arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/secure-rads/verifier-service/jwt-signing-key"
environment:
ALGORITHM_PCR_TABLE: !Ref AlgorithmPCRTable
ATTESTATION_SESSION_TABLE: !Ref AttestationSessionTable
ATTESTATION_CHALLENGE_TABLE: !Ref AttestationChallengeTable
RUN_ATTESTATION_TABLE: !Ref RunAttestationTable
JWT_SIGNING_KEY_PARAM: /secure-rads/verifier-service/jwt-signing-key
COST_HOST: ${env:COST_HOST_SECURE_RADS}

Expand Down Expand Up @@ -128,6 +132,19 @@ resources:
AttributeName: ExpiresAt
Enabled: true

# One row per run that has attested. The conditional put is what makes a run single-use: concurrency-safe
# first writer wins, and every later /attest for the same run id is rejected.
RunAttestationTable:
Type: AWS::DynamoDB::Table
Properties:
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: RunId
AttributeType: S
KeySchema:
- AttributeName: RunId
KeyType: HASH

# PEM bundle containing registry-service's client cert public cert
# (csav/registry-service/tls/client.crt) - upload it here before deploy.
TruststoreBucket:
Expand Down
2 changes: 2 additions & 0 deletions secure/verifier-service/src/handlers/attest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { APIGatewayProxyHandlerV2 } from "aws-lambda";
import { verifyAttestationDocument } from "../lib/attestation.js";
import { type AttestBody, attestRequest } from "../lib/attestFlow.js";
import { consumeChallenge } from "../lib/challenge.js";
import { claimRunAttestation } from "../lib/runAttestation.js";
import { issueTokenPair } from "../lib/tokens.js";

const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({}));
Expand Down Expand Up @@ -66,6 +67,7 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => {
registered: registered.Item as { PCR0: string; PCR1: string; PCR2: string },
verifyDocument: verifyAttestationDocument,
consumeChallenge,
claimRunAttestation,
issueTokens: issueTokenPair,
});
} finally {
Expand Down
6 changes: 6 additions & 0 deletions secure/verifier-service/src/lib/attestFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface AttestDeps {
registered: RegisteredPcrs;
verifyDocument(raw: Buffer): AttestationDocument;
consumeChallenge(challenge: string, algorithmId: string, runId: string): Promise<boolean>;
claimRunAttestation(algorithmId: string, runId: string): Promise<boolean>;
issueTokens(algorithmId: string, runId: string): Promise<unknown>;
}

Expand Down Expand Up @@ -62,6 +63,11 @@ export async function attestRequest(body: AttestBody, deps: AttestDeps): Promise
return { statusCode: 401, body: "PCR mismatch: enclave measurements do not match registered algorithm" };
}

// A run attests once. Claiming after the measurement check keeps a wrong-image request from burning a run.
if (!(await deps.claimRunAttestation(body.algorithmId, body.runId))) {
return { statusCode: 409, body: "run already attested" };
}

const tokens = await deps.issueTokens(body.algorithmId, body.runId);
return { statusCode: 200, body: JSON.stringify(tokens) };
}
36 changes: 36 additions & 0 deletions secure/verifier-service/src/lib/runAttestation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient, PutCommand } from "@aws-sdk/lib-dynamodb";
import { CostPhase, costEvent } from "@srads/common/cost";
import { requiredEnv } from "@srads/common/env";

const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({}));
const tableName = requiredEnv("RUN_ATTESTATION_TABLE");

export async function claimRunAttestation(algorithmId: string, runId: string): Promise<boolean> {
try {
const write = await ddb.send(
new PutCommand({
TableName: tableName,
Item: {
RunId: runId,
AlgorithmId: algorithmId,
AttestedAt: new Date().toISOString(),
},
ConditionExpression: "attribute_not_exists(RunId)",
ReturnConsumedCapacity: "TOTAL",
}),
);
await costEvent(
algorithmId,
runId,
CostPhase.Execution,
"dynamodb",
"write-capacity",
write.ConsumedCapacity?.CapacityUnits ?? 0,
);
return true;
} catch (err) {
if ((err as Error).name === "ConditionalCheckFailedException") return false;
throw err;
}
}