diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..3c93d00 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,81 @@ + + +## Related pull requests + + + +- + +## Summary + + + +## What ships + + + +- +- + +## Behavior changes + + + +- + +## What this addresses + + + +- + +## Not included + + + +- + +## Verify locally + +### Checkout + +```sh +gh pr checkout +``` + +### Static checks + + + +```sh +tofu fmt -check -recursive +tofu init -backend=false -input=false -lockfile=readonly +tofu validate -no-color +``` + +### Smoke + + + +```sh +tofu plan -no-color +``` + +Expected: . + +## Migration notes + + diff --git a/README.md b/README.md index f9c6c5b..f6341d1 100644 --- a/README.md +++ b/README.md @@ -9,21 +9,39 @@ settings plus `protect-main` and `protect-tags` rulesets. - `variables.tf` — `repository_policies` inventory (single source of truth). - `locals.tf` — `check_templates` copy-paste source for check lists. - `repositories.tf` — `module.repository_policy` wiring. +- `organization.tf` — organization settings and Actions/workflow permissions. - `modules/repository-policy/` — shared policy module (identical across orgs). - `checks.tf` — invariant guards (no scripts). - `imports.tf` — bootstrap import triples (one per repo: settings + 2 rulesets). - `providers.tf`, `versions.tf`, `outputs.tf` — provider, pins, outputs. +## Authentication + +Run tofu with `GITHUB_TOKEN` exported in the shell, or via the mise tasks +`mise run tofu:plan` / `mise run tofu:apply`, which inject the organization +token from 1Password. The token needs Administration: write on every managed +repository. It also needs org admin on `jackin-project` for the organization +settings and Actions policies in `organization.tf`. + ## Adding a repository 1. Add one entry to `repository_policies` in `variables.tf`, copying a check - list from `locals.tf` (`standard` = `["Required", "DCO"]`, - `policy` = `["Policy"]`); bespoke checks inline with a comment citing the - producing workflow. Repos with no CI use `required_checks = []` plus a - non-empty `no_ci_reason` and extend the allowlist check in `checks.tf`. + list from `locals.tf` (`standard` = `["Required", "DCO"]`, `policy` = + `["Policy"]`); bespoke checks inline with a comment citing the producing + workflow. Repos with no CI use `required_checks = []` plus a non-empty + `no_ci_reason` and extend the allowlist check in `checks.tf`. Always add + the name to the mandatory list in `mandatory_target_repositories_present` + in `checks.tf` (updating its count and message). 2. Add one import triple (settings + `protect_main` + `protect_tags`) to `imports.tf` using the live numeric ruleset IDs. +## Organization overlays + +- `organization.tf` manages the org profile (`github_organization_settings`), + Actions availability/allow policy (`github_actions_organization_permissions`), + and default `GITHUB_TOKEN` workflow permissions + (`github_actions_organization_workflow_permissions`). + ## Verification ```sh @@ -31,3 +49,6 @@ tofu fmt -check -recursive tofu init -backend=false -input=false -lockfile=readonly tofu validate -no-color ``` + +OpenTofu is pinned via `mise.toml` (opentofu 1.13.1); existing repos are +imported via `imports.tf` on first apply. diff --git a/imports.tf b/imports.tf index cd3e060..2a039ec 100644 --- a/imports.tf +++ b/imports.tf @@ -4,6 +4,21 @@ # Adopt the existing GitHub resources into the default local state before managing them. # These stable IDs prevent a fresh state from planning duplicate repositories or rulesets. +import { + to = github_organization_settings.jackin_project + id = "273541039" +} + +import { + to = github_actions_organization_permissions.jackin_project + id = "jackin-project" +} + +import { + to = github_actions_organization_workflow_permissions.jackin_project + id = "jackin-project" +} + import { to = module.repository_policy.github_repository.managed_settings["homebrew-tap"] id = "homebrew-tap" diff --git a/mise.toml b/mise.toml index bb6e558..5d5900d 100644 --- a/mise.toml +++ b/mise.toml @@ -9,3 +9,25 @@ opentofu = "1.13.1" python = "3.14" uv = "0.11.29" "pipx:reuse" = { version = "6.2.0", extras = "charset-normalizer", depends = ["python"] } + +[tasks."tofu:plan"] +description = "Run tofu plan" +run = """ +set -eu +export OP_ACCOUNT='zhokhov.1password.com' +GITHUB_TOKEN="$(op read 'op://Private/hq3g4pvryg4iise4vxwhk6p5jy/jackin-project-opentofu')" || { echo "op read failed, refusing to run" >&2; exit 1; } +export GITHUB_TOKEN +[ -n "${GITHUB_TOKEN:-}" ] || { echo "GITHUB_TOKEN is empty, refusing to run" >&2; exit 1; } +exec tofu plan "$@" +""" + +[tasks."tofu:apply"] +description = "Run tofu apply" +run = """ +set -eu +export OP_ACCOUNT='zhokhov.1password.com' +GITHUB_TOKEN="$(op read 'op://Private/hq3g4pvryg4iise4vxwhk6p5jy/jackin-project-opentofu')" || { echo "op read failed, refusing to run" >&2; exit 1; } +export GITHUB_TOKEN +[ -n "${GITHUB_TOKEN:-}" ] || { echo "GITHUB_TOKEN is empty, refusing to run" >&2; exit 1; } +exec tofu apply "$@" +""" diff --git a/organization.tf b/organization.tf new file mode 100644 index 0000000..47786e1 --- /dev/null +++ b/organization.tf @@ -0,0 +1,50 @@ +# SPDX-FileCopyrightText: 2026 Alexey Zhokhov +# SPDX-License-Identifier: Apache-2.0 + +# Organization-wide policy. Actions permissions and workflow defaults match the +# live baseline (tightening waits for per-repo workflow audits). New-repository +# security defaults are intentionally hardened (detection-only, future repos). + +resource "github_organization_settings" "jackin_project" { + billing_email = "alexey@zhokhov.com" + + name = "" + description = "" + blog = "" + email = "jackin@tailrocks.com" + location = "Singapore" + + has_organization_projects = true + has_repository_projects = true + default_repository_permission = "read" + members_can_create_repositories = true + + members_can_create_public_repositories = true + members_can_create_private_repositories = true + + members_can_create_pages = true + members_can_create_public_pages = true + members_can_create_private_pages = true + + members_can_fork_private_repositories = false + web_commit_signoff_required = false + + dependabot_alerts_enabled_for_new_repositories = true + dependabot_security_updates_enabled_for_new_repositories = true + dependency_graph_enabled_for_new_repositories = true + secret_scanning_enabled_for_new_repositories = true + secret_scanning_push_protection_enabled_for_new_repositories = true +} + +resource "github_actions_organization_permissions" "jackin_project" { + enabled_repositories = "all" + allowed_actions = "all" + sha_pinning_required = false +} + +resource "github_actions_organization_workflow_permissions" "jackin_project" { + organization_slug = var.github_organization + + default_workflow_permissions = "write" + can_approve_pull_request_reviews = false +} diff --git a/outputs.tf b/outputs.tf index 15b6a23..48bc517 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,6 +1,10 @@ # SPDX-FileCopyrightText: 2026 Alexey Zhokhov # SPDX-License-Identifier: Apache-2.0 +output "organization" { + value = var.github_organization +} + output "managed_repositories" { description = "Set of managed repository names (inventory keys)" value = module.repository_policy.managed_repositories