Skip to content

ci(repo): OpenTofu 로 저장소·조직 워크플로 권한 코드화 - #8

Merged
lens0021 merged 2 commits into
mainfrom
ci/repo-settings-as-code
Jul 12, 2026
Merged

ci(repo): OpenTofu 로 저장소·조직 워크플로 권한 코드화#8
lens0021 merged 2 commits into
mainfrom
ci/repo-settings-as-code

Conversation

@lens0021

Copy link
Copy Markdown
Collaborator

배경

release-please 첫 실행이 "GitHub Actions is not permitted to create or approve pull requests"로 실패했다. 원인을 좁혀보니 chaotic-ground 조직이 워크플로 기본 권한을 read 로 강제하고 있어서("Write permissions for workflows are disabled by the organization") 리포별로 write 를 요청해도 거부됐다.

wikven(chaotic-ground/wikven)의 .tf 구성과 동일한 방식(OpenTofu + lens0021/repo-settings-as-code)으로 관리하도록 이 저장소에도 .tf/ 디렉터리를 추가했다.

변경

  • main.tf/variable.tf: wikven 과 동일한 provider·변수 선언.
  • repository.tf: github_repository.this 를 geulbus 현재 실제 설정 그대로 import(적용 시 diff 없음 — 의도치 않은 변경 없음 확인됨).
  • permissions.tf: github_workflow_repository_permissions 로 geulbus 리포의 default_workflow_permissions=write, can_approve_pull_request_reviews=true 선언.
  • org_permissions.tf: github_actions_organization_workflow_permissions 로 조직 기본값도 write/true 로(리포 레벨만으로는 조직이 막고 있어 실제로 안 먹힘 — 근본 원인이 여기라 조직 레벨도 같이 선언).
  • tf.yml: wikven 과 동일하게 lens0021/repo-settings-as-code 로 PR엔 plan 코멘트, main push/dispatch 엔 drift 이슈 관리.

검증

로컬에서 tofu init/plan/apply 로 실제 적용을 이미 완료했다(이 PR은 그 변경을 코드로 문서화·추적하는 것). gh api 로 조직·리포 양쪽 다 default_workflow_permissions=write, can_approve_pull_request_reviews=true 로 바뀐 것 확인:

$ gh api orgs/chaotic-ground/actions/permissions/workflow
{"default_workflow_permissions":"write","can_approve_pull_request_reviews":true}
$ gh api repos/chaotic-ground/geulbus/actions/permissions/workflow
{"default_workflow_permissions":"write","can_approve_pull_request_reviews":true}

🤖 Generated with Claude Code

