Skip to content

feat(gh): manage GitHub organization and repository settings as code #5311

Open
6 of 16 issues completed
Open

Description

@dan-petty

Update 2026-11-26 (infra move): ADR 0032 and ADR 0035 changed this plan.

  • devops repos onboard owns the repository settings. The baseline is in dan-petty/infra.
  • OpenTofu keeps only the organization checks and the transfer check.
  • A shared module goes in dan-petty/infra. The root stacks go in dan-petty/homelab (tf/github/).

No tf/ code goes in devops-cli.


Problem or Motivation

The settings of the dan-petty repositories and of the retric-ai organization exist only in GitHub. No record says where these settings live, who changes them, or how to verify a repository transfer from dan-petty to retric-ai. No devops command reads rulesets, variables or org data, and no code stops an agent that writes to a settings route through devops gh api.

The owner approved this plan on 2026-11-13: "proceed as recommended with github org and repo management implementation". The owner accepted each recommendation below as written.

Proposed Solution & Architectural Design

Adopt design A (settings as code with OpenTofu) in a smaller form, with parts from designs B and C.

  • Engine. OpenTofu 1.13.9 with the provider integrations/github 6.13.0, at exact pins that Renovate updates. Two root stacks, tf/github/dan-petty and tf/github/retric-ai (one owner for each provider block), and the shared module tf/github/modules/repository. Import blocks with for_each stay in the code, so a plan can rebuild a lost state. The kubernetes backend keeps the state in a new tofu-state namespace.
  • Who does what. Agents write the stacks and run plan with a new read-only App. Only the owner runs apply. A nightly job with the read-only App finds drift.
  • Scope now. Only devops-cli, the probe repository, the org and its 3 repositories. Each later repository is one line in repos.yaml when the owner puts it on the move list. Labels, secret values, webhooks, App registrations, packages, Projects and the org code security configuration stay out of tofu.
  • Hard asserts. OpenTofu check blocks only give warnings. So each hard assert is a lifecycle postcondition on a data source, which is an error, and devops tf drift exits non-zero on a failed or unknown check.
  • Org settings are check-only, through the github_organization data source, so billing_email never goes into the state, the plan or Loki.
  • The devops-cli 'main' ruleset stays out of tofu until upstream [FEAT]: Support the code_quality rule and require_extra_approval_for_unattributed_changes in rulesets integrations/terraform-provider-github#3664 adds code_quality and code_coverage. Postconditions assert its rule types.
  • Parts from designs B and C. The gh pass-through groups (repo, ruleset, variable, org) on the feat(cli): tool commands pass unknown arguments to the tool #5223 registry. One agent-write guard on the settings routes of devops gh api and on the pass-through write verbs. A per-owner App installation map in the roadmap Service that refuses an unknown installation. A probe repository that moves to retric-ai and back. A Service pause in the move window. A 14-day window for the old packages. Only public repositories move now.
  • Transfer. No open tool does the transfer, so no command is built. A runbook in docs/ROUTINE_TASKS.md holds the preflight checks. The owner sends the transfer call through devops gh api, and the guard refuses that call for agents. An import-only plan in the target stack verifies the move: imports only, 0 to change, and each postcondition passes.
  • Order. First the guard, tofu and the devops tf fixes. Then the two stacks, the Service map and the drift job. Then the probe and the runbook. Then devops-cli, after feat(service): verify GitHub App webhooks with one secret #4417 and the feat(github): check the App grant at start and record the App identity #5252 App webhook. The devops-cli move is one-way: GitHub retires the name (65,957 clones in 14 days, measured 2026-11-13).

Target Subsystem

OpenTofu / Infrastructure as Code

Existing Tool Considered

