Skip to content

Commit

Permalink
fix!: Revert create least privilege default service account (terrafor…
Browse files Browse the repository at this point in the history
  • Loading branch information
apeabody authored Dec 26, 2023
1 parent afa5e07 commit dd53d92
Show file tree
Hide file tree
Showing 11 changed files with 237 additions and 20 deletions.
25 changes: 23 additions & 2 deletions autogen/main/sa.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,31 @@ 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-nodeService_account" {
resource "google_project_iam_member" "cluster_service_account-log_writer" {
count = var.create_service_account ? 1 : 0
project = google_service_account.cluster_service_account[0].project
role = "roles/container.nodeServiceAccount"
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"
member = google_service_account.cluster_service_account[0].member
}

Expand Down
7 changes: 7 additions & 0 deletions docs/upgrading_to_v30.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Upgrading to v30.0
The v30.0 release of *kubernetes-engine* is a backwards incompatible
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.
25 changes: 23 additions & 2 deletions modules/beta-autopilot-private-cluster/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,31 @@ 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-nodeService_account" {
resource "google_project_iam_member" "cluster_service_account-log_writer" {
count = var.create_service_account ? 1 : 0
project = google_service_account.cluster_service_account[0].project
role = "roles/container.nodeServiceAccount"
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"
member = google_service_account.cluster_service_account[0].member
}

Expand Down
25 changes: 23 additions & 2 deletions modules/beta-autopilot-public-cluster/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,31 @@ 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-nodeService_account" {
resource "google_project_iam_member" "cluster_service_account-log_writer" {
count = var.create_service_account ? 1 : 0
project = google_service_account.cluster_service_account[0].project
role = "roles/container.nodeServiceAccount"
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"
member = google_service_account.cluster_service_account[0].member
}

Expand Down
25 changes: 23 additions & 2 deletions modules/beta-private-cluster-update-variant/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,31 @@ 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-nodeService_account" {
resource "google_project_iam_member" "cluster_service_account-log_writer" {
count = var.create_service_account ? 1 : 0
project = google_service_account.cluster_service_account[0].project
role = "roles/container.nodeServiceAccount"
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"
member = google_service_account.cluster_service_account[0].member
}

Expand Down
25 changes: 23 additions & 2 deletions modules/beta-private-cluster/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,31 @@ 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-nodeService_account" {
resource "google_project_iam_member" "cluster_service_account-log_writer" {
count = var.create_service_account ? 1 : 0
project = google_service_account.cluster_service_account[0].project
role = "roles/container.nodeServiceAccount"
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"
member = google_service_account.cluster_service_account[0].member
}

Expand Down
25 changes: 23 additions & 2 deletions modules/beta-public-cluster-update-variant/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,31 @@ 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-nodeService_account" {
resource "google_project_iam_member" "cluster_service_account-log_writer" {
count = var.create_service_account ? 1 : 0
project = google_service_account.cluster_service_account[0].project
role = "roles/container.nodeServiceAccount"
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"
member = google_service_account.cluster_service_account[0].member
}

Expand Down
25 changes: 23 additions & 2 deletions modules/beta-public-cluster/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,31 @@ 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-nodeService_account" {
resource "google_project_iam_member" "cluster_service_account-log_writer" {
count = var.create_service_account ? 1 : 0
project = google_service_account.cluster_service_account[0].project
role = "roles/container.nodeServiceAccount"
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"
member = google_service_account.cluster_service_account[0].member
}

Expand Down
25 changes: 23 additions & 2 deletions modules/private-cluster-update-variant/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,31 @@ 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-nodeService_account" {
resource "google_project_iam_member" "cluster_service_account-log_writer" {
count = var.create_service_account ? 1 : 0
project = google_service_account.cluster_service_account[0].project
role = "roles/container.nodeServiceAccount"
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"
member = google_service_account.cluster_service_account[0].member
}

Expand Down
25 changes: 23 additions & 2 deletions modules/private-cluster/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,31 @@ 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-nodeService_account" {
resource "google_project_iam_member" "cluster_service_account-log_writer" {
count = var.create_service_account ? 1 : 0
project = google_service_account.cluster_service_account[0].project
role = "roles/container.nodeServiceAccount"
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"
member = google_service_account.cluster_service_account[0].member
}

Expand Down
25 changes: 23 additions & 2 deletions sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,31 @@ 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-nodeService_account" {
resource "google_project_iam_member" "cluster_service_account-log_writer" {
count = var.create_service_account ? 1 : 0
project = google_service_account.cluster_service_account[0].project
role = "roles/container.nodeServiceAccount"
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"
member = google_service_account.cluster_service_account[0].member
}

Expand Down

0 comments on commit dd53d92

Please sign in to comment.