Aller au contenu principal
Sommaire de la formation

Quelques ressources core

coolibra107 vues

2. Ressources core

  1. SecretStore
  2. ClusterSecretStore
  3. ExternalSecret
  4. ClusterExternalSecret
  5. PushSecret
  6. ClusterPushSecret

  • SecretStore (namespace scope)

Ressource de connexion à un provider (Vault, AWS, kubernetes etc.) pour un namespace donné.

    • Exemple provider Kubernetes:
apiVersion: external-secrets.io/v1
kind: SecretStore
metadata:
  name: k8s-store-default-ns
spec:
  provider:
    kubernetes:
      # with this, the store is able to pull only from `default` namespace
      remoteNamespace: default
      server:
        url: "https://myapiserver.tld" # Pas obligatoire si le  meme cluster k8s
        caProvider:
          type: ConfigMap
          name: kube-root-ca.crt
          key: ca.crt
      auth:
        serviceAccount:
          name: "my-store"

 

  • ClusterSecretStore (cluster scope)

Ressource de connexion à un provider (Vault, AWS, kubernetes etc.) à l'echelle du cluster.

    • Exemple provider Kubernetes:
apiVersion: external-secrets.io/v1
kind: ClusterSecretStore
metadata:
  name: k8s-store-default-ns
spec:
  provider:
    kubernetes:
      # with this, the store is able to pull only from `default` namespace
      remoteNamespace: default
      server:
        url: "https://myapiserver.tld" # Pas obligatoire si le  meme cluster k8s
        caProvider:
          type: ConfigMap
          name: kube-root-ca.crt
          key: ca.crt
      auth:
        serviceAccount:
          name: "my-store"

 

  • ExternalSecret (namespace scope)

Récupérer un secret depuis le provider (via un Store) et créer/mettre à jour un Secret Kubernetes.

    • Exemple: copie une clé d’un secret source vers un secret cible:
apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
  name: app-db-externalsecret
  namespace: app
spec:
  refreshInterval: 1h
  secretStoreRef:
    name: store-local
    kind: SecretStore
  target:
    name: app-db
    creationPolicy: Owner
  data:
  - secretKey: password
    remoteRef:
      key: db-credentials
      property: password

 

  • ClusterExternalSecret (cluster scope)

Déployer le même ExternalSecret dans plusieurs namespaces automatiquement. Pratique pour propager un secret standard (ex: CA, credentials génériques, registry pull, etc.).

    • Exemple: ExternalSecret nommé harbor-image-pull-regcred dans tous les namespaces qui matchent un label :
apiVersion: external-secrets.io/v1
kind: ClusterExternalSecret
metadata:
  name: harbor-dk-cfg
spec:
  # Le ClusterExternalSecret va créer un ExternalSecret dans chaque namespace qui match
  namespaceSelector:
    matchLabels:
      eso: enabled

  # Nom de l'ExternalSecret créé dans chaque namespace
  externalSecretName: harbor-dk-cfg

  # Le "template" de l'ExternalSecret qui sera répliqué
  externalSecretSpec:
    refreshInterval: 1h0m0s

    secretStoreRef:
      name: store-global
      kind: ClusterSecretStore

    target:
      name: harbor-image-pull-regcred
      creationPolicy: Owner
      template:
        type: kubernetes.io/dockerconfigjson
        engineVersion: v2
        data:
          # On construit le Secret dockerconfigjson à partir d'une valeur récupérée du provider
          # Ici `.mysecret` doit contenir le JSON complet attendu par docker config
          .dockerconfigjson: "{{ `{{ .mysecret }}` }}"

    data:
    - secretKey: mysecret
      remoteRef:
        key: harbor/docker-config
        # si ton provider expose une propriété précise, décommente et adapte
        # property: dockerconfigjson

 

  • PushSecret (scope: namespace)

Prendre un Secret Kubernetes existant et le pousser(ecrire) vers le provider. Cas typique : Migration vers Vault / centralisation / backup contrôlé.

Exemple : pousser Secret/app-db vers un backend vault:

apiVersion: external-secrets.io/v1alpha1
kind: PushSecret
metadata:
  name: push-app-db
  namespace: app
spec:
  updatePolicy: Replace # Policy to overwrite existing secrets in the provider on sync
  deletionPolicy: Delete # the provider' secret will be deleted if the PushSecret is deleted
  refreshInterval: 1h0m0s # Refresh interval for which push secret will reconcile
  secretStoreRefs:
  - name: vault-secret-store
    kind: SecretStore
  selector:
    secret:
      name: app-db
  data:
  - match:
      secretKey: password
      remoteRef:
        remoteKey: pushed/app-db
        property: password

 

 

  • ClusterPushSecret (scope: cluster)

Permet d’orchestrer des push depuis plusieurs namespaces (selon sélecteurs) à l'échelle du cluster.

Exemple: pousser un secret commun depuis les namespaces “enabled” :

apiVersion: external-secrets.io/v1alpha1
kind: ClusterPushSecret
metadata:
  name: push-common
spec:
  namespaceSelector:
    matchLabels:
      eso: enabled
  pushSecretName: push-common
  pushSecretSpec:
    updatePolicy: Replace # Policy to overwrite existing secrets in the provider on sync
    deletionPolicy: Delete # the provider' secret will be deleted if the PushSecret is deleted
    refreshInterval: 1h0m0s # Refresh interval for which push secret will reconcile
    secretStoreRefs:
    - name: vault-secret-store
      kind: ClusterSecretStore
    selector:
      secret:
        name: common-secret
    data:
    - match:
        secretKey: token
        remoteRef:
          remoteKey: pushed/common
          property: token

Commentaires

Connectez-vous pour rejoindre la discussion.

Aucun commentaire pour le moment.