본문으로 건너뛰기
Skillpedia
보안35k · #8370

securing-github-actions-workflows

하는 일

이 기능은 자동화된 워크플로(GitHub Actions라고 함)를 공격으로부터 보호하도록 돕습니다. 사용하는 도구가 항상 같은 특정 버전인지 확인하고, 그 도구에 주어진 권한이 작동에 꼭 필요한 최소한인지 보장하여, 악성 코드가 실행되는 것을 막습니다.

사용하는 경우

  • ✓워크플로가 민감한 정보(비밀 정보)를 다룰 때.
  • ✓워크플로가 코드를 운영 환경에 배포할 때.
  • ✓브랜치 이름이나 Pull Request 제목의 변경이 보안 문제를 일으키지 않도록 하고 싶을 때.

스킬 링크

https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/securing-github-actions-workflows/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/securing-github-actions-workflows/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“GitHub Actions 워크플로를 공격으로부터 어떻게 보호할 수 있나요?”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

이 기능은 워크플로에서 쓰는 외부 도구가 특정 버전에 고정되어 있는지 확인하고(SHA라는 고유 코드 사용), 기본 GitHub Actions 토큰의 권한을 제한하는 방식으로 작동합니다. 또한 PR 제목처럼 외부에서 들어온 정보가 명령에서 안전하지 않게 쓰이지 않도록 막습니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Securing GitHub Actions Workflows

When to Use

  • When GitHub Actions is the CI/CD platform and workflows need hardening against supply chain attacks
  • When workflows handle secrets, deploy to production, or have elevated permissions
  • When preventing script injection via untrusted PR titles, branch names, or commit messages
  • When requiring audit trails and approval gates for workflow modifications
  • When third-party actions pose supply chain risk through mutable version tags

Do not use for securing other CI/CD platforms (see platform-specific hardening guides), for application vulnerability scanning (use SAST/DAST), or for secret detection in code (use Gitleaks).

Prerequisites

  • GitHub repository with GitHub Actions enabled
  • GitHub organization admin access for organization-level settings
  • Understanding of GitHub Actions workflow syntax and events

Workflow

Step 1: Pin Actions to SHA Digests

# INSECURE: Mutable tag can be overwritten by attacker
- uses: actions/checkout@v4

# SECURE: Pinned to immutable SHA digest
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11  # v4.1.1

# Use Dependabot to auto-update pinned SHAs
# .github/dependabot.yml
version: 2
updates:
  - package-ecosystem: "github-actions"
    directory: "/"
    schedule:
      interval: "weekly"
    commit-message:
      prefix: "ci"

Step 2: Minimize GITHUB_TOKEN Permissions

# Set restrictive default permissions at workflow level
name: CI Pipeline
permissions: {}  # Start with no permissions

on: [push, pull_request]

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: read  # Only what's needed
    steps:
      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11

  deploy:
    runs-on: ubuntu-latest
    needs: build
    if: github.ref == 'refs/heads/main'
    permissions:
      contents: read
      deployments: write
      id-token: write  # For OIDC-based cloud auth
    steps:
      - name: Deploy
        run: echo "deploying"

Step 3: Prevent Script Injection

# VULNERABLE: User-controlled input in run step
- run: echo "PR title is ${{ github.event.pull_request.title }}"

# SECURE: Use environment variable (properly escaped by shell)
- name: Process PR
  env:
    PR_TITLE: ${{ github.event.pull_request.title }}
    PR_BODY: ${{ github.event.pull_request.body }}
  run: |
    echo "PR title is ${PR_TITLE}"
    echo "PR body is ${PR_BODY}"

# SECURE: Use actions/github-script for complex operations
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
  with:
    script: |
      const title = context.payload.pull_request.title;
      console.log(`PR title: ${title}`);

Step 4: Secure Fork Pull Request Handling

# DANGEROUS: pull_request_target runs with base repo permissions
# on: pull_request_target  # AVOID unless absolutely necessary

# SAFE: pull_request runs in fork context with limited permissions
on:
  pull_request:
    branches: [main]

# If pull_request_target is required, never checkout PR code:
on:
  pull_request_target:
    types: [labeled]

jobs:
  safe-job:
    if: contains(github.event.pull_request.labels.*.name, 'safe-to-test')
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      # NEVER do: actions/checkout with ref: ${{ github.event.pull_request.head.sha }}
      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
        # This checks out the BASE branch, not the PR

Step 5: Protect Secrets and Environment Variables

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: production  # Requires approval
    steps:
      - name: Deploy with secret
        env:
          # Secrets are masked in logs automatically
          DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
        run: |
          # Never echo secrets
          # echo "$DEPLOY_KEY"  # BAD
          deploy-tool --key-file <(echo "$DEPLOY_KEY")

      - name: Audit secret access
        run: |
          # Log that secret was used without exposing it
          echo "::notice::Deploy key accessed for production deployment"

Step 6: Implement Workflow Change Controls

# Require CODEOWNERS approval for workflow changes
# .github/CODEOWNERS
.github/workflows/ @security-team @platform-team
.github/actions/ @security-team @platform-team

# Organization settings:
# 1. Settings > Actions > General > Fork PR policies

…
자주 묻는 질문

‘SHA 다이제스트로 액션 고정하기(pinning)’란 무엇인가요?

버전 이름처럼 공격자가 바꿀 수 있는 이름 대신, 변경할 수 없는 고유 코드(SHA)로 외부 도구의 특정 버전을 식별하는 것입니다.

GITHUB_TOKEN의 권한을 제한하는 것이 왜 중요한가요?

GITHUB_TOKEN은 GitHub Actions가 사용하는 접근 키입니다. 권한을 제한하면 공격자가 이를 얻더라도 꼭 필요한 일만 할 수 있어 피해가 줄어듭니다.

‘스크립트 주입’이란 무엇이며 어떻게 막나요?

풀 리퀘스트 제목처럼 신뢰할 수 없는 정보가 명령 안에 끼어드는 공격입니다. 이 정보를 실행 가능한 코드가 아니라 텍스트로만 취급하거나, 안전한 도구로 처리해 막습니다.

상세 정보

작성자의 원본 설명

Hardens GitHub Actions workflows against supply chain attacks, credential theft, and privilege escalation: pinning actions to SHA digests, minimizing GITHUB_TOKEN permissions, protecting secrets, preventing script injection in workflow expressions, and requiring reviewers for workflow changes. Use when hardening GitHub Actions workflows that handle secrets, deploy to production, or run with elevat

repo: mukul975/Anthropic-Cybersecurity-Skills

인기도

GitHub 스타
35k
순위
#8370
라이선스
Apache-2.0
업데이트
2026. 8. 31.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