๐Ÿ”’ Security

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.

๐Ÿ“– Detailed Explanation

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.

๐Ÿ’ป Code Example

External Secrets Configuration Example (YAML/Python)

# 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

Monitoring External Secrets Status with Python

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')}")

๐Ÿ—ฃ๏ธ How It's Said in Practice

DevOps Engineer "Secrets are hardcoded in our current Helm chart, so adopting GitOps is difficult. How about introducing External Secrets Operator?"
Security Team "That's a good approach. If we bring the secrets managed in the central Vault into the cluster with ESO, audit logs will be unified as well. Please separate the SecretStore per namespace."
SRE Team Lead "Please set refreshInterval differentlyโ€”1 hour for production and 5 minutes for developmentโ€”and configure alerts for synchronization failures as well."
Interviewer "How do you establish a secret management strategy in Kubernetes?"
Candidate "In a GitOps environment, I use External Secrets Operator. I store only the ExternalSecret CRD in Git, and the actual values are managed in Vault or AWS Secrets Manager. Even during secret rotation, ESO synchronizes automatically, so changes can be applied without restarting pods. In multi-tenant environments, I centralize backend connections with ClusterSecretStore and control access per namespace with RBAC."

Take a mock interview on this topic โ†’ WIA SOOM AI Interview ยท Start for free

Reviewer "creationPolicy in the ExternalSecret is set to Owner, so if this ExternalSecret is deleted, the generated Secret will be deleted along with it. Is that intended?"
Author "Yes, since it's managed through GitOps, secrets should be cleaned up when the ExternalSecret is deleted. However, for important secrets, I'll change it to Orphan so that manual deletion is required."

โš ๏ธ Cautions

  • Credential security: The backend credentials (IAM roles, tokens, etc.) configured in a SecretStore are also sensitive information. Use IRSA (IAM Roles for Service Accounts) or Workload Identity to avoid storing long-term credentials.
  • Handling synchronization failures: If the external store becomes inaccessible, existing Secrets are retained but updates stop. Monitor the synchronization status and set up alerts to respond to failures.
  • Secret rotation timing: New values are reflected only after the refreshInterval has elapsed. If immediate reflection is needed, update an annotation on the ExternalSecret resource or use secret versioning.

๐Ÿ“š Learn More