-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: Fleet app operator permissions #1986
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
Merged
apeabody
merged 33 commits into
terraform-google-modules:master
from
hosseingolestani:fleet-app-operator-permissions
Jul 19, 2024
Merged
Changes from 13 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
926c088
added module for fleet app operator permissions
hosseingolestani 59b1c46
some fixes to the module variables
hosseingolestani d5c239b
used make docker_generate_docs to correct module input/output documen…
hosseingolestani fded424
added an empty-string default value for the user and group variables …
hosseingolestani 7f504ed
added an example module to leverage fleet-app-operator-permissions
hosseingolestani 8e77e74
changed app operator principal inputs from <user, group> to <app_oper…
hosseingolestani fd9b18e
added support for 'principal', 'principalSet, and 'serviceAccount' ap…
hosseingolestani 90473bf
simplified the simple_fleet_app_operator_permissions module
hosseingolestani 893360c
simplified simple_fleet_app_operator_permissions a bit more by removi…
hosseingolestani f427027
added basic go test for simple_fleet_app_operator_permissions
hosseingolestani 2afd832
fixed readme and issues raised by make docker_test_lint
hosseingolestani e4f9f05
Merge branch 'master' into fleet-app-operator-permissions
apeabody 67222db
made fleet-app-operator-permissions source path relative in the examp…
hosseingolestani fcfae5a
changed module variables so that users and groups can be provided as …
hosseingolestani 6d9b72b
changed module variable project_id to fleet_project_id
hosseingolestani f7f6809
simplified validation of the role module variable
hosseingolestani 9a654cf
corrected READMEs regarding how to use the fleet-app-operator-permiss…
hosseingolestani 1922a50
added config for a new project intended to be used for fleet-specific…
hosseingolestani 2015fa8
added test fixture for simple_fleet_app_operator_permissions to provi…
hosseingolestani 7d08847
small variable and validation fixes for fleet-app-operator-permissions
hosseingolestani 7cdfcf0
Merge branch 'master' into fleet-app-operator-permissions
hosseingolestani 4a4ee3e
made app operator an input to the example module and set it in the te…
hosseingolestani 838e7de
Merge branch 'master' into fleet-app-operator-permissions
hosseingolestani 51a2e1b
put back app operator service account in simple_fleet_app_operator_pe…
hosseingolestani 4bc10fb
added roles to gke-project-fleet to permit creation of fleet scope an…
hosseingolestani 622b266
defined IAM bindings for gke-project-fleet
hosseingolestani c1ffbee
broke down log view condition check in TestSimpleFleetAppOperatorPerm…
hosseingolestani 0f9e63d
Merge branch 'master' into fleet-app-operator-permissions
hosseingolestani 3940b0a
empty commit to run the tests
hosseingolestani 458cdf6
simplified log view access check in TestSimpleFleetAppOperatorPermiss…
hosseingolestani 41d1838
Merge branch 'master' into fleet-app-operator-permissions
apeabody 769d6f9
small fixes for fleet-app-operator-permissionsNotably, use (some part…
hosseingolestani 04119bb
Merge branch 'master' into fleet-app-operator-permissions
apeabody File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Simple App Operator Permissions Setup for a Fleet Scope | ||
|
||
This example illustrates how to create a Fleet Scope for a [team](https://cloud.google.com/kubernetes-engine/fleet-management/docs/team-management) and set up permissions for an app operator in the team. | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| project\_id | The project to which the Fleet belongs. | `string` | n/a | yes | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| project\_id | The project to which the Fleet belongs. | | ||
| wait | An output (Fleet Scope RBAC Role Binding ID) to use when you want to depend on granting permissions finishing. | | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
|
||
To provision this example, run the following from within this directory: | ||
- `terraform init` to get the plugins | ||
- `terraform plan` to see the infrastructure plan | ||
- `terraform apply` to apply the infrastructure build | ||
- `terraform destroy` to destroy the built infrastructure | ||
|
||
Example: | ||
|
||
``` | ||
terraform init | ||
|
||
terraform apply \ | ||
-var project_id="${PROJECT}" \ | ||
-var app_operator_team="frontend-team" \ | ||
-var app_operator_email="person@company.com" \ | ||
-var app_operator_role="EDIT" | ||
``` | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright 2024 Google LLC | ||
* | ||
* 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. | ||
*/ | ||
|
||
provider "google" { | ||
project = var.project_id | ||
} | ||
|
||
# Create a Service Account, which can be used as an app operator. | ||
resource "google_service_account" "service_account" { | ||
account_id = "app-operator-id" | ||
display_name = "Test App Operator Service Account" | ||
} | ||
|
||
# Create a Fleet Scope for the app operator's team. | ||
resource "google_gke_hub_scope" "scope" { | ||
scope_id = "app-operator-team" | ||
} | ||
|
||
# Grant permissions to the app operator to work with the Fleet Scope. | ||
module "permissions" { | ||
source = "../../modules/fleet-app-operator-permissions" | ||
|
||
project_id = var.project_id | ||
scope_id = google_gke_hub_scope.scope.scope_id | ||
app_operator_name = google_service_account.service_account.email | ||
is_user_app_operator = true | ||
role = "VIEW" | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Copyright 2024 Google LLC | ||
* | ||
* 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. | ||
*/ | ||
|
||
output "project_id" { | ||
description = "The project to which the Fleet belongs." | ||
value = var.project_id | ||
} | ||
|
||
output "wait" { | ||
description = "An output (Fleet Scope RBAC Role Binding ID) to use when you want to depend on granting permissions finishing." | ||
value = module.permissions.wait | ||
} | ||
|
21 changes: 21 additions & 0 deletions
21
examples/simple_fleet_app_operator_permissions/variables.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Copyright 2024 Google LLC | ||
* | ||
* 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. | ||
*/ | ||
|
||
variable "project_id" { | ||
description = "The project to which the Fleet belongs." | ||
type = string | ||
} | ||
|
31 changes: 31 additions & 0 deletions
31
examples/simple_fleet_app_operator_permissions/versions.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Copyright 2024 Google LLC | ||
* | ||
* 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. | ||
*/ | ||
|
||
terraform { | ||
required_version = ">= 1.2.0" | ||
|
||
required_providers { | ||
google = { | ||
source = "hashicorp/google" | ||
version = ">= 4.81.0" | ||
} | ||
google-beta = { | ||
source = "hashicorp/google-beta" | ||
version = ">= 4.81.0" | ||
} | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Terrafrom Module for Fleet App Operator Permissions | ||
|
||
This module bundles different permissions (IAM and RBAC Role Bindings) required for [Fleet team management](https://cloud.google.com/kubernetes-engine/fleet-management/docs/team-management). A platform admin can use this module to set up permissions for an app operator (user or group) in a team--including usage of Fleet Scopes, Connect Gateway, logging, and metrics--based on predefined roles (VIEW, EDIT, ADMIN). | ||
|
||
## Usage | ||
```tf | ||
Example: | ||
module "fleet_app_operator_permissions" { | ||
source = "terraform-google-modules/kubernetes-engine/google//modules/fleet-app-operator-permissions" | ||
|
||
project_id = "my-project-id" | ||
scope_id = "frontend-team" | ||
app_operator_name = "person@company.com" | ||
is_user_app_operator = true | ||
role = "EDIT" | ||
} | ||
``` | ||
|
||
To deploy this config: | ||
1. Run `terraform apply` | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| app\_operator\_name | The name of the app operator principal for the Fleet Scope, e.g., `person@google.com` (user), `people@google.com` (group), `principal://iam.googleapis.com/locations/global/workforcePools/my-pool/subject/person` (user), `principalSet://iam.googleapis.com/locations/global/workforcePools/my-pool/group/people` (group), `serviceAccount:my-service-account@my-project.iam.gserviceaccount.com` (user). | `string` | n/a | yes | | ||
| is\_user\_app\_operator | Whether the app operator is a user (`true`), or a group (`false`). | `bool` | n/a | yes | | ||
| project\_id | The project to which the Fleet belongs. | `string` | n/a | yes | | ||
| role | The principal role for the Fleet Scope (`VIEW`/`EDIT`/`ADMIN`). | `string` | n/a | yes | | ||
| scope\_id | The scope for which IAM and RBAC role bindings are created. | `string` | n/a | yes | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| project\_id | The project to which the Fleet belongs. | | ||
| wait | An output to use when you want to depend on Scope RBAC Role Binding creation finishing. | | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* Copyright 2024 Google LLC | ||
* | ||
* 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. | ||
*/ | ||
|
||
provider "google" { | ||
project = var.project_id | ||
} | ||
|
||
locals { | ||
principal = ( | ||
startswith(var.app_operator_name, "principal://") || startswith(var.app_operator_name, "principalSet://") ? var.app_operator_name : ( | ||
endswith(var.app_operator_name, "gserviceaccount.com") ? "serviceAccount:${var.app_operator_name}" : ( | ||
var.is_user_app_operator ? "user:${var.app_operator_name}" : "group:${var.app_operator_name}" | ||
))) | ||
project_level_scope_role = { | ||
"VIEW" = "roles/gkehub.scopeViewerProjectLevel" | ||
"EDIT" = "roles/gkehub.scopeEditorProjectLevel" | ||
"ADMIN" = "roles/gkehub.scopeEditorProjectLevel" # Same as EDIT | ||
} | ||
resource_level_scope_role = { | ||
"VIEW" = "roles/gkehub.scopeViewer" | ||
"EDIT" = "roles/gkehub.scopeEditor" | ||
"ADMIN" = "roles/gkehub.scopeAdmin" | ||
} | ||
} | ||
|
||
resource "google_project_iam_binding" "log_view_permissions" { | ||
project = var.project_id | ||
role = "roles/logging.viewAccessor" | ||
members = [ | ||
local.principal, | ||
] | ||
condition { | ||
title = "conditional log view access" | ||
description = "log view access for scope ${var.scope_id}" | ||
expression = "resource.name == \"projects/${var.project_id}/locations/global/buckets/fleet-o11y-scope-${var.scope_id}/views/fleet-o11y-scope-${var.scope_id}-k8s_container\" || resource.name == \"projects/${var.project_id}/locations/global/buckets/fleet-o11y-scope-${var.scope_id}/views/fleet-o11y-scope-${var.scope_id}-k8s_pod\"" | ||
} | ||
} | ||
|
||
resource "google_project_iam_binding" "project_level_scope_permissions" { | ||
project = var.project_id | ||
role = local.project_level_scope_role[var.role] | ||
members = [ | ||
local.principal, | ||
] | ||
} | ||
|
||
resource "google_gke_hub_scope_iam_binding" "resource_level_scope_permissions" { | ||
project = var.project_id | ||
scope_id = var.scope_id | ||
role = local.resource_level_scope_role[var.role] | ||
members = [ | ||
local.principal, | ||
] | ||
} | ||
|
||
resource "random_id" "rand" { | ||
byte_length = 8 | ||
} | ||
|
||
resource "google_gke_hub_scope_rbac_role_binding" "scope_rbac_user_role_binding" { | ||
count = var.is_user_app_operator ? 1 : 0 | ||
scope_rbac_role_binding_id = "tf-${random_id.rand.hex}" | ||
scope_id = var.scope_id | ||
user = var.app_operator_name | ||
role { | ||
predefined_role = var.role | ||
} | ||
} | ||
|
||
resource "google_gke_hub_scope_rbac_role_binding" "scope_rbac_group_role_binding" { | ||
count = var.is_user_app_operator ? 0 : 1 | ||
scope_rbac_role_binding_id = "tf-${random_id.rand.hex}" | ||
scope_id = var.scope_id | ||
group = var.app_operator_name | ||
role { | ||
predefined_role = var.role | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Copyright 2024 Google LLC | ||
* | ||
* 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. | ||
*/ | ||
|
||
output "project_id" { | ||
description = "The project to which the Fleet belongs." | ||
value = var.project_id | ||
} | ||
|
||
output "wait" { | ||
description = "An output to use when you want to depend on Scope RBAC Role Binding creation finishing." | ||
value = var.is_user_app_operator ? google_gke_hub_scope_rbac_role_binding.scope_rbac_user_role_binding[0].scope_rbac_role_binding_id : google_gke_hub_scope_rbac_role_binding.scope_rbac_group_role_binding[0].scope_rbac_role_binding_id | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Copyright 2024 Google LLC | ||
* | ||
* 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. | ||
*/ | ||
|
||
variable "project_id" { | ||
apeabody marked this conversation as resolved.
Show resolved
Hide resolved
|
||
description = "The project to which the Fleet belongs." | ||
type = string | ||
} | ||
|
||
variable "scope_id" { | ||
description = "The scope for which IAM and RBAC role bindings are created." | ||
type = string | ||
} | ||
|
||
variable "app_operator_name" { | ||
description = "The name of the app operator principal for the Fleet Scope, e.g., `person@google.com` (user), `people@google.com` (group), `principal://iam.googleapis.com/locations/global/workforcePools/my-pool/subject/person` (user), `principalSet://iam.googleapis.com/locations/global/workforcePools/my-pool/group/people` (group), `serviceAccount:my-service-account@my-project.iam.gserviceaccount.com` (user)." | ||
type = string | ||
} | ||
|
||
variable "is_user_app_operator" { | ||
apeabody marked this conversation as resolved.
Show resolved
Hide resolved
|
||
description = "Whether the app operator is a user (`true`), or a group (`false`)." | ||
type = bool | ||
} | ||
|
||
variable "role" { | ||
description = "The principal role for the Fleet Scope (`VIEW`/`EDIT`/`ADMIN`)." | ||
type = string | ||
validation { | ||
condition = var.role == "VIEW" || var.role == "EDIT" || var.role == "ADMIN" | ||
apeabody marked this conversation as resolved.
Show resolved
Hide resolved
|
||
error_message = "Allowed values for role are VIEW, EDIT, or ADMIN." | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.