Skip to content

Commit 36a9ebd

Browse files
author
Florian Perucki
committed
docs: add k8s authentication method example for hashicorp
1 parent 0e546ab commit 36a9ebd

File tree

3 files changed

+184
-0
lines changed

3 files changed

+184
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
name: ggscout-secrets
6+
stringData:
7+
# Kubernetes service account name for Vault authentication
8+
KUBERNETES_SERVICE_ACCOUNT: "ggscout-vault"
9+
10+
# Kubernetes namespace where ggscout is deployed
11+
KUBERNETES_NAMESPACE: "default"
12+
13+
# Vault Kubernetes authentication role
14+
VAULT_K8S_ROLE: "ggscout"
15+
16+
# GitGuardian API token
17+
GITGUARDIAN_API_KEY: "your_gitguardian_token"
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
# yaml-language-server: $schema=../../values.schema.json
3+
4+
inventory:
5+
config:
6+
sources:
7+
hashicorpvault:
8+
type: hashicorpvault
9+
vault_address: "https://your-vault-address-here.com"
10+
auth:
11+
auth_mode: "k8s"
12+
k8s:
13+
service_account: "${KUBERNETES_SERVICE_ACCOUNT}"
14+
namespace: "${KUBERNETES_NAMESPACE}"
15+
role: "${VAULT_K8S_ROLE}"
16+
fetch_all_versions: true # Fetch all versions of secrets or not
17+
path: "secret/dev" # Vault path or unspecified
18+
mode: "read/write" # Can be `read`, `write` or `read/write` depending on wether fetch and/or sync are enabled
19+
# To upload, set the gitguardian URL and tokens. Ensure the endpoint path ends with /v1
20+
# This is optional: omit this to prevent uploading and to only test collection.
21+
gitguardian:
22+
endpoint: "https://api.gitguardian.com/v1"
23+
api_token: "${GITGUARDIAN_API_KEY}"
24+
jobs:
25+
# Job to fetch defined sources
26+
fetch:
27+
# Set to `false` to disable the job
28+
enabled: true
29+
# Run every 15 minutes
30+
schedule: '*/15 * * * *'
31+
send: true
32+
# Job to be able to sync/write secrets from GitGuardian into you vault
33+
sync:
34+
# Set to `false` to disable the job
35+
enabled: true
36+
# Run every minute
37+
schedule: '* * * * *'
38+
39+
# Service account configuration for Kubernetes authentication
40+
serviceAccount:
41+
# Create a service account for Vault authentication
42+
create: true
43+
# Annotations can be used for IAM role bindings if needed
44+
annotations: {}
45+
# Use a specific name for the service account
46+
name: "ggscout-vault"
47+
48+
envFrom:
49+
- secretRef:
50+
name: ggscout-secrets

0 commit comments

Comments
 (0)