Skip to main content
Glama

GitOps Drift Remediation Agent

License: Apache 2.0 Node.js Version TypeScript

Kubernetes 클러스터와 GitOps 저장소에 연결하여 승인되지 않은 상태 드리프트를 식별하고, 안전한 복구 전략을 생성하며, 자동화된 API 패치 또는 Pull Request를 실행하는 프로덕션급 자율 에이전트입니다.


목차


Related MCP server: kube-lint-mcp

개요

GitOps Drift Remediation Agent는 Kubernetes 리소스의 실시간 상태를 선언된 GitOps 소스 오브 트루스와 지속적으로 모니터링하는 자율적이고 정책 기반의 플랫폼입니다. 드리프트가 감지되면 에이전트는 적용 가능한 복구 정책을 평가하고, 최소 JSON Patch 작업을 계산한 후, Kubernetes API를 통해 직접 적용하거나 GitOps 저장소에 Pull Request를 생성합니다. 모든 작업에는 완전한 감사 추적이 포함됩니다.

핵심 원칙

  • 최소 폭발 반경: 패치는 전체 리소스 교체가 아닌 가능한 가장 작은 diff로 계산됩니다

  • 정책 우선: 모든 복구 작업은 위험 등급이 있는 구성 가능하고 버전 관리되는 정책에 의해 게이트키핑됩니다

  • 불변 감사 로그: 모든 결정, 감지 및 변경은 암호화 컨텍스트와 함께 기록됩니다

  • GitOps 네이티브: 에이전트 자체가 GitOps로 관리되며 저장소로 PR을 발행합니다

  • MCP 지원: 모든 기능을 LLM 에이전트 통합을 위한 MCP 도구로 노출합니다


아키텍처

┌─────────────────────────────────────────────────────────────────────┐
│                    GitOps Drift Remediation Agent                   │
│                                                                     │
│  ┌─────────────┐    ┌──────────────┐    ┌────────────────────────┐ │
│  │  AST Differ │───▶│ Policy Engine│───▶│    Patch Engine        │ │
│  │             │    │              │    │                        │ │
│  │ • Deep diff │    │ • Risk tiers │    │ • JSON Patch RFC 6902  │ │
│  │ • Field     │    │ • Allow/deny │    │ • K8s API apply        │ │
│  │   tracking  │    │ • Dry-run    │    │ • PR generation        │ │
│  │ • Severity  │    │ • Approvals  │    │ • Rollback support     │ │
│  └─────────────┘    └──────────────┘    └────────────────────────┘ │
│         │                  │                       │                │
│         └──────────────────┴───────────────────────┘                │
│                            │                                        │
│                   ┌────────▼────────┐                               │
│                   │  Audit Logger   │                               │
│                   │                 │                               │
│                   │ • Structured    │                               │
│                   │   JSON logs     │                               │
│                   │ • Event chain   │                               │
│                   │ • Pino backend  │                               │
│                   └─────────────────┘                               │
│                                                                     │
│  ┌──────────────────────────────────────────────────────────────┐  │
│  │                      MCP Server                              │  │
│  │  detect_drift │ list_policies │ remediate │ get_audit_trail  │  │
│  └──────────────────────────────────────────────────────────────┘  │
└─────────────────────────────────────────────────────────────────────┘
         │                                          │
         ▼                                          ▼
  ┌─────────────┐                          ┌───────────────┐
  │  Kubernetes │                          │  GitOps Repo  │
  │  Cluster(s) │                          │  (Git/GitHub) │
  └─────────────┘                          └───────────────┘

기능

기능

설명

드리프트 감지

실시간 vs 원하는 Kubernetes 리소스 상태의 심층 AST 기반 diff

위험 분류

필드 경로별 자동 심각도 점수 산정(치명적 / 높음 / 중간 / 낮음)

정책 엔진

허용/거부 규칙, 드라이런, 승인 게이트가 있는 선언적이고 버전 관리되는 정책

패치 엔진

K8s 서버 사이드 apply를 지원하는 RFC 6902 JSON Patch 계산

GitOps PR

드리프트 diff와 복구 근거가 포함된 자동 Pull Request 생성

감사 추적

전체 결정 체인이 포함된 불변 구조화 감사 로그

MCP 서버

AI 에이전트 오케스트레이션을 위해 모든 에이전트 기능을 MCP 도구로 노출

CLI

대화형 및 자동화된 운영을 위한 전체 기능 CLI


설치

사전 요구 사항

  • Node.js >= 20.0.0

  • 대상 클러스터 액세스가 구성된 kubectl

  • GitOps 저장소용 Git 자격 증명(PR 모드용)

소스에서 설치

git clone https://github.com/your-org/gitops-drift-remediation-agent.git
cd gitops-drift-remediation-agent
npm install
npm run build
npm link   # optional: makes `drift-agent` available globally

구성

모든 구성은 환경 변수 또는 구성 파일을 통해 전달됩니다.

환경 변수

변수

필수

기본값

설명

KUBECONFIG

아니요

~/.kube/config

kubeconfig 파일 경로

KUBECONTEXT

아니요

current-context

사용할 Kubernetes 컨텍스트

GITOPS_REPO_URL

아니요

PR 모드용 GitOps 저장소 URL

GITOPS_BRANCH

아니요

main

PR 대상 브랜치

GITOPS_TOKEN

아니요

Git 제공자 토큰(GitHub/GitLab)

POLICY_CONFIG_PATH

아니요

./policies.yaml

복구 정책 구성 경로

AUDIT_LOG_PATH

아니요

./audit.log

감사 로그 출력 경로

AUDIT_LOG_LEVEL

아니요

