Skip to content

Commit d4ddfaf

Browse files
authored
Show how to configure gke datagatherer permissions (#158)
Signed-off-by: Charlie Egan <[email protected]>
1 parent dbfe5f6 commit d4ddfaf

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

docs/datagatherers/gke.md

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,48 @@ Specifically it must have the `container.clusters.get` permission. This can be
5959
given with the _Kubernetes Engine Cluster Viewer_ role
6060
(`roles/container.clusterViewer`).
6161

62-
A sample Terraform project can be found at
63-
[`./deployment/terraform/gke-datagatherer/`](deployment/terraform/gke-datagatherer).
64-
This can be used to create a GCP service account called `preflight` which
65-
is then bound to a custom role of the same name
66-
with the minimum required permissions.
62+
### Sample Terraform Configuration
63+
64+
This can be used to create a GCP service account called `preflight` which is
65+
then bound to a custom role of the same name with the minimum required
66+
permissions.
67+
68+
69+
```hcl
70+
terraform {
71+
required_version = "~> 0.12"
72+
}
73+
74+
variable "project_id" {
75+
type = string
76+
description = "The ID of the project where the cluster Preflight is going to check is."
77+
}
78+
79+
# https://www.terraform.io/docs/providers/google/index.html
80+
provider "google" {
81+
version = "2.5.1"
82+
project = var.project_id
83+
}
84+
85+
# https://www.terraform.io/docs/providers/google/r/google_service_account.html
86+
resource "google_service_account" "preflight_agent_service_account" {
87+
project = var.project_id
88+
account_id = "preflight-agent"
89+
display_name = "Service account for Preflight Agent"
90+
}
91+
92+
# https://www.terraform.io/docs/providers/google/r/google_project_iam_custom_role.html
93+
resource "google_project_iam_member" "preflight_agent_cluster_viewer" {
94+
project = var.project_id
95+
role = "roles/container.clusterViewer" # allows getting of credentials, all other permissions handled in k8s RBAC
96+
member = "serviceAccount:${google_service_account.preflight_agent_service_account.email}"
97+
}
98+
99+
# if using workload identity in GKE, use the following binding to allow the
100+
# agent to use the service account
101+
resource "google_project_iam_binding" "preflight_agent_workload_identity" {
102+
project = var.project_id
103+
role = "roles/iam.workloadIdentityUser"
104+
members = "serviceAccount:${var.project_id}.svc.id.goog[preflight/default]"
105+
}
106+
```

0 commit comments

Comments
 (0)