lens0021 and others added 2 commits July 13, 2026 01:27
release-please 첫 실행이 "GitHub Actions is not permitted to create or
approve pull requests"로 실패했다. 원인을 좁혀보니 chaotic-ground
조직이 워크플로 기본 권한을 read 로 강제하고 있어("Write permissions
for workflows are disabled by the organization"), 리포별로 write 를
요청해도 거부됐다.

wikven(chaotic-ground/wikven)의 .tf 구성과 같은 방식(OpenTofu +
lens0021/repo-settings-as-code)으로 관리하도록 이 저장소에도 .tf/
디렉터리를 추가했다.

- main.tf/variable.tf: wikven 과 동일한 provider·변수 선언.
- repository.tf: github_repository.this 를 geulbus 현재 실제 설정
  그대로 import(적용 시 diff 없음 — 의도치 않은 변경 없음 확인됨).
- permissions.tf: github_workflow_repository_permissions 로 geulbus
  리포의 default_workflow_permissions=write, can_approve_pull_request_
  reviews=true 선언.
- org_permissions.tf: github_actions_organization_workflow_permissions
  로 조직 기본값도 write/true 로(리포 레벨만으로는 조직이 막고 있어
  실제로 안 먹힘 — 근본 원인이 여기라 조직 레벨도 같이 선언).
- tf.yml: wikven 과 동일하게 lens0021/repo-settings-as-code 로 PR엔
  plan 코멘트, main push/dispatch 엔 drift 이슈 관리.

로컬에서 tofu init/plan/apply 로 실제 적용 완료, gh api 로 조직·리포
양쪽 다 default_workflow_permissions=write, can_approve_pull_request_
reviews=true 로 바뀐 것 확인.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
tf.yml 첫 실행이 403으로 실패했다:
"GET .../actions/permissions/workflow: 403 Resource not accessible by
integration" — 리포·조직 둘 다. 표준 GITHUB_TOKEN(설치 토큰)은
`permissions:` 블록을 아무리 넓게 줘도 이 엔드포인트 자체에 접근이
막혀 있다(자기 자신의 권한 상한을 스스로 못 올리게 하는 보안 장치로
보임). PAT/GitHub App 관리자 권한이 있어야만 되는데, wikven 도 애초에
이 리소스 타입을 관리 대상에 안 넣은 이유가 이거였다.

permissions.tf/org_permissions.tf 를 삭제해 CI 추적 대상에서 뺀다.
실제 설정 변경은 이미 로컬에서 admin:org 스코프가 있는 PAT로 적용
완료했고(이전 커밋 참고), gh api 로 재확인된 상태다 — 이 커밋은 CI가
계속 시도하다 실패하는 것만 막는다. 남은 repository.tf 는 표준
GITHUB_TOKEN 으로 문제없이 plan 된다(로컬 확인: No changes).

곁들여 .gitignore 의 tofu 상태 관련 패턴을 실제로 생기는 파일명
(.terraform.tfstate.lock.info, terraform.tfstate.<타임스탬프>.backup)
까지 커버하도록 보강.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

OpenTofu Plan

github_repository.this: Preparing import... [id=geulbus]
github_repository.this: Refreshing state... [id=geulbus]

OpenTofu used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  ~ update in-place (current -> planned)

OpenTofu will perform the following actions:

  # github_repository.this will be updated in-place
  # (imported from "geulbus")
  ~ resource "github_repository" "this" {
        allow_auto_merge            = false
        allow_forking               = true
        allow_merge_commit          = true
        allow_rebase_merge          = true
        allow_squash_merge          = true
        allow_update_branch         = false
        archived                    = false
        auto_init                   = false
        default_branch              = "main"
        delete_branch_on_merge      = false
        description                 = "날개셋(nalgaeset) 입력 설정과 호환되는 순수 Rust ibus 한글 입력기 (WIP)"
        etag                        = "W/\"b739f72db4708a31ce76018464a23d84e0bb3745ace090de0df253cc743a2ae6\""
        fork                        = "false"
        full_name                   = "chaotic-ground/geulbus"
        git_clone_url               = "git://github.com/chaotic-ground/geulbus.git"
        has_discussions             = false
        has_downloads               = true
        has_issues                  = true
        has_projects                = true
        has_wiki                    = true
        html_url                    = "https://github.com/chaotic-ground/geulbus"
        http_clone_url              = "https://github.com/chaotic-ground/geulbus.git"
        id                          = "geulbus"
        is_template                 = false
        merge_commit_message        = "PR_TITLE"
        merge_commit_title          = "MERGE_MESSAGE"
        name                        = "geulbus"
        node_id                     = "R_kgDOSsDcsA"
        primary_language            = "Rust"
        private                     = false
        repo_id                     = 1254153392
        squash_merge_commit_message = "COMMIT_MESSAGES"
        squash_merge_commit_title   = "COMMIT_OR_PR_TITLE"
        ssh_clone_url               = "git@github.com:chaotic-ground/geulbus.git"
        svn_url                     = "https://github.com/chaotic-ground/geulbus"
        topics                      = []
        visibility                  = "public"
        web_commit_signoff_required = false

      + security_and_analysis {
          + secret_scanning {
              + status = "disabled"
            }
          + secret_scanning_push_protection {
              + status = "disabled"
            }
        }
    }

Plan: 1 to import, 0 to add, 1 to change, 0 to destroy.

Warning: Argument is deprecated

  with github_repository.this,
  on repository.tf line 14, in resource "github_repository" "this":
  14:   has_downloads   = true

This attribute is no longer in use, but it hasn't been removed yet. It will
be removed in a future version. See
https://github.com/orgs/community/discussions/102145#discussioncomment-8351756

(and one more similar warning elsewhere)

─────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so OpenTofu can't
guarantee to take exactly these actions if you run "tofu apply" now.

View run

@lens0021
lens0021 merged commit 469c7de into main Jul 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant