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

Add service account to k8s-infra-ii-coop #2262

Closed
wants to merge 1 commit into from
Closed
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
41 changes: 41 additions & 0 deletions infra/gcp/clusters/projects/k8s-infra-ii-sandbox/permissions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

/**
* Copyright 2021 The Kubernetes Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

locals {
project_id = "k8s-infra-ii-sandbox"
}

resource "google_project" "project" {
name = local.project_id
project_id = local.project_id
}

#Create service account
resource "google_service_account" "ii-logs-sa@k8s-infra-ii-sandbox.iam.gserviceaccount.com" {
account_id = "ii-logs-sa-id"
Comment on lines +28 to +29
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
resource "google_service_account" "ii-logs-sa@k8s-infra-ii-sandbox.iam.gserviceaccount.com" {
account_id = "ii-logs-sa-id"
resource "google_service_account" "ii_logs_sa" {
account_id = "ii-logs"

display_name = "ii logs service account"
description = "service-account-to-facilitate-ii-log-analysis"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description = "service-account-to-facilitate-ii-log-analysis"
description = "service account to facilitate log analysis by ii"

project = google_project.project.id
}

resource "google_project_iam_binding" "k8s-infra-ii-sandbox" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/google_project_iam

google_project_iam_binding: Authoritative for a given role. Updates the IAM policy to grant a role to a list of members. Other roles within the IAM policy for the project are preserved.

Are you sure you want this behavior? It means nobody else gets roles/storage.objectViewer in this project except the service account.

What you might want instead want is to say "this service account should get this role, regardless of who else has the role"

Which would be

Suggested change
resource "google_project_iam_binding" "k8s-infra-ii-sandbox" {
resource "google_project_iam_member" "k8s-infra-ii-sandbox" {

project = google_project.project.id
role = "roles/storage.objectViewer"
members = [
"user:ii-logs-sa@k8s-infra-ii-sandbox.iam.gserviceaccount.com",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"user:ii-logs-sa@k8s-infra-ii-sandbox.iam.gserviceaccount.com",
"user:ii-logs@k8s-infra-ii-sandbox.iam.gserviceaccount.com",

]
}