본문으로 건너뛰기
Kreath Archive
TechProjectsBooksAbout
TechProjectsBooksAbout

내비게이션

  • Tech
  • Projects
  • Books
  • About
  • Tags

카테고리

  • AI / ML
  • 웹 개발
  • 프로그래밍
  • 개발 도구

연결

  • GitHub
  • Email
  • RSS
© 2026 Kreath Archive. All rights reserved.Built with Next.js + MDX
홈TechProjectsBooksAbout
//
  1. 홈
  2. 테크
  3. 9장: 보안 모니터링과 사고 대응
2026년 3월 12일·AI / ML·

9장: 보안 모니터링과 사고 대응

LLM 시스템의 보안 모니터링 아키텍처, 이상 탐지, 보안 대시보드, 사고 대응 프로세스, 그리고 지속적 보안 운영 체계를 다룹니다.

10분559자5개 섹션
llmtestingsecurity
공유
ai-security9 / 10
12345678910
이전8장: AI 규제와 컴플라이언스다음10장: 실전 프로젝트 — 보안 강화 LLM 애플리케이션

8장에서 규제와 컴플라이언스를 다뤘습니다. 이 장에서는 방어 체계가 실시간으로 동작하고 있는지 확인하는 보안 모니터링과, 보안 사고 발생 시의 대응 프로세스를 다룹니다. 가장 완벽한 방어 체계도 모니터링 없이는 효과를 알 수 없고, 사고 대응 계획 없이는 실제 공격에 대처할 수 없습니다.

보안 모니터링 아키텍처

모니터링 계층

[LLM 애플리케이션]
  ↓
[로그 수집기] → [스트림 처리] → [이상 탐지 엔진]
  ↓                                    ↓
[로그 스토리지]                    [알림 시스템]
  ↓                                    ↓
[대시보드]                        [사고 대응 팀]

수집해야 할 보안 로그

보안 로그 스키마
python
from dataclasses import dataclass, field
from datetime import datetime
from typing import Literal
 
@dataclass
class SecurityEvent:
    event_id: str
    timestamp: datetime
    event_type: Literal[
        "injection_attempt",      # 프롬프트 인젝션 시도
        "guardrail_triggered",    # 가드레일 작동
        "content_blocked",        # 유해 콘텐츠 차단
        "tool_abuse_attempt",     # 도구 남용 시도
        "rate_limit_exceeded",    # 속도 제한 초과
        "system_prompt_probe",    # 시스템 프롬프트 탐색
        "pii_detected",           # PII 감지
        "anomalous_pattern",      # 비정상 패턴
        "auth_failure",           # 인증 실패
    ]
    severity: Literal["low", "medium", "high", "critical"]
    user_id: str
    session_id: str
    input_text: str
    output_text: str | None
    guardrail_details: dict = field(default_factory=dict)
    metadata: dict = field(default_factory=dict)

이상 탐지

통계적 이상 탐지

사용 패턴 이상 탐지
python
import numpy as np
from collections import defaultdict
 
class UsageAnomalyDetector:
    def __init__(self, window_size: int = 100):
        self.window_size = window_size
        self.user_histories: dict[str, list] = defaultdict(list)
 
    def check_anomaly(self, user_id: str, event: dict) -> dict:
        """사용자별 이상 행동 탐지"""
        history = self.user_histories[user_id]
        history.append(event)
        if len(history) > self.window_size:
            history.pop(0)
 
        flags = []
 
        # 1. 요청 빈도 이상
        recent = [e for e in history if (event["timestamp"] - e["timestamp"]).seconds < 60]
        if len(recent) > 20:  # 분당 20회 이상
            flags.append({
                "type": "high_frequency",
                "value": len(recent),
                "threshold": 20,
            })
 
        # 2. 가드레일 트리거 빈도
        triggered = sum(1 for e in history if e.get("guardrail_triggered"))
        trigger_rate = triggered / len(history) if history else 0
        if trigger_rate > 0.3:  # 30% 이상 트리거
            flags.append({
                "type": "high_guardrail_trigger_rate",
                "value": trigger_rate,
                "threshold": 0.3,
            })
 
        # 3. 입력 길이 이상
        avg_length = np.mean([len(e.get("input", "")) for e in history])
        current_length = len(event.get("input", ""))
        if current_length > avg_length * 5:
            flags.append({
                "type": "unusual_input_length",
                "value": current_length,
                "average": avg_length,
            })
 
        return {
            "is_anomalous": len(flags) > 0,
            "flags": flags,
            "risk_score": min(len(flags) * 0.3, 1.0),
        }

