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

NOJIRA: Added possibility to define permissions as an optional module parameter #11

Merged
merged 2 commits into from
Dec 11, 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
5 changes: 2 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ resource "google_project_iam_custom_role" "castai_role" {
role_id = local.custom_role_id
title = "Role to manage GKE cluster via CAST AI"
description = "Role to manage GKE cluster via CAST AI"
permissions = toset(data.castai_gke_user_policies.gke.policy)
permissions = length(var.castai_role_permissions) > 0 ? var.castai_role_permissions : toset(data.castai_gke_user_policies.gke.policy)
andrejatcastai marked this conversation as resolved.
Show resolved Hide resolved
project = var.project_id
stage = "GA"
}
Expand All @@ -28,7 +28,7 @@ resource "google_project_iam_custom_role" "compute_manager_role" {
role_id = "castai.gkeAccess.${substr(sha1(each.key), 0, 8)}.tf"
title = "Role to manage GKE compute resources via CAST AI"
description = "Role to manage GKE compute resources via CAST AI"
permissions = toset(data.castai_gke_user_policies.gke.policy)
permissions = length(var.compute_manager_permissions) > 0 ? var.compute_manager_permissions : toset(data.castai_gke_user_policies.gke.policy)
stage = "GA"
}

Expand All @@ -39,4 +39,3 @@ resource "google_project_iam_binding" "compute_manager_binding" {
role = "projects/${each.key}/roles/castai.gkeAccess.${substr(sha1(each.key), 0, 8)}.tf"
members = compact(["serviceAccount:${local.service_account_email}", var.setup_cloud_proxy_workload_identity ? local.workload_identity_sa : null])
}

89 changes: 89 additions & 0 deletions output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,92 @@ output "service_account_email" {
value = var.create_service_account ? google_service_account.castai_service_account[0].email : ""
}

output "default_compute_manager_permissions" {
value = [
"container.clusters.get",
"container.clusters.update",
"container.certificateSigningRequests.approve",
"compute.instances.get",
"compute.instances.list",
"compute.instances.create",
"compute.instances.start",
"compute.instances.stop",
"compute.instances.delete",
"compute.instances.setLabels",
"compute.instances.setServiceAccount",
"compute.instances.setMetadata",
"compute.instances.setTags",
"compute.instanceGroupManagers.get",
"compute.instanceGroupManagers.update",
"compute.instanceGroups.get",
"compute.networks.use",
"compute.networks.useExternalIp",
"compute.subnetworks.get",
"compute.subnetworks.use",
"compute.subnetworks.useExternalIp",
"compute.addresses.use",
"compute.disks.use",
"compute.disks.create",
"compute.disks.setLabels",
"compute.images.get",
"compute.images.useReadOnly",
"compute.instanceTemplates.get",
"compute.instanceTemplates.list",
"compute.instanceTemplates.create",
"compute.instanceTemplates.delete",
"compute.regionOperations.get",
"compute.zoneOperations.get",
"compute.zones.list",
"compute.zones.get",
"serviceusage.services.list",
"resourcemanager.projects.getIamPolicy",
"compute.targetPools.get",
"compute.targetPools.addInstance",
"compute.targetPools.removeInstance",
"compute.instances.use"]
}

output "default_castai_role_permissions" {
value = [
"container.clusters.get",
"container.clusters.update",
"container.certificateSigningRequests.approve",
"compute.instances.get",
"compute.instances.list",
"compute.instances.create",
"compute.instances.start",
"compute.instances.stop",
"compute.instances.delete",
"compute.instances.setLabels",
"compute.instances.setServiceAccount",
"compute.instances.setMetadata",
"compute.instances.setTags",
"compute.instanceGroupManagers.get",
"compute.instanceGroupManagers.update",
"compute.instanceGroups.get",
"compute.networks.use",
"compute.networks.useExternalIp",
"compute.subnetworks.get",
"compute.subnetworks.use",
"compute.subnetworks.useExternalIp",
"compute.addresses.use",
"compute.disks.use",
"compute.disks.create",
"compute.disks.setLabels",
"compute.images.get",
"compute.images.useReadOnly",
"compute.instanceTemplates.get",
"compute.instanceTemplates.list",
"compute.instanceTemplates.create",
"compute.instanceTemplates.delete",
"compute.regionOperations.get",
"compute.zoneOperations.get",
"compute.zones.list",
"compute.zones.get",
"serviceusage.services.list",
"resourcemanager.projects.getIamPolicy",
"compute.targetPools.get",
"compute.targetPools.addInstance",
"compute.targetPools.removeInstance",
"compute.instances.use"]
}
13 changes: 12 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,20 @@ variable "cloud_proxy_service_account_namespace" {
default = "castai-agent"
}


variable "cloud_proxy_service_account_name" {
type = string
description = "Name of the cloud-proxy Kubernetes Service Account"
default = "castai-cloud-proxy"
}

variable "castai_role_permissions" {
description = "A set of permissions that will be granted to CAST AI role used by central system"
type = list(string)
default = []
}

variable "compute_manager_permissions" {
description = "A set of permissions that will be granted to compute manager role"
type = list(string)
default = []
}
Loading