set SecretStore connect to a existing vault server
apply a incomplete Secret , some vaule with fetch from the vault system.
sequenceDiagram
[Secert] ->>+ kubernetes: apply a `example-sync` secert to cluster
external-secrets ->>+ kubernetes: watch all secert
external-secrets ->>+ [ExternalSecret]: found the secert
[ExternalSecret] ->>- external-secrets: yes, this secert should maintain by operator
external-secrets ->>+ [SecretStore]: confirm vault connection info
external-secrets ->>+ valut: get the value by `remoteRef`
valut ->>- external-secrets: return the vaule
external-secrets ->>+ kubernetes: use vaule from vault to replace secert `example-sync`
install external-secrets
install external-secrets by helm.
The default install options will automatically install and manage the CRDs as part of your helm release. If you do not want the CRDs to be automatically upgraded and managed, you must set the installCRDs option to false. (e.g. --set installCRDs=false)
$ helm repo add hashicorp https://helm.releases.hashicorp.com $ helm install vault hashicorp/vault --set"server.dev.enabled=true" NAME: vault LAST DEPLOYED: Thu Aug 1 14:34:17 2024 NAMESPACE: default STATUS: deployed REVISION: 1 NOTES: Thank you for installing HashiCorp Vault!
Now that you have deployed Vault, you should look over the docs on using Vault with Kubernetes available here:
https://developer.hashicorp.com/vault/docs
Your release is named vault. To learn more about the release, try: $ helm status vault $ helm get manifest vault
set a key/value pair .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
$ kubectl exec -it vault-0 -c vault sh kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
apiVersion:external-secrets.io/v1beta1 kind:SecretStore metadata: name:vault-backend spec: provider: vault: server:"http://10.102.9.200:8200" path:"secret" # Version is the Vault KV secret engine version. # This can be either "v1" or "v2", defaults to "v2" version:"v2" auth: # points to a secret that contains a vault token # https://www.vaultproject.io/docs/auth/token tokenSecretRef: name:"vault-token" key:"token" --- apiVersion:v1 kind:Secret metadata: name:vault-token data: token:cm9vdA==# "root"
apply the file to kubernetes, take a look the value of CAPABILITIES of vault-backend it should be ReadWrite. this status means the operator can get/put the vaule to vault server.
1 2 3 4 5 6 7
$ kubectl apply -f SecretStore.yaml secretstore.external-secrets.io/vault-backend created secret/vault-token created $ kubectl get secretstores NAME AGE STATUS CAPABILITIES READY vault-backend 1s Valid ReadWrite True
install ExternalSecret.yaml. actually, this is a user case. the ExternalSecret help the cluster to render to secert file with true Secret vaule.
# metadataPolicy to fetch all the labels in JSON format -secretKey:tags remoteRef: metadataPolicy:Fetch key:foo --- apiVersion:v1 kind:Secret metadata: name:example-sync data: foobar:czNjcjN0
$ kubectl exec -it vault-0 -c vault sh kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
-secretKey:foobar remoteRef: key:foo property:my-value # metadataPolicy to fetch all the labels in JSON format -secretKey:tags remoteRef: metadataPolicy:Fetch key:foo