의미론적 이상 탐지

의미론적 이상 탐지
python
class SemanticAnomalyDetector:
    def __init__(self, client, service_description: str):
        self.client = client
        self.service_description = service_description
 
    async def check(self, user_input: str, conversation_history: list) -> dict:
        """대화 맥락에서 의미론적 이상 탐지"""
        recent_context = conversation_history[-5:]  # 최근 5턴
 
        response = await self.client.messages.create(
            model="claude-haiku-4-5-20251001",
            max_tokens=200,
            messages=[{
                "role": "user",
                "content": f"""보안 분석: 다음 사용자 입력이 서비스 맥락에서 비정상적인지 판단하세요.
 
서비스: {self.service_description}
 
최근 대화:
{chr(10).join(f"- {m['content'][:100]}" for m in recent_context)}
 
현재 입력: {user_input}
 
JSON 응답:
{{"is_anomalous": true/false, "reason": "사유", "risk_level": "low/medium/high"}}""",
            }],
        )
        return parse_json(response.content[0].text)

보안 대시보드

핵심 보안 지표 (KPIs)

지표설명목표값경고 임계값
가드레일 트리거율전체 요청 중 가드레일 작동 비율< 2%> 5%
인젝션 탐지율탐지된 인젝션 시도 수/시간모니터링급증 시 알림
PII 유출 시도출력에서 PII 감지된 횟수0> 0
가드레일 우회 추정보안 테스트에서의 우회 성공률< 1%> 3%
인증 실패율인증 실패 비율< 1%> 5%
평균 위험 점수모든 요청의 평균 위험 점수< 0.1> 0.3

알림 규칙

보안 알림 시스템
python
from dataclasses import dataclass
 
@dataclass
class AlertRule:
    name: str
    condition: str
    severity: str
    notification_channels: list[str]
    cooldown_minutes: int = 15
 
ALERT_RULES = [
    AlertRule(
        name="대량 인젝션 시도",
        condition="injection_attempts > 10 in 5 minutes",
        severity="critical",
        notification_channels=["slack", "pagerduty"],
        cooldown_minutes=5,
    ),
    AlertRule(
        name="PII 유출 감지",
        condition="pii_in_output > 0",
        severity="critical",
        notification_channels=["slack", "pagerduty", "email"],
        cooldown_minutes=0,  # 즉시
    ),
    AlertRule(
        name="가드레일 트리거율 상승",
        condition="guardrail_trigger_rate > 5%",
        severity="high",
        notification_channels=["slack"],
        cooldown_minutes=30,
    ),
    AlertRule(
        name="단일 사용자 이상 행동",
        condition="user_risk_score > 0.8",
        severity="high",
        notification_channels=["slack"],
        cooldown_minutes=15,
    ),
]

사고 대응 프로세스

사고 분류

등급설명대응 시간예시
P1 (Critical)서비스 전체에 영향, 데이터 유출15분 이내대규모 PII 유출, 시스템 장악
P2 (High)일부 사용자에 영향, 가드레일 우회1시간 이내반복적 인젝션 성공, 유해 콘텐츠 노출
P3 (Medium)제한적 영향, 정책 위반4시간 이내단발성 인젝션 성공, 편향 응답
P4 (Low)잠재적 위험, 탐색 시도24시간 이내인젝션 시도 (차단됨), 비정상 패턴

대응 플레이북

