From 34a4a90bd7f41c978785f57ef7b8343159845636 Mon Sep 17 00:00:00 2001
From: beck-8 <34204218+beck-8@users.noreply.github.com>
Date: Thu, 26 Nov 2026 22:33:43 +0800
Subject: [PATCH 01/13] Document FilOzone GitHub management operations
---
README.md | 1 +
docs/RUNBOOK.md | 79 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 80 insertions(+)
create mode 100644 docs/RUNBOOK.md
diff --git a/README.md b/README.md
index 54652c4..8f1323b 100644
--- a/README.md
+++ b/README.md
@@ -17,6 +17,7 @@ A robust template for managing GitHub configurations as code via Pull Requests.
- Learn more about [what GitHub Management is and how it works](docs/ABOUT.md).
- Get started with [setting up GitHub Management](docs/SETUP.md).
- Uncover [how to effectively utilize GitHub Management](docs/HOWTOS.md).
+- Read the [FilOzone runbook](docs/RUNBOOK.md).
## Active Users
diff --git a/docs/RUNBOOK.md b/docs/RUNBOOK.md
new file mode 100644
index 0000000..2987fa4
--- /dev/null
+++ b/docs/RUNBOOK.md
@@ -0,0 +1,79 @@
+# FilOzone github-mgmt runbook
+
+## How it works
+
+Edit `github/FilOzone.yml` to change managed GitHub settings through a PR. `Plan` previews the change, `Apply` makes it, and `Sync` reads GitHub back into Terraform state and YAML. [Organization configuration](../github/FilOzone.yml)
+
+| Backend | Value |
+| --- | --- |
+| FilOz AWS account and region | `941641221830`, `us-east-1` |
+| Bucket and workspace | `filoz-github-mgmt-filozone`, `FilOzone` |
+| State and lock paths | `org/FilOzone/terraform.tfstate` and `org/FilOzone/terraform.tfstate.tflock` |
+| OIDC roles | `filoz-github-mgmt-filozone-ro` and `filoz-github-mgmt-filozone-rw` |
+
+Keep the separate bootstrap state for changes to the versioned bucket or IAM roles. [Backend](../terraform/terraform_override.tf) · [Bootstrap](../terraform/bootstrap/aws.tf)
+
+### Workflow credentials
+
+GitHub Apps authenticate GitHub API calls. Use the read-only App to inspect configuration and the read-write App for steps that apply changes or push branches.
+
+| GitHub App | Jobs that use it |
+| --- | --- |
+| Read-only | `Plan`, the read step of `Fix`, `Apply` prepare, and `Clean Up` (in `push`) |
+| Read-write | `Apply`, `Sync`, `Update`, the push step of `Fix`, `Clean`, `Labels`, and `Upgrade` |
+
+AWS OIDC gives `Plan`, `Comment`, and `Fix` temporary read-only S3 credentials through `read`. `Apply`, `Sync`, and `Clean` use the read-write role through `write`. Both `write` and `push` are restricted to `master`. [GitHub OIDC documentation](https://docs.github.com/en/actions/how-tos/secure-your-work/security-harden-deployments/oidc-in-aws)
+
+## Change access through a PR
+
+1. Edit the relevant member, team, or collaborator in `github/FilOzone.yml`. Open a PR to `master` and check any `Fix` commits.
+2. Review each resource in the Terraform plan posted on the PR. For a long plan, open **Plan → Comment → Show terraform plans** in Actions.
+3. Squash and merge after approval. Check that **Terraform Apply** ran successfully for the merge commit, then verify the result in GitHub.
+4. Wait for `Apply` and `Update` before merging another PR. `Update` attempts to bring eligible open PRs up to date and trigger fresh plans. Update any skipped or conflicting PR branch manually and review its fresh plan. [Update script](../scripts/src/actions/update-pull-requests.ts)
+
+In #83, the single `destroy` removed one direct FOC-PM collaborator grant. Apply succeeded and we verified the grant was removed in GitHub. [Example PR](https://github.com/FilOzone/github-mgmt/pull/83) · [Apply run](https://github.com/FilOzone/github-mgmt/actions/runs/45827615933/job/139935891426)
+
+## Sync from GitHub
+
+Run **Actions → Sync → Run workflow** from `master` with workspace `FilOzone` or blank, `lock=true`, and `refresh=false`. Pause other merges while Sync writes back to `master`. Check that **Sync (FilOzone)** and **Push** succeeded, then review the YAML diff. The [`.sync` file](../.sync) records the run ID.
+
+For a backend cutover, pause merges and disable `Apply` before merging the backend PR. Let existing Apply runs finish. Run Sync against the new backend, re-enable Apply after Sync succeeds, then verify with a fresh Plan and Apply. The first import took about 20 minutes. The first Plan listed merge and sign-off defaults for seven archived repositories. Review the exact fields and verify the repositories stay archived before accepting that diff. [First Sync](https://github.com/FilOzone/github-mgmt/actions/runs/45818396464) · [First Plan](https://github.com/FilOzone/github-mgmt/pull/82#issuecomment-7192897522) · [Provider behavior](https://github.com/integrations/terraform-provider-github/blob/v6.6.0/github/resource_github_repository.go#L740-L746)
+
+## Recover from a failed Apply
+
+Pause other merges and open the failed run for the merge commit.
+
+- **AWS sign-in failed**. Check the role ARN, OIDC trust, and job environment. For GitHub sign-in, check the App ID, installation ID, and PEM secret location.
+- **Reviewed plan missing**. Check **Find sha for plan** and **Download reviewed terraform plan**. Fix failures before any writes and retry only if the reviewed plan is still current.
+- **Plan comparison failed or Apply may have made partial changes**. Check the affected GitHub settings and Terraform state, then review a fresh plan in a follow-up PR. Run `Sync` only when the current GitHub configuration should become the YAML.
+- Resume merges after Apply succeeds, the GitHub result is verified, and `Update` completes. [Apply workflow](../.github/workflows/apply.yml)
+
+## Recover from a stuck lock
+
+Record the lock ID and path from the error. Check for active or queued `Apply`, `Sync`, and `Clean` runs and confirm with the operator that no state writer is active. If automatic unlock failed, a maintainer can use their MFA-backed AWS session from a fresh checkout of `master`.
+
+```sh
+aws sts get-caller-identity --query Account --output text
+terraform -chdir=terraform init -input=false
+terraform -chdir=terraform workspace select FilOzone
+terraform -chdir=terraform workspace show
+```
+
+Verify account `941641221830`, workspace `FilOzone`, and the lock path above. Run `terraform -chdir=terraform force-unlock LOCK_ID` with the ID from the error. Keep locking enabled and review a fresh plan before resuming writes. [Terraform force-unlock](https://developer.hashicorp.com/terraform/language/state/locking#force-unlock)
+
+## Rotate credentials
+
+1. Check **Settings → Secrets and variables → Actions** and **Settings → Environments** for the active secrets. For environment-scoped secrets, place `RO_GITHUB_APP_*` in `read` and `push`, and `RW_GITHUB_APP_*` in `write` and `push`. If using `Upgrade`, also verify the upstream `GITHUB_APP_*` mapping in `push`.
+2. Have an App manager generate a new PEM and update the corresponding `RO_GITHUB_APP_PEM_FILE` or `RW_GITHUB_APP_PEM_FILE`. Check Plan and Fix for the read-only key. Check Apply and any push workflows using the read-write key, including Upgrade if retained. Revoke the old key after verification. [GitHub App key rotation](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/managing-private-keys-for-github-apps)
+
+AWS OIDC uses temporary credentials. Manage role and trust changes in the bootstrap Terraform. Retire any remaining legacy `RO_AWS_*` and `RW_AWS_*` repository secrets after cutover verification and approval.
+
+## Upgrade from upstream
+
+While `Upgrade` is enabled, run it from `master` with the chosen upstream commit SHA in `ref`, then review the generated PR. The `ref` selects the template revision. GitHub loads the reusable workflow from `@master`. [Upgrade workflow](../.github/workflows/upgrade.yml)
+
+If `Upgrade` is retired, use a normal PR.
+
+1. Check out a specific commit of `ipdxco/github-as-code` locally and copy the selected tracked files. Record the upstream SHA in the PR.
+2. Keep the old exclusions (`github/*.yml`, `terraform/*_override.tf`, `README.md`, `scripts/src/actions/fix-yaml-config.ts`, `.github/dependabot.yml`, and `.github/workflows/*_reusable.yml`). Preserve FilOzone's workflow customizations, bootstrap, and runbook. [Upstream file selection](https://github.com/ipdxco/github-as-code/blob/master/.github/workflows/upgrade_reusable.yml#L47-L53)
+3. Open a PR from a branch in this repository using your GitHub account. You can prepare the diff locally or with an agent. Keep the read-write App key in Actions secrets. Review Plan and verify Apply.
From b62b0c69e21d4fc030e7fddfb01faede4950c21c Mon Sep 17 00:00:00 2001
From: beck-8 <34204218+beck-8@users.noreply.github.com>
Date: Wed, 2 Dec 2026 20:42:17 +0800
Subject: [PATCH 02/13] Refine FilOzone GitHub management operations guide
---
README.md | 27 ++++++---------
docs/HOWTOS.md | 3 +-
docs/INFRA_ADMIN.md | 84 +++++++++++++++++++++++++++++++++++++++++++++
docs/RUNBOOK.md | 79 ------------------------------------------
docs/SETUP.md | 4 +--
5 files changed, 98 insertions(+), 99 deletions(-)
create mode 100644 docs/INFRA_ADMIN.md
delete mode 100644 docs/RUNBOOK.md
diff --git a/README.md b/README.md
index 8f1323b..d6690b0 100644
--- a/README.md
+++ b/README.md
@@ -1,24 +1,19 @@
-
+# FilOzone GitHub Management
-
+This repository manages FilOzone's GitHub organization settings through pull requests. The FilOz team maintains it from the [ipdxco/github-as-code template](https://github.com/ipdxco/github-as-code), using a similar setup in [filecoin-project/github-mgmt](https://github.com/filecoin-project/github-mgmt).
-# GitHub Management as Code
+## Request an access change
-A robust template for managing GitHub configurations as code via Pull Requests. Designed with the effective administration of multiple medium to large-sized GitHub organizations in mind.
+1. Edit the relevant membership, team, or repository collaborator in [`github/FilOzone.yml`](github/FilOzone.yml).
+2. Open a PR to `master` and explain what access is needed and why. The [github-mgmt stewards](https://github.com/orgs/FilOzone/teams/github-mgmt-stewards) are requested to review it. Check any formatting commits and review the Terraform plan on the PR.
+3. After approval and merge, [Apply](.github/workflows/apply.yml) applies the reviewed plan. Verify the result in GitHub after the Apply run succeeds.
-
+See [HOWTOS](docs/HOWTOS.md) for configuration examples and the [infrastructure admin guide](docs/INFRA_ADMIN.md) for operating the workflows and Terraform backend.
-## Importance of Access Control
+## Importance of access control
-**NOTE**: Possessing write access to the GitHub Management repository can equate to having administrative privileges over the organizations managed by that repository. Please exercise caution and ensure proper access control measures.
+Write access to this repository can affect administrative settings across the organization. Grant it with the same care as other organization administration access.
-## Dive Deeper
+## Why is it called github-mgmt?
-- Learn more about [what GitHub Management is and how it works](docs/ABOUT.md).
-- Get started with [setting up GitHub Management](docs/SETUP.md).
-- Uncover [how to effectively utilize GitHub Management](docs/HOWTOS.md).
-- Read the [FilOzone runbook](docs/RUNBOOK.md).
-
-## Active Users
-
-A broad range of diverse organizations are already leveraging our GitHub Management solution via Pull Request Workflow. You can find a comprehensive list of these organizations on our [GitHub Management Router repository](https://github.com/pl-strflt/github-mgmt-router). This list showcases the versatility and effectiveness of our GitHub Management system. Our solution can be tailored to meet your unique requirements, driving efficiency and streamlined GitHub organization management.
+`github-mgmt` is the name used for these repositories in the Filecoin community. The upstream template is now called `github-as-code`.
diff --git a/docs/HOWTOS.md b/docs/HOWTOS.md
index 01cd2ee..18219fa 100644
--- a/docs/HOWTOS.md
+++ b/docs/HOWTOS.md
@@ -97,8 +97,7 @@ Run the `Sync` workflow from `master` using **Actions → Sync → Run workflow*
### ...upgrade GitHub Management?
-- Run `Upgrade` GitHub Action workflow
-- Merge the pull request that the workflow created once the `Comment` check passes and you verify the plan posted as a comment - *the plan should not contain any changes*
+Use the [reviewed PR process for upstream upgrades](INFRA_ADMIN.md#upgrade-from-upstream).
### ...remove resources from GitHub Management state?
diff --git a/docs/INFRA_ADMIN.md b/docs/INFRA_ADMIN.md
new file mode 100644
index 0000000..43625a3
--- /dev/null
+++ b/docs/INFRA_ADMIN.md
@@ -0,0 +1,84 @@
+# FilOzone github-mgmt infrastructure admin guide
+
+This guide is for FilOz maintainers operating github-mgmt. See the [README](../README.md) to request access, [ABOUT](ABOUT.md) for the resource model, and [SETUP](SETUP.md) for installation details.
+
+## Terraform state
+
+[Plan](../.github/workflows/plan.yml) previews proposed changes. [Apply](../.github/workflows/apply.yml) runs after a merge to `master`, regenerates the plan, and applies it when it matches the reviewed plan. [Sync](../.github/workflows/sync.yml) reads GitHub into Terraform state and updates the YAML.
+
+| Backend | Value |
+| --- | --- |
+| FilOz AWS account and region | `941641221830`, `us-east-1` |
+| Versioned bucket and Terraform workspace | `filoz-github-mgmt-filozone`, `FilOzone` |
+| State object | `org/FilOzone/terraform.tfstate` |
+| State lock object | `org/FilOzone/terraform.tfstate.tflock` |
+| AWS OIDC roles | `filoz-github-mgmt-filozone-ro` and `filoz-github-mgmt-filozone-rw` |
+
+The [organization backend](../terraform/terraform_override.tf) stores the state used by the workflows. A separate [Terraform bootstrap](../terraform/bootstrap/aws.tf) manages the bucket and IAM roles and stores its own state locally. Keep the bootstrap state in access-controlled, backed-up storage. Before changing the bucket or roles, obtain the current bootstrap state from the maintainer and use it for the change. Store state files outside this repository. [Terraform guidance on sensitive data](https://developer.hashicorp.com/terraform/language/manage-sensitive-data)
+
+## GitHub Actions environments
+
+The [read-only App](https://github.com/organizations/FilOzone/settings/apps/filozone-mgmt-read-only) and [read-write App](https://github.com/organizations/FilOzone/settings/apps/filozone-mgmt-read-write) authenticate calls to GitHub. Their IDs, installation IDs, and PEM files are stored as [environment secrets](https://github.com/FilOzone/github-mgmt/settings/environments). Jobs that use S3 request temporary AWS credentials through [OIDC](https://docs.github.com/en/actions/how-tos/secure-your-work/security-harden-deployments/oidc-in-aws).
+
+| Environment | Allowed branches | GitHub App secrets | AWS access | Jobs |
+| --- | --- | --- | --- | --- |
+| [`read`](https://github.com/FilOzone/github-mgmt/settings/environments/15158011219/edit) | Any | `RO_GITHUB_APP_*` | Read-only role for Plan, Comment, and Fix | Plan (`plan`, `comment`), [Fix](../.github/workflows/fix.yml) (`fix`), Apply (`prepare`) |
+| [`write`](https://github.com/FilOzone/github-mgmt/settings/environments/15158017921/edit) | `master` | `RW_GITHUB_APP_*` | Read-write role for Apply, Sync, and Clean | Apply (`apply`), Sync (`sync`), [Clean](../.github/workflows/clean.yml), [Labels](../.github/workflows/labels.yml) |
+| [`push`](https://github.com/FilOzone/github-mgmt/settings/environments/15157620722/edit) | `master` | `RW_GITHUB_APP_*` and `RO_GITHUB_APP_*` for Clean Up | None | Sync (`push`), Fix (`push`), [Update](../.github/workflows/update.yml), [Clean Up](../.github/workflows/cleanup.yml) |
+
+The `read` jobs use the base branch workflow and read proposed YAML from the PR. The `write` environment is where jobs can assume the AWS state writer role. In `push`, trusted workflows use the same read-write App to publish generated changes without AWS state access. Fix can use that App on a PR event to push formatted YAML back to the PR branch.
+
+## Apply access changes
+
+- Review the full Plan before merging. For a long plan, open **Plan → Comment → Show terraform plans**. After merge, check that **Terraform Apply** ran successfully and verify the result in GitHub.
+- Wait for Apply and Update before merging the next PR. Update attempts to refresh eligible PR branches. Refresh any skipped or conflicting branch and review its new plan. Apply stops if the merged commit's plan differs from the reviewed plan.
+- `prevent_destroy` guards organization memberships and repositories managed by Terraform. Coordinate organization-member removal or repository deletion with the org owners, then run Sync to record the approved change. Normal PRs can remove team memberships and direct collaborator grants. [Terraform resources](../terraform/resources.tf)
+- GitHub prevents changes to collaborators and teams on archived repositories. The YAML for an archived repository is reduced to `archived: true`, and Terraform uses existing state for its grants. To change a grant, unarchive first and verify Apply and the grants restored in YAML, then change the grant in a separate PR. Re-archive after the access change has applied if the repository should stay archived. [GitHub archive behavior](https://docs.github.com/en/repositories/archiving-a-github-repository/archiving-repositories) · [Terraform locals](../terraform/locals.tf) · [Fix logic](../scripts/src/actions/shared/toggle-archived-repos.ts)
+- The Terraform override ignores changes to existing teams' description, parent, and privacy. Update those settings in GitHub. [Terraform overrides](../terraform/resources_override.tf)
+
+## Sync from GitHub
+
+Sync is scheduled for Sundays at 00:00 UTC. For a manual run, open [Sync in Actions](https://github.com/FilOzone/github-mgmt/actions/workflows/sync.yml) and select **Run workflow** on `master`. Leave `workspaces` blank or enter `FilOzone`. Keep `lock=true` and `refresh=false`. This setting skips the optional pre-import refresh. Sync still refreshes state after importing.
+
+Wait for existing state writes to finish and hold merges while Sync runs. Its Push job favors the sync branch when resolving merge conflicts and uses `git push --force` when publishing the result. Verify **Sync (FilOzone)** and **Push** succeeded and review what reached `master`. The [`.sync` file](../.sync) records the run ID.
+
+### Rebuild an empty backend
+
+Pause merges and disable Apply before merging the backend change. Let active state writers finish. Run Sync from `master` against the new backend and wait for both Sync and Push to succeed. Re-enable Apply and validate the new backend with a small PR and its resulting Apply. The initial FilOzone import through Push took about 20 minutes. [Initial Sync run](https://github.com/FilOzone/github-mgmt/actions/runs/45818396464)
+
+A first plan after a rebuild can show default merge and sign-off values on archived repositories. Check that the repositories remain archived and that the plan contains the expected fields. The currently pinned GitHub provider skips updates to repositories that stay archived. Review any other changes before merging. [Provider update logic](https://github.com/integrations/terraform-provider-github/blob/v6.6.0/github/resource_github_repository.go#L740-L746)
+
+## Recover from a failed Apply
+
+Pause other merges and inspect the failed run for the merge commit.
+
+- **Credential failure.** Check the AWS role ARN, OIDC trust, and job environment. For a GitHub sign-in failure, check the App ID, installation ID, and PEM secret in the job's environment.
+- **Reviewed plan missing.** Check **Find sha for plan** and **Download reviewed terraform plan**. Retry after fixing the cause and confirming the reviewed plan is still current.
+- **Plan mismatch, partial Apply, or drift.** Plan and Apply generate plans with `-refresh=false`, so they compare the YAML with saved state. Check affected settings in GitHub as well. If GitHub has the intended settings, run Sync and review the result. If the intended settings are in YAML, save that version first. Run Sync to reconcile state and YAML with GitHub, then restore the intended settings through a follow-up PR with a fresh plan.
+- Resume merges after Apply succeeds, the result is verified in GitHub, and Update finishes.
+
+## Recover from a stuck state lock
+
+An interrupted run or an expired AWS session can leave a lock behind. Get the lock ID and path from the error. Check for active or queued Apply, Sync, and Clean runs, and confirm with the other maintainers that the previous lock holder has stopped and no other writer will start during recovery.
+
+From a fresh checkout of `master`, use an MFA-backed AWS session that can read the backend and delete its lock. Check the AWS account with `aws sts get-caller-identity --query Account --output text` and continue for `941641221830`.
+
+```sh
+terraform -chdir=terraform init -input=false
+terraform -chdir=terraform workspace select FilOzone
+terraform -chdir=terraform workspace show
+```
+
+Verify the workspace and match the lock path from the error to the S3 lock object above. Run `terraform -chdir=terraform force-unlock LOCK_ID` with the lock ID from the failure. Keep locking enabled for the retry. If Sync was interrupted while importing, rerun it against the same backend and workspace to reuse the saved progress. Check the Terraform state version and the next Actions run to verify recovery. [Terraform lock recovery](https://developer.hashicorp.com/terraform/language/state/locking#force-unlock)
+
+## Rotate GitHub App credentials
+
+1. An App manager opens the App's settings and generates a new private key. Update `RO_GITHUB_APP_PEM_FILE` in both `read` and `push`, or `RW_GITHUB_APP_PEM_FILE` in both `write` and `push`, depending on the App being rotated.
+2. Verify the new credentials on the affected workflows. Check Plan and Fix for `read`, an Apply or Sync for `write`, and a token-generating job for `push`. Validate Clean Up in `push` when replacing its read-only App key.
+3. In the App's **Private keys** settings, match the old entry by fingerprint and delete it after verifying the replacement. Confirm that the old fingerprint is absent. [GitHub App key management](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/managing-private-keys-for-github-apps#deleting-private-keys)
+
+## Upgrade from upstream
+
+Bring upstream changes in through a normal PR. Record the chosen [ipdxco/github-as-code](https://github.com/ipdxco/github-as-code) commit and take selected changes while preserving FilOzone's workflow, OIDC and backend configuration, bootstrap, and docs.
+
+The existing dispatchable [Upgrade workflow](../.github/workflows/upgrade.yml) calls the upstream reusable workflow at a moving `@master` ref. Its copy step can overwrite the AWS OIDC workflow changes with versions that expect static AWS secrets. The current reusable job also expects `GITHUB_APP_*` in its token step, while FilOzone stores `RW_GITHUB_APP_*` in `push`. Use the reviewed PR path for upgrades. Review workflow and Terraform code in the PR diff, since Plan only takes `github/` from the PR branch. [Upstream copy logic](https://github.com/ipdxco/github-as-code/blob/eaa899daff9336aba205ab0c4652418d0bca3ec5/.github/workflows/upgrade_reusable.yml#L27-L52) · [Plan workflow](../.github/workflows/plan.yml)
diff --git a/docs/RUNBOOK.md b/docs/RUNBOOK.md
deleted file mode 100644
index 2987fa4..0000000
--- a/docs/RUNBOOK.md
+++ /dev/null
@@ -1,79 +0,0 @@
-# FilOzone github-mgmt runbook
-
-## How it works
-
-Edit `github/FilOzone.yml` to change managed GitHub settings through a PR. `Plan` previews the change, `Apply` makes it, and `Sync` reads GitHub back into Terraform state and YAML. [Organization configuration](../github/FilOzone.yml)
-
-| Backend | Value |
-| --- | --- |
-| FilOz AWS account and region | `941641221830`, `us-east-1` |
-| Bucket and workspace | `filoz-github-mgmt-filozone`, `FilOzone` |
-| State and lock paths | `org/FilOzone/terraform.tfstate` and `org/FilOzone/terraform.tfstate.tflock` |
-| OIDC roles | `filoz-github-mgmt-filozone-ro` and `filoz-github-mgmt-filozone-rw` |
-
-Keep the separate bootstrap state for changes to the versioned bucket or IAM roles. [Backend](../terraform/terraform_override.tf) · [Bootstrap](../terraform/bootstrap/aws.tf)
-
-### Workflow credentials
-
-GitHub Apps authenticate GitHub API calls. Use the read-only App to inspect configuration and the read-write App for steps that apply changes or push branches.
-
-| GitHub App | Jobs that use it |
-| --- | --- |
-| Read-only | `Plan`, the read step of `Fix`, `Apply` prepare, and `Clean Up` (in `push`) |
-| Read-write | `Apply`, `Sync`, `Update`, the push step of `Fix`, `Clean`, `Labels`, and `Upgrade` |
-
-AWS OIDC gives `Plan`, `Comment`, and `Fix` temporary read-only S3 credentials through `read`. `Apply`, `Sync`, and `Clean` use the read-write role through `write`. Both `write` and `push` are restricted to `master`. [GitHub OIDC documentation](https://docs.github.com/en/actions/how-tos/secure-your-work/security-harden-deployments/oidc-in-aws)
-
-## Change access through a PR
-
-1. Edit the relevant member, team, or collaborator in `github/FilOzone.yml`. Open a PR to `master` and check any `Fix` commits.
-2. Review each resource in the Terraform plan posted on the PR. For a long plan, open **Plan → Comment → Show terraform plans** in Actions.
-3. Squash and merge after approval. Check that **Terraform Apply** ran successfully for the merge commit, then verify the result in GitHub.
-4. Wait for `Apply` and `Update` before merging another PR. `Update` attempts to bring eligible open PRs up to date and trigger fresh plans. Update any skipped or conflicting PR branch manually and review its fresh plan. [Update script](../scripts/src/actions/update-pull-requests.ts)
-
-In #83, the single `destroy` removed one direct FOC-PM collaborator grant. Apply succeeded and we verified the grant was removed in GitHub. [Example PR](https://github.com/FilOzone/github-mgmt/pull/83) · [Apply run](https://github.com/FilOzone/github-mgmt/actions/runs/45827615933/job/139935891426)
-
-## Sync from GitHub
-
-Run **Actions → Sync → Run workflow** from `master` with workspace `FilOzone` or blank, `lock=true`, and `refresh=false`. Pause other merges while Sync writes back to `master`. Check that **Sync (FilOzone)** and **Push** succeeded, then review the YAML diff. The [`.sync` file](../.sync) records the run ID.
-
-For a backend cutover, pause merges and disable `Apply` before merging the backend PR. Let existing Apply runs finish. Run Sync against the new backend, re-enable Apply after Sync succeeds, then verify with a fresh Plan and Apply. The first import took about 20 minutes. The first Plan listed merge and sign-off defaults for seven archived repositories. Review the exact fields and verify the repositories stay archived before accepting that diff. [First Sync](https://github.com/FilOzone/github-mgmt/actions/runs/45818396464) · [First Plan](https://github.com/FilOzone/github-mgmt/pull/82#issuecomment-7192897522) · [Provider behavior](https://github.com/integrations/terraform-provider-github/blob/v6.6.0/github/resource_github_repository.go#L740-L746)
-
-## Recover from a failed Apply
-
-Pause other merges and open the failed run for the merge commit.
-
-- **AWS sign-in failed**. Check the role ARN, OIDC trust, and job environment. For GitHub sign-in, check the App ID, installation ID, and PEM secret location.
-- **Reviewed plan missing**. Check **Find sha for plan** and **Download reviewed terraform plan**. Fix failures before any writes and retry only if the reviewed plan is still current.
-- **Plan comparison failed or Apply may have made partial changes**. Check the affected GitHub settings and Terraform state, then review a fresh plan in a follow-up PR. Run `Sync` only when the current GitHub configuration should become the YAML.
-- Resume merges after Apply succeeds, the GitHub result is verified, and `Update` completes. [Apply workflow](../.github/workflows/apply.yml)
-
-## Recover from a stuck lock
-
-Record the lock ID and path from the error. Check for active or queued `Apply`, `Sync`, and `Clean` runs and confirm with the operator that no state writer is active. If automatic unlock failed, a maintainer can use their MFA-backed AWS session from a fresh checkout of `master`.
-
-```sh
-aws sts get-caller-identity --query Account --output text
-terraform -chdir=terraform init -input=false
-terraform -chdir=terraform workspace select FilOzone
-terraform -chdir=terraform workspace show
-```
-
-Verify account `941641221830`, workspace `FilOzone`, and the lock path above. Run `terraform -chdir=terraform force-unlock LOCK_ID` with the ID from the error. Keep locking enabled and review a fresh plan before resuming writes. [Terraform force-unlock](https://developer.hashicorp.com/terraform/language/state/locking#force-unlock)
-
-## Rotate credentials
-
-1. Check **Settings → Secrets and variables → Actions** and **Settings → Environments** for the active secrets. For environment-scoped secrets, place `RO_GITHUB_APP_*` in `read` and `push`, and `RW_GITHUB_APP_*` in `write` and `push`. If using `Upgrade`, also verify the upstream `GITHUB_APP_*` mapping in `push`.
-2. Have an App manager generate a new PEM and update the corresponding `RO_GITHUB_APP_PEM_FILE` or `RW_GITHUB_APP_PEM_FILE`. Check Plan and Fix for the read-only key. Check Apply and any push workflows using the read-write key, including Upgrade if retained. Revoke the old key after verification. [GitHub App key rotation](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/managing-private-keys-for-github-apps)
-
-AWS OIDC uses temporary credentials. Manage role and trust changes in the bootstrap Terraform. Retire any remaining legacy `RO_AWS_*` and `RW_AWS_*` repository secrets after cutover verification and approval.
-
-## Upgrade from upstream
-
-While `Upgrade` is enabled, run it from `master` with the chosen upstream commit SHA in `ref`, then review the generated PR. The `ref` selects the template revision. GitHub loads the reusable workflow from `@master`. [Upgrade workflow](../.github/workflows/upgrade.yml)
-
-If `Upgrade` is retired, use a normal PR.
-
-1. Check out a specific commit of `ipdxco/github-as-code` locally and copy the selected tracked files. Record the upstream SHA in the PR.
-2. Keep the old exclusions (`github/*.yml`, `terraform/*_override.tf`, `README.md`, `scripts/src/actions/fix-yaml-config.ts`, `.github/dependabot.yml`, and `.github/workflows/*_reusable.yml`). Preserve FilOzone's workflow customizations, bootstrap, and runbook. [Upstream file selection](https://github.com/ipdxco/github-as-code/blob/master/.github/workflows/upgrade_reusable.yml#L47-L53)
-3. Open a PR from a branch in this repository using your GitHub account. You can prepare the diff locally or with an agent. Keep the read-write App key in Actions secrets. Review Plan and verify Apply.
diff --git a/docs/SETUP.md b/docs/SETUP.md
index b6151f1..9e0b97c 100644
--- a/docs/SETUP.md
+++ b/docs/SETUP.md
@@ -47,8 +47,8 @@ FilOzone uses a versioned S3 bucket for Terraform state and [S3 lock files](http
## GitHub Actions Environments and Secrets
-- [ ] Create GitHub Actions environments named `read`, `write`, and `push`, and configure protection rules such as required reviewers. Workflows that read organization state reference `read`; workflows that write organization state reference `write`; workflows that push generated changes to the GitHub Management repository reference `push`.
-- [ ] [Create encrypted secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-an-organization) for the GitHub organization and allow the repository to access them (\*replace `$GITHUB_ORGANIZATION_NAME` with the GitHub organization name) - *these secrets are read by the GitHub Action workflows*
+- [ ] Create GitHub Actions environments named `read`, `write`, and `push`. Restrict `write` and `push` to the `master` branch. See the [environment and job mapping](INFRA_ADMIN.md#github-actions-environments).
+- [ ] Create the GitHub App credentials as environment secrets. Add the `RO_GITHUB_APP_*` secrets to `read` and `push`, and the `RW_GITHUB_APP_*` secrets to `write` and `push`.
- [ ] Go to `https://github.com/organizations/$GITHUB_ORGANIZATION_NAME/settings/apps/$GITHUB_APP_NAME` and copy the `App ID`
- [ ] `RO_GITHUB_APP_ID`
- [ ] `RW_GITHUB_APP_ID`
From dd9366a7f43224c56f73bf121c07a26800225ed4 Mon Sep 17 00:00:00 2001
From: beck-8 <34204218+beck-8@users.noreply.github.com>
Date: Wed, 2 Dec 2026 20:54:11 +0800
Subject: [PATCH 03/13] Document 1Password storage for bootstrap state
---
docs/INFRA_ADMIN.md | 2 +-
docs/SETUP.md | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/INFRA_ADMIN.md b/docs/INFRA_ADMIN.md
index 43625a3..a5e3285 100644
--- a/docs/INFRA_ADMIN.md
+++ b/docs/INFRA_ADMIN.md
@@ -14,7 +14,7 @@ This guide is for FilOz maintainers operating github-mgmt. See the [README](../R
| State lock object | `org/FilOzone/terraform.tfstate.tflock` |
| AWS OIDC roles | `filoz-github-mgmt-filozone-ro` and `filoz-github-mgmt-filozone-rw` |
-The [organization backend](../terraform/terraform_override.tf) stores the state used by the workflows. A separate [Terraform bootstrap](../terraform/bootstrap/aws.tf) manages the bucket and IAM roles and stores its own state locally. Keep the bootstrap state in access-controlled, backed-up storage. Before changing the bucket or roles, obtain the current bootstrap state from the maintainer and use it for the change. Store state files outside this repository. [Terraform guidance on sensitive data](https://developer.hashicorp.com/terraform/language/manage-sensitive-data)
+The [organization backend](../terraform/terraform_override.tf) stores the state used by the workflows. A separate [Terraform bootstrap](../terraform/bootstrap/aws.tf) manages the bucket and IAM roles and stores its own state locally. Keep the current bootstrap `terraform.tfstate` in the FilOz team’s 1Password. Before changing the bucket or roles, retrieve it from the team vault or ask a FilOz maintainer with vault access for the current copy. Update the vault copy after each successful bootstrap Apply. [Terraform guidance on sensitive data](https://developer.hashicorp.com/terraform/language/manage-sensitive-data)
## GitHub Actions environments
diff --git a/docs/SETUP.md b/docs/SETUP.md
index 9e0b97c..6fa87f7 100644
--- a/docs/SETUP.md
+++ b/docs/SETUP.md
@@ -14,7 +14,7 @@
FilOzone uses a versioned S3 bucket for Terraform state and [S3 lock files](https://developer.hashicorp.com/terraform/language/backend/s3#enabling-s3-state-locking). GitHub Actions uses [OIDC](https://docs.github.com/en/actions/how-tos/secure-your-work/security-harden-deployments/oidc-in-aws) to assume one of two IAM roles.
- [ ] Use the [bootstrap Terraform configuration](../terraform/bootstrap/aws.tf) to manage the bucket and roles in the FilOz AWS account. The account already has the GitHub Actions OIDC provider.
-- [ ] Keep the bootstrap Terraform state in secure storage and use that state for subsequent changes to the bucket and roles.
+- [ ] Store the bootstrap Terraform state in the FilOz team’s 1Password and use that state for subsequent changes to the bucket and roles. See [Terraform state in the admin guide](INFRA_ADMIN.md#terraform-state).
- [ ] If you change the backend, keep [terraform/terraform_override.tf](../terraform/terraform_override.tf), the IAM policies, and the workflow role ARNs in sync.
- [ ] Restrict the GitHub Actions `write` environment to `master`. The read-only role trusts the `read` environment, and the read-write role trusts the `write` environment.
From b586113c480bdf1aeaebef706b38f627dbad673a Mon Sep 17 00:00:00 2001
From: beck-8 <34204218+beck-8@users.noreply.github.com>
Date: Wed, 2 Dec 2026 20:57:48 +0800
Subject: [PATCH 04/13] Clarify FilOzone state recovery and operator steps
---
docs/INFRA_ADMIN.md | 14 +++++++++-----
docs/SETUP.md | 4 ++--
2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/docs/INFRA_ADMIN.md b/docs/INFRA_ADMIN.md
index a5e3285..eb68c68 100644
--- a/docs/INFRA_ADMIN.md
+++ b/docs/INFRA_ADMIN.md
@@ -14,7 +14,7 @@ This guide is for FilOz maintainers operating github-mgmt. See the [README](../R
| State lock object | `org/FilOzone/terraform.tfstate.tflock` |
| AWS OIDC roles | `filoz-github-mgmt-filozone-ro` and `filoz-github-mgmt-filozone-rw` |
-The [organization backend](../terraform/terraform_override.tf) stores the state used by the workflows. A separate [Terraform bootstrap](../terraform/bootstrap/aws.tf) manages the bucket and IAM roles and stores its own state locally. Keep the current bootstrap `terraform.tfstate` in the FilOz team’s 1Password. Before changing the bucket or roles, retrieve it from the team vault or ask a FilOz maintainer with vault access for the current copy. Update the vault copy after each successful bootstrap Apply. [Terraform guidance on sensitive data](https://developer.hashicorp.com/terraform/language/manage-sensitive-data)
+The [organization backend](../terraform/terraform_override.tf) stores the state used by the workflows. A separate [Terraform bootstrap](../terraform/bootstrap/aws.tf) manages the bucket and IAM roles and stores its own state locally. Keep the current bootstrap `terraform.tfstate` in the FilOz team’s 1Password. Before changing the bucket or roles, retrieve it from the team vault or ask a FilOz maintainer with vault access for the current copy. Coordinate with other maintainers so one person at a time uses and updates this local state. Update the vault copy after each successful bootstrap Apply. Keep state files outside Git. [Terraform guidance on sensitive data](https://developer.hashicorp.com/terraform/language/manage-sensitive-data)
## GitHub Actions environments
@@ -26,7 +26,7 @@ The [read-only App](https://github.com/organizations/FilOzone/settings/apps/filo
| [`write`](https://github.com/FilOzone/github-mgmt/settings/environments/15158017921/edit) | `master` | `RW_GITHUB_APP_*` | Read-write role for Apply, Sync, and Clean | Apply (`apply`), Sync (`sync`), [Clean](../.github/workflows/clean.yml), [Labels](../.github/workflows/labels.yml) |
| [`push`](https://github.com/FilOzone/github-mgmt/settings/environments/15157620722/edit) | `master` | `RW_GITHUB_APP_*` and `RO_GITHUB_APP_*` for Clean Up | None | Sync (`push`), Fix (`push`), [Update](../.github/workflows/update.yml), [Clean Up](../.github/workflows/cleanup.yml) |
-The `read` jobs use the base branch workflow and read proposed YAML from the PR. The `write` environment is where jobs can assume the AWS state writer role. In `push`, trusted workflows use the same read-write App to publish generated changes without AWS state access. Fix can use that App on a PR event to push formatted YAML back to the PR branch.
+On PR events, Plan and Fix run the base branch workflow and use the PR's `github/` directory as input. The `write` environment is where jobs can assume the AWS state writer role. In `push`, trusted workflows use the same read-write App to publish generated changes without AWS state access. Fix can use that App on a PR event to push formatted YAML back to the PR branch.
## Apply access changes
@@ -42,9 +42,13 @@ Sync is scheduled for Sundays at 00:00 UTC. For a manual run, open [Sync in Acti
Wait for existing state writes to finish and hold merges while Sync runs. Its Push job favors the sync branch when resolving merge conflicts and uses `git push --force` when publishing the result. Verify **Sync (FilOzone)** and **Push** succeeded and review what reached `master`. The [`.sync` file](../.sync) records the run ID.
+## Recover organization state
+
+Hold unrelated merges and disable Apply. Coordinate with maintainers to pause routine Sync and Clean runs, then let active state writers finish. If the S3 state object was lost or corrupted, use the exact bucket and state key listed above. Copy the last known-good version to the same key as a new current version. Compare the recovered state with the actual GitHub settings before resuming writes. If GitHub changed after the snapshot, use the drift recovery steps below and enable Apply before merging any recovery PR. Resume normal workflows and merges after verification. [S3 version recovery](https://docs.aws.amazon.com/AmazonS3/latest/userguide/RestoringPreviousVersions.html)
+
### Rebuild an empty backend
-Pause merges and disable Apply before merging the backend change. Let active state writers finish. Run Sync from `master` against the new backend and wait for both Sync and Push to succeed. Re-enable Apply and validate the new backend with a small PR and its resulting Apply. The initial FilOzone import through Push took about 20 minutes. [Initial Sync run](https://github.com/FilOzone/github-mgmt/actions/runs/45818396464)
+Use a full Sync when initializing a new backend or when no usable state version remains. Keep Apply disabled. If switching backends, merge the backend change first. Run Sync from `master` against the intended backend and wait for both Sync and Push to succeed. Re-enable Apply and validate the backend with a small PR and its resulting Apply. The initial FilOzone import through Push took about 20 minutes. [Initial Sync run](https://github.com/FilOzone/github-mgmt/actions/runs/45818396464)
A first plan after a rebuild can show default merge and sign-off values on archived repositories. Check that the repositories remain archived and that the plan contains the expected fields. The currently pinned GitHub provider skips updates to repositories that stay archived. Review any other changes before merging. [Provider update logic](https://github.com/integrations/terraform-provider-github/blob/v6.6.0/github/resource_github_repository.go#L740-L746)
@@ -53,7 +57,7 @@ A first plan after a rebuild can show default merge and sign-off values on archi
Pause other merges and inspect the failed run for the merge commit.
- **Credential failure.** Check the AWS role ARN, OIDC trust, and job environment. For a GitHub sign-in failure, check the App ID, installation ID, and PEM secret in the job's environment.
-- **Reviewed plan missing.** Check **Find sha for plan** and **Download reviewed terraform plan**. Retry after fixing the cause and confirming the reviewed plan is still current.
+- **Reviewed plan missing.** Check **Find sha for plan** and **Download reviewed terraform plan**. Retry the failed run after fixing the cause and confirming the reviewed plan is still current. A fresh manual dispatch looks for a Plan artifact for the selected commit.
- **Plan mismatch, partial Apply, or drift.** Plan and Apply generate plans with `-refresh=false`, so they compare the YAML with saved state. Check affected settings in GitHub as well. If GitHub has the intended settings, run Sync and review the result. If the intended settings are in YAML, save that version first. Run Sync to reconcile state and YAML with GitHub, then restore the intended settings through a follow-up PR with a fresh plan.
- Resume merges after Apply succeeds, the result is verified in GitHub, and Update finishes.
@@ -74,7 +78,7 @@ Verify the workspace and match the lock path from the error to the S3 lock objec
## Rotate GitHub App credentials
1. An App manager opens the App's settings and generates a new private key. Update `RO_GITHUB_APP_PEM_FILE` in both `read` and `push`, or `RW_GITHUB_APP_PEM_FILE` in both `write` and `push`, depending on the App being rotated.
-2. Verify the new credentials on the affected workflows. Check Plan and Fix for `read`, an Apply or Sync for `write`, and a token-generating job for `push`. Validate Clean Up in `push` when replacing its read-only App key.
+2. Verify the new credentials on the affected workflows. Check Plan and Fix for `read`, an Apply or Sync for `write`, and a token-generating job for `push`. Verify the read-only key in `push` on an approved Clean Up run. That workflow can update the cleanup branch.
3. In the App's **Private keys** settings, match the old entry by fingerprint and delete it after verifying the replacement. Confirm that the old fingerprint is absent. [GitHub App key management](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/managing-private-keys-for-github-apps#deleting-private-keys)
## Upgrade from upstream
diff --git a/docs/SETUP.md b/docs/SETUP.md
index 6fa87f7..24508d3 100644
--- a/docs/SETUP.md
+++ b/docs/SETUP.md
@@ -63,7 +63,7 @@ FilOzone uses a versioned S3 bucket for Terraform state and [S3 lock files](http
*NOTE*: Advanced users might want to modify the resource types and their arguments/attributes managed by GitHub Management at this stage.
-*NOTE*: You can manage more than one organization from a single GitHub Management repository. To do so create more YAMLs under `github` directory. Remember to set up secrets for all your organizations.
+This deployment manages the `FilOzone` Terraform workspace. The bootstrap IAM policies scope state access to that workspace and the backend's default key.
- [ ] [Clone the repository](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository)
- [ ] Replace placeholder strings in the clone - *the repository needs to be customised for the specific organization it is supposed to manage*
@@ -74,7 +74,7 @@ FilOzone uses a versioned S3 bucket for Terraform state and [S3 lock files](http
## GitHub Management Sync Flow
-- [ ] Follow [How to synchronize GitHub Management with GitHub?](HOWTOS.md#synchronize-github-management-with-github) to commit the terraform lock and initialize terraform state
+- [ ] Follow [How to synchronize GitHub Management with GitHub?](HOWTOS.md#synchronize-github-management-with-github) to initialize the FilOzone workspace state
## GitHub Management Repository Protections
From 02be484493f5426a85d5b6882972a79c7bc61fc7 Mon Sep 17 00:00:00 2001
From: beck-8 <34204218+beck-8@users.noreply.github.com>
Date: Wed, 2 Dec 2026 21:06:03 +0800
Subject: [PATCH 05/13] Shorten S3 state recovery guidance
---
docs/INFRA_ADMIN.md | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/docs/INFRA_ADMIN.md b/docs/INFRA_ADMIN.md
index eb68c68..ab9ddb5 100644
--- a/docs/INFRA_ADMIN.md
+++ b/docs/INFRA_ADMIN.md
@@ -44,11 +44,13 @@ Wait for existing state writes to finish and hold merges while Sync runs. Its Pu
## Recover organization state
-Hold unrelated merges and disable Apply. Coordinate with maintainers to pause routine Sync and Clean runs, then let active state writers finish. If the S3 state object was lost or corrupted, use the exact bucket and state key listed above. Copy the last known-good version to the same key as a new current version. Compare the recovered state with the actual GitHub settings before resuming writes. If GitHub changed after the snapshot, use the drift recovery steps below and enable Apply before merging any recovery PR. Resume normal workflows and merges after verification. [S3 version recovery](https://docs.aws.amazon.com/AmazonS3/latest/userguide/RestoringPreviousVersions.html)
+If the S3 state is missing or corrupt, pause merges and new state writes, and let active writers finish. Copy the last known-good version of `terraform.tfstate` to the same S3 key to make it current. Check the restored state against GitHub and [reconcile any differences](#recover-from-a-failed-apply) before resuming normal writes. [S3 version recovery](https://docs.aws.amazon.com/AmazonS3/latest/userguide/RestoringPreviousVersions.html)
+
+For a failed run that left a lock, see [Recover from a stuck state lock](#recover-from-a-stuck-state-lock).
### Rebuild an empty backend
-Use a full Sync when initializing a new backend or when no usable state version remains. Keep Apply disabled. If switching backends, merge the backend change first. Run Sync from `master` against the intended backend and wait for both Sync and Push to succeed. Re-enable Apply and validate the backend with a small PR and its resulting Apply. The initial FilOzone import through Push took about 20 minutes. [Initial Sync run](https://github.com/FilOzone/github-mgmt/actions/runs/45818396464)
+Use a full Sync when initializing a new backend or when no usable state version remains. Pause merges, disable Apply, and let active state writers finish. If switching backends, merge the backend change first. Run Sync from `master` against the intended backend and wait for both Sync and Push to succeed. Re-enable Apply and validate the backend with a small PR and its resulting Apply. The initial FilOzone import through Push took about 20 minutes. [Initial Sync run](https://github.com/FilOzone/github-mgmt/actions/runs/45818396464)
A first plan after a rebuild can show default merge and sign-off values on archived repositories. Check that the repositories remain archived and that the plan contains the expected fields. The currently pinned GitHub provider skips updates to repositories that stay archived. Review any other changes before merging. [Provider update logic](https://github.com/integrations/terraform-provider-github/blob/v6.6.0/github/resource_github_repository.go#L740-L746)
From 2b973bacab99544a17fe9a3c8c65774fc538082a Mon Sep 17 00:00:00 2001
From: beck-8 <34204218+beck-8@users.noreply.github.com>
Date: Wed, 2 Dec 2026 21:11:02 +0800
Subject: [PATCH 06/13] Retire the automatic upstream upgrade workflow
---
.github/workflows/upgrade.yml | 19 -------------------
docs/INFRA_ADMIN.md | 6 +++---
2 files changed, 3 insertions(+), 22 deletions(-)
delete mode 100644 .github/workflows/upgrade.yml
diff --git a/.github/workflows/upgrade.yml b/.github/workflows/upgrade.yml
deleted file mode 100644
index 9cc6b50..0000000
--- a/.github/workflows/upgrade.yml
+++ /dev/null
@@ -1,19 +0,0 @@
-name: Upgrade
-
-on:
- workflow_dispatch:
- inputs:
- ref:
- required: false
- description: The github-as-code ref to upgrade to
- default: master
-
-jobs:
- upgrade:
- uses: ipdxco/github-as-code/.github/workflows/upgrade_reusable.yml@master
- with:
- ref: ${{ inputs.ref }}
- secrets:
- GITHUB_APP_ID: ${{ secrets.RW_GITHUB_APP_ID }}
- GITHUB_APP_INSTALLATION_ID: ${{ secrets[format('RW_GITHUB_APP_INSTALLATION_ID_{0}', github.repository_owner)] || secrets.RW_GITHUB_APP_INSTALLATION_ID }}
- GITHUB_APP_PEM_FILE: ${{ secrets.RW_GITHUB_APP_PEM_FILE }}
diff --git a/docs/INFRA_ADMIN.md b/docs/INFRA_ADMIN.md
index ab9ddb5..61f3afa 100644
--- a/docs/INFRA_ADMIN.md
+++ b/docs/INFRA_ADMIN.md
@@ -85,6 +85,6 @@ Verify the workspace and match the lock path from the error to the S3 lock objec
## Upgrade from upstream
-Bring upstream changes in through a normal PR. Record the chosen [ipdxco/github-as-code](https://github.com/ipdxco/github-as-code) commit and take selected changes while preserving FilOzone's workflow, OIDC and backend configuration, bootstrap, and docs.
-
-The existing dispatchable [Upgrade workflow](../.github/workflows/upgrade.yml) calls the upstream reusable workflow at a moving `@master` ref. Its copy step can overwrite the AWS OIDC workflow changes with versions that expect static AWS secrets. The current reusable job also expects `GITHUB_APP_*` in its token step, while FilOzone stores `RW_GITHUB_APP_*` in `push`. Use the reviewed PR path for upgrades. Review workflow and Terraform code in the PR diff, since Plan only takes `github/` from the PR branch. [Upstream copy logic](https://github.com/ipdxco/github-as-code/blob/eaa899daff9336aba205ab0c4652418d0bca3ec5/.github/workflows/upgrade_reusable.yml#L27-L52) · [Plan workflow](../.github/workflows/plan.yml)
+1. Select a commit of [ipdxco/github-as-code](https://github.com/ipdxco/github-as-code) and record its SHA in the PR description.
+2. Apply selected upstream changes. Preserve FilOzone's OIDC workflows, Terraform backend and bootstrap, and local documentation. Keep upgrades on the manual PR path.
+3. Open a PR and review the workflow and Terraform diffs directly. [Plan](../.github/workflows/plan.yml) only takes the PR's `github/` directory as input. Review the Plan and verify Apply after merge.
From 18eeed526487e9acb045b1598d6dd17a1fffa835 Mon Sep 17 00:00:00 2001
From: beck-8 <34204218+beck-8@users.noreply.github.com>
Date: Wed, 2 Dec 2026 21:15:53 +0800
Subject: [PATCH 07/13] Remove the one-time FilOzone migration note
---
docs/INFRA_ADMIN.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/INFRA_ADMIN.md b/docs/INFRA_ADMIN.md
index 61f3afa..4a2e114 100644
--- a/docs/INFRA_ADMIN.md
+++ b/docs/INFRA_ADMIN.md
@@ -50,7 +50,7 @@ For a failed run that left a lock, see [Recover from a stuck state lock](#recove
### Rebuild an empty backend
-Use a full Sync when initializing a new backend or when no usable state version remains. Pause merges, disable Apply, and let active state writers finish. If switching backends, merge the backend change first. Run Sync from `master` against the intended backend and wait for both Sync and Push to succeed. Re-enable Apply and validate the backend with a small PR and its resulting Apply. The initial FilOzone import through Push took about 20 minutes. [Initial Sync run](https://github.com/FilOzone/github-mgmt/actions/runs/45818396464)
+Use a full Sync when initializing a new backend or when no usable state version remains. Pause merges, disable Apply, and let active state writers finish. If switching backends, merge the backend change first. Run Sync from `master` against the intended backend and wait for both Sync and Push to succeed. Re-enable Apply and validate the backend with a small PR and its resulting Apply.
A first plan after a rebuild can show default merge and sign-off values on archived repositories. Check that the repositories remain archived and that the plan contains the expected fields. The currently pinned GitHub provider skips updates to repositories that stay archived. Review any other changes before merging. [Provider update logic](https://github.com/integrations/terraform-provider-github/blob/v6.6.0/github/resource_github_repository.go#L740-L746)
From ebcbb0ed1c6192640128361d467347c8327c49f1 Mon Sep 17 00:00:00 2001
From: beck-8 <34204218+beck-8@users.noreply.github.com>
Date: Wed, 2 Dec 2026 21:51:21 +0800
Subject: [PATCH 08/13] Keep the observed FilOzone rebuild time
---
docs/INFRA_ADMIN.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/INFRA_ADMIN.md b/docs/INFRA_ADMIN.md
index 4a2e114..61f3afa 100644
--- a/docs/INFRA_ADMIN.md
+++ b/docs/INFRA_ADMIN.md
@@ -50,7 +50,7 @@ For a failed run that left a lock, see [Recover from a stuck state lock](#recove
### Rebuild an empty backend
-Use a full Sync when initializing a new backend or when no usable state version remains. Pause merges, disable Apply, and let active state writers finish. If switching backends, merge the backend change first. Run Sync from `master` against the intended backend and wait for both Sync and Push to succeed. Re-enable Apply and validate the backend with a small PR and its resulting Apply.
+Use a full Sync when initializing a new backend or when no usable state version remains. Pause merges, disable Apply, and let active state writers finish. If switching backends, merge the backend change first. Run Sync from `master` against the intended backend and wait for both Sync and Push to succeed. Re-enable Apply and validate the backend with a small PR and its resulting Apply. The initial FilOzone import through Push took about 20 minutes. [Initial Sync run](https://github.com/FilOzone/github-mgmt/actions/runs/45818396464)
A first plan after a rebuild can show default merge and sign-off values on archived repositories. Check that the repositories remain archived and that the plan contains the expected fields. The currently pinned GitHub provider skips updates to repositories that stay archived. Review any other changes before merging. [Provider update logic](https://github.com/integrations/terraform-provider-github/blob/v6.6.0/github/resource_github_repository.go#L740-L746)
From 4c0c596bc2389d0078c6d82d522d854bcafbff22 Mon Sep 17 00:00:00 2001
From: beck-8 <34204218+beck-8@users.noreply.github.com>
Date: Wed, 2 Dec 2026 22:14:44 +0800
Subject: [PATCH 09/13] Document FilOzone organization member removal
---
README.md | 2 ++
docs/INFRA_ADMIN.md | 9 ++++++++-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index d6690b0..d77639a 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,8 @@ This repository manages FilOzone's GitHub organization settings through pull req
2. Open a PR to `master` and explain what access is needed and why. The [github-mgmt stewards](https://github.com/orgs/FilOzone/teams/github-mgmt-stewards) are requested to review it. Check any formatting commits and review the Terraform plan on the PR.
3. After approval and merge, [Apply](.github/workflows/apply.yml) applies the reviewed plan. Verify the result in GitHub after the Apply run succeeds.
+To request that someone be removed from FilOzone, open a PR to revoke their team memberships and direct repository access. Keep their entry in `members` and add a comment explaining that an organization owner will remove them in GitHub. See the [member removal procedure](docs/INFRA_ADMIN.md#remove-a-member-from-filozone) for the steps after merge.
+
See [HOWTOS](docs/HOWTOS.md) for configuration examples and the [infrastructure admin guide](docs/INFRA_ADMIN.md) for operating the workflows and Terraform backend.
## Importance of access control
diff --git a/docs/INFRA_ADMIN.md b/docs/INFRA_ADMIN.md
index 61f3afa..c7d2844 100644
--- a/docs/INFRA_ADMIN.md
+++ b/docs/INFRA_ADMIN.md
@@ -32,10 +32,17 @@ On PR events, Plan and Fix run the base branch workflow and use the PR's `github
- Review the full Plan before merging. For a long plan, open **Plan → Comment → Show terraform plans**. After merge, check that **Terraform Apply** ran successfully and verify the result in GitHub.
- Wait for Apply and Update before merging the next PR. Update attempts to refresh eligible PR branches. Refresh any skipped or conflicting branch and review its new plan. Apply stops if the merged commit's plan differs from the reviewed plan.
-- `prevent_destroy` guards organization memberships and repositories managed by Terraform. Coordinate organization-member removal or repository deletion with the org owners, then run Sync to record the approved change. Normal PRs can remove team memberships and direct collaborator grants. [Terraform resources](../terraform/resources.tf)
+- `prevent_destroy` guards organization memberships and repositories managed by Terraform. Use the [member removal procedure](#remove-a-member-from-filozone) for organization members. Coordinate repository deletion with an org owner and run Sync after the approved deletion. Normal PRs can remove team memberships and direct collaborator grants. [Terraform resources](../terraform/resources.tf)
- GitHub prevents changes to collaborators and teams on archived repositories. The YAML for an archived repository is reduced to `archived: true`, and Terraform uses existing state for its grants. To change a grant, unarchive first and verify Apply and the grants restored in YAML, then change the grant in a separate PR. Re-archive after the access change has applied if the repository should stay archived. [GitHub archive behavior](https://docs.github.com/en/repositories/archiving-a-github-repository/archiving-repositories) · [Terraform locals](../terraform/locals.tf) · [Fix logic](../scripts/src/actions/shared/toggle-archived-repos.ts)
- The Terraform override ignores changes to existing teams' description, parent, and privacy. Update those settings in GitHub. [Terraform overrides](../terraform/resources_override.tf)
+### Remove a member from FilOzone
+
+1. Open a PR to remove the person's team memberships and direct grants on repositories. Keep their entry in the `members` section and add a comment explaining that an org owner will remove them in GitHub.
+2. After the PR merges, verify that Apply succeeded and that GitHub shows the team memberships and direct grants were removed.
+3. A FilOzone org owner selects the member on the [People](https://github.com/orgs/FilOzone/people) page, chooses **Remove from organization**, and confirms the removal. [GitHub member removal](https://docs.github.com/en/organizations/managing-membership-in-your-organization/removing-a-member-from-your-organization)
+4. A maintainer runs [Sync](#sync-from-github) from `master`. Check that Sync and Push succeed and that the member no longer appears in `github/FilOzone.yml`.
+
## Sync from GitHub
Sync is scheduled for Sundays at 00:00 UTC. For a manual run, open [Sync in Actions](https://github.com/FilOzone/github-mgmt/actions/workflows/sync.yml) and select **Run workflow** on `master`. Leave `workspaces` blank or enter `FilOzone`. Keep `lock=true` and `refresh=false`. This setting skips the optional pre-import refresh. Sync still refreshes state after importing.
From 1e8a74854a5be102a25f6fac56c093b660942f39 Mon Sep 17 00:00:00 2001
From: Steve Loeppky
Date: Wed, 2 Dec 2026 19:29:09 -0800
Subject: [PATCH 10/13] Explain why there are three environments and fix the
README FAQ
Restore the reasoning for read, write and push (why read allows any branch, why push has no AWS role) and use the github-mgmt naming history from the review.
---
README.md | 2 +-
docs/INFRA_ADMIN.md | 8 +++++++-
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index d77639a..735786e 100644
--- a/README.md
+++ b/README.md
@@ -18,4 +18,4 @@ Write access to this repository can affect administrative settings across the or
## Why is it called github-mgmt?
-`github-mgmt` is the name used for these repositories in the Filecoin community. The upstream template is now called `github-as-code`.
+[ipdxco/github-as-code](https://github.com/ipdxco/github-as-code) grew out of [filecoin-project/github-mgmt](https://github.com/filecoin-project/github-mgmt). github-mgmt was the original name, and it's the one that has stuck in the Filecoin community.
diff --git a/docs/INFRA_ADMIN.md b/docs/INFRA_ADMIN.md
index c7d2844..af5f437 100644
--- a/docs/INFRA_ADMIN.md
+++ b/docs/INFRA_ADMIN.md
@@ -26,7 +26,13 @@ The [read-only App](https://github.com/organizations/FilOzone/settings/apps/filo
| [`write`](https://github.com/FilOzone/github-mgmt/settings/environments/15158017921/edit) | `master` | `RW_GITHUB_APP_*` | Read-write role for Apply, Sync, and Clean | Apply (`apply`), Sync (`sync`), [Clean](../.github/workflows/clean.yml), [Labels](../.github/workflows/labels.yml) |
| [`push`](https://github.com/FilOzone/github-mgmt/settings/environments/15157620722/edit) | `master` | `RW_GITHUB_APP_*` and `RO_GITHUB_APP_*` for Clean Up | None | Sync (`push`), Fix (`push`), [Update](../.github/workflows/update.yml), [Clean Up](../.github/workflows/cleanup.yml) |
-On PR events, Plan and Fix run the base branch workflow and use the PR's `github/` directory as input. The `write` environment is where jobs can assume the AWS state writer role. In `push`, trusted workflows use the same read-write App to publish generated changes without AWS state access. Fix can use that App on a PR event to push formatted YAML back to the PR branch.
+Why three environments:
+
+- `read` runs on PRs, before the change is reviewed, so it allows any branch and gets only the read-only App and the read-only state role. An unmerged PR can't change the organization or the state. On PR events, Plan and Fix run the base branch workflow and use the PR's `github/` directory as input.
+- `write` changes the organization and the Terraform state. Only `master` can use it, so only reviewed and merged code gets the read-write App and the state writer role. The read-write AWS role trusts only this environment.
+- `push` commits generated changes back to this repository (formatted YAML, Sync results, updated PR branches). It needs the read-write App to push, but not the state, so it has no AWS role. Fix's `push` job runs on PR events and pushes formatted YAML to the PR branch, which is another reason to keep state access out of `push`.
+
+The App secrets exist only in these environments, so a job without `environment:` gets no App credentials.
## Apply access changes
From 27054a8711296b2df2cc3dff69c7d54cd8ba2c64 Mon Sep 17 00:00:00 2001
From: Steve Loeppky
Date: Wed, 2 Dec 2026 20:06:19 -0800
Subject: [PATCH 11/13] Address review: clearer terms, linked workflows,
bootstrap state in S3
- Define "GitHub settings" and "Terraform state" and use them instead of the ambiguous "organization".
- Link workflow and environment names throughout.
- Explain the settings Terraform ignores, why members and repositories can't be removed through github-mgmt, and why member removal still starts with a PR.
- Make a full Sync the single state rebuild path and say "don't merge PRs" instead of "pause merges".
- Store the bootstrap state in the bucket under bootstrap/terraform.tfstate instead of 1Password.
- Link the filecoin-project admin guide.
---
docs/INFRA_ADMIN.md | 88 +++++++++++++++++++++++---------------
docs/SETUP.md | 2 +-
terraform/bootstrap/aws.tf | 8 ++++
3 files changed, 62 insertions(+), 36 deletions(-)
diff --git a/docs/INFRA_ADMIN.md b/docs/INFRA_ADMIN.md
index af5f437..3f543a5 100644
--- a/docs/INFRA_ADMIN.md
+++ b/docs/INFRA_ADMIN.md
@@ -1,10 +1,12 @@
# FilOzone github-mgmt infrastructure admin guide
-This guide is for FilOz maintainers operating github-mgmt. See the [README](../README.md) to request access, [ABOUT](ABOUT.md) for the resource model, and [SETUP](SETUP.md) for installation details.
+This guide is for FilOz maintainers operating github-mgmt. See the [README](../README.md) to request access, [ABOUT](ABOUT.md) for the resource model, and [SETUP](SETUP.md) for installation details. [filecoin-project/github-mgmt](https://github.com/filecoin-project/github-mgmt) is operated the same way; see its [admin guide](https://github.com/filecoin-project/github-mgmt/blob/master/docs/INFRA_ADMIN.md).
+
+In this guide, "GitHub settings" means FilOzone's GitHub organization configuration (members, teams, repositories and their access), and "Terraform state" means Terraform's record of those settings, stored in S3.
## Terraform state
-[Plan](../.github/workflows/plan.yml) previews proposed changes. [Apply](../.github/workflows/apply.yml) runs after a merge to `master`, regenerates the plan, and applies it when it matches the reviewed plan. [Sync](../.github/workflows/sync.yml) reads GitHub into Terraform state and updates the YAML.
+[Plan] previews proposed changes. [Apply] runs after a merge to `master`, regenerates the plan, and applies it when it matches the reviewed plan. [Sync] reads FilOzone's GitHub settings into the Terraform state and updates the YAML.
| Backend | Value |
| --- | --- |
@@ -12,9 +14,10 @@ This guide is for FilOz maintainers operating github-mgmt. See the [README](../R
| Versioned bucket and Terraform workspace | `filoz-github-mgmt-filozone`, `FilOzone` |
| State object | `org/FilOzone/terraform.tfstate` |
| State lock object | `org/FilOzone/terraform.tfstate.tflock` |
+| Bootstrap state object | `bootstrap/terraform.tfstate` |
| AWS OIDC roles | `filoz-github-mgmt-filozone-ro` and `filoz-github-mgmt-filozone-rw` |
-The [organization backend](../terraform/terraform_override.tf) stores the state used by the workflows. A separate [Terraform bootstrap](../terraform/bootstrap/aws.tf) manages the bucket and IAM roles and stores its own state locally. Keep the current bootstrap `terraform.tfstate` in the FilOz team’s 1Password. Before changing the bucket or roles, retrieve it from the team vault or ask a FilOz maintainer with vault access for the current copy. Coordinate with other maintainers so one person at a time uses and updates this local state. Update the vault copy after each successful bootstrap Apply. Keep state files outside Git. [Terraform guidance on sensitive data](https://developer.hashicorp.com/terraform/language/manage-sensitive-data)
+The [Terraform state backend](../terraform/terraform_override.tf) stores the state used by the workflows. A separate [Terraform bootstrap](../terraform/bootstrap/aws.tf) manages the bucket and the IAM roles. It keeps its own state in the same bucket under `bootstrap/terraform.tfstate`, with S3 lock files. The workflow roles can only access the `org/FilOzone/` state keys, so they can't read or change the bootstrap state. To change the bucket or roles, run `terraform -chdir=terraform/bootstrap init` and `plan` with your own MFA-backed AWS session; the state contains no secrets.
## GitHub Actions environments
@@ -22,63 +25,66 @@ The [read-only App](https://github.com/organizations/FilOzone/settings/apps/filo
| Environment | Allowed branches | GitHub App secrets | AWS access | Jobs |
| --- | --- | --- | --- | --- |
-| [`read`](https://github.com/FilOzone/github-mgmt/settings/environments/15158011219/edit) | Any | `RO_GITHUB_APP_*` | Read-only role for Plan, Comment, and Fix | Plan (`plan`, `comment`), [Fix](../.github/workflows/fix.yml) (`fix`), Apply (`prepare`) |
-| [`write`](https://github.com/FilOzone/github-mgmt/settings/environments/15158017921/edit) | `master` | `RW_GITHUB_APP_*` | Read-write role for Apply, Sync, and Clean | Apply (`apply`), Sync (`sync`), [Clean](../.github/workflows/clean.yml), [Labels](../.github/workflows/labels.yml) |
-| [`push`](https://github.com/FilOzone/github-mgmt/settings/environments/15157620722/edit) | `master` | `RW_GITHUB_APP_*` and `RO_GITHUB_APP_*` for Clean Up | None | Sync (`push`), Fix (`push`), [Update](../.github/workflows/update.yml), [Clean Up](../.github/workflows/cleanup.yml) |
+| [`read`][read] | Any | `RO_GITHUB_APP_*` | Read-only role | [Plan] (`plan`, `comment`), [Fix] (`fix`), [Apply] (`prepare`) |
+| [`write`][write] | `master` | `RW_GITHUB_APP_*` | Read-write role | [Apply] (`apply`), [Sync] (`sync`), [Clean], [Labels] |
+| [`push`][push] | `master` | `RW_GITHUB_APP_*`, and `RO_GITHUB_APP_*` for [Clean Up] | None | [Sync] (`push`), [Fix] (`push`), [Update], [Clean Up] |
Why three environments:
-- `read` runs on PRs, before the change is reviewed, so it allows any branch and gets only the read-only App and the read-only state role. An unmerged PR can't change the organization or the state. On PR events, Plan and Fix run the base branch workflow and use the PR's `github/` directory as input.
-- `write` changes the organization and the Terraform state. Only `master` can use it, so only reviewed and merged code gets the read-write App and the state writer role. The read-write AWS role trusts only this environment.
-- `push` commits generated changes back to this repository (formatted YAML, Sync results, updated PR branches). It needs the read-write App to push, but not the state, so it has no AWS role. Fix's `push` job runs on PR events and pushes formatted YAML to the PR branch, which is another reason to keep state access out of `push`.
+- `read` runs on PRs, before the change is reviewed, so it allows any branch and gets only the read-only App and the read-only state role. An unmerged PR can't change FilOzone's GitHub settings or the Terraform state. On PR events, [Plan] and [Fix] run the base branch workflow and use the PR's `github/` directory as input.
+- `write` changes FilOzone's GitHub settings and the Terraform state. Only `master` can use it, so only reviewed and merged code gets the read-write App and the state writer role. The read-write AWS role trusts only this environment.
+- `push` commits generated changes back to this repository (formatted YAML, Sync results, updated PR branches). It needs the read-write App to push, but not the Terraform state, so it has no AWS role. [Fix]'s `push` job runs on PR events and pushes formatted YAML to the PR branch, which is another reason to keep state access out of `push`.
The App secrets exist only in these environments, so a job without `environment:` gets no App credentials.
## Apply access changes
-- Review the full Plan before merging. For a long plan, open **Plan → Comment → Show terraform plans**. After merge, check that **Terraform Apply** ran successfully and verify the result in GitHub.
-- Wait for Apply and Update before merging the next PR. Update attempts to refresh eligible PR branches. Refresh any skipped or conflicting branch and review its new plan. Apply stops if the merged commit's plan differs from the reviewed plan.
-- `prevent_destroy` guards organization memberships and repositories managed by Terraform. Use the [member removal procedure](#remove-a-member-from-filozone) for organization members. Coordinate repository deletion with an org owner and run Sync after the approved deletion. Normal PRs can remove team memberships and direct collaborator grants. [Terraform resources](../terraform/resources.tf)
-- GitHub prevents changes to collaborators and teams on archived repositories. The YAML for an archived repository is reduced to `archived: true`, and Terraform uses existing state for its grants. To change a grant, unarchive first and verify Apply and the grants restored in YAML, then change the grant in a separate PR. Re-archive after the access change has applied if the repository should stay archived. [GitHub archive behavior](https://docs.github.com/en/repositories/archiving-a-github-repository/archiving-repositories) · [Terraform locals](../terraform/locals.tf) · [Fix logic](../scripts/src/actions/shared/toggle-archived-repos.ts)
-- The Terraform override ignores changes to existing teams' description, parent, and privacy. Update those settings in GitHub. [Terraform overrides](../terraform/resources_override.tf)
+- Review the full plan from [Plan] before merging. For a long plan, open **Plan → Comment → Show terraform plans**. After merge, check that the **Terraform Apply** step of [Apply] succeeded and verify the result in GitHub.
+- Wait for [Apply] and [Update] to finish before merging the next PR. [Update] attempts to refresh eligible PR branches. Refresh any skipped or conflicting branch and review its new plan. [Apply] stops if the merged commit's plan differs from the reviewed plan.
+- github-mgmt can't remove organization members or delete repositories: `prevent_destroy` blocks both ([Terraform resources](../terraform/resources.tf)). Removing a member or deleting a repository can't be cleanly undone, so a deleted YAML line or a typo must not be able to do it. An org owner does it in GitHub instead; see [Remove a member from FilOzone](#remove-a-member-from-filozone). For a repository, prefer archiving; if it must be deleted, an org owner deletes it in GitHub and a maintainer runs [Sync]. Normal PRs can remove team memberships and direct collaborator grants.
+- GitHub prevents changes to collaborators and teams on archived repositories. The YAML for an archived repository is reduced to `archived: true`, and Terraform uses the existing state for its grants. To change a grant, unarchive the repository in one PR and check that [Apply] succeeded and the grants are back in the YAML, then change the grant in a separate PR. Re-archive after the access change has applied if the repository should stay archived. [GitHub archive behavior](https://docs.github.com/en/repositories/archiving-a-github-repository/archiving-repositories) · [Terraform locals](../terraform/locals.tf) · [Fix logic](../scripts/src/actions/shared/toggle-archived-repos.ts)
+- Some settings can't be changed through github-mgmt. [Terraform overrides](../terraform/resources_override.tf) tell Terraform to ignore changes to them on existing teams and repositories, so editing them in the YAML has no effect. Change them in GitHub instead, and the next [Sync] records them. They include a team's description, parent team and privacy, and a repository's description, topics, homepage, default branch, merge options, and issues, projects, wiki and Pages settings.
### Remove a member from FilOzone
-1. Open a PR to remove the person's team memberships and direct grants on repositories. Keep their entry in the `members` section and add a comment explaining that an org owner will remove them in GitHub.
-2. After the PR merges, verify that Apply succeeded and that GitHub shows the team memberships and direct grants were removed.
+An org owner could simply remove the person in GitHub and run [Sync]. We use a PR first anyway: it records who asked for the removal and why, gives a place to discuss it, and removes the person's team memberships and direct repository grants through the normal reviewed flow.
+
+1. Open a PR that removes the person's team memberships and direct grants on repositories, and explains who requested the removal and why. Keep their entry in the `members` section and add a comment saying an org owner will remove them in GitHub.
+2. After the PR merges, verify that [Apply] succeeded and that GitHub shows the team memberships and direct grants were removed.
3. A FilOzone org owner selects the member on the [People](https://github.com/orgs/FilOzone/people) page, chooses **Remove from organization**, and confirms the removal. [GitHub member removal](https://docs.github.com/en/organizations/managing-membership-in-your-organization/removing-a-member-from-your-organization)
-4. A maintainer runs [Sync](#sync-from-github) from `master`. Check that Sync and Push succeed and that the member no longer appears in `github/FilOzone.yml`.
+4. A maintainer runs [Sync](#sync-from-github) from `master`. Check that the **Sync (FilOzone)** and **Push** jobs succeed and that the member no longer appears in `github/FilOzone.yml`.
## Sync from GitHub
-Sync is scheduled for Sundays at 00:00 UTC. For a manual run, open [Sync in Actions](https://github.com/FilOzone/github-mgmt/actions/workflows/sync.yml) and select **Run workflow** on `master`. Leave `workspaces` blank or enter `FilOzone`. Keep `lock=true` and `refresh=false`. This setting skips the optional pre-import refresh. Sync still refreshes state after importing.
+[Sync] is scheduled for Sundays at 00:00 UTC. For a manual run, open [Sync in Actions](https://github.com/FilOzone/github-mgmt/actions/workflows/sync.yml) and select **Run workflow** on `master`. Leave `workspaces` blank or enter `FilOzone`. Keep `lock=true` and `refresh=false`. This setting skips the optional pre-import refresh; [Sync] still refreshes the Terraform state after importing.
-Wait for existing state writes to finish and hold merges while Sync runs. Its Push job favors the sync branch when resolving merge conflicts and uses `git push --force` when publishing the result. Verify **Sync (FilOzone)** and **Push** succeeded and review what reached `master`. The [`.sync` file](../.sync) records the run ID.
+Wait for running [Apply], [Sync] and [Clean] runs to finish, and don't merge PRs while [Sync] runs. Its **Push** job favors the sync branch when resolving merge conflicts and uses `git push --force` when publishing the result. Verify that the **Sync (FilOzone)** and **Push** jobs succeeded and review what reached `master`. The [`.sync` file](../.sync) records the run ID.
-## Recover organization state
+## Rebuild the Terraform state
-If the S3 state is missing or corrupt, pause merges and new state writes, and let active writers finish. Copy the last known-good version of `terraform.tfstate` to the same S3 key to make it current. Check the restored state against GitHub and [reconcile any differences](#recover-from-a-failed-apply) before resuming normal writes. [S3 version recovery](https://docs.aws.amazon.com/AmazonS3/latest/userguide/RestoringPreviousVersions.html)
+If the Terraform state is missing or corrupt, or when switching to a new backend, rebuild it from FilOzone's GitHub settings with a full [Sync]:
-For a failed run that left a lock, see [Recover from a stuck state lock](#recover-from-a-stuck-state-lock).
+1. Don't merge any PRs until the rebuild is done. Disable [Apply in Actions](https://github.com/FilOzone/github-mgmt/actions/workflows/apply.yml) (**⋯ → Disable workflow**) and let running [Apply], [Sync] and [Clean] runs finish.
+2. If switching backends, merge the backend change first.
+3. Run [Sync](#sync-from-github) from `master` and wait for the **Sync (FilOzone)** and **Push** jobs to succeed. The initial FilOzone import took about 20 minutes ([run](https://github.com/FilOzone/github-mgmt/actions/runs/45818396464)).
+4. Re-enable [Apply], then check the new state with a small PR and its [Apply] run.
-### Rebuild an empty backend
+The first plan after a rebuild can show default merge and sign-off values on archived repositories. Check that the repositories remain archived and that the plan contains only those fields; the pinned GitHub provider skips updates to repositories that stay archived ([provider update logic](https://github.com/integrations/terraform-provider-github/blob/v6.6.0/github/resource_github_repository.go#L740-L746)). Review any other changes before merging.
-Use a full Sync when initializing a new backend or when no usable state version remains. Pause merges, disable Apply, and let active state writers finish. If switching backends, merge the backend change first. Run Sync from `master` against the intended backend and wait for both Sync and Push to succeed. Re-enable Apply and validate the backend with a small PR and its resulting Apply. The initial FilOzone import through Push took about 20 minutes. [Initial Sync run](https://github.com/FilOzone/github-mgmt/actions/runs/45818396464)
-
-A first plan after a rebuild can show default merge and sign-off values on archived repositories. Check that the repositories remain archived and that the plan contains the expected fields. The currently pinned GitHub provider skips updates to repositories that stay archived. Review any other changes before merging. [Provider update logic](https://github.com/integrations/terraform-provider-github/blob/v6.6.0/github/resource_github_repository.go#L740-L746)
+For a failed run that left a lock, see [Recover from a stuck state lock](#recover-from-a-stuck-state-lock).
## Recover from a failed Apply
-Pause other merges and inspect the failed run for the merge commit.
+Don't merge other PRs until this is resolved. Inspect the failed [Apply] run for the merge commit.
- **Credential failure.** Check the AWS role ARN, OIDC trust, and job environment. For a GitHub sign-in failure, check the App ID, installation ID, and PEM secret in the job's environment.
-- **Reviewed plan missing.** Check **Find sha for plan** and **Download reviewed terraform plan**. Retry the failed run after fixing the cause and confirming the reviewed plan is still current. A fresh manual dispatch looks for a Plan artifact for the selected commit.
-- **Plan mismatch, partial Apply, or drift.** Plan and Apply generate plans with `-refresh=false`, so they compare the YAML with saved state. Check affected settings in GitHub as well. If GitHub has the intended settings, run Sync and review the result. If the intended settings are in YAML, save that version first. Run Sync to reconcile state and YAML with GitHub, then restore the intended settings through a follow-up PR with a fresh plan.
-- Resume merges after Apply succeeds, the result is verified in GitHub, and Update finishes.
+- **Reviewed plan missing.** Check the **Find sha for plan** and **Download reviewed terraform plan** steps. Retry the failed run after fixing the cause and confirming the reviewed plan is still current. A fresh manual dispatch looks for a [Plan] artifact for the selected commit.
+- **Plan mismatch, partial Apply, or drift.** [Plan] and [Apply] generate plans with `-refresh=false`, so they compare the YAML with the saved Terraform state. Check the affected settings in GitHub as well. If GitHub has the intended settings, run [Sync] and review the result. If the intended settings are in the YAML, save that version first, run [Sync] to reconcile the Terraform state and YAML with GitHub, then restore the intended settings through a follow-up PR with a fresh plan.
+- Resume merging after [Apply] succeeds, the result is verified in GitHub, and [Update] finishes.
## Recover from a stuck state lock
-An interrupted run or an expired AWS session can leave a lock behind. Get the lock ID and path from the error. Check for active or queued Apply, Sync, and Clean runs, and confirm with the other maintainers that the previous lock holder has stopped and no other writer will start during recovery.
+An interrupted run or an expired AWS session can leave a lock behind. Get the lock ID and path from the error. Check for active or queued [Apply], [Sync] and [Clean] runs, and confirm with the other maintainers that the previous lock holder has stopped and no other writer will start during recovery.
From a fresh checkout of `master`, use an MFA-backed AWS session that can read the backend and delete its lock. Check the AWS account with `aws sts get-caller-identity --query Account --output text` and continue for `941641221830`.
@@ -88,16 +94,28 @@ terraform -chdir=terraform workspace select FilOzone
terraform -chdir=terraform workspace show
```
-Verify the workspace and match the lock path from the error to the S3 lock object above. Run `terraform -chdir=terraform force-unlock LOCK_ID` with the lock ID from the failure. Keep locking enabled for the retry. If Sync was interrupted while importing, rerun it against the same backend and workspace to reuse the saved progress. Check the Terraform state version and the next Actions run to verify recovery. [Terraform lock recovery](https://developer.hashicorp.com/terraform/language/state/locking#force-unlock)
+Verify the workspace and match the lock path from the error to the state lock object above. Run `terraform -chdir=terraform force-unlock LOCK_ID` with the lock ID from the failure. Keep locking enabled for the retry. If [Sync] was interrupted while importing, rerun it against the same backend and workspace to reuse the saved progress. Check the Terraform state version and the next Actions run to verify recovery. [Terraform lock recovery](https://developer.hashicorp.com/terraform/language/state/locking#force-unlock)
## Rotate GitHub App credentials
-1. An App manager opens the App's settings and generates a new private key. Update `RO_GITHUB_APP_PEM_FILE` in both `read` and `push`, or `RW_GITHUB_APP_PEM_FILE` in both `write` and `push`, depending on the App being rotated.
-2. Verify the new credentials on the affected workflows. Check Plan and Fix for `read`, an Apply or Sync for `write`, and a token-generating job for `push`. Verify the read-only key in `push` on an approved Clean Up run. That workflow can update the cleanup branch.
+1. An App manager opens the App's settings and generates a new private key. Update `RO_GITHUB_APP_PEM_FILE` in both [`read`][read] and [`push`][push], or `RW_GITHUB_APP_PEM_FILE` in both [`write`][write] and [`push`][push], depending on the App being rotated.
+2. Verify the new credentials on the affected workflows: [Plan] and [Fix] for `read`, an [Apply] or [Sync] for `write`, and a token-generating job for `push`. Verify the read-only key in `push` on an approved [Clean Up] run; that workflow can update the cleanup branch.
3. In the App's **Private keys** settings, match the old entry by fingerprint and delete it after verifying the replacement. Confirm that the old fingerprint is absent. [GitHub App key management](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/managing-private-keys-for-github-apps#deleting-private-keys)
## Upgrade from upstream
1. Select a commit of [ipdxco/github-as-code](https://github.com/ipdxco/github-as-code) and record its SHA in the PR description.
2. Apply selected upstream changes. Preserve FilOzone's OIDC workflows, Terraform backend and bootstrap, and local documentation. Keep upgrades on the manual PR path.
-3. Open a PR and review the workflow and Terraform diffs directly. [Plan](../.github/workflows/plan.yml) only takes the PR's `github/` directory as input. Review the Plan and verify Apply after merge.
+3. Open a PR and review the workflow and Terraform diffs directly. [Plan] only takes the PR's `github/` directory as input. Review the plan and verify [Apply] after merge.
+
+[Plan]: ../.github/workflows/plan.yml
+[Apply]: ../.github/workflows/apply.yml
+[Sync]: ../.github/workflows/sync.yml
+[Fix]: ../.github/workflows/fix.yml
+[Update]: ../.github/workflows/update.yml
+[Clean]: ../.github/workflows/clean.yml
+[Clean Up]: ../.github/workflows/cleanup.yml
+[Labels]: ../.github/workflows/labels.yml
+[read]: https://github.com/FilOzone/github-mgmt/settings/environments/15158011219/edit
+[write]: https://github.com/FilOzone/github-mgmt/settings/environments/15158017921/edit
+[push]: https://github.com/FilOzone/github-mgmt/settings/environments/15157620722/edit
diff --git a/docs/SETUP.md b/docs/SETUP.md
index 24508d3..09ea9e2 100644
--- a/docs/SETUP.md
+++ b/docs/SETUP.md
@@ -14,7 +14,7 @@
FilOzone uses a versioned S3 bucket for Terraform state and [S3 lock files](https://developer.hashicorp.com/terraform/language/backend/s3#enabling-s3-state-locking). GitHub Actions uses [OIDC](https://docs.github.com/en/actions/how-tos/secure-your-work/security-harden-deployments/oidc-in-aws) to assume one of two IAM roles.
- [ ] Use the [bootstrap Terraform configuration](../terraform/bootstrap/aws.tf) to manage the bucket and roles in the FilOz AWS account. The account already has the GitHub Actions OIDC provider.
-- [ ] Store the bootstrap Terraform state in the FilOz team’s 1Password and use that state for subsequent changes to the bucket and roles. See [Terraform state in the admin guide](INFRA_ADMIN.md#terraform-state).
+- [ ] The bootstrap keeps its Terraform state in the same bucket under `bootstrap/terraform.tfstate`. For a brand-new bucket, apply the bootstrap once with local state, then run `terraform -chdir=terraform/bootstrap init -migrate-state` to move the state into S3. See [Terraform state in the admin guide](INFRA_ADMIN.md#terraform-state).
- [ ] If you change the backend, keep [terraform/terraform_override.tf](../terraform/terraform_override.tf), the IAM policies, and the workflow role ARNs in sync.
- [ ] Restrict the GitHub Actions `write` environment to `master`. The read-only role trusts the `read` environment, and the read-write role trusts the `write` environment.
diff --git a/terraform/bootstrap/aws.tf b/terraform/bootstrap/aws.tf
index ee690b5..f8e4833 100644
--- a/terraform/bootstrap/aws.tf
+++ b/terraform/bootstrap/aws.tf
@@ -7,6 +7,14 @@ terraform {
}
required_version = "~> 1.12.0"
+
+ # The bucket below must exist before this backend can be used.
+ backend "s3" {
+ region = "us-east-1"
+ bucket = "filoz-github-mgmt-filozone"
+ key = "bootstrap/terraform.tfstate"
+ use_lockfile = true
+ }
}
provider "aws" {
From a76c722b7cb40bef8dc2e1af65e761e2b689f9eb Mon Sep 17 00:00:00 2001
From: Steve Loeppky
Date: Wed, 2 Dec 2026 20:10:12 -0800
Subject: [PATCH 12/13] Fix accuracy issues found in the Codex review
- Sync reads the current state first, so a corrupt state needs its last good S3 version restored (or the object deleted) before rebuilding.
- Give the full first-time bootstrap sequence (local apply, then -migrate-state).
- Sync leaves ignored settings out of the YAML rather than recording them; name the four allow-merge toggles and branch protections.
- Describe the workflow roles' actual state-object scope.
- Restore the per-job qualifiers in the environments table's AWS column.
- The write environment is limited to master; review is what controls master.
- Update the App key UI label and point HOWTOS to the single Sync procedure.
---
docs/HOWTOS.md | 4 +---
docs/INFRA_ADMIN.md | 16 ++++++++--------
docs/SETUP.md | 2 +-
3 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/docs/HOWTOS.md b/docs/HOWTOS.md
index 18219fa..8ca866a 100644
--- a/docs/HOWTOS.md
+++ b/docs/HOWTOS.md
@@ -91,9 +91,7 @@ I push my changes to a new branch and create a PR. An admin reviews the PR and m
### ...synchronize GitHub Management with GitHub?
-Run the `Sync` workflow from `master` using **Actions → Sync → Run workflow**.
-
-`Sync` imports the current GitHub configuration into the FilOzone Terraform state in S3 and force-pushes the updated YAML to `master`.
+`Sync` imports the current GitHub configuration into the FilOzone Terraform state in S3 and force-pushes the updated YAML to `master`. Follow [Sync from GitHub](INFRA_ADMIN.md#sync-from-github) in the admin guide to run it.
### ...upgrade GitHub Management?
diff --git a/docs/INFRA_ADMIN.md b/docs/INFRA_ADMIN.md
index 3f543a5..cb99ea1 100644
--- a/docs/INFRA_ADMIN.md
+++ b/docs/INFRA_ADMIN.md
@@ -17,7 +17,7 @@ In this guide, "GitHub settings" means FilOzone's GitHub organization configurat
| Bootstrap state object | `bootstrap/terraform.tfstate` |
| AWS OIDC roles | `filoz-github-mgmt-filozone-ro` and `filoz-github-mgmt-filozone-rw` |
-The [Terraform state backend](../terraform/terraform_override.tf) stores the state used by the workflows. A separate [Terraform bootstrap](../terraform/bootstrap/aws.tf) manages the bucket and the IAM roles. It keeps its own state in the same bucket under `bootstrap/terraform.tfstate`, with S3 lock files. The workflow roles can only access the `org/FilOzone/` state keys, so they can't read or change the bootstrap state. To change the bucket or roles, run `terraform -chdir=terraform/bootstrap init` and `plan` with your own MFA-backed AWS session; the state contains no secrets.
+The [Terraform state backend](../terraform/terraform_override.tf) stores the state used by the workflows. A separate [Terraform bootstrap](../terraform/bootstrap/aws.tf) manages the bucket and the IAM roles. It keeps its own state in the same bucket under `bootstrap/terraform.tfstate`, with S3 lock files. The workflow roles' policies only cover the FilOzone and default-workspace state objects and their lock files, not `bootstrap/terraform.tfstate`, so the workflows can't read or change the bootstrap state. To change the bucket or roles, run `terraform -chdir=terraform/bootstrap init` and `plan` with your own MFA-backed AWS session; the state contains no secrets.
## GitHub Actions environments
@@ -25,14 +25,14 @@ The [read-only App](https://github.com/organizations/FilOzone/settings/apps/filo
| Environment | Allowed branches | GitHub App secrets | AWS access | Jobs |
| --- | --- | --- | --- | --- |
-| [`read`][read] | Any | `RO_GITHUB_APP_*` | Read-only role | [Plan] (`plan`, `comment`), [Fix] (`fix`), [Apply] (`prepare`) |
-| [`write`][write] | `master` | `RW_GITHUB_APP_*` | Read-write role | [Apply] (`apply`), [Sync] (`sync`), [Clean], [Labels] |
+| [`read`][read] | Any | `RO_GITHUB_APP_*` | Read-only role for Plan, Comment, and Fix | [Plan] (`plan`, `comment`), [Fix] (`fix`), [Apply] (`prepare`) |
+| [`write`][write] | `master` | `RW_GITHUB_APP_*` | Read-write role for Apply, Sync, and Clean | [Apply] (`apply`), [Sync] (`sync`), [Clean], [Labels] |
| [`push`][push] | `master` | `RW_GITHUB_APP_*`, and `RO_GITHUB_APP_*` for [Clean Up] | None | [Sync] (`push`), [Fix] (`push`), [Update], [Clean Up] |
Why three environments:
- `read` runs on PRs, before the change is reviewed, so it allows any branch and gets only the read-only App and the read-only state role. An unmerged PR can't change FilOzone's GitHub settings or the Terraform state. On PR events, [Plan] and [Fix] run the base branch workflow and use the PR's `github/` directory as input.
-- `write` changes FilOzone's GitHub settings and the Terraform state. Only `master` can use it, so only reviewed and merged code gets the read-write App and the state writer role. The read-write AWS role trusts only this environment.
+- `write` changes FilOzone's GitHub settings and the Terraform state. Only workflows running from `master` can use it, and the normal reviewed-PR flow controls what reaches `master`, so in practice only reviewed and merged code gets the read-write App and the state writer role. The read-write AWS role trusts only this environment.
- `push` commits generated changes back to this repository (formatted YAML, Sync results, updated PR branches). It needs the read-write App to push, but not the Terraform state, so it has no AWS role. [Fix]'s `push` job runs on PR events and pushes formatted YAML to the PR branch, which is another reason to keep state access out of `push`.
The App secrets exist only in these environments, so a job without `environment:` gets no App credentials.
@@ -43,7 +43,7 @@ The App secrets exist only in these environments, so a job without `environment:
- Wait for [Apply] and [Update] to finish before merging the next PR. [Update] attempts to refresh eligible PR branches. Refresh any skipped or conflicting branch and review its new plan. [Apply] stops if the merged commit's plan differs from the reviewed plan.
- github-mgmt can't remove organization members or delete repositories: `prevent_destroy` blocks both ([Terraform resources](../terraform/resources.tf)). Removing a member or deleting a repository can't be cleanly undone, so a deleted YAML line or a typo must not be able to do it. An org owner does it in GitHub instead; see [Remove a member from FilOzone](#remove-a-member-from-filozone). For a repository, prefer archiving; if it must be deleted, an org owner deletes it in GitHub and a maintainer runs [Sync]. Normal PRs can remove team memberships and direct collaborator grants.
- GitHub prevents changes to collaborators and teams on archived repositories. The YAML for an archived repository is reduced to `archived: true`, and Terraform uses the existing state for its grants. To change a grant, unarchive the repository in one PR and check that [Apply] succeeded and the grants are back in the YAML, then change the grant in a separate PR. Re-archive after the access change has applied if the repository should stay archived. [GitHub archive behavior](https://docs.github.com/en/repositories/archiving-a-github-repository/archiving-repositories) · [Terraform locals](../terraform/locals.tf) · [Fix logic](../scripts/src/actions/shared/toggle-archived-repos.ts)
-- Some settings can't be changed through github-mgmt. [Terraform overrides](../terraform/resources_override.tf) tell Terraform to ignore changes to them on existing teams and repositories, so editing them in the YAML has no effect. Change them in GitHub instead, and the next [Sync] records them. They include a team's description, parent team and privacy, and a repository's description, topics, homepage, default branch, merge options, and issues, projects, wiki and Pages settings.
+- Some settings can't be changed through github-mgmt. [Terraform overrides](../terraform/resources_override.tf) tell Terraform to ignore changes to them on existing teams, repositories and branch protections, so editing them in the YAML has no effect, and [Sync] leaves them out of the YAML. Change them in GitHub instead. Examples: a team's description, parent team and privacy; a repository's description, topics, homepage, default branch, the four allow-merge toggles, and issues, projects, wiki and Pages settings. The override file is the full list.
### Remove a member from FilOzone
@@ -62,10 +62,10 @@ Wait for running [Apply], [Sync] and [Clean] runs to finish, and don't merge PRs
## Rebuild the Terraform state
-If the Terraform state is missing or corrupt, or when switching to a new backend, rebuild it from FilOzone's GitHub settings with a full [Sync]:
+If the Terraform state is missing or corrupt, or when switching to a new backend, rebuild it from FilOzone's GitHub settings with a full [Sync]. [Sync] reads the current state before importing, so it can start from a missing state but not from a corrupt one:
1. Don't merge any PRs until the rebuild is done. Disable [Apply in Actions](https://github.com/FilOzone/github-mgmt/actions/workflows/apply.yml) (**⋯ → Disable workflow**) and let running [Apply], [Sync] and [Clean] runs finish.
-2. If switching backends, merge the backend change first.
+2. If the state object is corrupt, make the last good version current or delete the object so [Sync] starts empty. The bucket is versioned, so earlier versions stay available ([restoring S3 object versions](https://docs.aws.amazon.com/AmazonS3/latest/userguide/RestoringPreviousVersions.html)). If switching backends, merge the backend change first.
3. Run [Sync](#sync-from-github) from `master` and wait for the **Sync (FilOzone)** and **Push** jobs to succeed. The initial FilOzone import took about 20 minutes ([run](https://github.com/FilOzone/github-mgmt/actions/runs/45818396464)).
4. Re-enable [Apply], then check the new state with a small PR and its [Apply] run.
@@ -100,7 +100,7 @@ Verify the workspace and match the lock path from the error to the state lock ob
1. An App manager opens the App's settings and generates a new private key. Update `RO_GITHUB_APP_PEM_FILE` in both [`read`][read] and [`push`][push], or `RW_GITHUB_APP_PEM_FILE` in both [`write`][write] and [`push`][push], depending on the App being rotated.
2. Verify the new credentials on the affected workflows: [Plan] and [Fix] for `read`, an [Apply] or [Sync] for `write`, and a token-generating job for `push`. Verify the read-only key in `push` on an approved [Clean Up] run; that workflow can update the cleanup branch.
-3. In the App's **Private keys** settings, match the old entry by fingerprint and delete it after verifying the replacement. Confirm that the old fingerprint is absent. [GitHub App key management](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/managing-private-keys-for-github-apps#deleting-private-keys)
+3. In the App's **Credentials → Key pairs** settings, match the old entry by fingerprint and delete it after verifying the replacement. Confirm that the old fingerprint is absent. [GitHub App key management](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/managing-private-keys-for-github-apps#deleting-private-keys)
## Upgrade from upstream
diff --git a/docs/SETUP.md b/docs/SETUP.md
index 09ea9e2..caaa2ed 100644
--- a/docs/SETUP.md
+++ b/docs/SETUP.md
@@ -14,7 +14,7 @@
FilOzone uses a versioned S3 bucket for Terraform state and [S3 lock files](https://developer.hashicorp.com/terraform/language/backend/s3#enabling-s3-state-locking). GitHub Actions uses [OIDC](https://docs.github.com/en/actions/how-tos/secure-your-work/security-harden-deployments/oidc-in-aws) to assume one of two IAM roles.
- [ ] Use the [bootstrap Terraform configuration](../terraform/bootstrap/aws.tf) to manage the bucket and roles in the FilOz AWS account. The account already has the GitHub Actions OIDC provider.
-- [ ] The bootstrap keeps its Terraform state in the same bucket under `bootstrap/terraform.tfstate`. For a brand-new bucket, apply the bootstrap once with local state, then run `terraform -chdir=terraform/bootstrap init -migrate-state` to move the state into S3. See [Terraform state in the admin guide](INFRA_ADMIN.md#terraform-state).
+- [ ] The bootstrap keeps its Terraform state in the bucket it creates, under `bootstrap/terraform.tfstate`. For a brand-new bucket: comment out the `backend "s3"` block in [aws.tf](../terraform/bootstrap/aws.tf), run `terraform init` and `terraform apply` in `terraform/bootstrap` with local state, restore the block, then run `terraform -chdir=terraform/bootstrap init -migrate-state` and check that `terraform plan` shows no changes. See [Terraform state in the admin guide](INFRA_ADMIN.md#terraform-state).
- [ ] If you change the backend, keep [terraform/terraform_override.tf](../terraform/terraform_override.tf), the IAM policies, and the workflow role ARNs in sync.
- [ ] Restrict the GitHub Actions `write` environment to `master`. The read-only role trusts the `read` environment, and the read-write role trusts the `write` environment.
From 1290febd76d60bf587fdfe9abe71ca1aedea778c Mon Sep 17 00:00:00 2001
From: beck-8 <34204218+beck-8@users.noreply.github.com>
Date: Thu, 3 Dec 2026 13:44:21 +0800
Subject: [PATCH 13/13] Clarify FilOzone Terraform state migration and recovery
---
docs/INFRA_ADMIN.md | 20 ++++++++++----------
docs/SETUP.md | 5 +++--
2 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/docs/INFRA_ADMIN.md b/docs/INFRA_ADMIN.md
index cb99ea1..8e4500a 100644
--- a/docs/INFRA_ADMIN.md
+++ b/docs/INFRA_ADMIN.md
@@ -1,8 +1,6 @@
# FilOzone github-mgmt infrastructure admin guide
-This guide is for FilOz maintainers operating github-mgmt. See the [README](../README.md) to request access, [ABOUT](ABOUT.md) for the resource model, and [SETUP](SETUP.md) for installation details. [filecoin-project/github-mgmt](https://github.com/filecoin-project/github-mgmt) is operated the same way; see its [admin guide](https://github.com/filecoin-project/github-mgmt/blob/master/docs/INFRA_ADMIN.md).
-
-In this guide, "GitHub settings" means FilOzone's GitHub organization configuration (members, teams, repositories and their access), and "Terraform state" means Terraform's record of those settings, stored in S3.
+This guide is for FilOz maintainers operating github-mgmt. See the [README](../README.md) to request access, [ABOUT](ABOUT.md) for the resource model, and [SETUP](SETUP.md) for installation details.
## Terraform state
@@ -12,12 +10,14 @@ In this guide, "GitHub settings" means FilOzone's GitHub organization configurat
| --- | --- |
| FilOz AWS account and region | `941641221830`, `us-east-1` |
| Versioned bucket and Terraform workspace | `filoz-github-mgmt-filozone`, `FilOzone` |
-| State object | `org/FilOzone/terraform.tfstate` |
-| State lock object | `org/FilOzone/terraform.tfstate.tflock` |
+| Organization state object | `org/FilOzone/terraform.tfstate` |
+| Organization state lock object | `org/FilOzone/terraform.tfstate.tflock` |
| Bootstrap state object | `bootstrap/terraform.tfstate` |
| AWS OIDC roles | `filoz-github-mgmt-filozone-ro` and `filoz-github-mgmt-filozone-rw` |
-The [Terraform state backend](../terraform/terraform_override.tf) stores the state used by the workflows. A separate [Terraform bootstrap](../terraform/bootstrap/aws.tf) manages the bucket and the IAM roles. It keeps its own state in the same bucket under `bootstrap/terraform.tfstate`, with S3 lock files. The workflow roles' policies only cover the FilOzone and default-workspace state objects and their lock files, not `bootstrap/terraform.tfstate`, so the workflows can't read or change the bootstrap state. To change the bucket or roles, run `terraform -chdir=terraform/bootstrap init` and `plan` with your own MFA-backed AWS session; the state contains no secrets.
+The [Terraform state backend](../terraform/terraform_override.tf) stores the state used by the workflows. The [Terraform bootstrap](../terraform/bootstrap/aws.tf) manages the bucket and IAM roles using its own state and lock in the same bucket. The workflow roles' policies only cover the FilOzone and default-workspace state objects and their lock files, not `bootstrap/terraform.tfstate`, so the workflows can't read or change the bootstrap state.
+
+To change the bucket or roles, use your MFA-backed AWS session to run `terraform -chdir=terraform/bootstrap init` and `terraform -chdir=terraform/bootstrap plan`. If the plan proposes creating the existing bucket or IAM roles, check the bootstrap backend and state before applying. Keep both state files private. [Terraform state security](https://developer.hashicorp.com/terraform/language/manage-sensitive-data#state-security-best-practices)
## GitHub Actions environments
@@ -60,12 +60,12 @@ An org owner could simply remove the person in GitHub and run [Sync]. We use a P
Wait for running [Apply], [Sync] and [Clean] runs to finish, and don't merge PRs while [Sync] runs. Its **Push** job favors the sync branch when resolving merge conflicts and uses `git push --force` when publishing the result. Verify that the **Sync (FilOzone)** and **Push** jobs succeeded and review what reached `master`. The [`.sync` file](../.sync) records the run ID.
-## Rebuild the Terraform state
+## Recover or rebuild the organization state
-If the Terraform state is missing or corrupt, or when switching to a new backend, rebuild it from FilOzone's GitHub settings with a full [Sync]. [Sync] reads the current state before importing, so it can start from a missing state but not from a corrupt one:
+Use these steps for `org/FilOzone/terraform.tfstate`. To recover `bootstrap/terraform.tfstate`, restore a known-good version of that object and verify it with a bootstrap plan.
-1. Don't merge any PRs until the rebuild is done. Disable [Apply in Actions](https://github.com/FilOzone/github-mgmt/actions/workflows/apply.yml) (**⋯ → Disable workflow**) and let running [Apply], [Sync] and [Clean] runs finish.
-2. If the state object is corrupt, make the last good version current or delete the object so [Sync] starts empty. The bucket is versioned, so earlier versions stay available ([restoring S3 object versions](https://docs.aws.amazon.com/AmazonS3/latest/userguide/RestoringPreviousVersions.html)). If switching backends, merge the backend change first.
+1. Pause unrelated merges. Disable [Apply in Actions](https://github.com/FilOzone/github-mgmt/actions/workflows/apply.yml) (**⋯ → Disable workflow**) and let running [Apply], [Sync] and [Clean] runs finish.
+2. If a known-good version is available, copy it to the same key as the new current version. If the state is unreadable and no usable version remains, confirm versioning is enabled and delete the key without a version ID to add a delete marker. This preserves earlier versions and lets [Sync] start empty. If switching backends, merge the backend PR before running [Sync]. [Restore an S3 object version](https://docs.aws.amazon.com/AmazonS3/latest/userguide/RestoringPreviousVersions.html) · [S3 delete markers](https://docs.aws.amazon.com/AmazonS3/latest/userguide/DeleteMarker.html)
3. Run [Sync](#sync-from-github) from `master` and wait for the **Sync (FilOzone)** and **Push** jobs to succeed. The initial FilOzone import took about 20 minutes ([run](https://github.com/FilOzone/github-mgmt/actions/runs/45818396464)).
4. Re-enable [Apply], then check the new state with a small PR and its [Apply] run.
diff --git a/docs/SETUP.md b/docs/SETUP.md
index caaa2ed..76d9e28 100644
--- a/docs/SETUP.md
+++ b/docs/SETUP.md
@@ -14,7 +14,8 @@
FilOzone uses a versioned S3 bucket for Terraform state and [S3 lock files](https://developer.hashicorp.com/terraform/language/backend/s3#enabling-s3-state-locking). GitHub Actions uses [OIDC](https://docs.github.com/en/actions/how-tos/secure-your-work/security-harden-deployments/oidc-in-aws) to assume one of two IAM roles.
- [ ] Use the [bootstrap Terraform configuration](../terraform/bootstrap/aws.tf) to manage the bucket and roles in the FilOz AWS account. The account already has the GitHub Actions OIDC provider.
-- [ ] The bootstrap keeps its Terraform state in the bucket it creates, under `bootstrap/terraform.tfstate`. For a brand-new bucket: comment out the `backend "s3"` block in [aws.tf](../terraform/bootstrap/aws.tf), run `terraform init` and `terraform apply` in `terraform/bootstrap` with local state, restore the block, then run `terraform -chdir=terraform/bootstrap init -migrate-state` and check that `terraform plan` shows no changes. See [Terraform state in the admin guide](INFRA_ADMIN.md#terraform-state).
+- [ ] The bootstrap stores its state at `bootstrap/terraform.tfstate`. To create a new bucket, temporarily comment out the `backend "s3"` block in [aws.tf](../terraform/bootstrap/aws.tf), run `terraform init` and `terraform apply` in `terraform/bootstrap` with local state, then restore the block.
+- [ ] To migrate an existing local state, confirm the S3 state key is empty. With an MFA-backed AWS session, keep a private backup, place `terraform.tfstate` in `terraform/bootstrap/`, and run `terraform -chdir=terraform/bootstrap init -migrate-state`. From a fresh checkout of the same revision, run `init` and `plan` in `terraform/bootstrap`. Keep the backup until the plan reports **No changes**. [Terraform backend migration](https://developer.hashicorp.com/terraform/cli/commands/init#backend-initialization)
- [ ] If you change the backend, keep [terraform/terraform_override.tf](../terraform/terraform_override.tf), the IAM policies, and the workflow role ARNs in sync.
- [ ] Restrict the GitHub Actions `write` environment to `master`. The read-only role trusts the `read` environment, and the read-write role trusts the `write` environment.
@@ -89,7 +90,7 @@ This deployment manages the `FilOzone` Terraform workspace. The bootstrap IAM po
- [ ] If the repository is public, [require approval for all outside collaborators](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository#configuring-required-approval-for-workflows-from-public-forks)
- [ ] If the repository is private, [disable sending write tokens or secrets to workflows from fork pull requests](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository#enabling-workflows-for-private-repository-forks)
- [ ] Pull remote changes to the default branch
-- [ ] Enable required PRs, peer reviews, status checks and branch up-to-date check on the repository by making sure [github/$ORGANIZATION_NAME.yml](github/$ORGANIZATION_NAME.yml) contains the following entry:
+- [ ] Enable required PRs, peer reviews, status checks and branch up-to-date check on the repository by making sure `github/$ORGANIZATION_NAME.yml` contains the following entry:
```yaml
repositories:
$GITHUB_MGMT_REPOSITORY_NAME: