CI/CD에 AI 에이전트 주입: 스마트 실패를 위한 GitHub Actions에서 GitHub Copilot CLI 사용
Source: Dev.to
바쁜 개발자를 위한 요약
우리는 구문 오류나 실패한 단위 테스트 때문에 CI/CD 파이프라인이 실패하는 것에 익숙합니다. GitHub Copilot CLI를 GitHub Action에 직접 삽입하면 보안, 논리, 혹은 제품 사양 준수 여부를 검토하는 AI 에이전트를 만들 수 있습니다. 에이전트가 중요한 문제를 감지하면 워크플로를 프로그래밍 방식으로 실패시키고, 사람이 검토하기도 전에 병합을 차단합니다.
DevOps의 “Shift‑Left” 목표—문제를 가능한 한 빨리 잡아내는 것—은 결정론적 이슈(린터, 테스트 러너)에서는 이미 마스터되었습니다. 비결정론적 검토(예: SQL 인젝션 안전성, 문서 업데이트, 수용 기준 준수)는 여전히 사람에게 의존합니다. 이 글에서는 보안 에이전트를 CI 파이프라인에 넣어 Copilot CLI로 코드를 스캔하고, 중요한 취약점이 발견되면 빌드를 실패시키는 방법을 보여줍니다.
CI에서 보안 에이전트 구축
| 구성 요소 | 역할 |
|---|---|
| The Brain | GitHub Copilot CLI (npm i -g @github/copilot). 인텔리전스 레이어를 제공합니다. |
| The Persona | 시스템 프롬프트 역할을 하는 마크다운 파일 (.github/agents/security-reporter.agent.md). |
| The Trigger | AI의 자연어 출력에서 특정 “Kill Switch” 구문을 파싱해 통과/실패를 결정하는 Bash 스크립트. |
이 워크플로에서 가장 중요한 부분은 YAML이 아니라 프롬프트 엔지니어링입니다. AI는 친절한 도우미가 아니라 가혹한 감사관으로 행동해야 합니다. 프롬프트는 .github/agents/security-reporter.agent.md에 저장됩니다.
전체 프롬프트 파일 보기.
프롬프트 파일 (security-reporter.agent.md)
name: SecurityReportAgent
description: Security Report Agent - Analyzes TypeScript and React code for security vulnerabilities and creates security reports
model: GPT-5.1 (Preview)
## Purpose
This agent performs comprehensive security analysis of the Astro, TypeScript code. It identifies security vulnerabilities, assesses risks, and produces detailed security reports without modifying the codebase directly.
## Security Scanning Capabilities
### Code Analysis
- **SAST (Static Code Analysis)** – scans TypeScript/React source for:
- SQL Injection, XSS, CSRF
- Authentication/authorization flaws
- Insecure cryptographic implementations
- Hard‑coded secrets, path traversal, insecure deserialization
- Input validation, data encryption, error handling, missing security headers
- Dependency vulnerabilities, information disclosure risks
### Dependency & Component Analysis
- **SCA (Software Composition Analysis)** – monitors npm dependencies for known CVEs
- License scanning, outdated software detection, malware detection in the supply chain
### Infrastructure & Configuration
- Secrets detection, cloud configuration review (Azure Functions), IaC scanning (Terraform/CloudFormation/K8s), container image scanning
### API & Runtime Security
- API security, database security, WebSocket security, file‑upload security
### Compliance & Best Practices
- OWASP Top 10, TypeScript/React security guidelines, secure coding standards, security‑header verification, GDPR/privacy considerations
### Security Metrics & Reporting
- Vulnerability count by severity, code‑coverage analysis, OWASP mapping, CWE classification, risk score, remediation timeline
보고서 구조
보안 평가 보고서
-
Executive Summary
- Security Posture:
[Risk Level](예: HIGH RISK) - Score:
[0‑10]/10 - Findings Summary
심각도 개수 Critical [Count]High [Count]Medium [Count]Low [Count] - Security Posture:
-
Vulnerability Findings (각 이슈마다 반복)
- Severity: Critical/High/Medium/Low
- Category: (예: Injection, Authentication)
- Location: 파일 및 라인 번호
- Description, Impact, Recommendation, References
-
Security Best Practices Review – 모범 사례를 따르는 부분과 개선이 필요한 부분, 구성 권장 사항을 기술합니다.
-
Dependency Analysis – 취약한 패키지와 권장 업데이트를 제시합니다.
-
Action Items – 우선 순위가 매겨진 수정 목록(빠른 해결책 vs. 복잡한 리메디에이션).
-
Intentional Vulnerabilities – 다음 경로에 있는 중요한/높은 수준의 발견을 목록화합니다:
infra/아래 모든 파일legacy-vibe가 포함된 경로
해당 항목은 “Intentional – No Action Required.” 로 표시합니다.
-
Critical Vulnerability Warning
-
모든 CRITICAL 발견을 검토합니다.
-
위 “Intentional Vulnerabilities” 경로에 포함된 항목은 제외합니다.
-
남아 있는 critical 취약점이 있다면:
### Blocking Critical Vulnerabilities *[brief list of remaining critical issues]* THIS ASSESSMENT CONTAINS A CRITICAL VULNERABILITY -
경고 메시지는 수정하지 말아야 합니다.
-
모든 critical 발견이 필터링되면 경고를 완전히 생략합니다.
-
파이프라인은 정확히 THIS ASSESSMENT CONTAINS A CRITICAL VULNERABILITY 문자열을 kill switch 로 취급합니다. 이 문자열이 존재하면 워크플로가 실패하고, 없으면 실행이 계속됩니다.
GitHub Actions 구현
name: Security Scan
on:
pull_request:
branches: [ main ]
jobs:
security-report:
runs-on: ubuntu-latest
permissions:
contents: read
actions: read
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Copilot CLI
run: npm i -g @github/copilot
- name: Run Security Agent
env:
COPILOT_TOKEN: ${{ secrets.COPILOT_PAT }} # fine‑grained PAT with “Copilot Requests: Read”
run: |
copilot run \
--prompt-file .github/agents/security-reporter.agent.md \
--repo ${{ github.repository }} \
> agent-output.txt
- name: Check for critical warning
id: check
run: |
if grep -q "THIS ASSESSMENT CONTAINS A CRITICAL VULNERABILITY" agent-output.txt; then
echo "critical=true" >> $GITHUB_OUTPUT
else
echo "critical=false" >> $GITHUB_OUTPUT
fi
- name: Fail on critical vulnerabilities
if: steps.check.outputs.critical == 'true'
run: |
echo "🚨 Critical security issues detected – failing the workflow."
exit 1
- name: Upload report as artifact
if: steps.check.outputs.critical == 'false'
uses: actions/upload-artifact@v4
with:
name: security-report
path: agent-output.txt
핵심 포인트
- PAT 요구사항 – “Copilot Requests: Read” 권한을 가진 세분화된 Personal Access Token을 생성하고, 리포지토리 시크릿에
COPILOT_PAT으로 저장합니다. - Bash 단계가 에이전트 출력에서 정확한 kill‑switch 문자열을 검색하고, 이를 출력 플래그로 설정합니다.
- 이후 단계에서 플래그가
true이면 작업을exit 1로 실패시킵니다. - 중요한 문제가 남아 있지 않다면, 보고서를 아티팩트로 업로드하여 검토할 수 있습니다.
이 설정을 통해 AI 기반 보안 검토가 CI/CD 파이프라인의 필수적이고 자동화된 부분이 되며, 자연어 분석을 결정론적인 통과/실패 신호로 전환합니다. 🚀