사고 대응 자동화
python
class IncidentResponder:
    async def respond(self, incident: dict):
        severity = incident["severity"]
 
        if severity == "critical":
            await self._critical_response(incident)
        elif severity == "high":
            await self._high_response(incident)
        elif severity == "medium":
            await self._medium_response(incident)
 
    async def _critical_response(self, incident: dict):
        """P1 사고 대응"""
        # 1. 즉시 영향받는 사용자/세션 차단
        await self._block_affected_sessions(incident)
 
        # 2. 온콜 팀에 긴급 알림
        await self._alert_oncall(incident, priority="urgent")
 
        # 3. 자동 증거 수집
        evidence = await self._collect_evidence(incident)
 
        # 4. 필요시 서비스 격리
        if incident.get("data_exfiltration"):
            await self._isolate_service(incident["service"])
 
        # 5. 사고 타임라인 기록 시작
        await self._start_incident_timeline(incident, evidence)
 
    async def _high_response(self, incident: dict):
        """P2 사고 대응"""
        # 1. 해당 사용자 세션 종료
        await self._terminate_session(incident["session_id"])
 
        # 2. 팀 알림
        await self._alert_team(incident)
 
        # 3. 가드레일 강화 (임시)
        await self._tighten_guardrails(incident["attack_type"])
 
        # 4. 증거 수집
        await self._collect_evidence(incident)

사후 분석 (Post-Mortem)

사고 보고서 템플릿
python
INCIDENT_REPORT_TEMPLATE = """
# AI 보안 사고 보고서
 
## 사고 개요
- 사고 ID: {incident_id}
- 발생 시간: {timestamp}
- 탐지 시간: {detected_at}
- 해결 시간: {resolved_at}
- 심각도: {severity}
- 영향 범위: {impact}
 
## 타임라인
{timeline}
 
## 근본 원인
{root_cause}
 
## 영향 분석
- 영향받은 사용자 수: {affected_users}
- 유출된 데이터: {data_exposed}
- 서비스 영향: {service_impact}
 
## 대응 조치
{response_actions}
 
## 재발 방지 대책
{preventive_measures}
 
## 후속 조치 (Action Items)
{action_items}
"""
Tip

사고 대응의 핵심은 사전 준비입니다. 사고가 발생한 후에 대응 프로세스를 만드는 것은 너무 늦습니다. 정기적으로 모의 사고 훈련(Tabletop Exercise)을 실시하여 팀의 대응 역량을 점검하고, 플레이북을 업데이트하세요.

정리

보안 모니터링은 방어 체계의 "눈"입니다. 통계적 이상 탐지와 의미론적 분석을 결합하여 실시간으로 위협을 감지하고, 심각도 기반의 사고 대응 프로세스로 신속하게 대처합니다. 보안 대시보드의 핵심 지표를 지속적으로 추적하고, 사후 분석을 통해 방어 체계를 지속적으로 개선하는 것이 운영 보안의 핵심입니다.

다음 마지막 장에서는 시리즈 전체에서 다룬 기법을 종합하여 보안 강화 LLM 애플리케이션을 구축하는 실전 프로젝트를 진행합니다.

이 글이 도움이 되셨나요?

관련 주제 더 보기

#llm#testing#security

관련 글

AI / ML

10장: 실전 프로젝트 — 보안 강화 LLM 애플리케이션

시리즈 전체의 보안 기법을 종합하여 프로덕션 수준의 보안 강화 LLM 애플리케이션을 설계하고 구현합니다. 다층 방어, 가드레일, 모니터링을 통합한 실전 시스템입니다.

2026년 3월 14일·13분
AI / ML

8장: AI 규제와 컴플라이언스

EU AI Act를 중심으로 글로벌 AI 규제의 핵심 요구사항, 위험 분류 체계, 기술적 컴플라이언스 전략, 그리고 책임 있는 AI 개발 프레임워크를 다룹니다.

2026년 3월 10일·13분
AI / ML

7장: 레드티밍과 보안 테스트 자동화

AI 시스템의 레드티밍 방법론, 자동화된 보안 테스트, 프롬프트 인젝션 퍼징, 그리고 지속적 보안 검증 파이프라인 구축을 다룹니다.

2026년 3월 8일·14분
이전 글8장: AI 규제와 컴플라이언스
다음 글10장: 실전 프로젝트 — 보안 강화 LLM 애플리케이션

댓글

목차

약 10분 남음
  • 보안 모니터링 아키텍처
    • 모니터링 계층
    • 수집해야 할 보안 로그
  • 이상 탐지
    • 통계적 이상 탐지
    • 의미론적 이상 탐지
  • 보안 대시보드
    • 핵심 보안 지표 (KPIs)
    • 알림 규칙
  • 사고 대응 프로세스
    • 사고 분류
    • 대응 플레이북
    • 사후 분석 (Post-Mortem)
  • 정리