|
31 | 31 | # 7. Creates the RDS Proxy `vortex-bench-proxy` in front of the RDS |
32 | 32 | # instance, also with IAM auth. |
33 | 33 | # 8. Creates two GitHub Actions OIDC IAM roles trusted to |
34 | | -# `token.actions.githubusercontent.com` for the `vortex-data/vortex` repo |
35 | | -# (branches `develop` + `ct/bench-v4`), each scoped to an instance dbuser: |
| 34 | +# `token.actions.githubusercontent.com`, each scoped to its repository |
| 35 | +# develop branch and one instance dbuser: |
36 | 36 | # - `GitHubBenchmarkSchemaRole`: `rds-db:connect` on the `migrator` |
37 | 37 | # Postgres user (schema deploys; migration 002 in PR-1.3). |
38 | 38 | # - `GitHubBenchmarkIngestRole`: `rds-db:connect` on the `bench_ingest` |
@@ -69,7 +69,8 @@ readonly DB_MASTER_USERNAME="${DB_MASTER_USERNAME:-postgres}" |
69 | 69 | readonly SCHEMA_ROLE_NAME="${SCHEMA_ROLE_NAME:-GitHubBenchmarkSchemaRole}" |
70 | 70 | readonly INGEST_ROLE_NAME="${INGEST_ROLE_NAME:-GitHubBenchmarkIngestRole}" |
71 | 71 | readonly PROXY_ROLE_NAME="${PROXY_ROLE_NAME:-vortex-bench-proxy-role}" |
72 | | -readonly GITHUB_REPO="${GITHUB_REPO:-vortex-data/vortex}" |
| 72 | +readonly SCHEMA_GITHUB_REPO="${SCHEMA_GITHUB_REPO:-vortex-data/benchmarks-website}" |
| 73 | +readonly INGEST_GITHUB_REPO="${INGEST_GITHUB_REPO:-vortex-data/vortex}" |
73 | 74 | # Postgres role created by migrations/002 in PR-1.3; the OIDC role's |
74 | 75 | # rds-db:connect permission is scoped to this user. NOT overridable (unlike the |
75 | 76 | # other names above): the role name is hardcoded in migrations/002 |
@@ -409,36 +410,29 @@ ensure_oidc_provider() { |
409 | 410 | OIDC_PROVIDER_ARN="$provider_arn" |
410 | 411 | } |
411 | 412 |
|
| 413 | +# Exact subjects deliberately exclude PRs, tags, and retired migration branches. |
| 414 | +# Reprovisioning replaces trust with this declared policy, including on existing roles. |
| 415 | +github_trust_policy() { |
| 416 | + jq -n --arg account "$TARGET_ACCOUNT" --arg repo "$1" '{ |
| 417 | + Version: "2012-10-17", |
| 418 | + Statement: [{ |
| 419 | + Effect: "Allow", |
| 420 | + Principal: {Federated: ("arn:aws:iam::" + $account + ":oidc-provider/token.actions.githubusercontent.com")}, |
| 421 | + Action: "sts:AssumeRoleWithWebIdentity", |
| 422 | + Condition: {StringEquals: { |
| 423 | + "token.actions.githubusercontent.com:aud": "sts.amazonaws.com", |
| 424 | + "token.actions.githubusercontent.com:sub": ("repo:" + $repo + ":ref:refs/heads/develop") |
| 425 | + }} |
| 426 | + }] |
| 427 | + }' |
| 428 | +} |
| 429 | + |
412 | 430 | ensure_schema_role() { |
413 | 431 | log "Step 6: GitHub Actions OIDC role ${SCHEMA_ROLE_NAME}." |
414 | 432 | ensure_oidc_provider |
415 | 433 |
|
416 | | - # Trust-policy sub-claim is scoped to the specific branches the |
417 | | - # schema-deploy.yml workflow runs on (`develop` + `ct/bench-v4`); this |
418 | | - # restriction is the gate against unauthorized OIDC role assumption. A |
419 | | - # `schema-deploy` GitHub Environment / manual-approval gate was deliberately |
420 | | - # declined per the 2026-05-29 deploy-model decision (it only re-confirms the |
421 | | - # authorization already given at PR merge; execution safety comes from the |
422 | | - # per-PR testcontainer migration test), NOT deferred for lack of repo-admin. |
423 | 434 | local trust_policy |
424 | | - trust_policy=$(cat <<EOF |
425 | | -{ |
426 | | - "Version": "2012-10-17", |
427 | | - "Statement": [{ |
428 | | - "Effect": "Allow", |
429 | | - "Principal": {"Federated": "${OIDC_PROVIDER_ARN}"}, |
430 | | - "Action": "sts:AssumeRoleWithWebIdentity", |
431 | | - "Condition": { |
432 | | - "StringEquals": {"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"}, |
433 | | - "StringLike": {"token.actions.githubusercontent.com:sub": [ |
434 | | - "repo:${GITHUB_REPO}:ref:refs/heads/develop", |
435 | | - "repo:${GITHUB_REPO}:ref:refs/heads/ct/bench-v4" |
436 | | - ]} |
437 | | - } |
438 | | - }] |
439 | | -} |
440 | | -EOF |
441 | | -) |
| 435 | + trust_policy=$(github_trust_policy "$SCHEMA_GITHUB_REPO") |
442 | 436 |
|
443 | 437 | if SCHEMA_ROLE_ARN=$(aws iam get-role --role-name "$SCHEMA_ROLE_NAME" \ |
444 | 438 | --query 'Role.Arn' --output text 2>/dev/null); then |
@@ -493,29 +487,8 @@ ensure_ingest_role() { |
493 | 487 | log "Step 6b: GitHub Actions OIDC role ${INGEST_ROLE_NAME}." |
494 | 488 | ensure_oidc_provider |
495 | 489 |
|
496 | | - # Same branch-scoped trust as the schema role: the Phase-2 dual-write CI |
497 | | - # workflows (bench.yml / sql-benchmarks.yml / v3-commit-metadata.yml) ingest on |
498 | | - # push to `develop`, plus `ct/bench-v4` during the migration's dual-write soak. |
499 | | - # The sub-claim restriction is the gate against unauthorized role assumption. |
500 | 490 | local trust_policy |
501 | | - trust_policy=$(cat <<EOF |
502 | | -{ |
503 | | - "Version": "2012-10-17", |
504 | | - "Statement": [{ |
505 | | - "Effect": "Allow", |
506 | | - "Principal": {"Federated": "${OIDC_PROVIDER_ARN}"}, |
507 | | - "Action": "sts:AssumeRoleWithWebIdentity", |
508 | | - "Condition": { |
509 | | - "StringEquals": {"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"}, |
510 | | - "StringLike": {"token.actions.githubusercontent.com:sub": [ |
511 | | - "repo:${GITHUB_REPO}:ref:refs/heads/develop", |
512 | | - "repo:${GITHUB_REPO}:ref:refs/heads/ct/bench-v4" |
513 | | - ]} |
514 | | - } |
515 | | - }] |
516 | | -} |
517 | | -EOF |
518 | | -) |
| 491 | + trust_policy=$(github_trust_policy "$INGEST_GITHUB_REPO") |
519 | 492 |
|
520 | 493 | if INGEST_ROLE_ARN=$(aws iam get-role --role-name "$INGEST_ROLE_NAME" \ |
521 | 494 | --query 'Role.Arn' --output text 2>/dev/null); then |
|
631 | 604 | # ----------------------------------------------------------------------------- |
632 | 605 |
|
633 | 606 | main() { |
| 607 | + [ -z "${GITHUB_REPO+x}" ] || die "GITHUB_REPO was replaced by SCHEMA_GITHUB_REPO and INGEST_GITHUB_REPO." |
| 608 | + if [ "$#" -gt 0 ]; then |
| 609 | + if [ "$#" -eq 2 ] && [ "$1" = "--print-trust" ]; then |
| 610 | + case "$2" in |
| 611 | + schema) github_trust_policy "$SCHEMA_GITHUB_REPO" ;; |
| 612 | + ingest) github_trust_policy "$INGEST_GITHUB_REPO" ;; |
| 613 | + *) die "Expected schema or ingest." ;; |
| 614 | + esac |
| 615 | + return |
| 616 | + fi |
| 617 | + die "Usage: provision.sh [--print-trust schema|ingest]" |
| 618 | + fi |
634 | 619 | verify_prereqs |
635 | 620 | discover_default_vpc |
636 | 621 | ensure_db_subnet_group |
|
0 commit comments