|
| 1 | +# HashiCorp Vault with Kubernetes Authentication |
| 2 | + |
| 3 | +This example demonstrates how to configure ggscout to authenticate with HashiCorp Vault using Kubernetes authentication when running in a Kubernetes cluster. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +1. HashiCorp Vault with Kubernetes auth method enabled |
| 8 | +2. Proper Vault policies and roles configured |
| 9 | +3. ggscout deployed in a Kubernetes cluster |
| 10 | + |
| 11 | +## Vault Configuration |
| 12 | + |
| 13 | +### 1. Enable Kubernetes Auth Method |
| 14 | + |
| 15 | +```bash |
| 16 | +# Enable Kubernetes auth method |
| 17 | +vault auth enable kubernetes |
| 18 | +``` |
| 19 | + |
| 20 | +See HashiCorp Vault reference [documentation](https://developer.hashicorp.com/vault/docs/auth/kubernetes#configuration) |
| 21 | + |
| 22 | +### 2. Configure Kubernetes Auth Method |
| 23 | + |
| 24 | +```bash |
| 25 | +# Configure the Kubernetes auth method |
| 26 | +vault write auth/kubernetes/config \ |
| 27 | + token_reviewer_jwt="$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" \ |
| 28 | + kubernetes_host="https://$KUBERNETES_PORT_443_TCP_ADDR:443" \ |
| 29 | + kubernetes_ca_cert=@/var/run/secrets/kubernetes.io/serviceaccount/ca.crt |
| 30 | +``` |
| 31 | + |
| 32 | +### 3. Create Vault Policy |
| 33 | + |
| 34 | +```bash |
| 35 | +# Create policy for ggscout |
| 36 | +vault policy write ggscout-policy - <<EOF |
| 37 | +# Allow reading secrets from KV2 engine |
| 38 | +path "secret/data/*" { |
| 39 | + capabilities = ["read", "list"] |
| 40 | +} |
| 41 | +
|
| 42 | +path "secret/metadata/*" { |
| 43 | + capabilities = ["read", "list"] |
| 44 | +} |
| 45 | +
|
| 46 | +# Allow reading from KV1 engine (if used) |
| 47 | +path "secret/*" { |
| 48 | + capabilities = ["read", "list"] |
| 49 | +} |
| 50 | +EOF |
| 51 | +``` |
| 52 | + |
| 53 | +### 4. Create Vault Kubernetes Role |
| 54 | + |
| 55 | +```bash |
| 56 | +# Create Kubernetes auth role |
| 57 | +vault write auth/kubernetes/role/ggscout \ |
| 58 | + bound_service_account_names=ggscout-vault \ |
| 59 | + bound_service_account_namespaces=default \ |
| 60 | + policies=ggscout-policy \ |
| 61 | + ttl=24h |
| 62 | +``` |
| 63 | + |
| 64 | +## Deployment |
| 65 | + |
| 66 | +### 1. Update Configuration |
| 67 | + |
| 68 | +Edit the `secret.yaml` file to match your environment: |
| 69 | + |
| 70 | +- `KUBERNETES_SERVICE_ACCOUNT`: Must match the service account name in values.yaml |
| 71 | +- `KUBERNETES_NAMESPACE`: The namespace where ggscout will be deployed |
| 72 | +- `VAULT_K8S_ROLE`: The Vault role created above |
| 73 | +- `GITGUARDIAN_API_KEY`: Your GitGuardian API token |
| 74 | + |
| 75 | +Edit the `values.yaml` file: |
| 76 | + |
| 77 | +- `vault_address`: Your Vault server URL |
| 78 | +- `path`: The Vault path to collect secrets from |
| 79 | +- `gitguardian.endpoint`: Your GitGuardian instance URL |
| 80 | + |
| 81 | +### 2. Deploy with Helm |
| 82 | + |
| 83 | +```bash |
| 84 | +# Add the ggscout Helm repository |
| 85 | +helm repo add ggscout https://gitguardian.github.io/nhi-scout-helm-charts |
| 86 | +helm repo update |
| 87 | + |
| 88 | +# Apply the secret first |
| 89 | +kubectl apply -f secret.yaml |
| 90 | + |
| 91 | +# Install ggscout with Kubernetes authentication |
| 92 | +helm install ggscout-vault ggscout/ggscout -f values.yaml |
| 93 | +``` |
| 94 | + |
| 95 | +## Verification |
| 96 | + |
| 97 | +Check that ggscout can authenticate with Vault: |
| 98 | + |
| 99 | +```bash |
| 100 | +# Check the logs of the ggscout pods |
| 101 | +kubectl logs -l app.kubernetes.io/name=ggscout |
| 102 | + |
| 103 | +# Verify the service account was created |
| 104 | +kubectl get serviceaccount ggscout-vault |
| 105 | + |
| 106 | +# Check if the CronJobs are running |
| 107 | +kubectl get cronjobs |
| 108 | +``` |
| 109 | + |
| 110 | +## Troubleshooting |
| 111 | + |
| 112 | +1. **Service Account Issues**: Ensure the service account name matches between `values.yaml` and `secret.yaml` |
| 113 | +2. **Vault Role Binding**: Verify the Vault role is bound to the correct service account and namespace |
| 114 | +3. **Network Connectivity**: Ensure ggscout pods can reach your Vault instance |
| 115 | +4. **Token Permissions**: Verify the Vault policy grants the necessary permissions |
| 116 | + |
| 117 | +For more detailed troubleshooting, enable debug logging by setting `log_level: debug` in the values.yaml file. |
0 commit comments