Skip to content

Commit 66e6f78

Browse files
author
iru
authored
feat(vm,cloud-scan): enables organizational use-case (#23)
1 parent 3ee5fc4 commit 66e6f78

File tree

20 files changed

+241
-64
lines changed

20 files changed

+241
-64
lines changed

.github/workflows/ci-pull-request.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
- "secure_config_posture_identity_access/organization/main.tf"
4141
- "secure_threat_detection/single/main.tf"
4242
- "secure_threat_detection/organization/main.tf"
43+
- "agentless-scan/organization/main.tf"
4344
steps:
4445
- name: Set up Go
4546
uses: actions/setup-go@v2

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ deps: $(TFLINT)
1818
lint: $(TFLINT)
1919
$(MAKE) -C modules lint
2020

21+
fmt-check: fmt
2122
fmt:
2223
terraform fmt -check -recursive modules
24+
fmt-fix:
25+
terraform fmt -recursive modules
2326

2427
clean:
2528
find -name ".terraform" -type d | xargs rm -rf

modules/services/agentless-scan/README.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,16 @@ The following resources will be created on each instrumented project:
1212
- For the **Host Data Extraction**: Enable Sysdig to create a disk copy on our SaaS platform, to be able to extract
1313
the data required for security assessment.
1414

15-
![permission-diagram.png](permission-diagram.png)
1615

17-
Organizational support will be added later on.
16+
## Single Project Setup
17+
![permission_diagram_single](./permissions_diagram_single.png)
18+
19+
## Organizational Setup
20+
21+
Set `is_organizatinal=true` together with the `organization_domain=YOUR_DOMAIN`
22+
23+
![permission_diagram_org](./permissions_diagram_org.png)
24+
1825

1926
<br/><br/>
2027

@@ -37,8 +44,8 @@ While on Controlled Availability check with your Sysdig representative.
3744

3845
| Name | Version |
3946
|------|---------|
40-
| <a name="provider_google"></a> [google](#provider\_google) | >= 4.1, < 5.0 |
41-
| <a name="provider_random"></a> [random](#provider\_random) | >= 3.1, < 4.0 |
47+
| <a name="provider_google"></a> [google](#provider\_google) | 4.84.0 |
48+
| <a name="provider_random"></a> [random](#provider\_random) | 3.6.0 |
4249

4350
## Modules
4451

@@ -51,26 +58,33 @@ No modules.
5158
| [google_iam_workload_identity_pool.agentless](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/iam_workload_identity_pool) | resource |
5259
| [google_iam_workload_identity_pool_provider.agentless](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/iam_workload_identity_pool_provider) | resource |
5360
| [google_iam_workload_identity_pool_provider.agentless_gcp](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/iam_workload_identity_pool_provider) | resource |
54-
| [google_project_iam_binding.admin-account-iam](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/project_iam_binding) | resource |
61+
| [google_organization_iam_binding.admin_account_iam](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/organization_iam_binding) | resource |
62+
| [google_organization_iam_binding.controller_custom](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/organization_iam_binding) | resource |
63+
| [google_organization_iam_custom_role.controller](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/organization_iam_custom_role) | resource |
64+
| [google_organization_iam_custom_role.worker_role](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/organization_iam_custom_role) | resource |
65+
| [google_project_iam_binding.admin_account_iam](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/project_iam_binding) | resource |
5566
| [google_project_iam_binding.controller_custom](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/project_iam_binding) | resource |
5667
| [google_project_iam_custom_role.controller](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/project_iam_custom_role) | resource |
5768
| [google_project_iam_custom_role.worker_role](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/project_iam_custom_role) | resource |
5869
| [google_service_account.controller](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/service_account) | resource |
5970
| [google_service_account_iam_member.controller_custom](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/service_account_iam_member) | resource |
6071
| [google_service_account_iam_member.controller_custom_gcp](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/service_account_iam_member) | resource |
6172
| [random_id.suffix](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id) | resource |
73+
| [google_organization.org](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/organization) | data source |
6274
| [google_project.project](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/project) | data source |
6375

6476
## Inputs
6577

6678
| Name | Description | Type | Default | Required |
6779
|------|-------------|------|---------|:--------:|
80+
| <a name="input_is_organizational"></a> [is\_organizational](#input\_is\_organizational) | Optional. Determines whether module must scope whole organization. Otherwise single project will be scoped | `bool` | `false` | no |
81+
| <a name="input_organization_domain"></a> [organization\_domain](#input\_organization\_domain) | Optional. If `is_organizational=true` is set, its mandatory to specify this value, with the GCP Organization domain. e.g. sysdig.com | `string` | `null` | no |
6882
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | GCP Project ID | `string` | n/a | yes |
69-
| <a name="input_worker_identity"></a> [worker\_identity](#input\_worker\_identity) | Sysdig provided Identity for the Service Account in charge of performing the host disk analysis | `string` | n/a | yes |
70-
| <a name="input_role_name"></a> [role\_name](#input\_role\_name) | Name for the Worker Role on the Customer infrastructure | `string` | `"SysdigAgentlessHostRole"` | no |
71-
| <a name="input_suffix"></a> [suffix](#input\_suffix) | By default a random value will be autogenerated.<br/>Suffix word to enable multiple deployments with different naming<br/>(Workload Identity Pool and Providers have a soft deletion on Google Platform that will disallow name re-utilization) | `string` | `null` | no |
83+
| <a name="input_role_name"></a> [role\_name](#input\_role\_name) | Optional. Name for the Worker Role on the Customer infrastructure | `string` | `"SysdigAgentlessHostRole"` | no |
84+
| <a name="input_suffix"></a> [suffix](#input\_suffix) | Optional. Suffix word to enable multiple deployments with different naming<br/>(Workload Identity Pool and Providers have a soft deletion on Google Platform that will disallow name re-utilization)<br/>By default a random value will be autogenerated. | `string` | `null` | no |
7285
| <a name="input_sysdig_account_id"></a> [sysdig\_account\_id](#input\_sysdig\_account\_id) | Sysdig provided GCP Account designated for the host scan.<br/>One of `sysdig_backend` or `sysdig_account_id`must be provided | `string` | `null` | no |
7386
| <a name="input_sysdig_backend"></a> [sysdig\_backend](#input\_sysdig\_backend) | Sysdig provided AWS Account designated for the host scan.<br/>One of `sysdig_backend` or `sysdig_account_id`must be provided | `string` | `null` | no |
87+
| <a name="input_worker_identity"></a> [worker\_identity](#input\_worker\_identity) | Sysdig provided Identity for the Service Account in charge of performing the host disk analysis | `string` | n/a | yes |
7488

7589
## Outputs
7690

modules/services/agentless-scan/controller.tf

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,6 @@ resource "google_service_account" "controller" {
44
display_name = "Sysdig Agentless Host Scanning"
55
}
66

7-
resource "google_project_iam_custom_role" "controller" {
8-
project = var.project_id
9-
role_id = "${var.role_name}Controller${title(local.suffix)}"
10-
title = "Role for Sysdig Agentless Host Workers"
11-
permissions = [
12-
# networks
13-
"compute.networks.list",
14-
"compute.networks.get",
15-
# instances
16-
"compute.instances.list",
17-
"compute.instances.get",
18-
# disks
19-
"compute.disks.list",
20-
"compute.disks.get",
21-
# workload identity federation
22-
"iam.serviceAccounts.getAccessToken",
23-
]
24-
}
25-
26-
resource "google_project_iam_binding" "controller_custom" {
27-
project = var.project_id
28-
role = google_project_iam_custom_role.controller.id
29-
30-
members = [
31-
"serviceAccount:${google_service_account.controller.email}",
32-
]
33-
}
34-
357
resource "google_iam_workload_identity_pool" "agentless" {
368
workload_identity_pool_id = "sysdig-ahs-${local.suffix}"
379
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
resource "google_organization_iam_custom_role" "controller" {
2+
count = local.is_organizational ? 1 : 0
3+
4+
org_id = data.google_organization.org[0].org_id
5+
role_id = "${var.role_name}Discovery${title(local.suffix)}"
6+
title = "${var.role_name}, for Host Discovery"
7+
permissions = local.host_discovery_permissions
8+
}
9+
10+
resource "google_organization_iam_binding" "controller_custom" {
11+
count = local.is_organizational ? 1 : 0
12+
13+
org_id = data.google_organization.org[0].org_id
14+
role = google_organization_iam_custom_role.controller[0].id
15+
members = [
16+
"serviceAccount:${google_service_account.controller.email}",
17+
]
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
resource "google_project_iam_custom_role" "controller" {
2+
count = local.is_organizational ? 0 : 1
3+
4+
project = var.project_id
5+
role_id = "${var.role_name}Discovery${title(local.suffix)}"
6+
title = "${var.role_name}, for Host Discovery"
7+
permissions = local.host_discovery_permissions
8+
}
9+
10+
resource "google_project_iam_binding" "controller_custom" {
11+
count = local.is_organizational ? 0 : 1
12+
13+
project = var.project_id
14+
role = google_project_iam_custom_role.controller[0].id
15+
members = [
16+
"serviceAccount:${google_service_account.controller.email}",
17+
]
18+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
data "google_project" "project" {
22
project_id = var.project_id
3+
}
4+
5+
data "google_organization" "org" {
6+
count = local.is_organizational ? 1 : 0
7+
domain = var.organization_domain
38
}

modules/services/agentless-scan/locals.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
locals {
22
suffix = var.suffix == null ? random_id.suffix[0].hex : var.suffix
3+
4+
is_organizational = var.is_organizational && var.organization_domain != null ? true : false
5+
6+
host_discovery_permissions = [
7+
# networks
8+
"compute.networks.list",
9+
"compute.networks.get",
10+
# instances
11+
"compute.instances.list",
12+
"compute.instances.get",
13+
# disks
14+
"compute.disks.list",
15+
"compute.disks.get",
16+
# workload identity federation
17+
"iam.serviceAccounts.getAccessToken",
18+
]
19+
20+
host_scan_permissions = [
21+
# general stuff
22+
"compute.zoneOperations.get",
23+
# disks
24+
"compute.disks.get",
25+
"compute.disks.useReadOnly",
26+
]
327
}
428

529

-121 KB
Binary file not shown.
124 KB
Loading

0 commit comments

Comments
 (0)