A SopsSecret resource defines one or more Kubernetes secrets.
1. Define the SopsSecret
Create a YAML file (e.g., jenkins-secrets.yaml) following the isindir.github.com/v1alpha3 API version. You can define secretTemplates which include labels, annotations, stringData, and data.
2. Encrypt the file using sops
Use the sops CLI to encrypt your file for your chosen provider:
AWS KMS:
sops encrypt --kms 'arn:aws:kms:<region>:<account>:alias/<key-alias-name>' --encrypted-suffix='Templates' jenkins-secrets.yaml > jenkins-secrets.enc.yaml
GCP KMS:
sops encrypt --gcp-kms 'projects/<project-name>/locations/<location>/keyRings/<keyring-name>/cryptoKeys/<key-name>' --encrypted-suffix='Templates' jenkins-secrets.yaml > jenkins-secrets.enc.yaml
Azure Key Vault:
sops encrypt --azure-kv 'https://<vault-url>/keys/<key-name>/<key-version>' --encrypted-suffix='Templates' jenkins-secrets.yaml > jenkins-secrets.enc.yaml
PGP:
sops encrypt --pgp '<pgp-finger-print>' --encrypted-suffix='Templates' jenkins-secrets.yaml > jenkins-secrets.enc.yaml
Note: Using --encrypted-suffix='Templates' is recommended to ensure the resulting file is compatible with Kubernetes. Using --encrypted-regex should be done with caution as it may result in files inapplicable to the cluster.
apiVersion: isindir.github.com/v1alpha3
kind: SopsSecret
metadata:
name: example-sopssecret
spec:
suspend: false
secretTemplates:
- name: jenkins-secret
labels:
"jenkins.io/credentials-type": "usernamePassword"
stringData:
username: myUsername
password: 'Pa$$word'