Vault Agent와 자동화
1️⃣1️⃣ Vault Agent와 자동화
Vault Agent는 Vault 환경에서 자동화를 위한 핵심 구성 요소입니다. 시크릿을 주기적으로 가져오고, 인증과 갱신을 자동으로 처리하며, 파일로 템플릿 렌더링까지 지원하여 Vault 운영을 자동화할 수 있습니다.
이 장에서는 Vault Agent의 개념부터 실습 예제, 자동화 흐름까지 상세히 알아보겠습니다.
1. Vault Agent 소개 및 역할
Vault Agent는 Vault 클라이언트를 대신하여 다음을 자동으로 수행합니다:
- ✅ Vault 서버에 자동 인증 (예: Kubernetes, AppRole 등)
- 🔁 시크릿의 자동 갱신(Renewal) 및 Token 갱신
- 📁 시크릿을 파일로 저장 (템플릿을 사용해 렌더링)
🧩 주요 사용 시나리오
시나리오 | 설명 |
---|---|
Kubernetes Pod에서 시크릿 자동 주입 | Vault Agent Injector 또는 Sidecar |
Legacy VM 환경에서 인증 자동화 | Vault Agent + AppRole |
Config 파일에 DB 정보 렌더링 | Vault Agent + Template |
🖼️ 아키텍처 다이어그램
┌────────────────────┐
│ Vault Server │
└────────┬───────────┘
│
┌────────────────▼─────────────────┐
│ Vault Agent │
│ ┌─────────────────────────────┐ │
│ │ Auto Auth (e.g., AppRole)│ │
│ └─────────────────────────────┘ │
│ ┌─────────────────────────────┐ │
│ │ Renewal / Token Watch │ │
│ └─────────────────────────────┘ │
│ ┌─────────────────────────────┐ │
│ │ Template → Rendered Secrets │──┼──> /config/db-creds.conf
│ └─────────────────────────────┘ │
└─────────────────────────────────┘
2. Vault Agent + Template으로 파일 자동 생성
Vault Agent는 템플릿 파일(.hcl
)을 기반으로 시크릿을 특정 위치에 자동 생성할 수 있습니다.
📄 vault-agent-config.hcl
auto_auth {
method "approle" {
mount_path = "auth/approle"
config = {
role_id_file_path = "./role_id"
secret_id_file_path = "./secret_id"
}
}
sink "file" {
config = {
path = "./token"
}
}
}
template {
source = "./db-creds.tpl"
destination = "/config/db-creds.conf"
}
🧾 db-creds.tpl
템플릿
username = "{{ with secret "secret/data/db" }}{{ .Data.data.username }}{{ end }}"
password = "{{ with secret "secret/data/db" }}{{ .Data.data.password }}{{ end }}"
▶️ 실행 예시
vault agent -config=vault-agent-config.hcl
/config/db-creds.conf
에 DB 사용자 정보 자동 생성- Token은 자동으로 관리되고, TTL 갱신 시 템플릿 파일도 재생성됨
3. Renewal 자동화, 인증 자동화 구성
Vault Agent는 다음 두 가지를 통해 완전 자동화를 달성합니다:
✅ 자동 인증 (Auto Auth)
AppRole
,Kubernetes
,Azure
,GCP
등 다양한 인증 메커니즘을 지원- Agent가 시작될 때 자동으로 Vault에 로그인하여 Token 획득
auto_auth {
method "kubernetes" {
mount_path = "auth/kubernetes"
config = {
role = "demo-role"
}
}
}
🔁 자동 갱신 (Auto Renewal)
- Vault에서 발급받은 토큰 및 시크릿의 TTL(Time-To-Live)을 감지하여 자동 갱신
- 템플릿으로 렌더링된 파일은 시크릿 갱신 시 자동으로 재생성
vault {
address = "http://127.0.0.1:8200"
}
vault_agent {
cache {
use_auto_auth_token = true
}
}
✅ 정리
기능 | 설명 |
---|---|
Vault Agent | 인증, 갱신, 템플릿 렌더링 담당 |
auto_auth | Vault 인증 자동화 (K8s, AppRole 등) |
template | 시크릿을 파일로 자동 생성 |
renewal | 시크릿 TTL 감지 및 갱신 처리 |
📦 실전 시나리오 예시
-
Vault에 DB 크리덴셜 저장
vault kv put secret/db username="admin" password="s3cret123"
-
AppRole 발급 및 Agent 설정
vault auth enable approle vault write auth/approle/role/demo-role \ secret_id_ttl=60m \ token_ttl=60m \ token_max_ttl=120m \ policies=default
-
Vault Agent 구성 후 실행 → 파일 자동 생성 및 갱신
마지막 수정일자