DEV Community

Cover image for Vault Secret as an External Secret
Raymond
Raymond

Posted on

Vault Secret as an External Secret

This guide to help people who are new to Vault create a Kubernetes Secret through Vault

There are two ways to use Vault Secret:

  • Adding the annotations
  • Use External Secret Operator

External SecretSource: external-secrets.io

I used the second step in this article because I used ArgoCD before and wanted to visualize all the resources I created.

Walkthrough

Create Secret

Enable Secret Engine

Path

Value

Create a Secret for the Vault token

kubectl create secret generic vault-token --from-literal=token=<token>
Enter fullscreen mode Exit fullscreen mode

or

echo -n "token" | base64
Enter fullscreen mode Exit fullscreen mode
apiVersion: v1
data:
  token: <Encoded Vault Token>
kind: Secret
metadata:
  name: vault-token
type: Opaque

Enter fullscreen mode Exit fullscreen mode

Install External Secrets using Helm

helm repo add external-secrets <https://charts.external-secrets.io>
helm install external-secrets external-secrets/external-secrets
Enter fullscreen mode Exit fullscreen mode

SecretStore

Note

Create secret-store.yaml file

apiVersion: external-secrets.io/v1beta1
kind: SecretStore
metadata:
  name: secret-store
spec:
  provider:
    vault:
      server: http://<serverAddresss>:<port>
      path: <path> ----- see the picture above
      version: "<version>" ---- See the version near the path above
      auth:
        tokenSecretRef:
          name: vault-token
          key: token
Enter fullscreen mode Exit fullscreen mode

ExternalService

Create external-secret.yaml file

apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
  name: external-secret
spec:
  refreshInterval: 5m  ------ Time for fetching new values
  secretStoreRef:
    name: secret-store  ------- Secret Store Name 
    kind: SecretStore
  target:
    name: secret-to-be-created   --------- Secret Name
    creationPolicy: Owner
  dataFrom:
  - extract:
      key: "<key>"  ------- See the picture above
Enter fullscreen mode Exit fullscreen mode

It will automatically get all values from Vault Secret and create a new secret if it does not exist.

Preferences

HashiCorp Vault


English is not my first language, and I am not good at it, but I want to improve and enhance my English every day. Writing a blog is the best way I have chosen. Please let me know if there is anything confusing because of my English.

Top comments (0)