C.W.K.
Stream
Lesson 07 of 12 · published

GITHUB_TOKEN

~12 min · github-token, permissions, scope

Level 0Apprentice
0 XP0/101 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

자동 발급 runner ID

모든 workflow run 은 자동 발급 GITHUB_TOKEN 받아. 현재 repo 에 scope 된 runner 의 installation token. PAT 발급 없이 GitHub API 호출용.

${{ secrets.GITHUB_TOKEN }} 또는 ${{ github.token }} 로 사용. Run 동안만 살고 만료.

기본 권한은 너무 관대

2023 까지 GITHUB_TOKEN 은 대부분에 write default (contents, issues, pull-requests). 이제 org default 는 'permissive' (legacy) 나 'restricted' (read all) 둘 중. 항상 확인하고 restricted 선호.

Workflow 별 permissions: 로 scope:

  • contents: read — checkout, push 없음.
  • contents: write — commit, tag, release push.
  • pull-requests: write — PR 코멘트, PR 생성.
  • issues: write — issue 코멘트.
  • id-token: write — OIDC token 요청 (다음 lesson).
  • packages: write — GHCR 에 push.
  • security-events: write — code scanning 위한 SARIF 업로드.

Code

Least-privilege workflow·yaml
name: ci
on: { pull_request: {}, push: { branches: [main] } }

# Workflow-wide default: read-only.
permissions:
  contents: read

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: pytest -q

  comment-on-pr:
    if: github.event_name == 'pull_request'
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write   # only this job needs write
    steps:
      - uses: actions/github-script@v7
        with:
          script: |
            github.rest.issues.createComment({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.issue.number,
              body: 'CI ran successfully ✓',
            });

External links

Exercise

Repo 의 각 workflow audit. contents: read default 의 명시적 top-level permissions: 블록 추가. 더 필요한 몇 개는 job 별 override. Push 하고 새 실패 관찰 (그게 진짜 발견).

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.