External Secrets
External Secrets Operator
A Kubernetes operator that integrates Kubernetes with external secret stores such as AWS Secrets Manager, HashiCorp Vault, and Azure Key Vault and automatically synchronizes Secret resources.
External Secrets Operator
A Kubernetes operator that integrates Kubernetes with external secret stores such as AWS Secrets Manager, HashiCorp Vault, and Azure Key Vault and automatically synchronizes Secret resources.
External Secrets Operator (ESO) is an open-source project that automates integration with external secret management systems in Kubernetes environments. As a CNCF Sandbox project, it enables centralized secret management in enterprise environments to be integrated in a Kubernetes-native way.
The core concept of ESO is the ExternalSecret CRD (Custom Resource Definition). When this resource is defined, the ESO controller retrieves secrets from an external store, automatically creates them as Kubernetes Secrets, and synchronizes them periodically. This allows secrets to be managed declaratively in GitOps workflows without directly exposing secret values.
Supported backends include AWS Secrets Manager, AWS Parameter Store, HashiCorp Vault, Google Secret Manager, Azure Key Vault, IBM Cloud Secrets Manager, CyberArk Conjur, Doppler, and 1Password. Backend connections are configured through SecretStore or ClusterSecretStore resources, and can be reused at the namespace level or across the entire cluster.
Security best practices include configuring IAM policies that apply the principle of least privilege, configuring periodic secret rotation, and separating SecretStores in multi-tenant environments. In addition, the PushSecret feature can be used to export Kubernetes Secrets to an external store, enabling bidirectional synchronization.
# SecretStore ์ ์ - AWS Secrets Manager ์ฐ๋
apiVersion: external-secrets.io/v1beta1
kind: SecretStore
metadata:
name: aws-secrets-store
namespace: production
spec:
provider:
aws:
service: SecretsManager
region: ap-northeast-2
auth:
jwt:
serviceAccountRef:
name: external-secrets-sa
---
# ExternalSecret ์ ์ - ์ธ๋ถ ์ํฌ๋ฆฟ์ Kubernetes Secret์ผ๋ก ๋๊ธฐํ
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
name: database-credentials
namespace: production
spec:
refreshInterval: 1h # ๋๊ธฐํ ์ฃผ๊ธฐ
secretStoreRef:
name: aws-secrets-store
kind: SecretStore
target:
name: db-secret # ์์ฑ๋ Kubernetes Secret ์ด๋ฆ
creationPolicy: Owner
template:
type: Opaque
data:
# ํ
ํ๋ฆฟ์ ์ฌ์ฉํ ๊ฐ ๋ณํ
connection-string: |
postgresql://{{ .username }}:{{ .password }}@{{ .host }}:5432/{{ .database }}
data:
- secretKey: username
remoteRef:
key: prod/database/credentials
property: username
- secretKey: password
remoteRef:
key: prod/database/credentials
property: password
- secretKey: host
remoteRef:
key: prod/database/credentials
property: host
- secretKey: database
remoteRef:
key: prod/database/credentials
property: database
from kubernetes import client, config
from kubernetes.client.rest import ApiException
import json
# Kubernetes ์ค์ ๋ก๋
config.load_incluster_config() # ํด๋ฌ์คํฐ ๋ด๋ถ์์ ์คํ ์
# config.load_kube_config() # ๋ก์ปฌ์์ ์คํ ์
# Custom Objects API ํด๋ผ์ด์ธํธ
api = client.CustomObjectsApi()
def get_external_secret_status(namespace: str, name: str) -> dict:
"""ExternalSecret ๋ฆฌ์์ค์ ๋๊ธฐํ ์ํ ํ์ธ"""
try:
external_secret = api.get_namespaced_custom_object(
group="external-secrets.io",
version="v1beta1",
namespace=namespace,
plural="externalsecrets",
name=name
)
status = external_secret.get("status", {})
conditions = status.get("conditions", [])
# SecretSynced ์กฐ๊ฑด ํ์ธ
for condition in conditions:
if condition["type"] == "Ready":
return {
"name": name,
"namespace": namespace,
"synced": condition["status"] == "True",
"reason": condition.get("reason", "Unknown"),
"message": condition.get("message", ""),
"last_sync": status.get("refreshTime")
}
return {"name": name, "synced": False, "reason": "NoCondition"}
except ApiException as e:
return {"name": name, "error": str(e)}
def list_all_external_secrets() -> list:
"""ํด๋ฌ์คํฐ ๋ด ๋ชจ๋ ExternalSecret ์ํ ์กฐํ"""
results = []
external_secrets = api.list_cluster_custom_object(
group="external-secrets.io",
version="v1beta1",
plural="externalsecrets"
)
for es in external_secrets.get("items", []):
metadata = es["metadata"]
status = get_external_secret_status(
namespace=metadata["namespace"],
name=metadata["name"]
)
results.append(status)
return results
def check_secret_sync_health() -> dict:
"""์ ์ฒด ExternalSecret ๋๊ธฐํ ์ํ ํฌ์ค์ฒดํฌ"""
all_secrets = list_all_external_secrets()
total = len(all_secrets)
synced = sum(1 for s in all_secrets if s.get("synced", False))
failed = [s for s in all_secrets if not s.get("synced", False)]
return {
"total": total,
"synced": synced,
"failed_count": len(failed),
"failed_secrets": failed,
"health": "healthy" if len(failed) == 0 else "degraded"
}
# ์ฌ์ฉ ์์
if __name__ == "__main__":
# ํน์ ExternalSecret ์ํ ํ์ธ
status = get_external_secret_status("production", "database-credentials")
print(f"๋๊ธฐํ ์ํ: {status}")
# ์ ์ฒด ํฌ์ค์ฒดํฌ
health = check_secret_sync_health()
print(f"์ ์ฒด ์ํ: {health['synced']}/{health['total']} ๋๊ธฐํ๋จ")
if health["failed_secrets"]:
print("๋๊ธฐํ ์คํจํ ์ํฌ๋ฆฟ:")
for secret in health["failed_secrets"]:
print(f" - {secret['namespace']}/{secret['name']}: {secret.get('reason')}")
Take a mock interview on this topic โ WIA SOOM AI Interview ยท Start for free