info

로그 수준(debug/info/warn/error)

DRY_RUN

아니요

false

전역 드라이런 모드

MCP_PORT

아니요

3000

MCP 서버 HTTP 포트

NAMESPACE_FILTER

아니요

*

쉼표로 구분된 네임스페이스 필터


사용법

CLI 명령

# Detect drift across all namespaces
drift-agent detect --namespace production --output json

# Detect and auto-remediate with policy gate
drift-agent remediate --namespace production --policy strict --dry-run

# List active policies
drift-agent policy list

# Show audit trail for a resource
drift-agent audit --resource deployments/my-app --namespace production

# Start MCP server
drift-agent mcp-server --port 3000

프로그래매틱 API

import { AstDiffer } from './src/detector/ast-differ';
import { RemediationPolicy } from './src/policy/remediation-policy';
import { PatchEngine } from './src/remediator/patch-engine';

const differ = new AstDiffer();
const drifts = await differ.detectDrift(liveResource, desiredResource);

const policy = new RemediationPolicy(policyConfig);
const decision = await policy.evaluate(drifts, resourceContext);

if (decision.approved) {
  const engine = new PatchEngine(k8sClient);
  await engine.applyRemediation(decision.patches, resourceRef);
}

MCP 서버

에이전트는 모든 에이전트 기능을 LLM 기반 에이전트(Claude, GPT-4 등)를 위한 도구로 제공하는 MCP(Model Context Protocol) 서버를 노출합니다.

서버 시작

drift-agent mcp-server --port 3000
# or
npm run mcp:server

사용 가능한 MCP 도구

도구

설명

detect_drift

리소스 또는 네임스페이스의 드리프트 감지

list_policies

구성된 모든 복구 정책 나열

evaluate_policy

특정 정책에 대한 드리프트 평가

apply_remediation

계산된 복구 패치 적용

get_audit_trail

리소스에 대한 감사 이벤트 검색

generate_pr

드리프트 복구를 위한 GitOps PR 생성

rollback_remediation

이전에 적용된 복구 롤백

MCP 클라이언트 구성

{
  "mcpServers": {
    "gitops-drift-agent": {
      "url": "http://localhost:3000/mcp",
      "transport": "http"
    }
  }
}

정책 엔진

정책은 선언적으로 정의되며 복구 수명 주기의 모든 측면을 제어합니다.

정책 구조

apiVersion: drift.gitops.io/v1
kind: RemediationPolicy
metadata:
  name: production-strict
spec:
  riskTier: high
  autoRemediate: false
  requireApproval: true
  dryRunFirst: true
  rules:
    - field: "spec.replicas"
      action: restore
      severity: high
    - field: "spec.template.spec.containers[*].image"
      action: block
      severity: critical
  excludeFields:
    - "metadata.annotations['kubectl.kubernetes.io/last-applied-configuration']"
    - "metadata.resourceVersion"
    - "metadata.uid"

감사 및 원격 측정

모든 에이전트 작업은 구조화된 JSON 형식으로 기록됩니다:

{
  "timestamp": "2024-06-01T12:00:00.000Z",
  "eventId": "evt_01J0ABC123",
  "eventType": "DRIFT_DETECTED",
  "severity": "high",
  "resource": {
    "kind": "Deployment",
    "name": "my-app",
    "namespace": "production",
    "apiVersion": "apps/v1"
  },
  "drift": {
    "field": "spec.replicas",
    "desired": 3,
    "live": 1,
    "changeType": "edited"
  },
  "policy": {
    "name": "production-strict",
    "decision": "remediate",
    "riskTier": "high"
  },
  "actor": {
    "agentVersion": "1.0.0",
    "kubeContext": "prod-cluster"
  }
}

개발

# Install dependencies
npm install

# Run in development mode (ts-node)
npm run dev -- detect --namespace default

# Type check only
npm run typecheck

# Lint
npm run lint

# Format
npm run format

# Build
npm run build

테스트

# Run all tests
npm test

# Run with coverage
npm run test:coverage

# Run in watch mode
npm run test:watch

테스트는 tests/ 아래에 구성되며 Jest와 ts-jest를 사용합니다. Kubernetes 클라이언트 및 파일 시스템 작업에 대한 목(mock)이 제공됩니다.


보안 고려 사항

  1. 최소 권한: 에이전트는 대상 리소스에 대해 get, list, watch, patch 권한만 필요합니다 — delete 또는 create는 절대 필요하지 않습니다

  2. 기본 드라이런: 모든 정책 등급은 명시적으로 활성화될 때까지 기본적으로 드라이런입니다

  3. 승인 게이트: 높음 및 치명적 위험 변경은 정책을 통한 명시적 승인이 필요합니다

  4. 감사 불변성: 감사 로그는 추가 전용입니다. 로그 순환은 외부에서 처리됩니다

  5. 시크릿 마스킹: 시크릿 리소스 값은 로그와 PR에서 항상 마스킹됩니다

  6. Kubeconfig 격리: 에이전트는 kubeconfig를 절대 변경하지 않습니다


기여

CONTRIBUTING.md를 참조하세요. 모든 기여에는 다음이 필요합니다:

  • 80% 이상의 커버리지로 테스트 스위트 통과

  • 새로운 린트 경고 없음

  • 새로운 변경 경로에 대한 감사 로그 항목

  • 새로운 복구 작업에 대한 정책 평가


라이선스

Apache 2.0 — LICENSE 참조.

F
license - not found
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

View all related MCP servers

Related MCP Connectors

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/felipeassis10/gitops-drift-remediation-agent'

If you have feedback or need assistance with the MCP directory API, please join our Discord server