Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Update least privilege default service account #1844

Merged
merged 3 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions autogen/main/sa.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,10 @@ resource "google_service_account" "cluster_service_account" {
display_name = "Terraform-managed service account for cluster ${var.name}"
}

resource "google_project_iam_member" "cluster_service_account-log_writer" {
resource "google_project_iam_member" "cluster_service_account-nodeService_account" {
count = var.create_service_account ? 1 : 0
project = google_service_account.cluster_service_account[0].project
role = "roles/logging.logWriter"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-metric_writer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-log_writer[0].project
role = "roles/monitoring.metricWriter"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-monitoring_viewer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-metric_writer[0].project
role = "roles/monitoring.viewer"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-resourceMetadata-writer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-monitoring_viewer[0].project
role = "roles/stackdriver.resourceMetadata.writer"
role = "roles/container.defaultNodeServiceAccount"
member = google_service_account.cluster_service_account[0].member
}

Expand Down
3 changes: 2 additions & 1 deletion docs/upgrading_to_v30.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ release.

### Default cluster service account permissions modified

When `create_service_account` is `true`, the service account will now be created with the `Logs Writer`, `Monitoring Metric Writer`, `Monitoring Viewer` and `Stackdriver Resource Metadata Writer` roles instead of the deprecated `Kubernetes Engine Node Service Account` role.
When `create_service_account` is `true`, the service account will now be created with `Kubernetes Engine Default Node Service Account` role instead of `Kubernetes Engine Node Service Account` roles which is deprecated now.
This is the Google recommended least privileged role to be used for the service account attached to the GKE Nodes.
25 changes: 2 additions & 23 deletions modules/beta-autopilot-private-cluster/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,10 @@ resource "google_service_account" "cluster_service_account" {
display_name = "Terraform-managed service account for cluster ${var.name}"
}

resource "google_project_iam_member" "cluster_service_account-log_writer" {
resource "google_project_iam_member" "cluster_service_account-nodeService_account" {
count = var.create_service_account ? 1 : 0
project = google_service_account.cluster_service_account[0].project
role = "roles/logging.logWriter"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-metric_writer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-log_writer[0].project
role = "roles/monitoring.metricWriter"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-monitoring_viewer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-metric_writer[0].project
role = "roles/monitoring.viewer"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-resourceMetadata-writer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-monitoring_viewer[0].project
role = "roles/stackdriver.resourceMetadata.writer"
role = "roles/container.defaultNodeServiceAccount"
member = google_service_account.cluster_service_account[0].member
}

Expand Down
25 changes: 2 additions & 23 deletions modules/beta-autopilot-public-cluster/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,10 @@ resource "google_service_account" "cluster_service_account" {
display_name = "Terraform-managed service account for cluster ${var.name}"
}

resource "google_project_iam_member" "cluster_service_account-log_writer" {
resource "google_project_iam_member" "cluster_service_account-nodeService_account" {
count = var.create_service_account ? 1 : 0
project = google_service_account.cluster_service_account[0].project
role = "roles/logging.logWriter"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-metric_writer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-log_writer[0].project
role = "roles/monitoring.metricWriter"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-monitoring_viewer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-metric_writer[0].project
role = "roles/monitoring.viewer"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-resourceMetadata-writer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-monitoring_viewer[0].project
role = "roles/stackdriver.resourceMetadata.writer"
role = "roles/container.defaultNodeServiceAccount"
member = google_service_account.cluster_service_account[0].member
}

Expand Down
25 changes: 2 additions & 23 deletions modules/beta-private-cluster-update-variant/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,10 @@ resource "google_service_account" "cluster_service_account" {
display_name = "Terraform-managed service account for cluster ${var.name}"
}

resource "google_project_iam_member" "cluster_service_account-log_writer" {
resource "google_project_iam_member" "cluster_service_account-nodeService_account" {
count = var.create_service_account ? 1 : 0
project = google_service_account.cluster_service_account[0].project
role = "roles/logging.logWriter"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-metric_writer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-log_writer[0].project
role = "roles/monitoring.metricWriter"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-monitoring_viewer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-metric_writer[0].project
role = "roles/monitoring.viewer"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-resourceMetadata-writer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-monitoring_viewer[0].project
role = "roles/stackdriver.resourceMetadata.writer"
role = "roles/container.defaultNodeServiceAccount"
member = google_service_account.cluster_service_account[0].member
}

Expand Down
25 changes: 2 additions & 23 deletions modules/beta-private-cluster/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,10 @@ resource "google_service_account" "cluster_service_account" {
display_name = "Terraform-managed service account for cluster ${var.name}"
}

resource "google_project_iam_member" "cluster_service_account-log_writer" {
resource "google_project_iam_member" "cluster_service_account-nodeService_account" {
count = var.create_service_account ? 1 : 0
project = google_service_account.cluster_service_account[0].project
role = "roles/logging.logWriter"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-metric_writer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-log_writer[0].project
role = "roles/monitoring.metricWriter"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-monitoring_viewer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-metric_writer[0].project
role = "roles/monitoring.viewer"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-resourceMetadata-writer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-monitoring_viewer[0].project
role = "roles/stackdriver.resourceMetadata.writer"
role = "roles/container.defaultNodeServiceAccount"
member = google_service_account.cluster_service_account[0].member
}

Expand Down
25 changes: 2 additions & 23 deletions modules/beta-public-cluster-update-variant/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,10 @@ resource "google_service_account" "cluster_service_account" {
display_name = "Terraform-managed service account for cluster ${var.name}"
}

resource "google_project_iam_member" "cluster_service_account-log_writer" {
resource "google_project_iam_member" "cluster_service_account-nodeService_account" {
count = var.create_service_account ? 1 : 0
project = google_service_account.cluster_service_account[0].project
role = "roles/logging.logWriter"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-metric_writer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-log_writer[0].project
role = "roles/monitoring.metricWriter"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-monitoring_viewer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-metric_writer[0].project
role = "roles/monitoring.viewer"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-resourceMetadata-writer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-monitoring_viewer[0].project
role = "roles/stackdriver.resourceMetadata.writer"
role = "roles/container.defaultNodeServiceAccount"
member = google_service_account.cluster_service_account[0].member
}

Expand Down
25 changes: 2 additions & 23 deletions modules/beta-public-cluster/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,10 @@ resource "google_service_account" "cluster_service_account" {
display_name = "Terraform-managed service account for cluster ${var.name}"
}

resource "google_project_iam_member" "cluster_service_account-log_writer" {
resource "google_project_iam_member" "cluster_service_account-nodeService_account" {
count = var.create_service_account ? 1 : 0
project = google_service_account.cluster_service_account[0].project
role = "roles/logging.logWriter"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-metric_writer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-log_writer[0].project
role = "roles/monitoring.metricWriter"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-monitoring_viewer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-metric_writer[0].project
role = "roles/monitoring.viewer"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-resourceMetadata-writer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-monitoring_viewer[0].project
role = "roles/stackdriver.resourceMetadata.writer"
role = "roles/container.defaultNodeServiceAccount"
member = google_service_account.cluster_service_account[0].member
}

Expand Down
25 changes: 2 additions & 23 deletions modules/private-cluster-update-variant/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,10 @@ resource "google_service_account" "cluster_service_account" {
display_name = "Terraform-managed service account for cluster ${var.name}"
}

resource "google_project_iam_member" "cluster_service_account-log_writer" {
resource "google_project_iam_member" "cluster_service_account-nodeService_account" {
count = var.create_service_account ? 1 : 0
project = google_service_account.cluster_service_account[0].project
role = "roles/logging.logWriter"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-metric_writer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-log_writer[0].project
role = "roles/monitoring.metricWriter"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-monitoring_viewer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-metric_writer[0].project
role = "roles/monitoring.viewer"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-resourceMetadata-writer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-monitoring_viewer[0].project
role = "roles/stackdriver.resourceMetadata.writer"
role = "roles/container.defaultNodeServiceAccount"
member = google_service_account.cluster_service_account[0].member
}

Expand Down
25 changes: 2 additions & 23 deletions modules/private-cluster/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,10 @@ resource "google_service_account" "cluster_service_account" {
display_name = "Terraform-managed service account for cluster ${var.name}"
}

resource "google_project_iam_member" "cluster_service_account-log_writer" {
resource "google_project_iam_member" "cluster_service_account-nodeService_account" {
count = var.create_service_account ? 1 : 0
project = google_service_account.cluster_service_account[0].project
role = "roles/logging.logWriter"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-metric_writer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-log_writer[0].project
role = "roles/monitoring.metricWriter"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-monitoring_viewer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-metric_writer[0].project
role = "roles/monitoring.viewer"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-resourceMetadata-writer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-monitoring_viewer[0].project
role = "roles/stackdriver.resourceMetadata.writer"
role = "roles/container.defaultNodeServiceAccount"
member = google_service_account.cluster_service_account[0].member
}

Expand Down
25 changes: 2 additions & 23 deletions sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,10 @@ resource "google_service_account" "cluster_service_account" {
display_name = "Terraform-managed service account for cluster ${var.name}"
}

resource "google_project_iam_member" "cluster_service_account-log_writer" {
resource "google_project_iam_member" "cluster_service_account-nodeService_account" {
count = var.create_service_account ? 1 : 0
project = google_service_account.cluster_service_account[0].project
role = "roles/logging.logWriter"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-metric_writer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-log_writer[0].project
role = "roles/monitoring.metricWriter"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-monitoring_viewer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-metric_writer[0].project
role = "roles/monitoring.viewer"
member = google_service_account.cluster_service_account[0].member
}

resource "google_project_iam_member" "cluster_service_account-resourceMetadata-writer" {
count = var.create_service_account ? 1 : 0
project = google_project_iam_member.cluster_service_account-monitoring_viewer[0].project
role = "roles/stackdriver.resourceMetadata.writer"
role = "roles/container.defaultNodeServiceAccount"
member = google_service_account.cluster_service_account[0].member
}

Expand Down