Skip to content

Commit 4424e2c

Browse files
authored
feat(permissions): Additional resource permissions [ENG-45898] (#3)
* variable for organization access [ENG-45898] * using variable to assign the viewer role or not [ENG-45898] * add permissions to read folder and project names [ENG-45898] * update readme file [ENG-45898] * rename connect_multiple_projects [ENG-45898] * move up the count prop [ENG-45898]
1 parent 1930639 commit 4424e2c

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module "service_account_creation" {
1313
gcp_org_domain = "YOUR_ORGANIZATION_DOMAIN"
1414
# gcp_project_id = "YOUR_PROJECT_ID" # if it's unset, the project by default is used
1515
# drata_role_name = "YOUR_ROLE_NAME" # if it's unset, the default name is DrataReadOnly
16+
# connect_multiple_projects = false # if it's unset, the default value is true
1617
}
1718
1819
output "drata_service_account_key" {
@@ -37,9 +38,10 @@ The following steps demonstrate how to connect GCP in Drata when using this terr
3738
4. Replace `YOUR_ORGANIZATION_DOMAIN` with the GCP organization domain.
3839
5. Replace `YOUR_PROJECT_ID` if the desired project is not the default project in your organization.
3940
6. Replace the given `drata_role_name` if you don't want the role added to be the default: `DrataReadOnly`.
40-
7. Back in your terminal, run `terraform init` to download/update the module.
41-
8. Run `terraform apply` and **IMPORTANT** review the plan output before typing `yes`.
42-
9. If successful, run the command to generate the json key file
41+
7. If you don't wish to connect multiple projects to Drata the `connect_multiple_projects` variable must be `false` otherwise `true` or unset.
42+
8. Back in your terminal, run `terraform init` to download/update the module.
43+
9. Run `terraform apply` and **IMPORTANT** review the plan output before typing `yes`.
44+
10. If successful, run the command to generate the json key file
4345
- `terraform output -raw drata_service_account_key > drata-gcp-private-key.json` .
4446
11. Verify the file has been generated.
4547
12. Go to the GCP connection drawer and select Upload File to upload the `drata-gcp-private-key.json` file.
@@ -68,10 +70,11 @@ No modules.
6870
| Name | Type |
6971
|------|------|
7072
| [google_organization_iam_custom_role.drata_org_role](https://registry.terraform.io/providers/hashicorp/google/5.16.0/docs/resources/organization_iam_custom_role) | resource |
73+
| [google_organization_iam_member.drata_organization_viewer_role](https://registry.terraform.io/providers/hashicorp/google/5.16.0/docs/resources/organization_iam_member) | resource |
7174
| [google_organization_iam_member.organization](https://registry.terraform.io/providers/hashicorp/google/5.16.0/docs/resources/organization_iam_member) | resource |
7275
| [google_project_iam_custom_role.drata_project_role](https://registry.terraform.io/providers/hashicorp/google/5.16.0/docs/resources/project_iam_custom_role) | resource |
7376
| [google_project_iam_member.drata_member_project_role](https://registry.terraform.io/providers/hashicorp/google/5.16.0/docs/resources/project_iam_member) | resource |
74-
| [google_project_iam_member.drata_viewer_role](https://registry.terraform.io/providers/hashicorp/google/5.16.0/docs/resources/project_iam_member) | resource |
77+
| [google_project_iam_member.drata_project_viewer_role](https://registry.terraform.io/providers/hashicorp/google/5.16.0/docs/resources/project_iam_member) | resource |
7578
| [google_project_service.services](https://registry.terraform.io/providers/hashicorp/google/5.16.0/docs/resources/project_service) | resource |
7679
| [google_service_account.drata](https://registry.terraform.io/providers/hashicorp/google/5.16.0/docs/resources/service_account) | resource |
7780
| [google_service_account_key.drata_key](https://registry.terraform.io/providers/hashicorp/google/5.16.0/docs/resources/service_account_key) | resource |
@@ -82,6 +85,7 @@ No modules.
8285

8386
| Name | Description | Type | Default | Required |
8487
|------|-------------|------|---------|:--------:|
88+
| <a name="input_connect_multiple_projects"></a> [connect\_multiple\_projects](#input\_connect\_multiple\_projects) | Tells the service account whether it can see all the projects or not. | `bool` | `true` | no |
8589
| <a name="input_drata_role_name"></a> [drata\_role\_name](#input\_drata\_role\_name) | Role name. | `string` | `"DrataReadOnly"` | no |
8690
| <a name="input_gcp_org_domain"></a> [gcp\_org\_domain](#input\_gcp\_org\_domain) | GCP Organization domain. | `string` | n/a | yes |
8791
| <a name="input_gcp_project_id"></a> [gcp\_project\_id](#input\_gcp\_project\_id) | Project identifier of the gcp organization. If it is not provided, the provider project is used. | `string` | `null` | no |

main.tf

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ resource "google_organization_iam_custom_role" "drata_org_role" {
3535
role_id = "${var.drata_role_name}OrganizationalRole"
3636
title = "Drata Read-Only Organizational Role"
3737
description = "Service Account with read-only access for Drata Autopilot to get organizational IAM data"
38-
permissions = ["resourcemanager.organizations.getIamPolicy", "storage.buckets.get", "storage.buckets.getIamPolicy"]
38+
permissions = ["resourcemanager.organizations.getIamPolicy", "storage.buckets.get", "storage.buckets.getIamPolicy", "resourcemanager.folders.get", "resourcemanager.organizations.get"]
3939
org_id = data.google_organization.gcp_organization.org_id
4040
}
4141

@@ -52,21 +52,28 @@ resource "google_service_account_key" "drata_key" {
5252
}
5353

5454
# assignation of roles to the service account
55-
# project role
55+
# project custom role
5656
resource "google_project_iam_member" "drata_member_project_role" {
5757
project = local.PROJECT_ID
5858
role = google_project_iam_custom_role.drata_project_role.name
5959
member = "serviceAccount:${google_service_account.drata.email}"
6060
}
61-
# organization role
61+
# organization custom role
6262
resource "google_organization_iam_member" "organization" {
6363
org_id = data.google_organization.gcp_organization.org_id
6464
role = google_organization_iam_custom_role.drata_org_role.name
6565
member = "serviceAccount:${google_service_account.drata.email}"
6666
}
67-
# viewer role
68-
resource "google_project_iam_member" "drata_viewer_role" {
67+
# project viewer role
68+
resource "google_project_iam_member" "drata_project_viewer_role" {
6969
project = local.PROJECT_ID
7070
role = "roles/viewer"
7171
member = "serviceAccount:${google_service_account.drata.email}"
7272
}
73+
# organization viewer role
74+
resource "google_organization_iam_member" "drata_organization_viewer_role" {
75+
count = var.connect_multiple_projects ? 1 : 0
76+
org_id = data.google_organization.gcp_organization.org_id
77+
role = "roles/viewer"
78+
member = "serviceAccount:${google_service_account.drata.email}"
79+
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ variable "gcp_org_domain" {
99
description = "GCP Organization domain."
1010
}
1111

12+
variable "connect_multiple_projects" {
13+
type = bool
14+
description = "Tells the service account whether it can see all the projects or not."
15+
default = true
16+
}
17+
1218
variable "gcp_services" {
1319
type = list(string)
1420
default = ["cloudresourcemanager.googleapis.com", "compute.googleapis.com", "admin.googleapis.com", "sqladmin.googleapis.com", "monitoring.googleapis.com"]

0 commit comments

Comments
 (0)