본문 바로가기!

K8S Operator

[K8S Operator] Vault Secrets Operator(VSO)

728x90
반응형

1. Vault 란?

  • Hashicorp 솔루션으로 아이덴티티를 기반으로 중앙에서 데이터(Secrets)와 암호화를 관리하는 시스템
  • 패스워드, 인증서등을 안전하게 저장하고 사용자 인증과 권한 부여를 통해 제어되며 감사 가능
  • 클라우드 환경에서 사용하기 적합하며, 다양한 인증 방법과 통합되어 보안 강화 가능

 

 

2. Vault Secrets Operator(VSO)란?

  • Vault Secrets Operator는 기본적으로 Vault secrets을 K8S에 동기화할 책임이 있는(responsible) CRD 집합으로 쿠버네티스 시크릿 오버레이터를 구현하는 새로운 통합 방법 (참고 URL)

  • Operator는 하나 이상의 볼트서버에서 동적, 정적 및 PKI 시크릿을 포함 시크릿 관리의 전체 라이프사이클 동기화를 지원
  • Operator는 시크릿 로테이션을 관리하고 Deployment의 rolling update를 통해 애플리케이션에 직접 notifying하거나 rolling update를 트리거 하는등 로테이션 후 작업을 수행 가능
  • 지원되는 Kuberenetes 
    • EKS, GKE, AKS, 레드햇 오픈시프트
  • 지원되는 K8S Version
    • 1.28, 1.27, 1.26, 1.25, 1.24

 

3. Vault Secrets Operator설치

참고 : https://developer.hashicorp.com/vault/tutorials/kubernetes/vault-secrets-operator

 

  • Vault Cluster 설치
# HashiCorp Repo를 추가
helm repo add hashicorp https://helm.releases.hashicorp.com

# 저장소 업데이트
helm repo update

# Vault 버전 확인
helm search repo hashicorp/vault

# Vault 설치
helm install vault hashicorp/vault -n vault --create-namespace --values vault/vault-values.yaml
  • VSO Helm chart 설치
# Helm 저장소 등록
helm repo add hashicorp https://helm.releases.hashicorp.com
helm search repo hashicorp

# VSO Helm 차트 실행
helm install vault-secrets-operator-system hashicorp/vault-secrets-operator --namespace vault-secrets-operator-system --create-namespace --values install/values.yaml
kubectl get pods -n vault-secrets-operator-system

 

  • PostgreSQL 설치
# Dynamic Secret을 위한 PostgreSQL 설치
helm repo add bitnami https://charts.bitnami.com/bitnami
# Helm 저장소를 확인하여 버전을 확인
helm search repo bitnami | grep postgresql
bitnami/postgresql                              13.2.16         16.1.0          PostgreSQL (Postgres) is an open source object-...
bitnami/postgresql-ha                           12.1.8          16.1.0          This PostgreSQL cluster solution includes the P...

helm upgrade --install postgres bitnami/postgresql --namespace postgres --set auth.audit.logConnections=true --create-namespace --set auth.postgresPassword=secret-pass

kubectl get pods -n postgres
NAME                    READY   STATUS    RESTARTS   AGE
postgres-postgresql-0   1/1     Running   0          2m21s

kubectl exec -n postgres postgres-postgresql-0 -it -- /bin/bash
# Shell에 접속한 후 PGPASSWORD 환경변수를 설정하고 psql 명령으로 샘플 쿼리를 수행
export PGPASSWORD=$POSTGRES_PASSWORD
psql -U postgres -c "SELECT usename, valuntil FROM pg_user; "
exit

 

 

  • Vault에 접속하여 Database Secret Engine 활성화 및 설정
# Vault 인스턴스 접속
kubectl exec --stdin=true --tty=true vault-0 -n vault -- /bin/sh

# Database Secret Engine 활성화
vault secrets enable -path=demo-db database

# Database Secret Engine 연결 Config 구성
vault write demo-db/config/demo-db \
   plugin_name=postgresql-database-plugin \
   allowed_roles="dev-postgres" \
   connection_url="postgresql://{{username}}:{{password}}@postgres-postgresql.postgres.svc.cluster.local:5432/postgres?sslmode=disable" \
   username="postgres" \
   password="secret-pass"

# Postgres Pod에 대한 Role 생성
vault write demo-db/roles/dev-postgres \
   db_name=demo-db \
   creation_statements="CREATE ROLE \"{{name}}\" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}'; \
      GRANT ALL PRIVILEGES ON DATABASE postgres TO \"{{name}}\";" \
   backend=demo-db \
   name=dev-postgres \
   default_ttl="1m" \
   max_ttl="1m"

# policy 생성
vault policy write demo-auth-policy-db - <<EOF
path "demo-db/creds/dev-postgres" {
   capabilities = ["read"]
}
EOF

 

  • Vault - Dynamic Secret 설정

Postgres용 Vault의 동적 비밀 엔진을 사용하여 Postgres 데이터베이스에 대한 임시 클라이언트 자격 증명을 생성

vault write auth/demo-auth-mount/role/auth-role \
   bound_service_account_names=default \
   bound_service_account_namespaces=demo-ns \
   token_ttl=0 \
   token_period=120 \
   token_policies=demo-auth-policy-db \
   audience=vault

 

  • 해당 Vault Secret에 접속 가능한 애플리케이션 생성

 

참조 : https://github.com/hashicorp-education/learn-vault-secrets-operator/blob/main/dynamic-secrets/app-deployment.yaml

 

kubectl apply -f dynamic-secrets/.

 

 

  • secret 정보 확인

 

 

비밀번호 및 유저정보가 자동으로 변경되어 접근 가능한것을 확인 가능

728x90
반응형