diff --git a/modules/integrations/event-bridge/README.md b/modules/integrations/event-bridge/README.md new file mode 100644 index 0000000..1eed083 --- /dev/null +++ b/modules/integrations/event-bridge/README.md @@ -0,0 +1,87 @@ +# AWS Event Bridge Module + +This Module creates the resources required to send CloudTrail logs to Sysdig via AWS EventBridge for Log Ingestion. These resources enable Threat Detection in the given single account, or AWS Organization. + +The following resources will be created in each instrumented account through CloudFormation StackSet in provided regions: +- An `EventBridge Rule` that captures all CloudTrail events from the defaul EventBridge Bus +- An `EventBridge Target` that sends these events to an EventBridge Bus is Sysdig's AWS Account +- An `IAM Role` and associated policies that gives the EventBridge Bus in the source account permission to call PutEvent on the EventBridge Bus in Sysdig's Account. + +When run in Organizational mode, this module will be deployed via CloudFormation StackSets that should be created in the management account. They will create the above resources in each account in the organization, +and automatically in any member accounts that are later added to the organization. If a delegated admin account is used, only SERVICE_MANAGED stacksets will be created in the delegated admin account, +responsible for creating the above resources in each account in the organization. + +This module will also deploy an Event Bridge Component in Sysdig Backend for onboarded Sysdig Cloud Account. + + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 1.0.0 | +| [aws](#requirement\_aws) | >= 5.60.0 | +| [sysdig](#requirement\_sysdig) | +| [random](#requirement\_random) | >= 3.1 | + + +## Providers + +| Name | Version | +|------|---------| +| [aws](#provider\_aws) | >= 5.60.0 | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [random_id.suffix](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id) | resource | +| [aws_iam_role.event_bus_invoke_remote_event_bus](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource | +| [aws_iam_role.event_bus_stackset_admin_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource | +| [aws_iam_role.event_bus_stackset_execution_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource | +| [aws_cloudformation_stack_set.single-acc-stackset](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudformation_stack_set) | resource | +| [aws_cloudformation_stack_set_instance.single_acc_stackset_instance](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudformation_stack_set_instance) | resource | +| [sysdig_secure_cloud_auth_account_component.aws_event_bridge](https://registry.terraform.io/providers/sysdiglabs/sysdig/latest/docs/resources/secure_cloud_auth_account_component) | resource | +| [aws_iam_policy_document.cloud_trail_events](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | +| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source | +| [sysdig_secure_cloud_ingestion_assets.assets](https://registry.terraform.io/providers/sysdiglabs/sysdig/latest/docs/data-sources/secure_cloud_ingestion_assets) | 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 | +| [sysdig_secure_tenant_external_id.external_id](https://registry.terraform.io/providers/sysdiglabs/sysdig/latest/docs/data-sources/secure_tenant_external_id) | data source | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [event\_pattern](#input\_event\_pattern) | Event pattern for CloudWatch Event Rule | `string` | `"{\n \"detail-type\": [\n \"AWS API Call via CloudTrail\",\n \"AWS Console Sign In via CloudTrail\",\n \"AWS Service Event via CloudTrail\",\n \"Object Access Tier Changed\",\n \"Object ACL Updated\",\n \"Object Created\",\n \"Object Deleted\",\n \"Object Restore Completed\",\n \"Object Restore Expired\",\n \"Object Restore Initiated\",\n \"Object Storage Class Changed\",\n \"Object Tags Added\",\n \"Object Tags Deleted\",\n \"GuardDuty Finding\"\n ]\n}\n"` | no | +| [failure\_tolerance\_percentage](#input\_failure\_tolerance\_percentage) | The percentage of accounts, per Region, for which stack operations can fail before AWS CloudFormation stops the operation in that Region | `number` | `90` | no | +| [is\_organizational](#input\_is\_organizational) | (Optional) Set this field to 'true' to deploy EventBridge to an AWS Organization (Or specific OUs) | `bool` | `false` | no | +| [mgt\_stackset](#input\_mgt\_stackset) | (Optional) Indicates if the management stackset should be deployed | `bool` | `true` | no | +| [name](#input\_name) | (Optional) Name to be assigned to all child resources. A suffix may be added internally when required. Use default value unless you need to install multiple instances | `string` | `"sysdig-secure-events"` | no | +| [org\_units](#input\_org\_units) | (Optional) List of Organization Unit IDs in which to setup EventBridge. By default, EventBridge will be setup in all accounts within the Organization. This field is ignored if `is_organizational = false` | `set(string)` | `[]` | no | +| [regions](#input\_regions) | (Optional) List of regions in which to setup EventBridge. By default, current region is selected | `set(string)` | `[]` | no | +| [rule\_state](#input\_rule\_state) | State of the rule. When state is ENABLED, the rule is enabled for all events except those delivered by CloudTrail. To also enable the rule for events delivered by CloudTrail, set state to ENABLED\_WITH\_ALL\_CLOUDTRAIL\_MANAGEMENT\_EVENTS. | `string` | `"ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENTS"` | no | +| [stackset\_admin\_role\_arn](#input\_stackset\_admin\_role\_arn) | (Optional) stackset admin role to run SELF\_MANAGED stackset | `string` | `""` | no | +| [stackset\_execution\_role\_name](#input\_stackset\_execution\_role\_name) | (Optional) stackset execution role name to run SELF\_MANAGED stackset | `string` | `""` | no | +| [auto\_create\_stackset\_roles](#input\_auto\_create\_stackset\_roles) | Whether to auto create the custom stackset roles to run SELF_MANAGED stackset | `bool` | `true` | no | +| [tags](#input\_tags) | (Optional) Tags to be attached to all Sysdig resources. | `map(string)` |
{| no | +| [timeout](#input\_timeout) | Default timeout values for create, update, and delete operations | `string` | `"30m"` | no | +| [delegated_admin](#input\_delegated\_admin) | Whether to create the resources using an delegated admin account | `bool` | `false` | no | +| [sysdig\_secure\_account\_id](#input\_sysdig\_secure\_account\_id) | ID of the Sysdig Cloud Account to enable Event Bridge integration for (incase of organization, ID of the Sysdig management account) | `string` | n/a | yes | + +## Outputs + +| Name | Description | +|------|-------------| +| [event\_bridge\_component\_id](#output\_event\_bridge\_component\_id) | Component identifier of Event Bridge integration created in Sysdig Backend for Log Ingestion | + + +## Authors + +Module is maintained by [Sysdig](https://sysdig.com). + +## License + +Apache 2 Licensed. See LICENSE for full details. diff --git a/modules/integrations/event-bridge/main.tf b/modules/integrations/event-bridge/main.tf new file mode 100644 index 0000000..e1d868a --- /dev/null +++ b/modules/integrations/event-bridge/main.tf @@ -0,0 +1,271 @@ +#----------------------------------------------------------------------------------------------------------------------------------------- +# For both Single Account and Organizational installs, resources are created using CloudFormation StackSet. +# For Organizational installs, see organizational.tf. +# +# For single installs, the resources in this file are used to instrument the singleton account, whether it is a management account or a +# member account. (delegated admin account is a noop here for single installs) +# +# For organizational installs, resources in this file get created for management account only. (because service-managed stacksets do not +# include the management account they are create in, even if this account is within the target Organization). +# If a delegated admin account is used (determined via delegated_admin flag), resources will skip creation. This is because we don't want +# to create these stacksets if user provides a delegated admin account instead of management account. +#----------------------------------------------------------------------------------------------------------------------------------------- + +#----------------------------------------------------------------------------------------- +# Fetch the data sources +#----------------------------------------------------------------------------------------- +data "aws_caller_identity" "current" {} + +data "sysdig_secure_cloud_ingestion_assets" "assets" {} + +data "sysdig_secure_trusted_cloud_identity" "trusted_identity" { + cloud_provider = "aws" +} + +data "sysdig_secure_tenant_external_id" "external_id" {} + +#----------------------------------------------------------------------------------------- +# These locals indicate the region list passed. +#----------------------------------------------------------------------------------------- +locals { + region_set = toset(var.regions) +} + +#----------------------------------------------------------------------------------------- +# Generate a unique name for resources using random suffix and account ID hash +#----------------------------------------------------------------------------------------- +locals { + account_id_hash = substr(md5(data.aws_caller_identity.current.account_id), 0, 4) + eb_resource_name = "${var.name}-${random_id.suffix.hex}-${local.account_id_hash}" +} + +#----------------------------------------------------------------------------------------------------------------------- +# A random resource is used to generate unique Event Bridge name suffix for resources. +# This prevents conflicts when recreating an Event Bridge resources with the same name. +#----------------------------------------------------------------------------------------------------------------------- +resource "random_id" "suffix" { + byte_length = 3 +} + +#----------------------------------------------------------------------------------------------------------------------------------------- +# Self-managed stacksets require pair of StackSetAdministrationRole & StackSetExecutionRole IAM roles with self-managed permissions. +# +# If auto_create_stackset_roles is true, terraform will create this IAM Admin role in the source account with permissions to create +# stacksets. If false, and values for stackset Admin role ARN is provided stackset will use it, else AWS will look for +# predefined/default AWSCloudFormationStackSetAdministrationRole. +#----------------------------------------------------------------------------------------------------------------------------------------- + +resource "aws_iam_role" "event_bus_stackset_admin_role" { + count = !var.auto_create_stackset_roles ? 0 : 1 + name = "AWSCloudFormationStackSetAdministrationRoleForEB" + tags = var.tags + + assume_role_policy = <
"product": "sysdig-secure-for-cloud"
}