github-actions について
github-actionsは、GitHub Actionsのワークフロー作成と保守を支援するスキルです。アクションのバージョン、シークレット、インジェクションリスク、権限、Runnerのツール、一般的な構成について説明します。
主な機能
- 01アクションのバージョンと構成の案内
- 02シークレット管理とインジェクション対策
- 03最小権限の設定指針
- 04Runnerのプリインストールツール一覧
- 05一般的なイベントとアクションの例
活用シーン
- 01ワークフローのセキュリティ上の問題を確認
- 02CIジョブの権限を選定
- 03Runnerツールの重複設定を回避
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ dalestudy/ skills --skill github-actionsインストール後、Claude Code で/github-actionsを入力して読み込まれたか確認します。
詳細
GitHub Actions
参考: GitHub Actions のワークフロー実行と結果の確認、Issue/PR の管理など、
ghCLI 関連の作業では、githubスキルも一緒に読み込んで参照してください。
注意事項(アンチパターン)
1. 古いバージョンの使用
# ❌ 오래된 버전 - 가장 흔한 실수
uses: actions/checkout@v4 # v6가 최신인 경우
# ✅ 최신 메이저 버전 (gh release view로 확인 후 사용)
uses: actions/checkout@v6
最新バージョンで提供されるパフォーマンスの改善とセキュリティパッチを逃さないようにします。
バージョンの確認コマンド:
gh release view --repo {owner}/{repo} --json tagName --jq '.tagName'
# 예시
gh release view --repo actions/checkout --json tagName --jq '.tagName'
gh release view --repo oven-sh/setup-bun --json tagName --jq '.tagName'
参考:セキュリティに敏感な環境や信頼性の低いサードパーティーアクションには、SHA ピニング(
@a1b2c3...)を検討してください。
2. 機密情報のハードコーディング
# ❌ 하드코딩 - 보안 위험
env:
API_KEY: "sk-1234567890"
DATABASE_PASSWORD: "mypassword123"
# ✅ secrets 사용
env:
API_KEY: ${{ secrets.API_KEY }}
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
パスワードや API Key などの機密情報がそのまま露出し、セキュリティ事故につながる可能性があります。 セキュリティ上重要な情報は、必ずリポジトリまたは組織のシークレットとして保存し、読み込んでください。
3. 入力値インジェクションの脆弱性
# ❌ 인젝션 취약 - github.event 직접 사용
run: echo "${{ github.event.issue.title }}"
run: gh issue comment ${{ github.event.issue.number }} --body "${{ github.event.comment.body }}"
# ✅ 환경변수로 전달하여 인젝션 방지
env:
ISSUE_TITLE: ${{ github.event.issue.title }}
COMMENT_BODY: ${{ github.event.comment.body }}
run: |
echo "$ISSUE_TITLE"
gh issue comment ${{ github.event.issue.number }} --body "$COMMENT_BODY"
悪意のあるユーザーが、Issue のタイトルやコメントにシェルコマンドを注入する可能性があります。
4. pull_request_target イベントの誤用
# ⚠️ 위험 - 포크의 코드를 신뢰된 컨텍스트에서 실행
on: pull_request_target
steps:
- uses: actions/checkout@v{N}
with:
ref: ${{ github.event.pull_request.head.sha }} # 위험!
pull_request_target イベントでは、フォークからの PR でもシークレットにアクセスできます。フォークのコードをチェックアウトすると、悪意のあるコードが実行される可能性があります。
5. プリインストール済みツールの重複設定
# ❌ 불필요한 setup - node, npm, npx는 이미 설치됨
steps:
- uses: actions/setup-node@v{N}
- run: npx some-command
# ✅ 바로 사용
steps:
- run: npx some-command
- run: python script.py
- run: docker build .
重複インストールは、ワークフローの実行時間を延ばし、不要なネットワークリクエストを発生させます。
主なプリインストール済みツール: Node.js、npm、npx、Python、pip、Ruby、gem、Go、Docker、git、gh、curl、wget、jq、yq
主な未インストールツール: Bun、Deno、Rust、Zig、pnpm、Poetry、Ruff
プリインストール済みツールの確認:
- Ubuntu:https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md
- macOS:https://github.com/actions/runner-images/blob/main/images/macos/macos-15-Readme.md
- Windows:https://github.com/actions/runner-images/blob/main/images/windows/Windows2022-Readme.md
ベストプラクティス
最小権限の原則
権限は、できるだけ下位のレベルで宣言します。範囲を狭く保ちます。
# ✅ 권한 범위: workflow > job > step (좁을수록 좋음)
jobs:
build:
permissions:
contents: read # job 레벨에서 필요한 권한만
推奨されるワークフロー構成
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
# 버전은 gh release view로 확인 후 사용
- uses: actions/checkout@v{N}
- name: Setup Bun
uses: oven-sh/setup-bun@v{N}
よく使用されるイベント
on:
push: # 푸시 시
branches: [main]
pull_request: # PR 생성/업데이트 시
branches: [main]
workflow_dispatch: # 수동 실행
schedule: # 스케줄 실행
- cron: "0 0 * * 1" # 매주 월요일 00:00 UTC
release: # 릴리스 생성 시
types: [published]
workflow_call: # 다른 워크플로우에서 호출
よく使用される権限
permissions:
contents: read # CI (빌드/테스트), 코드 체크아웃
contents: write # 커밋/푸시
pull-requests: write # PR 코멘트 봇
issues: write # 이슈 코멘트
packages: write # 패키지 배포 (contents: write와 함께)
id-token: write # OIDC 클라우드 인증 (contents: read와 함께)
よく使用されるアクション
# 버전은 gh release view --repo {owner}/{repo} --json tagName --jq '.tagName'으로 확인
steps:
- uses: actions/cache@v{N} # 의존성 캐싱
- uses: actions/checkout@v{N} # 코드 체크아웃
- uses: actions/download-artifact@v{N} # 아티팩트 다운로드
- uses: actions/upload-artifact@v{N} # 아티팩트 업로드
- uses: oven-sh/setup-bun@v{N} # Bun 설정