Vault integration with Gitlab CI
Vault integration with Gitalb CI to retrieve secrets in job pipelines
Installation is done in kubernetes, if already have gitlab and vault running ignore helm and kubectl steps.
Install consul helm (optional if doing allinone with minikube)
helm repo add hashicorp https://helm.releases.hashicorp.com
helm repo update
helm install consul hashicorp/consulInstall vault
helm install vault hashicorp/vaultVerify vault installation, for now vault is not initialized so pods are 0/1
kubectl exec vault-0 -- vault status
Key Value
--- -----
Seal Type shamir
Initialized false
Sealed true
Total Shares 0
Threshold 0
Unseal Progress 0/0
Unseal Nonce n/a
Version 1.18.1
Build Date 2024-10-29T14:21:31Z
Storage Type file
HA Enabled false
command terminated with exit code 2Initialize vault
Note the root_token for the initial web ui login
Unseal vault
Repeat the same for the other vault-* pods if existing
Exec into the pod to initialize vault config, use root token from the vault keys file we generated
Enable kv-v2 engine
Create demo password
Verify secret retrieval
Create ingress for web access
Gitlab CI integration
Enable jwt
Download certificates from gitlab if are self signed
Generate jwt connection to gitlab
Create a policy to read secrets
Create demo role
Configure in gitlab CI variables
VAULT_SERVER_URL: http://vault-server:8200
VAULT_AUTH_ROLE: demo
Create the demo secret
Example gitlab pipeline
Output from the job
Policy template access secrets by gitlab group namespace
Get accessor name for jwt in vault, may need to install jq or can regex with grep, awk, etc
Create a policy pointing the accessor name and namespace_path
Role for the policy, note the claim mappings.
Create x number of project, subprojects and groups. Test if they can access their secrets within their namespace_name path.
Note subgroups can only access secrets within its subgroup path
Last updated
Was this helpful?