diff --git a/.env.example b/.env.example index 36c1f43..91c92f0 100644 --- a/.env.example +++ b/.env.example @@ -29,6 +29,12 @@ COST_HOST_RADS=cost.r.secure-rads.org COST_HOST_SECURE_RADS=cost.sr.secure-rads.org PDM_HOST=pdm.sr.secure-rads.org KMS_HOST=kms.sr.secure-rads.org +# rads baseline hostnames (the baseline tree uses .r. endpoints). +PDM_HOST_RADS=pdm.r.secure-rads.org +REGISTRY_HOST_RADS=registry.r.secure-rads.org +# Custom domain for the rads execution-service API. Set it before deploying the +# rads tree; its ACM certificate is looked up by hostname at deploy time. +EXECUTION_HOST_RADS= VERIFIER_HOST=verifier.sr.secure-rads.org VERIFIER_ATTEST_HOST=verifier-attest.sr.secure-rads.org VERIFIER_URL=https://verifier.sr.secure-rads.org/algorithms diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..01d76d7 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,138 @@ +name: deploy + +on: + workflow_dispatch: + inputs: + tree: + description: Tree to deploy + type: choice + options: + - all + - secure + - rads + default: all + units: + description: Optional space-separated units (see scripts/deploy.sh list) + type: string + default: "" + dry_run: + description: Print commands without changing AWS + type: boolean + default: false + registry_image: + description: Build and ship the secure registry-service image + type: boolean + default: true + +permissions: + contents: read + id-token: write + +concurrency: + group: deploy-${{ github.ref }} + cancel-in-progress: false + +jobs: + deploy: + runs-on: blacksmith-4vcpu-ubuntu-2404-arm + env: + AWS_REGION: ${{ vars.AWS_REGION || 'ap-southeast-2' }} + AVAILABILITY_ZONE: ${{ vars.AVAILABILITY_ZONE }} + RADS_EXECUTOR_AMI_ID: ${{ vars.RADS_EXECUTOR_AMI_ID }} + SCE_ENCLAVE_AMI_ID: ${{ vars.SCE_ENCLAVE_AMI_ID }} + CERT_ARN_RADS: ${{ vars.CERT_ARN_RADS }} + CERT_ARN_SECURE_RADS: ${{ vars.CERT_ARN_SECURE_RADS }} + TRANSPARENCY_DOMAIN_RADS: ${{ vars.TRANSPARENCY_DOMAIN_RADS }} + TRANSPARENCY_DOMAIN_SECURE_RADS: ${{ vars.TRANSPARENCY_DOMAIN_SECURE_RADS }} + LOG_HOST_RADS: ${{ vars.LOG_HOST_RADS }} + LOG_HOST_SECURE_RADS: ${{ vars.LOG_HOST_SECURE_RADS }} + TELEMETRY_HOST_RADS: ${{ vars.TELEMETRY_HOST_RADS }} + TELEMETRY_HOST_SECURE_RADS: ${{ vars.TELEMETRY_HOST_SECURE_RADS }} + COST_HOST_RADS: ${{ vars.COST_HOST_RADS }} + COST_HOST_SECURE_RADS: ${{ vars.COST_HOST_SECURE_RADS }} + PDM_HOST: ${{ vars.PDM_HOST }} + PDM_HOST_RADS: ${{ vars.PDM_HOST_RADS }} + REGISTRY_HOST_RADS: ${{ vars.REGISTRY_HOST_RADS }} + EXECUTION_HOST_RADS: ${{ vars.EXECUTION_HOST_RADS }} + KMS_HOST: ${{ vars.KMS_HOST }} + VERIFIER_HOST: ${{ vars.VERIFIER_HOST }} + VERIFIER_ATTEST_HOST: ${{ vars.VERIFIER_ATTEST_HOST }} + VERIFIER_URL: ${{ vars.VERIFIER_URL }} + VERIFIER_JWKS_URL: ${{ vars.VERIFIER_JWKS_URL }} + VERIFIER_JWKS_PUBKEY_SHA256: ${{ vars.VERIFIER_JWKS_PUBKEY_SHA256 }} + VERIFIER_PUBKEY_SHA256: ${{ vars.VERIFIER_PUBKEY_SHA256 }} + VERIFIER_HOST_PUBKEY_SHA256: ${{ vars.VERIFIER_HOST_PUBKEY_SHA256 }} + PDM_HOST_PUBKEY_SHA256: ${{ vars.PDM_HOST_PUBKEY_SHA256 }} + KMS_HOST_PUBKEY_SHA256: ${{ vars.KMS_HOST_PUBKEY_SHA256 }} + LOG_HOST_PUBKEY_SHA256: ${{ vars.LOG_HOST_PUBKEY_SHA256 }} + TELEMETRY_HOST_PUBKEY_SHA256: ${{ vars.TELEMETRY_HOST_PUBKEY_SHA256 }} + CLOUDFLARE_ZONE: ${{ vars.CLOUDFLARE_ZONE }} + CLOUDFLARE_EMAIL: ${{ secrets.CLOUDFLARE_EMAIL }} + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + steps: + - uses: actions/checkout@v5 + + - uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ vars.AWS_DEPLOY_ROLE_ARN }} + aws-region: ${{ vars.AWS_REGION || 'ap-southeast-2' }} + + - uses: oven-sh/setup-bun@v2 + with: + bun-version: 1.x + + - name: Write registry trust material + if: inputs.tree != 'rads' + env: + REGISTRY_TLS_CERT_B64: ${{ secrets.REGISTRY_TLS_CERT_B64 }} + REGISTRY_TLS_KEY_B64: ${{ secrets.REGISTRY_TLS_KEY_B64 }} + run: | + set -euo pipefail + if [ -z "$REGISTRY_TLS_CERT_B64" ] && [ -z "$REGISTRY_TLS_KEY_B64" ]; then + echo "registry TLS secrets are not set; verifier and registry-image will fail if selected" >&2 + exit 0 + fi + [ -n "$REGISTRY_TLS_CERT_B64" ] && [ -n "$REGISTRY_TLS_KEY_B64" ] || { + echo "REGISTRY_TLS_CERT_B64 and REGISTRY_TLS_KEY_B64 must be set together" >&2 + exit 1 + } + mkdir -p secure/csav/registry-service/tls + printf '%s' "$REGISTRY_TLS_CERT_B64" | base64 -d >secure/csav/registry-service/tls/client.crt + printf '%s' "$REGISTRY_TLS_KEY_B64" | base64 -d >secure/csav/registry-service/tls/client.key + chmod 600 secure/csav/registry-service/tls/client.crt secure/csav/registry-service/tls/client.key + + - name: Write CSAV SSH key + if: inputs.tree != 'rads' && inputs.registry_image + env: + CSAV_SSH_KEY_B64: ${{ secrets.CSAV_SSH_KEY_B64 }} + run: | + set -euo pipefail + [ -n "$CSAV_SSH_KEY_B64" ] || { echo "CSAV_SSH_KEY_B64 is not set" >&2; exit 1; } + mkdir -p .ssh + printf '%s' "$CSAV_SSH_KEY_B64" | base64 -d >.ssh/csav-key.pem + chmod 400 .ssh/csav-key.pem + + - name: Log in to GHCR + if: inputs.tree != 'rads' && inputs.registry_image + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ vars.GHCR_USER || github.repository_owner }} + password: ${{ secrets.GHCR_TOKEN }} + + - name: Deploy + env: + TREE: ${{ inputs.tree }} + UNITS: ${{ inputs.units }} + DRY_RUN: ${{ inputs.dry_run }} + REGISTRY_IMAGE: ${{ inputs.registry_image }} + run: | + set -euo pipefail + args=("$TREE") + if [ -n "$UNITS" ]; then + read -r -a units <<<"$UNITS" + args+=("${units[@]}") + fi + [ "$DRY_RUN" = "true" ] && args+=(--dry-run) + [ "$REGISTRY_IMAGE" = "false" ] && args+=(--skip-registry-image) + scripts/deploy.sh deploy "${args[@]}" diff --git a/README.md b/README.md index 3afd784..a30860f 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ instance. Use a dedicated research account. full deployment in a new account and region. - [`docs/running.md`](docs/running.md) - requirements, cost and account safety, make targets, CSV exports. +- [`docs/deploy.md`](docs/deploy.md) - the single deploy entrypoint and the manual CI pipeline. - [`docs/cost-service.md`](docs/cost-service.md) - how per-run AWS costs are metered. - [`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. diff --git a/docs/deploy.md b/docs/deploy.md new file mode 100644 index 0000000..adde213 --- /dev/null +++ b/docs/deploy.md @@ -0,0 +1,133 @@ +# Deploying from CI + +The deploy pipeline has one entrypoint, `scripts/deploy.sh`, and a manual GitHub Actions +workflow, `.github/workflows/deploy.yml`. Both trees deploy through the same script, in dependency +order, deriving inter-service values (queue URLs and ARNs, table names, bucket names, role ARNs) +from CloudFormation stack outputs. + +This covers application and infrastructure deployment. It does not seed data, build sample +algorithms, or manage Cloudflare DNS. + +## Units + +`scripts/deploy.sh list` prints the units in dependency order. The same order is used by the +workflow. + +| Tree | Units | +| --- | --- | +| `secure` | storage, verifier-service, result-consumer, log-service, telemetry-service, cost-service, pdm-service, kms-service, csav, execution-service, registry-image, transparency-portal | +| `rads` | result-consumer, log-service, telemetry-service, cost-service, pdm-service, registry-service, execution-service, transparency-portal | + +A full tree deploy runs every unit. Named units deploy only what you name; dependencies are not +deployed automatically. + +## Local use + +The script reads the root `.env` (see `.env.example`) like the Makefiles do. `make env` populates +the discoverable values first. + +```sh +scripts/deploy.sh list +scripts/deploy.sh deploy secure --dry-run +scripts/deploy.sh deploy rads rads/log-service +scripts/deploy.sh deploy secure --skip-registry-image +``` + +`--dry-run` prints the commands but still resolves inputs from AWS (read-only calls). + +## Manual workflow + +Run `deploy` from the Actions tab (`workflow_dispatch`). Inputs: + +- `tree`: `all`, `secure`, or `rads`. +- `units`: optional space-separated unit names, for example `secure/log-service secure/pdm-service`. +- `dry_run`: print commands without changing AWS. +- `registry_image`: build and ship the secure registry-service image (default on). + +Deploys are serialized per branch with a concurrency group. + +## Authentication + +The workflow uses GitHub OIDC; there are no long-lived AWS keys. Set the repository variable +`AWS_DEPLOY_ROLE_ARN` to a role that trusts +`token.actions.githubusercontent.com`. Trust policy: + +```json +{ + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": { + "Federated": "arn:aws:iam:::oidc-provider/token.actions.githubusercontent.com" + }, + "Action": "sts:AssumeRoleWithWebIdentity", + "Condition": { + "StringEquals": { + "token.actions.githubusercontent.com:aud": "sts.amazonaws.com" + }, + "StringLike": { + "token.actions.githubusercontent.com:sub": "repo:Secure-RADS/st-dp:ref:refs/heads/*" + } + } + } + ] +} +``` + +The role needs CloudFormation, Lambda, S3, DynamoDB, SQS, API Gateway, CloudFront, EC2, IAM, SSM, +ACM, and CloudWatch Logs permissions. The serverless services and the CSAV stack create IAM roles, +so this is close to account admin. Run it in a dedicated account and treat it as production-adjacent. + +## 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. + +| 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 | +| `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 | +| `TELEMETRY_HOST_RADS`, `TELEMETRY_HOST_SECURE_RADS` | telemetry-service hostnames | +| `COST_HOST_RADS`, `COST_HOST_SECURE_RADS` | cost-service hostnames | +| `PDM_HOST`, `PDM_HOST_RADS` | PDM hostnames | +| `KMS_HOST`, `VERIFIER_HOST`, `VERIFIER_ATTEST_HOST`, `VERIFIER_URL` | secure service hostnames | +| `REGISTRY_HOST_RADS`, `EXECUTION_HOST_RADS` | rads registry and execution API hostnames | +| `VERIFIER_JWKS_URL`, `VERIFIER_JWKS_PUBKEY_SHA256` | JWKS endpoint and pin used by pdm/log/kms | +| `VERIFIER_PUBKEY_SHA256`, `VERIFIER_HOST_PUBKEY_SHA256`, `PDM_HOST_PUBKEY_SHA256`, `KMS_HOST_PUBKEY_SHA256`, `LOG_HOST_PUBKEY_SHA256`, `TELEMETRY_HOST_PUBKEY_SHA256` | TLS pins baked into the registry image | +| `GHCR_USER` | account that can pull `ghcr.io/secure-rads/nsjail-docker` | +| `CLOUDFLARE_ZONE` | Cloudflare zone | + +## Repository secrets + +| Secret | Purpose | +| --- | --- | +| `GHCR_TOKEN` | pull the private nsjail base image | +| `REGISTRY_TLS_CERT_B64`, `REGISTRY_TLS_KEY_B64` | base64 of the existing `secure/csav/registry-service/tls/client.{crt,key}` | +| `CSAV_SSH_KEY_B64` | base64 of `.ssh/csav-key.pem`, used to ship the registry image | +| `CLOUDFLARE_EMAIL`, `CLOUDFLARE_API_TOKEN` | Cloudflare API credentials | + +`REGISTRY_TLS_CERT_B64` must be the same client certificate the verifier truststore was created +from. Generating a new certificate rotates the trust material and breaks registration until the +verifier is redeployed with the new truststore. + +## Registry image + +The secure registry-service image builds on a Blacksmith arm64 runner, so `--platform linux/arm64` +is native and needs no QEMU. It builds `sce-unit-base` and `eif-build-base` first, pulls the private +`ghcr.io/secure-rads/nsjail-docker` base, ships the tarball over SSH, and restarts the compose +service on the CSAV host. + +## Known gaps + +- The TLS pins and `VERIFIER_JWKS_PUBKEY_SHA256` are captured from live endpoints after a fresh + deploy. Set them before deploying `secure/pdm-service`, `secure/log-service`, `secure/kms-service`, + or the registry image. +- The verifier JWT signing key must already exist at the SSM path the service reads. See + `docs/getting-started.md`. +- The CSAV key pair and the CSAV instance must already exist before the registry image ships. +- `EXECUTION_HOST_RADS` has no default. Set it before deploying the rads tree. diff --git a/docs/getting-started.md b/docs/getting-started.md index ac3c06e..206a9c6 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -130,6 +130,9 @@ This file is ignored by Git and must not be shared through the repository. ## 4. Deploy in Sydney +`scripts/deploy.sh` and the manual CI workflow automate this section; see +[`docs/deploy.md`](deploy.md). The steps below are the manual path. + Set the certificate ARNs before deploying. Devbox already exports `REGION=ap-southeast-2`: ```sh @@ -165,7 +168,7 @@ Upload the truststore, then deploy verifier-service again with its immutable S3 ```sh TRUSTSTORE_BUCKET=$(aws cloudformation describe-stacks --region "$REGION" \ - --stack-name verifier-service-dev \ + --stack-name secure-rads-verifier-service-dev \ --query "Stacks[0].Outputs[?OutputKey=='TruststoreBucketName'].OutputValue" --output text) TRUSTSTORE_VERSION=$(aws s3api put-object --bucket "$TRUSTSTORE_BUCKET" \ --key truststore.pem --body secure/csav/registry-service/tls/client.crt \ diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100755 index 0000000..7713519 --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,491 @@ +#!/usr/bin/env bash +set -euo pipefail + +repo_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) +cd "$repo_root" + +usage() { + cat <<'EOF' +usage: scripts/deploy.sh [tree] [unit...] [options] + + list print deployable units in dependency order + deploy [tree] [unit...] deploy a tree (all|secure|rads) or named units + +options: + --dry-run print commands without changing AWS + --skip-registry-image skip the secure registry-service image build/ship + +tree defaults to all. Named units must come from `list`; missing dependencies +are not deployed automatically. +EOF +} + +die() { + printf 'deploy: %s\n' "$*" >&2 + exit 1 +} + +need() { + local key + for key in "$@"; do + [ -n "${!key-}" ] || die "$key is required" + done +} + +run() { + printf '+ %s\n' "$*" + [ "$dry_run" = 1 ] && return 0 + "$@" +} + +stack_output() { + local stack="$1" key="$2" value + value=$(aws cloudformation describe-stacks --stack-name "$stack" --region "$region" \ + --query "Stacks[0].Outputs[?OutputKey=='$key'].OutputValue" --output text) + [ -n "$value" ] && [ "$value" != None ] || die "no $key output on stack $stack" + printf '%s' "$value" +} + +cert_for() { + local host="$1" acm_region="${2:-$region}" arn candidate + arn=$(aws acm list-certificates --region "$acm_region" --certificate-statuses ISSUED \ + --query "CertificateSummaryList[?DomainName=='$host'].CertificateArn | [0]" --output text) + if [ -z "$arn" ] || [ "$arn" = None ]; then + for candidate in $(aws acm list-certificates --region "$acm_region" \ + --certificate-statuses ISSUED --query 'CertificateSummaryList[].CertificateArn' --output text); do + if aws acm describe-certificate --region "$acm_region" --certificate-arn "$candidate" \ + --query 'Certificate.SubjectAlternativeNames' --output text | tr '\t' '\n' | grep -qx "$host"; then + arn=$candidate + break + fi + done + fi + [ -n "$arn" ] && [ "$arn" != None ] || die "no ISSUED ACM certificate for $host in $acm_region" + printf '%s' "$arn" +} + +sls() { + local dir="$1" + shift + if [ "$dry_run" = 1 ]; then + printf '+ (cd %s && bun install --frozen-lockfile && bunx serverless deploy %s)\n' "$dir" "$*" + return 0 + fi + ( + cd "$dir" + bun install --frozen-lockfile + bunx serverless deploy "$@" + ) +} + +ensure_env_file() { + [ -f .env ] && return 0 + local key default value + : >.env + while IFS='=' read -r key default; do + value="${!key-}" + [ -n "$value" ] || value="$default" + printf '%s=%s\n' "$key" "$value" >>.env + done < <(sed -n 's/^\([A-Za-z_][A-Za-z0-9_]*\)=\(.*\)$/\1=\2/p' .env.example) + chmod 600 .env +} + +load_env() { + if [ "$dry_run" = 1 ] && [ ! -f .env ]; then + region=${AWS_REGION:-ap-southeast-2} + return 0 + fi + ensure_env_file + [ "$dry_run" = 1 ] || scripts/derive-env.sh >/dev/null + set -a + # shellcheck disable=SC1091 + . ./.env + set +a + region=${AWS_REGION:-ap-southeast-2} +} + +units_secure=( + secure/storage + secure/verifier-service + secure/result-consumer + secure/log-service + secure/telemetry-service + secure/cost-service + secure/pdm-service + secure/kms-service + secure/csav + secure/sce/execution-service + secure/registry-image + secure/transparency-portal +) + +units_rads=( + rads/result-consumer + rads/log-service + rads/telemetry-service + rads/cost-service + rads/pdm-service + rads/csav/registry-service + rads/sce/execution-service + rads/transparency-portal +) + +describe_unit() { + case "$1" in + secure/storage) echo "S3 artifact bucket + algorithms table (CloudFormation)" ;; + secure/result-consumer) echo "run-results queue + table (serverless)" ;; + secure/log-service) echo "subject-access log API (serverless)" ;; + secure/telemetry-service) echo "run timeline API (serverless)" ;; + secure/cost-service) echo "cost API (serverless)" ;; + secure/verifier-service) echo "attestation + JWKS APIs, truststore (serverless, two-pass)" ;; + secure/pdm-service) echo "personal data API (serverless)" ;; + secure/kms-service) echo "KMS broker API (serverless)" ;; + secure/csav) echo "CSAV EC2 host (CloudFormation)" ;; + secure/sce/execution-service) echo "enclave execution API (serverless)" ;; + secure/registry-image) echo "registry-service container image build + ship" ;; + secure/transparency-portal) echo "transparency SPA (CloudFormation + S3 + CloudFront)" ;; + rads/result-consumer) echo "run-results queue + table (serverless)" ;; + rads/log-service) echo "subject-access log API (serverless)" ;; + rads/telemetry-service) echo "run timeline API (serverless)" ;; + rads/cost-service) echo "cost API (serverless)" ;; + rads/pdm-service) echo "personal data API (serverless)" ;; + rads/csav/registry-service) echo "images bucket + algorithms table + registry API (serverless)" ;; + rads/sce/execution-service) echo "executor control plane (serverless)" ;; + rads/transparency-portal) echo "transparency SPA (CloudFormation + S3 + CloudFront)" ;; + *) echo "unknown unit" ;; + esac +} + +unit_secure_storage() { + run make -C secure/csav/registry-service deploy-storage +} + +unit_secure_result_consumer() { + need TELEMETRY_HOST_SECURE_RADS COST_HOST_SECURE_RADS + sls secure/result-consumer --param="region=$region" +} + +unit_secure_log_service() { + need LOG_HOST_SECURE_RADS VERIFIER_JWKS_URL VERIFIER_JWKS_PUBKEY_SHA256 + local arn + arn=$(cert_for "$LOG_HOST_SECURE_RADS") + sls secure/log-service \ + --param="region=$region" \ + --param="domainName=$LOG_HOST_SECURE_RADS" \ + --param="certificateArn=$arn" +} + +unit_secure_telemetry_service() { + need TELEMETRY_HOST_SECURE_RADS + local arn + arn=$(cert_for "$TELEMETRY_HOST_SECURE_RADS") + sls secure/telemetry-service \ + --param="region=$region" \ + --param="domainName=$TELEMETRY_HOST_SECURE_RADS" \ + --param="certificateArn=$arn" +} + +unit_secure_cost_service() { + need COST_HOST_SECURE_RADS + local arn + arn=$(cert_for "$COST_HOST_SECURE_RADS") + sls secure/cost-service \ + --param="region=$region" \ + --param="domainName=$COST_HOST_SECURE_RADS" \ + --param="certificateArn=$arn" +} + +unit_secure_verifier_service() { + need VERIFIER_HOST VERIFIER_ATTEST_HOST VERIFIER_JWKS_URL COST_HOST_SECURE_RADS + local cert public_cert truststore version + cert=$(cert_for "$VERIFIER_HOST") + public_cert=$(cert_for "$VERIFIER_ATTEST_HOST") + sls secure/verifier-service \ + --param="region=$region" \ + --param="domainName=$VERIFIER_HOST" \ + --param="certificateArn=$cert" \ + --param="publicDomainName=$VERIFIER_ATTEST_HOST" \ + --param="publicCertificateArn=$public_cert" + + truststore=secure/csav/registry-service/tls/client.crt + [ "$dry_run" = 1 ] || [ -f "$truststore" ] || die "$truststore is required for the verifier truststore" + if [ "$dry_run" = 1 ]; then + printf '+ aws s3api put-object --bucket --key truststore.pem --body %s\n' "$truststore" + version="" + else + version=$(aws s3api put-object \ + --bucket "$(stack_output secure-rads-verifier-service-dev TruststoreBucketName)" \ + --key truststore.pem \ + --body "$truststore" \ + --query VersionId --output text) + fi + sls secure/verifier-service \ + --param="region=$region" \ + --param="domainName=$VERIFIER_HOST" \ + --param="certificateArn=$cert" \ + --param="publicDomainName=$VERIFIER_ATTEST_HOST" \ + --param="publicCertificateArn=$public_cert" \ + --param="truststoreVersionId=$version" +} + +unit_secure_pdm_service() { + need PDM_HOST LOG_HOST_SECURE_RADS COST_HOST_SECURE_RADS VERIFIER_JWKS_URL VERIFIER_JWKS_PUBKEY_SHA256 + local arn + arn=$(cert_for "$PDM_HOST") + sls secure/pdm-service \ + --param="region=$region" \ + --param="domainName=$PDM_HOST" \ + --param="certificateArn=$arn" +} + +unit_secure_kms_service() { + need KMS_HOST COST_HOST_SECURE_RADS VERIFIER_JWKS_URL VERIFIER_JWKS_PUBKEY_SHA256 + local arn algorithm_table data_key_table + arn=$(cert_for "$KMS_HOST") + algorithm_table=$(stack_output secure-rads-registry-service-storage AlgorithmTableName) + data_key_table=$(stack_output secure-rads-pdm-service-dev DataKeyTableName) + sls secure/kms-service \ + --param="region=$region" \ + --param="domainName=$KMS_HOST" \ + --param="certificateArn=$arn" \ + --param="algorithmTable=$algorithm_table" \ + --param="dataKeyTable=$data_key_table" +} + +unit_secure_csav() { + run make -C secure/csav deploy +} + +unit_secure_execution_service() { + run make -C secure/sce deploy +} + +unit_secure_registry_image() { + need VERIFIER_URL VERIFIER_PUBKEY_SHA256 VERIFIER_ATTEST_HOST VERIFIER_HOST_PUBKEY_SHA256 \ + PDM_HOST_PUBKEY_SHA256 LOG_HOST_PUBKEY_SHA256 KMS_HOST KMS_HOST_PUBKEY_SHA256 \ + TELEMETRY_HOST_PUBKEY_SHA256 + [ -f secure/csav/registry-service/tls/client.crt ] || die "secure/csav/registry-service/tls/client.crt is required" + [ -f secure/csav/registry-service/tls/client.key ] || die "secure/csav/registry-service/tls/client.key is required" + run make -C secure/csav/registry-service ship remote-up +} + +unit_secure_transparency_portal() { + run make -C secure/transparency-portal deploy-infra + run make -C secure/transparency-portal deploy +} + +unit_rads_result_consumer() { + need TELEMETRY_HOST_RADS COST_HOST_RADS + sls rads/result-consumer --param="region=$region" +} + +unit_rads_log_service() { + need LOG_HOST_RADS + local arn + arn=$(cert_for "$LOG_HOST_RADS") + sls rads/log-service \ + --param="region=$region" \ + --param="domainName=$LOG_HOST_RADS" \ + --param="certificateArn=$arn" +} + +unit_rads_telemetry_service() { + need TELEMETRY_HOST_RADS + local arn + arn=$(cert_for "$TELEMETRY_HOST_RADS") + sls rads/telemetry-service \ + --param="region=$region" \ + --param="domainName=$TELEMETRY_HOST_RADS" \ + --param="certificateArn=$arn" +} + +unit_rads_cost_service() { + need COST_HOST_RADS + local arn + arn=$(cert_for "$COST_HOST_RADS") + sls rads/cost-service \ + --param="region=$region" \ + --param="domainName=$COST_HOST_RADS" \ + --param="certificateArn=$arn" +} + +unit_rads_pdm_service() { + need PDM_HOST_RADS LOG_HOST_RADS COST_HOST_RADS + local arn + arn=$(cert_for "$PDM_HOST_RADS") + sls rads/pdm-service \ + --param="region=$region" \ + --param="domainName=$PDM_HOST_RADS" \ + --param="certificateArn=$arn" +} + +unit_rads_registry_service() { + need REGISTRY_HOST_RADS TELEMETRY_HOST_RADS COST_HOST_RADS + local arn + arn=$(cert_for "$REGISTRY_HOST_RADS") + sls rads/csav/registry-service \ + --param="region=$region" \ + --param="domainName=$REGISTRY_HOST_RADS" \ + --param="certificateArn=$arn" +} + +unit_rads_execution_service() { + need EXECUTION_HOST_RADS PDM_HOST_RADS RADS_EXECUTOR_AMI_ID AVAILABILITY_ZONE \ + LOG_HOST_RADS TELEMETRY_HOST_RADS COST_HOST_RADS + local arn images_bucket algorithm_table run_results_table run_results_queue_url \ + run_results_queue_arn pdm_table vpc + arn=$(cert_for "$EXECUTION_HOST_RADS") + vpc=$(default_vpc) + images_bucket=$(stack_output rads-registry-service-dev ImagesBucketName) + algorithm_table=$(stack_output rads-registry-service-dev AlgorithmsTableName) + run_results_table=$(stack_output rads-result-consumer-dev RunResultsTableName) + run_results_queue_url=$(stack_output rads-result-consumer-dev RunResultsQueueUrl) + run_results_queue_arn=$(stack_output rads-result-consumer-dev RunResultsQueueArn) + pdm_table=$(stack_output rads-pdm-service-dev PersonalDataTableName) + sls rads/sce/execution-service \ + --param="region=$region" \ + --param="vpcId=$vpc" \ + --param="imagesBucket=$images_bucket" \ + --param="algorithmTable=$algorithm_table" \ + --param="runResultsTable=$run_results_table" \ + --param="runResultsQueueUrl=$run_results_queue_url" \ + --param="runResultsQueueArn=$run_results_queue_arn" \ + --param="pdmUrl=https://$PDM_HOST_RADS" \ + --param="pdmTable=$pdm_table" \ + --param="domainName=$EXECUTION_HOST_RADS" \ + --param="certificateArn=$arn" +} + +unit_rads_transparency_portal() { + run make -C rads/transparency-portal deploy-infra + run make -C rads/transparency-portal deploy +} + +default_vpc() { + need AWS_REGION + aws ec2 describe-vpcs --region "$region" --filters Name=is-default,Values=true \ + --query 'Vpcs[0].VpcId' --output text +} + +deploy_unit() { + case "$1" in + secure/storage) unit_secure_storage ;; + secure/result-consumer) unit_secure_result_consumer ;; + secure/log-service) unit_secure_log_service ;; + secure/telemetry-service) unit_secure_telemetry_service ;; + secure/cost-service) unit_secure_cost_service ;; + secure/verifier-service) unit_secure_verifier_service ;; + secure/pdm-service) unit_secure_pdm_service ;; + secure/kms-service) unit_secure_kms_service ;; + secure/csav) unit_secure_csav ;; + secure/sce/execution-service) unit_secure_execution_service ;; + secure/registry-image) unit_secure_registry_image ;; + secure/transparency-portal) unit_secure_transparency_portal ;; + rads/result-consumer) unit_rads_result_consumer ;; + rads/log-service) unit_rads_log_service ;; + rads/telemetry-service) unit_rads_telemetry_service ;; + rads/cost-service) unit_rads_cost_service ;; + rads/pdm-service) unit_rads_pdm_service ;; + rads/csav/registry-service) unit_rads_registry_service ;; + rads/sce/execution-service) unit_rads_execution_service ;; + rads/transparency-portal) unit_rads_transparency_portal ;; + *) die "unknown unit: $1 (run 'scripts/deploy.sh list')" ;; + esac +} + +planned_units() { + local tree="$1" + shift + local -a tree_units unit want + case "$tree" in + all) tree_units=("${units_secure[@]}" "${units_rads[@]}") ;; + secure) tree_units=("${units_secure[@]}") ;; + rads) tree_units=("${units_rads[@]}") ;; + *) die "unknown tree: $tree (all|secure|rads)" ;; + esac + + if [ $# -eq 0 ]; then + printf '%s\n' "${tree_units[@]}" + return 0 + fi + + for unit in "${tree_units[@]}"; do + for want in "$@"; do + [ "$unit" = "$want" ] && printf '%s\n' "$unit" + done + done +} + +cmd=${1:-} +[ -n "$cmd" ] || { + usage + exit 1 +} +shift + +dry_run=0 +skip_registry_image=0 +positional=() +for arg in "$@"; do + case "$arg" in + --dry-run) dry_run=1 ;; + --skip-registry-image) skip_registry_image=1 ;; + -h | --help) + usage + exit 0 + ;; + -*) die "unknown option: $arg" ;; + *) positional+=("$arg") ;; + esac +done + +if [ "$cmd" = list ] || [ "$cmd" = --list ] || [ "$cmd" = -l ]; then + for unit in "${units_secure[@]}" "${units_rads[@]}"; do + printf '%-34s %s\n' "$unit" "$(describe_unit "$unit")" + done + exit 0 +fi + +[ "$cmd" = deploy ] || { + usage + exit 1 +} + +tree=${positional[0]:-all} +[ ${#positional[@]} -gt 0 ] && positional=("${positional[@]:1}") +[ "$tree" = secure-rads ] && tree=secure + +case "$tree" in +all | secure | rads) ;; +*) die "unknown tree: $tree (all|secure|rads)" ;; +esac + +case "$tree" in +all) allowed=("${units_secure[@]}" "${units_rads[@]}") ;; +secure) allowed=("${units_secure[@]}") ;; +rads) allowed=("${units_rads[@]}") ;; +esac +for requested in "${positional[@]}"; do + known=0 + for unit in "${allowed[@]}"; do + [ "$requested" = "$unit" ] && known=1 && break + done + [ "$known" = 1 ] || die "unknown unit for tree $tree: $requested (run 'scripts/deploy.sh list')" +done + +load_env + +mapfile -t plan < <(planned_units "$tree" "${positional[@]}") +[ ${#plan[@]} -gt 0 ] || die "no units selected for tree $tree" +if [ "$skip_registry_image" = 1 ]; then + filtered=() + for unit in "${plan[@]}"; do + [ "$unit" = secure/registry-image ] || filtered+=("$unit") + done + plan=("${filtered[@]}") +fi + +for unit in "${plan[@]}"; do + printf '==> %s\n' "$unit" + deploy_unit "$unit" +done