OpenTofu 1.13.9 (MPL-2.0) with integrations/github 6.13.0 (MIT) for the settings as code, and gh 2.104.0 (MIT) for the pass-through groups. No open tool does the transfer: gh has no verb (cli/cli#5292), GitHub Enterprise Importer needs Enterprise Cloud, and the provider has no transfer resource. Not chosen: safe-settings 3.0.0 as a policy App (release 3.0.0 has no repository.transferred handler, it covers only the org repositories, and it adds a service that the internet can reach with write access to each org repository); a thin audit CLI with a home-grown baseline (it does again what tofu does).

Cost: about 9M tokens to build, about 13.5 agent-days (about 7 calendar days with 3 agents) and about 3 h of owner time. Keep: about 250k tokens a month. Fix: about 200k to 300k tokens for each provider regression.

Decisions

  1. Decided 2026-11-13. Which settings engine do we adopt? OpenTofu 1.13.9 with integrations/github 6.13.0. Agents plan and the owner applies.
  2. Decided 2026-11-13. Which repos move, and in which order? First the throwaway probe repo, to retric-ai and back. Then devops-cli. acp, vibes and dreamscaper move only after each has a first release. homelab, dotfiles, the personal website, the forks and the other personal repositories stay with dan-petty. Dormant repos are archived in place.
  3. Decided 2026-11-13. Do you accept that the devops-cli move is one-way? Yes. GitHub retires dan-petty/devops-cli at the transfer (65,957 clones in 14 days), and a transfer back is not verified. Rollback is a fix forward in retric-ai.
  4. Decided 2026-11-13. Where does the OpenTofu state live? The kubernetes backend in a new tofu-state namespace. The import blocks in the code rebuild a lost state.
  5. Decided 2026-11-13. Which identity plans? A new public App, devops-settings-reader. It is owned by retric-ai, has read permissions only and no webhook, and is installed on both accounts. Agents on the workstation and the drift job use it.
  6. Decided 2026-11-13. Which token scopes does the owner token get? Add read:packages for all time. Add admin:org only for org applies and the move window, then remove it ('gh auth refresh -s admin:org', then '-r admin:org'). Keep delete_repo off, and archive the probe instead of a delete.
  7. Decided 2026-11-13. Does tofu manage org settings? Check-only. Use data github_organization with postconditions for 2FA, the default permission and member privileges. The owner changes these in the UI. billing_email then never goes into the state, the plan or Loki.
  8. Decided 2026-11-13. Which App model do devops-cli-service (settings say devops-roadmap), devops-cli-argocd and the release App use? Make each App public, and let the Service accept only the installation IDs in its per-owner map. homelab stays personal and keeps the same App. Also confirm the real slug and the identity of the release App.
  9. Decided 2026-11-13. Which org baseline do you set before the first move? Require 2FA (UI). Set the Claude App to selected repositories. Members cannot delete repos, change visibility or create public repos. Enforce the 'GitHub recommended' security configuration and attach it to each moved repo. Turn on push protection for devops-cli. Keep Actions allowed_actions at 'all' until an audit shows that all action uses are pinned.
  10. Decided 2026-11-13. How do we treat the devops-cli 'main' ruleset in tofu? Keep it out of tofu, with postconditions on its rule types, until upstream [FEAT]: Support the code_quality rule and require_extra_approval_for_unattributed_changes in rulesets integrations/terraform-provider-github#3664 adds code_quality and code_coverage.
  11. Decided 2026-11-13. What happens to the Pages URL? Set a custom domain under the verified retric.ai domain right after the move. The reference PR fixes the links.
  12. Decided 2026-11-13. Which image namespace do we use after the move? ghcr.io/retric-ai/devops-cli/*. release.yml publishes there automatically. Keep the dan-petty packages for 14 days, then delete them.
  13. Decided 2026-11-13. How do we handle the repo webhooks at the move? Finish feat(service): verify GitHub App webhooks with one secret #4417 and the feat(github): check the App grant at start and record the App identity #5252 App webhook (owner step 2 of feat(github): check the App grant at start and record the App identity #5252) before devops-cli moves, so no key depends on owner/name.
  14. Decided 2026-11-13. Does devops-cli build a transfer command? No. Use a runbook with preflight GETs and the owner call 'devops gh api -X POST repos/{o}/{r}/transfer -f new_owner=retric-ai'. The guard refuses this call for agents. Build a command only if moves become frequent.
  15. Decided 2026-11-13. Do you approve the probe? Yes. Use a public throwaway repo with a ruleset, a release environment with a dummy secret and a variable, a repo variable, a discussion, a label and a release. Move it to retric-ai and back, then archive it.
  16. Decided 2026-11-13. Do we remove devops gh branch-protection? Yes. It manages classic protection only, its default file is missing, and no repo uses classic protection.
  17. Decided 2026-11-13. How do we handle seats? Move only public repos now. Check each collaborator before a private repo moves, because the org has 1 seat and it is filled.

Owner steps

  • Approve the plan and the probe repository (decisions 1 to 17, 2026-11-13).
  • Register the read-only App devops-settings-reader: owned by retric-ai, public, read permissions only, webhook off. Install it on dan-petty and on retric-ai (decision 5).
  • Put the credentials of devops-settings-reader in the keyring for workstation plans, and create the Kubernetes Secret object for the nightly drift job (orders 6 and 13).
  • Add read:packages to the owner gh login for all time. Keep delete_repo off (decision 6).
  • Add admin:org only for org applies and the move window (gh auth refresh -s admin:org), then remove it (gh auth refresh -r admin:org) (decision 6).
  • Set the org baseline in the GitHub UI before the first move: require 2FA; set the Claude App to selected repositories; members cannot delete repositories, change visibility or create public repositories; enforce the 'GitHub recommended' security configuration and attach it to each moved repository; turn on push protection for devops-cli; keep Actions allowed_actions at 'all' (decision 9).
  • Make the roadmap App, devops-cli-argocd and the release App public, install them on retric-ai, and give the installation IDs for the per-owner map. Confirm the real slug of the roadmap App and the identity of the release App (decision 8, order 12).
  • Finish the App webhook of feat(github): check the App grant at start and record the App identity #5252 (its owner step) and feat(service): verify GitHub App webhooks with one secret #4417 before devops-cli moves (decision 13).
  • Review each import plan and run each apply with the gh login: devops-cli (order 10), then the org stack with admin:org (order 11).
  • Make one UI change on the probe repository to prove the nightly drift job (order 13).
  • Create the public probe repository, then send the transfer call to retric-ai and back: uv run devops gh api -X POST repos/<owner>/<probe-repo>/transfer -f new_owner=<target>. Archive the probe after the test; do not delete it (decisions 6 and 15, order 15).
  • Pause the Service in each move window, then send the devops-cli transfer call: uv run devops gh api -X POST repos/dan-petty/devops-cli/transfer -f new_owner=retric-ai (decisions 2, 3 and 14).
  • If the probe shows that environment secrets do not move, enter the release environment secret again after the devops-cli move.
  • Set a custom domain under retric.ai for the devops-cli Pages site right after the move (decision 11).
  • Merge the reference pull request (order 16) right after the move is verified.
  • Delete the dan-petty devops-cli packages 14 days after the move (decision 12).
  • Archive the dormant repositories in place with devops gh repo archive (decision 2).
  • Before a private repository moves, check each collaborator against the org seats (decision 17).

Risks

  • The devops-cli move is one-way. GitHub retires dan-petty/devops-cli at the transfer (65,957 clones in 14 days, measured 2026-11-13). The probe repo cannot show this effect.
  • Environment secrets may not move (contested). If RELEASE_APP_PRIVATE_KEY is lost, the next release fails until the owner enters it again. The probe and a postcondition must settle this first.
  • Ruleset rule loss: provider 6.13.0 has no code_quality or code_coverage schema (upstream [FEAT]: Support the code_quality rule and require_extra_approval_for_unattributed_changes in rulesets integrations/terraform-provider-github#3664), so a managed update drops those rules from the merge gate. Mitigation: the 'main' ruleset stays out of tofu, and postconditions assert it.
  • False drift: a read-only identity does not see bypass_actors (upstream [BUG]: Ruleset bypass_actors drift on every plan when the token cannot administer the ruleset integrations/terraform-provider-github#3687), and it may not see security_and_analysis. The first import plan must run with both identities and record each difference.
  • Blind spots: tofu sees only declared resources. A new hook, environment or App appears only through a list data source with a postcondition.
  • Agents share the owner token and a kubeconfig that can write. The guards in devops gh api and devops tf stop errors, not intent. Bare tofu or curl with admin:org could change org settings, so admin:org stays on only for the time windows.
  • Rate limit: provider calls bypass run_gh. Owner applies on the workstation use the same budget as devops gh. Mitigation: the reader App for plans and a budget floor before a plan.
  • Homelab dependency: when the cluster is down, nobody can plan or apply, and it is not known whether etcd is backed up. The import blocks in the code rebuild the state.
  • After a move, the roadmap Service stops for the repo until the App is installable on retric-ai and the map is live. The Valkey keys, the metric series and the Job names start again.
  • Moved workflows lose access to the ghcr.io/dan-petty packages. A release after the move that runs before the reference PR merges uses the new namespace, and the cluster keeps the old images until the PR merges.
  • The Claude App gets contents, workflows and repository_hooks write on each moved repo, unless the owner changes it to selected repositories first.
  • A public roadmap App lets any account install it and send events to the receiver. The installation allowlist in the Service map is necessary.
  • The young and experimental parts: -generate-config-out is experimental, the provider has 2 maintainers, and v7.0.0 is open. Mitigation: exact pins, and a plan diff on each Renovate bump.
  • Documentation defects that confuse the App model: docs/roadmap/onboard.md and the check suites say devops-cli-service, but the settings and ADR 0015 say devops-roadmap. feat(roadmap): onboard writes labels.yml and clear-status.yml from --from #3742 and feat(roadmap): onboard writes the labels file and the status workflow #3753 look like duplicates.

Not verified yet

The probe and the first plans must show these:

  • Not documented by GitHub, so the probe must show it: whether repository rulesets, environments, environment secrets and variables, Actions variables, Discussions, Actions run history, artifacts, caches and alerts move on a transfer.
  • Whether a transfer back to the retired name dan-petty/devops-cli works.
  • The real slug, name and visibility of the roadmap App. Check suites on 2026-11-13 show devops-cli-service, the settings say devops-roadmap, and GET apps/ returns 404. The identity of the release App (RELEASE_APP_CLIENT_ID) is also unknown.
  • The GHCR package list under dan-petty (this needs read:packages). Also whether GITHUB_TOKEN in a retric-ai repo can create the new org packages under the org package settings.
  • The cause of the 404 on orgs/retric-ai/rulesets for an org-admin token.
  • Whether a read-only App sees bypass_actors and security_and_analysis. Upstream [BUG]: Ruleset bypass_actors drift on every plan when the token cannot administer the ruleset integrations/terraform-provider-github#3687 says that bypass_actors are hidden.
  • The provider docs on main show cache_path and the github_organization data source settings fields. Nobody confirmed that both exist in the 6.13.0 release.
  • Whether 2FA for the org can be set only in the UI (the research found no API that sets it).
  • Whether etcd in the homelab cluster is backed up.
  • Whether Argo CD follows the git redirect for the old repoURL until the reference PR merges.
  • Whether any external system trusts the devops-cli OIDC sub claim. release.yml has no PyPI publish and uses attest-build-provenance.
  • That Projects v2 boards stay with the owner account (from the research, with no primary statement found). Also the repo list of the self-hosted Renovate config.
  • The seat rule for outside collaborators comes from one reading of the billing docs. Nobody read it again.
  • The identity of the second write collaborator on 6 repos (not printed on purpose).
  • The design A sketch.tf was not validated, because tofu is not installed. The output quality of -generate-config-out was not tested.
  • All token and day costs are estimates scaled from similar modules, not measurements.
  • The community discussion URL for environment secrets (number 188227) comes from the research data. Nobody opened it.

Children

Alternatives check of 2026-11-28: in-use.
The item already names this tool.
Tool: integrations/terraform-provider-github (https://github.com/integrations/terraform-provider-github), MIT, last activity 2026-11-27, maintained.
Reason: The provider reads organization settings through data sources and shows drift in a plan, which fits the reduced org-check and transfer-check scope, but it has no transfer resource and 6.13.0 lacks the code_quality rules.

Covers:

  • Organization settings read through data sources, check-only, no billing_email in state
  • Drift shown by a scheduled plan against declared configuration
  • Import blocks rebuild a lost state from live settings

Lacks:

  • No resource or verb to transfer a repository between owners
  • No code_quality or code_coverage rule schema in 6.13.0
  • A read-only identity hides bypass_actors, which gives false drift

Sub-issues

Sub-issues

6 of 16 Issues completed
Loading 16 sub-issues

Activity

  1. added
    type/feature
    source/agent
    scope/gh
    status/new
    value/high
    effort/high
    on Nov 13, 2026
  2. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor
  3. added
    priority/p2-medium
    on Nov 13, 2026
  4. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor

    Owner step done (2026-11-13): the read-only App devops-settings-reader exists and is installed on both owners.

    • Owner: retric-ai. Public. No webhook events.
    • App ID: 5737929. Client ID: Iv23li5gO9oQW3VHTtjz (use the client ID as the JWT issuer, as GitHub recommends).
    • Installation IDs: dan-petty 181445924, retric-ai 181446084.
    • The owner holds the private key. It is not in the keyring or in a Kubernetes Secret object yet.

    For the builders of #5320, #5325, dan-petty/homelab#360 and #5328: read the client ID and the installation ID of each owner from settings, and the private key from the keyring, in the shape of service.github_app.*. The PR that adds the setting names the one owner command that stores the key; the owner runs it.

    Open item: the App now holds every read permission. A follow-up comment lists the minimal read set that the stacks and the drift job need, with the GitHub documentation source for each, so the owner can remove the rest.

  5. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor

    Owner decision (2026-11-13): devops-settings-reader keeps read access to every permission. The owner said: "I am fine with read all for the devops-settings-reader App, we can use it for planning migration functionality for other features and settings". It stays read-only: it holds no write permission and no webhook. The open item in the previous comment is closed: no permission trim.

  6. devops-cli-service commented on Nov 16, 2026

    @devops-cli-service
    Contributor

    Alternatives check: in-use

    Reason: The searches and the repository facts show the tool the issue already names — OpenTofu 1.13.9 with the integrations/terraform-provider-github 6.13.0 provider — is an open, maintained engine that does the whole settings-as-code job (declare org/repo settings, plan, import and detect drift), and the issue adopts it as its engine. Only provider gaps (no transfer resource, no code_quality/code_coverage ruleset schema) fall outside, and the issue already routes those to a runbook and postconditions.

    The repository already uses this tool.

    Tool: opentofu/opentofu (https://github.com/opentofu/opentofu)

    • License: MPL-2.0
    • Last activity: 2026-11-16
    • Maintained: yes

    Covers:

    • Declares GitHub repository and organization settings as code with OpenTofu and the integrations/github provider
    • Plan/apply workflow with import blocks to rebuild lost state
    • Nightly plan for drift detection
    • Org settings check-only through the github_organization data source so billing_email stays out of state
    • Postconditions/data-source asserts as hard checks

    Lacks:

    • The provider has no repository transfer resource, so the transfer is a manual runbook call
    • Provider 6.13.0 has no code_quality or code_coverage ruleset schema (upstream integrations/terraform-provider-github#3664)
    • A read-only identity may not see bypass_actors or security_and_analysis (upstream integrations/terraform-provider-github#3687)
    • Label values, secret values, webhooks, App registrations, packages and Projects stay outside tofu

    Tools considered:

    Searches run:

    • manage GitHub organization and repository settings as code OpenTofu terraform-provider-github, results: 5
    • safe-settings GitHub App organization repository settings as code, results: 5
    • terraform-provider-github manage repository settings as code, results: 5
    • GitHub organization settings as code tool drift detection, results: 5
    • integrations/terraform-provider-github repository rulesets, results: 5
    • OpenTofu GitHub provider, results: 5
    • safe-settings repository, results: 5

    Sources:

    Checked on 2026-11-16. A person decides what this means for the item. The check changes no label and closes no issue.

  7. dan-petty commented on Nov 21, 2026

    @dan-petty
    OwnerAuthor

    ADR 0032 (#6674) moves the shared module of ADR 0026 to dan-petty/infra as tf/modules/github-repository. The root stacks go to dan-petty/homelab tf/github/, because they name private repositories (owner decision of 2026-11-21). Build the module in infra and the stacks in that home. #6679 deletes only the cloud stubs of tf/ and keeps tf/github if this item adds it first.

  8. devops-cli-service commented on Nov 22, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: in-use, tool https://github.com/opentofu/opentofu. A person decides what the new result means for the item.

    Searches (6)

    Tools considered:

    Searches run:

    • open source tool manage GitHub organization and repository settings as code, results: 5
    • safe-settings GitHub App sync repository settings from YAML, results: 5
    • github/safe-settings repository, results: 5
    • integrations/terraform-provider-github repository rulesets organization settings, results: 5
    • GitHub repository settings as code drift detection tool 2026, results: 5
    • OpenTofu GitHub provider manage repositories as code, results: 5

    Sources:

  9. dan-petty commented on Nov 22, 2026

    @dan-petty
    OwnerAuthor

    Owner decision of 2026-11-22 (#6773, D1): the repository settings (merge methods, rulesets, environments, variables) move from this tofu design to the command devops repos onboard of #6773, with devops repos onboard --all --plan as the drift check. A new ADR amends ADR 0026 decisions 1, 4 and 7. Tofu keeps only the organization checks and the transfer check. The parts of this item that hold repository settings need a new scope before any build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/highpriority/p2-mediumscope/ghsource/agentstatus/newtype/featurevalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions