Managing secrets
We will use External Secrets Operator to access the secrets stored in an external secret manager which, in this case, is Infisical.
Having the secrets stored in an external secret manager allows us to have a single source of truth for all the secrets, and we can manage them in a centralized way. Moreover, we avoid hardcoding the secrets in the manifests files or in the Helm chart values, as we cannot rely on the private access of the git repository.
Usage
Manage secrets
Manage the secrets in the Infisical dashboard.
Setup Kubernetes secret store
Guide: Infisical provider
Example:
apiVersion: v1
kind: Secret
metadata:
name: universal-auth-credentials
namespace: external-secrets
type: Opaque
stringData:
clientId: 7cb513c6-7be3-...
clientSecret: f5a65ed594e...
apiVersion: external-secrets.io/v1beta1
kind: ClusterSecretStore
metadata:
name: infisical-kubernetes-prod
spec:
provider:
infisical:
auth:
universalAuthCredentials:
clientId:
key: clientId
namespace: external-secrets
name: universal-auth-credentials
clientSecret:
key: clientSecret
namespace: external-secrets
name: universal-auth-credentials
secretsScope:
projectSlug: kubernetes-r-x6q
environmentSlug: prod
secretsPath: /
recursive: true
hostAPI: https://eu.infisical.com
Access secrets from Kubernetes
Create an ExternalSecret to reference the secret in the Infisical dashboard.
Example:
apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
name: harbor-secret-key
namespace: harbor
spec:
secretStoreRef:
kind: ClusterSecretStore
name: infisical-kubernetes-prod
target:
name: harbor-secret-key
data:
- secretKey: secretKey
remoteRef:
key: HARBOR_SECRET_KEY
One secret, multiple keys
Raw secret:
{
"key1": "value1",
"key2": "value2"
}
ExternalSecret:
apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
name: infisical-secrets
namespace: infisical
spec:
secretStoreRef:
kind: ClusterSecretStore
name: infisical-kubernetes-prod
target:
name: infisical-secrets
dataFrom:
- extract:
key: INFISICAL_ENVS
Update secret
To refresh a secret and avoid waiting for the TTL (1h by default), you can update the secret manually like this:
kubectl annotate externalsecrets harbor-secret-key force-sync=$(date +%s) --namespace harbor --overwrite