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

Create least privilege default service account #1416

Closed
jawnsy opened this issue Oct 1, 2022 · 2 comments · Fixed by #1757
Closed

Create least privilege default service account #1416

jawnsy opened this issue Oct 1, 2022 · 2 comments · Fixed by #1757
Labels
enhancement New feature or request good first issue Good for newcomers P2 high priority issues triaged Scoped and ready for work

Comments

@jawnsy
Copy link

jawnsy commented Oct 1, 2022

TL;DR

safer-cluster previously used GKE's recommendations for a minimal service account, but a new "Kubernetes Engine Node Service Account" has since been introduced and it may be preferable to use that instead

Terraform Resources

No response

Detailed design

Change the created service account to use the single roles/container.nodeServiceAccount role, rather than the four roles we are currently using (roles/logging.logWriter, roles/monitoring.metricWriter, roles/monitoring.viewer, roles/stackdriver.resourceMetadata.writer):

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/logging.logWriter"
member = "serviceAccount:${google_service_account.cluster_service_account[0].email}"
}
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 = "serviceAccount:${google_service_account.cluster_service_account[0].email}"
}
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 = "serviceAccount:${google_service_account.cluster_service_account[0].email}"
}
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 = "serviceAccount:${google_service_account.cluster_service_account[0].email}"

Additional information

Changing the defaults would technically be a breaking change, but breaking changes that improve security are usually excluded from compatibility guidelines. If users want to preserve the existing behavior, they can grant the service account necessary permissions. Most clusters should not need to use the node service account for anything, instead relying on workload identity for individual service-scoped permissions

@jawnsy jawnsy added the enhancement New feature or request label Oct 1, 2022
@bharathkkb
Copy link
Member

Thanks for the suggestion. This is definitely something we can add and it would help maintainability too as we don't need to keep track of newer roles as the product evolves.

@bharathkkb bharathkkb added good first issue Good for newcomers triaged Scoped and ready for work P2 high priority issues labels Oct 6, 2022
@jawnsy
Copy link
Author

jawnsy commented Oct 8, 2022

@bharathkkb I'm happy to open a PR for this - are you okay with the approach of a "breaking" change of removing the now-unnecessary roles?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers P2 high priority issues triaged Scoped and ready for work
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants