-
Notifications
You must be signed in to change notification settings - Fork 5
Add modular foundational support for GCP #36
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
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
b114965
adding modular onboarding module
haresh-suresh 86f73ff
fix var refns
haresh-suresh 7321bbe
adding modular onboarding example
haresh-suresh c40389c
adding config posture module for modular onboarding
haresh-suresh 4e8d930
updating README
haresh-suresh d217b53
fix role naming & version metadata
haresh-suresh 9ddecae
updating examples for onboarding & cspm org
haresh-suresh 3f53ac9
cleanup foundational READMEs
haresh-suresh c910664
use external_id datasource
haresh-suresh a0cb312
update README
haresh-suresh 8a0eea2
remove mgmt_group_ids in cspm module
haresh-suresh 7d9e1d7
bump sysdig provider version to be consistent & have latest datasources
haresh-suresh d18b821
updating examples
haresh-suresh 299dacf
update example
haresh-suresh 657ad41
add explicit dependency
haresh-suresh 1189524
switch to svc principal key for onboarding
haresh-suresh 420bf8b
rm unnecessary binding in config posture
haresh-suresh 22a885a
update READMEs and var defns
haresh-suresh 59e13be
rm management group ids in config posture
haresh-suresh 09b630e
Merge branch 'master' into add-modular-foundational
haresh-suresh 16ed163
set right sysdig versions
haresh-suresh 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # GCP Config Posture Module | ||
|
|
||
| This module will deploy Config Posture resources in GCP for a single project, or for a GCP Organization. | ||
| The Config Posture module serves the following functions: | ||
| - retrieving inventory for single project, or for all projects within an Organization. | ||
| - retrieving organization metadata in the case of organizational onboarding within GCP Organization. | ||
|
|
||
| If instrumenting a project, the following resources will be created: | ||
| - All the necessary `Service Accounts` and `Policies` to enable the Config posture operation at the project level | ||
| - A `Workload Identity Pool`, `Provider` and added custom role permissions to the `Service Account`, to allow Sysdig to authenticate to GCP on your behalf to validate resources. | ||
| - A cloud account component in the Sysdig Backend, associated with the GCP project and with the required component to serve the config posture functions. | ||
|
|
||
| If instrumenting an Organziation, the following resources will be created: | ||
| - All the necessary `Service Accounts` and `Policies` to enable the Config Posture operation at the organization level | ||
| - A `Workload Identity Pool`, `Provider` and added custom role permissions to the `Service Account`, to allow Sysdig to authenticate to GCP on your behalf to validate resources. | ||
| - A cloud account component in the Sysdig Backend, associated with the GCP project and with the required component to serve the config posture functions. | ||
|
|
||
| Note: | ||
| - The outputs from the foundational module, such as `sysdig_secure_account_id` are needed as inputs to the other features/integrations modules for subsequent modular installs. | ||
|
|
||
| <!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
| ## Requirements | ||
|
|
||
| | Name | Version | | ||
| |------|-----------| | ||
| | <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 | | ||
| | <a name="requirement_google"></a> [google](#requirement\_google) | >= 4.21.0 | | ||
| | <a name="requirement_sysdig"></a> [sysdig](#requirement\_sysdig) | >= 1.34.0 | | ||
|
|
||
| ## Providers | ||
|
|
||
| | Name | Version | | ||
| |------|---------| | ||
| | <a name="provider_google"></a> [google](#provider\_google) | 5.0.0 | | ||
| | <a name="provider_random"></a> [random](#provider\_random) | >= 3.1 | | ||
|
|
||
| ## Modules | ||
|
|
||
| No modules. | ||
|
|
||
| ## Resources | ||
|
|
||
| | [google_service_account.posture_auth](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/service_account) | resource | | ||
| | [google_organization.org](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/organization) | data source | | ||
| | [sysdig_secure_trusted_cloud_identity.trusted_identity](https://registry.terraform.io/providers/sysdiglabs/sysdig/latest/docs/data-sources/secure_trusted_cloud_identity) | data source | | ||
| | [google_project.project](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/project) | data source | | ||
| | [sysdig_secure_tenant_external_id](https://registry.terraform.io/providers/sysdiglabs/sysdig/latest/docs/data-sources/secure_tenant_external_id) | data source | | ||
| | [random_id.suffix](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id) | resource | | ||
| | [google_iam_workload_identity_pool.posture_auth_pool](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/iam_workload_identity_pool) | resource | | ||
| | [google_iam_workload_identity_pool_provider.posture_auth_pool_provider](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/iam_workload_identity_pool_provider) | resource | | ||
| | [google_project_iam_member.cspm](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/google_project_iam#google_project_iam_member) | resource | | ||
| | [google_service_account_iam_member.custom_posture_auth](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/google_service_account_iam#google_service_account_iam_member) | resource | | ||
| | [google_organization_iam_member.cspm](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/google_organization_iam#google_organization_iam_member) | resource | | ||
| | [sysdig_secure_cloud_auth_account_component.google_service_principal](https://registry.terraform.io/providers/sysdiglabs/sysdig/latest/docs/resources/secure_cloud_auth_account_component) | resource | | ||
|
|
||
haresh-suresh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ## Inputs | ||
|
|
||
| | Name | Description | Type | Default | Required | | ||
| |------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|------|-----------------------------------------------|:--------:| | ||
| | <a name="input_is_organizational"></a> [is\_organizational](#input\_is\_organizational) | (Optional) Set this field to 'true' to deploy secure-for-cloud to a GCP Organization. | `bool` | `false` | no | | ||
| | <a name="input_organization_domain"></a> [organization\_domain](#input\_organization\_domain) | Organization domain. e.g. sysdig.com | `string` | `""` | no | | ||
| | <a name="input_project_id"></a> [project\_id](#input\_project\_id) | (Required) Target Project identifier provided by the customer | `string` | n/a | yes | | ||
| | <a name="input_suffix"></a> [suffix](#input\_suffix) | (Optional) Suffix to uniquely identify resources during multiple installs. If not provided, random value is autogenerated | `string` | `null` | no | | ||
| | <a name="input_sysdig_secure_account_id"></a> [sysdig\_secure\_account\_id](#input\_sysdig\_secure\_account\_id) | (Required) The GUID of the management project or single project per sysdig representation | `string` | n/a | yes | | ||
|
|
||
| ## Outputs | ||
|
|
||
| | Name | Description | | ||
| |--------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------| | ||
| | <a name="output_service_principal_component_id"></a> [service\_principal\_component\_id](#output\_service\_principal\_component\_id) | The component id of the config posture service principal with its WIF metadata | | ||
| <!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
|
|
||
| ## Authors | ||
|
|
||
| Module is maintained by [Sysdig](https://sysdig.com). | ||
|
|
||
| ## License | ||
|
|
||
| Apache 2 Licensed. See LICENSE for full details. | ||
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,105 @@ | ||
| #------------------------------------------------------------------# | ||
| # Fetch and compute required data for Workload Identity Federation # | ||
| #------------------------------------------------------------------# | ||
|
|
||
| data "sysdig_secure_trusted_cloud_identity" "trusted_identity" { | ||
| cloud_provider = "gcp" | ||
| } | ||
|
|
||
| data "sysdig_secure_tenant_external_id" "external_id" {} | ||
|
|
||
| data "google_project" "project" { | ||
| project_id = var.project_id | ||
| } | ||
|
|
||
| // suffix to uniquely identify WIF pool and provider during multiple installs. If suffix value is not provided, this will generate a random value. | ||
| resource "random_id" "suffix" { | ||
| count = var.suffix == null ? 1 : 0 | ||
| byte_length = 3 | ||
| } | ||
|
|
||
| locals { | ||
| suffix = var.suffix == null ? random_id.suffix[0].hex : var.suffix | ||
| } | ||
|
|
||
| resource "google_service_account" "posture_auth" { | ||
| # service account name cannot be longer than 30 characters | ||
| account_id = "sysdig-posture-${local.suffix}" | ||
| display_name = "Sysdig Config Posture Auth Service Account" | ||
| project = var.project_id | ||
| } | ||
|
|
||
| #------------------------------------------------------------# | ||
| # Configure Workload Identity Federation for auth # | ||
| # See https://cloud.google.com/iam/docs/access-resources-aws # | ||
| #------------------------------------------------------------# | ||
|
|
||
| resource "google_iam_workload_identity_pool" "posture_auth_pool" { | ||
| project = var.project_id | ||
| workload_identity_pool_id = "sysdig-secure-posture-${local.suffix}" | ||
| } | ||
|
|
||
| resource "google_iam_workload_identity_pool_provider" "posture_auth_pool_provider" { | ||
| project = var.project_id | ||
| workload_identity_pool_id = google_iam_workload_identity_pool.posture_auth_pool.workload_identity_pool_id | ||
| workload_identity_pool_provider_id = "sysdig-posture-${local.suffix}" | ||
| display_name = "Sysdigcloud config posture auth" | ||
| description = "AWS based pool provider for Sysdig Secure Data Config Posture resources" | ||
| disabled = false | ||
|
|
||
| attribute_condition = "attribute.aws_role==\"arn:aws:sts::${data.sysdig_secure_trusted_cloud_identity.trusted_identity.aws_account_id}:assumed-role/${data.sysdig_secure_trusted_cloud_identity.trusted_identity.aws_role_name}/${data.sysdig_secure_tenant_external_id.external_id.external_id}\"" | ||
|
|
||
| attribute_mapping = { | ||
| "google.subject" = "assertion.arn", | ||
| "attribute.aws_role" = "assertion.arn" | ||
| } | ||
|
|
||
| aws { | ||
| account_id = data.sysdig_secure_trusted_cloud_identity.trusted_identity.aws_account_id | ||
| } | ||
| } | ||
|
|
||
| #--------------------------------------------------------------------------------------------- | ||
| # role permissions for CSPM (GCP Predefined Roles for Sysdig Cloud Secure Posture Management) | ||
| #--------------------------------------------------------------------------------------------- | ||
| resource "google_project_iam_member" "cspm" { | ||
| for_each = var.is_organizational ? [] : toset(["roles/cloudasset.viewer", "roles/iam.workloadIdentityUser", "roles/logging.viewer", "roles/cloudfunctions.viewer", "roles/cloudbuild.builds.viewer", "roles/orgpolicy.policyViewer"]) | ||
|
|
||
| project = var.project_id | ||
| role = each.key | ||
| member = "serviceAccount:${google_service_account.posture_auth.email}" | ||
| } | ||
|
|
||
| # attaching WIF as a member to the service account for auth | ||
| resource "google_service_account_iam_member" "custom_posture_auth" { | ||
| service_account_id = google_service_account.posture_auth.name | ||
| role = "roles/iam.workloadIdentityUser" | ||
| member = "principalSet://iam.googleapis.com/projects/${data.google_project.project.number}/locations/global/workloadIdentityPools/${google_iam_workload_identity_pool.posture_auth_pool.workload_identity_pool_id}/attribute.aws_role/arn:aws:sts::${data.sysdig_secure_trusted_cloud_identity.trusted_identity.aws_account_id}:assumed-role/${data.sysdig_secure_trusted_cloud_identity.trusted_identity.aws_role_name}/${data.sysdig_secure_tenant_external_id.external_id.external_id}" | ||
| } | ||
|
|
||
| #-------------------------------------------------------------------------------------------------------------- | ||
| # Call Sysdig Backend to add the service-principal integration for Config Posture to the Sysdig Cloud Account | ||
| #-------------------------------------------------------------------------------------------------------------- | ||
| resource "sysdig_secure_cloud_auth_account_component" "google_service_principal" { | ||
| account_id = var.sysdig_secure_account_id | ||
| type = "COMPONENT_SERVICE_PRINCIPAL" | ||
| instance = "secure-posture" | ||
| version = "v0.1.0" | ||
| service_principal_metadata = jsonencode({ | ||
| gcp = { | ||
| workload_identity_federation = { | ||
| pool_id = google_iam_workload_identity_pool.posture_auth_pool.workload_identity_pool_id | ||
| pool_provider_id = google_iam_workload_identity_pool_provider.posture_auth_pool_provider.workload_identity_pool_provider_id | ||
| project_number = data.google_project.project.number | ||
| } | ||
| email = google_service_account.posture_auth.email | ||
| } | ||
| }) | ||
| depends_on = [ | ||
haresh-suresh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| google_service_account.posture_auth, | ||
| google_iam_workload_identity_pool.posture_auth_pool, | ||
| google_iam_workload_identity_pool_provider.posture_auth_pool_provider, | ||
| google_project_iam_member.cspm, | ||
| google_service_account_iam_member.custom_posture_auth | ||
| ] | ||
| } | ||
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,23 @@ | ||
| #--------------# | ||
| # Organization # | ||
| #--------------# | ||
|
|
||
| data "google_organization" "org" { | ||
| count = var.is_organizational ? 1 : 0 | ||
| domain = var.organization_domain | ||
| } | ||
|
|
||
| ################################################### | ||
| # Setup Service Account permissions | ||
| ################################################### | ||
|
|
||
| #--------------------------------------------------------------------------------------------- | ||
| # role permissions for CSPM (GCP Predefined Roles for Sysdig Cloud Secure Posture Management) | ||
| #--------------------------------------------------------------------------------------------- | ||
| resource "google_organization_iam_member" "cspm" { | ||
| for_each = var.is_organizational ? toset(["roles/cloudasset.viewer", "roles/iam.workloadIdentityUser", "roles/logging.viewer", "roles/cloudfunctions.viewer", "roles/cloudbuild.builds.viewer", "roles/orgpolicy.policyViewer"]) : [] | ||
|
|
||
| org_id = data.google_organization.org[0].org_id | ||
| role = each.key | ||
| member = "serviceAccount:${google_service_account.posture_auth.email}" | ||
| } |
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,5 @@ | ||
| output "service_principal_component_id" { | ||
| value = "${sysdig_secure_cloud_auth_account_component.google_service_principal.type}/${sysdig_secure_cloud_auth_account_component.google_service_principal.instance}" | ||
| description = "Component identifier of Service Principal created in Sysdig Backend for Config Posture" | ||
| depends_on = [sysdig_secure_cloud_auth_account_component.google_service_principal] | ||
| } |
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,27 @@ | ||
| variable "project_id" { | ||
| type = string | ||
| description = "(Required) Target Project identifier provided by the customer" | ||
| } | ||
|
|
||
| variable "is_organizational" { | ||
| description = "(Optional) Set this field to 'true' to deploy secure-for-cloud to a GCP Organization." | ||
| type = bool | ||
| default = false | ||
| } | ||
|
|
||
| variable "organization_domain" { | ||
| type = string | ||
| description = "(Optional) Organization domain. e.g. sysdig.com" | ||
| default = "" | ||
| } | ||
|
|
||
| variable "suffix" { | ||
| type = string | ||
| description = "Suffix to uniquely identify resources during multiple installs. If not provided, random value is autogenerated" | ||
| default = null | ||
| } | ||
|
|
||
| variable "sysdig_secure_account_id" { | ||
| type = string | ||
| description = "ID of the Sysdig Cloud Account to enable Config Posture for (in case of organization, ID of the Sysdig management account)" | ||
| } |
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,18 @@ | ||
| terraform { | ||
| required_version = ">= 1.0.0" | ||
|
|
||
| required_providers { | ||
| google = { | ||
| source = "hashicorp/google" | ||
| version = ">= 4.21.0" | ||
| } | ||
| sysdig = { | ||
| source = "sysdiglabs/sysdig" | ||
| version = ">= 1.34.0" | ||
| } | ||
| random = { | ||
| source = "hashicorp/random" | ||
| version = ">= 3.1" | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.