Skip to content

Commit 113e44e

Browse files
authored
Merge pull request #62 from GitGuardian/amascia/-/gke-doc
chore(gke): improve GCP doc with GKE
2 parents 0ca5f44 + 174b491 commit 113e44e

File tree

1 file changed

+69
-13
lines changed
  • charts/ggscout/examples/gcpsecretmanager-workload

1 file changed

+69
-13
lines changed

charts/ggscout/examples/gcpsecretmanager-workload/README.md

Lines changed: 69 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
This example demonstrates how to configure ggscout to authenticate with Google Cloud Secret Manager using Workload Identity Federation for Kubernetes. This approach eliminates the need for service account keys by allowing Kubernetes ServiceAccounts to directly authenticate to Google Cloud APIs.
44

5+
Note that the configuration has been made even simpler if ggscout is deployed in a Google Kubernetes Engine (GKE) cluster.
6+
57
## Prerequisites
68

79
### Required Tools
@@ -25,6 +27,7 @@ Your Kubernetes cluster must support:
2527
For managed Kubernetes services:
2628
- **EKS**: No additional configuration needed
2729
- **AKS**: Enable the OIDC issuer feature
30+
- **GKE**: Make sure you cluster (and node pools) have [Worload Identity Federation enabled](https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity#enable_on_clusters_and_node_pools).
2831
- **Self-hosted**: Configure `kube-apiserver` to support ServiceAccount token volume projections
2932

3033
## Setup Process
@@ -54,6 +57,9 @@ gcloud services enable secretmanager.googleapis.com \
5457

5558
The method depends on your Kubernetes cluster type:
5659

60+
#### For Google Kubernetes Engine (GKE)
61+
This step is not necessary.
62+
5763
#### For Amazon EKS:
5864
```bash
5965
export CLUSTER_NAME="your-cluster-name"
@@ -77,6 +83,16 @@ kubectl get --raw /.well-known/openid-configuration | jq -r .issuer
7783

7884
### Step 3: Create Workload Identity Pool and Provider
7985

86+
#### For Google Kubernetes Engine (GKE)
87+
This step is not necessary. You will however need to have defined the following variables for the next steps:
88+
89+
```bash
90+
export NAMESPACE="default" # or your preferred namespace
91+
export KSA_NAME="ggscout-ksa" # Kubernetes ServiceAccount name
92+
```
93+
94+
#### For other configurations
95+
8096
```bash
8197
# Set configuration variables
8298
export POOL_ID="ggscout-pool"
@@ -90,8 +106,12 @@ gcloud iam workload-identity-pools create $POOL_ID \
90106
--description="Workload Identity Pool for ggscout" \
91107
--display-name="ggscout Workload Identity Pool" \
92108
--project=$PROJECT_ID
109+
```
93110

94-
# For EKS and AKS (using OIDC metadata endpoints)
111+
The last commands vary depending on your cluster type
112+
113+
##### For EKS and AKS (using OIDC metadata endpoints)
114+
```bash
95115
gcloud iam workload-identity-pools providers create-oidc $PROVIDER_ID \
96116
--location="global" \
97117
--workload-identity-pool=$POOL_ID \
@@ -101,7 +121,7 @@ gcloud iam workload-identity-pools providers create-oidc $PROVIDER_ID \
101121
--project=$PROJECT_ID
102122
```
103123

104-
#### For Self-hosted Kubernetes (requires JWKS upload):
124+
##### For Self-hosted Kubernetes (requires JWKS upload):
105125
```bash
106126
# Download the cluster's JWKS
107127
kubectl get --raw /openid/v1/jwks > cluster-jwks.json
@@ -131,6 +151,9 @@ gcloud iam service-accounts create $GSA_NAME \
131151
gcloud projects add-iam-policy-binding $PROJECT_ID \
132152
--member="serviceAccount:$GSA_NAME@$PROJECT_ID.iam.gserviceaccount.com" \
133153
--role="roles/secretmanager.secretAccessor"
154+
gcloud projects add-iam-policy-binding $PROJECT_ID \
155+
--member="serviceAccount:$GSA_NAME@$PROJECT_ID.iam.gserviceaccount.com" \
156+
--role="roles/secretmanager.viewer"
134157
```
135158

136159
### Step 5: Create Kubernetes ServiceAccount and Configure IAM Binding
@@ -141,7 +164,23 @@ kubectl create namespace $NAMESPACE --dry-run=client -o yaml | kubectl apply -f
141164

142165
# Create Kubernetes ServiceAccount
143166
kubectl create serviceaccount $KSA_NAME --namespace $NAMESPACE
167+
```
144168

169+
#### For GKE
170+
```bash
171+
# Allow the Kubernetes ServiceAccount to impersonate the Google Cloud ServiceAccount
172+
kubectl annotate serviceaccount $KSA_NAME \
173+
--namespace $NAMESPACE \
174+
iam.gke.io/gcp-service-account=$GSA_NAME@$PROJECT_ID.iam.gserviceaccount.com
175+
176+
gcloud iam service-accounts add-iam-policy-binding \
177+
$GSA_NAME@$PROJECT_ID.iam.gserviceaccount.com \
178+
--role="roles/iam.workloadIdentityUser" \
179+
--member="serviceAccount:$PROJECT_ID.svc.id.goog[$NAMESPACE/$KSA_NAME]"
180+
```
181+
182+
#### For other cluster types
183+
```bash
145184
# Allow the Kubernetes ServiceAccount to impersonate the Google Cloud ServiceAccount
146185
gcloud iam service-accounts add-iam-policy-binding \
147186
$GSA_NAME@$PROJECT_ID.iam.gserviceaccount.com \
@@ -152,8 +191,36 @@ gcloud iam service-accounts add-iam-policy-binding \
152191

153192
### Step 6: Update Configuration Files
154193

194+
Update the `secret.yaml` file with your GitGuardian API key:
195+
196+
```yaml
197+
apiVersion: v1
198+
kind: Secret
199+
metadata:
200+
name: ggscout-secrets
201+
stringData:
202+
GITGUARDIAN_API_KEY: "your_gitguardian_token" # Replace with your actual token
203+
```
204+
155205
Update the `values.yaml` file with your specific configuration:
156206

207+
#### GKE
208+
209+
```yaml
210+
inventory:
211+
config:
212+
sources:
213+
gcp:
214+
type: gcpsecretmanager
215+
fetch_all_versions: true
216+
mode: "read"
217+
gitguardian:
218+
endpoint: "https://your-gg-instance/v1" # Replace with your GitGuardian endpoint
219+
api_token: "${GITGUARDIAN_API_KEY}"
220+
```
221+
222+
#### Other cluster type
223+
157224
```yaml
158225
inventory:
159226
config:
@@ -174,17 +241,6 @@ inventory:
174241
api_token: "${GITGUARDIAN_API_KEY}"
175242
```
176243

177-
Update the `secret.yaml` file with your GitGuardian API key:
178-
179-
```yaml
180-
apiVersion: v1
181-
kind: Secret
182-
metadata:
183-
name: ggscout-secrets
184-
stringData:
185-
GITGUARDIAN_API_KEY: "your_gitguardian_token" # Replace with your actual token
186-
```
187-
188244
## Deployment
189245

190246
### 1. Add the ggscout Helm repository

0 commit comments

Comments
 (0)