Skip to content

Commit

Permalink
Support for Modular Agentless Scanning for Volume access (org) (#10)
Browse files Browse the repository at this point in the history
Change summary:
----------------
- Added the respective tf file for Org onboarding case
- Added test example for scanning (org)
- Updated the self-managed stacksets during org onboarding
  to skip creation with delegated_admin conditional check
- Updated the README
- Added top-level README

Testing:
--------
Validated the changes with org onboarding of actual OU with
mgmt account on AWS.
  • Loading branch information
ravinadhruve10 authored Aug 26, 2024
1 parent b31f8dc commit a505838
Show file tree
Hide file tree
Showing 5 changed files with 404 additions and 15 deletions.
94 changes: 93 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,93 @@
# terraform-aws-secure
# Sysdig Secure for Cloud in AWS

Terraform module that deploys the [**Sysdig Secure for Cloud** stack in **AWS**](https://docs.sysdig.com/en/docs/installation/sysdig-secure-for-cloud/deploy-sysdig-secure-for-cloud-on-aws).
<br/>

With Modular Onboarding, introducing the following design and install structure for `terraform-aws-secure`:

* **[Onboarding]**: It onboards an AWS Account or Organization for the first time to Sysdig Secure for Cloud, and collects
inventory and organizational hierarchy in the given AWS Organization. Managed through `onboarding` module. <br/>

Provides unified threat-detection, compliance, forensics and analysis through these major components:

* **[CSPM](https://docs.sysdig.com/en/docs/sysdig-secure/posture/)**: It evaluates periodically your cloud configuration, using Cloud Custodian, against some benchmarks and returns the results and remediation you need to fix. Managed through `config-posture` module. <br/>

* **[CDR (Cloud Detection and Response)](https://docs.sysdig.com/en/docs/sysdig-secure/insights/)**: It sends periodically activity logs to Sysdig by directing those to a dedicated Event Bridge which will be queried by the Sysdig backend to retrieve the data for log ingestion. Enabled via `event-bridge` integrations module. <br/>

* **[Vulnerability Management Agentless Scanning](https://docs.sysdig.com/en/docs/sysdig-secure/vulnerabilities/)**: It uses disk snapshots to provide highly accurate views of vulnerability risk, access to public exploits, and risk management. Managed through `agentless-scanning` module. <br/>

For other Cloud providers check: [GCP](https://github.com/draios/terraform-google-secure-for-cloud), [Azure](https://github.com/draios/terraform-azurerm-secure-for-cloud)

<br/>

## Modules

### Feature modules

These are independent feature modules which deploy and manage all the required Cloud resources and Sysdig resources
for the respective Sysdig features. They manage both, onboarding a single AWS Account or an AWS Organization to Sysdig Secure for Cloud.

`onboarding`, `config-posture` and `agentless-scanning` are independent feature modules.

### Integrations

The modules under `integrations` are feature agnostic modules which deploy and manage all the required Cloud resources and Sysdig resources
for shared Sysdig integrations. That is to say, one or more Sysdig features can be enabled by installing an integration.

These modules manage both, onboarding a single AWS Account or an AWS Organization to Sysdig Secure for Cloud.

`event-bridge` is an integration module.

## Examples and usage

The modules in this repository can be installed on a single AWS account, or on an entire AWS Organization, or organizational units within the org.

The `test` directory has sample `examples` for all these module deployments i.e under `single_account`, or `organization` sub-folders.

For example, to onboard a single AWS account, with CSPM enabled, with modular installation :-
1. Run the terraform snippet under `test/examples/single_account/onboarding_with_posture.tf` with
the appropriate attribute values populated.
2. This will install the `onboarding` module, which will also create a Cloud Account on Sysdig side.
3. It will also install the `config-posture` module, which will also install cloud resources as well as Sysdig resources
for successfully running CSPM scans.
4. On Sysdig side, you will be able to see the Cloud account onboarded with required components, and CSPM feature installed and enabled.

To run this example you need have your [aws master-account profile configured in CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) and to execute:
```terraform
$ terraform init
$ terraform plan
$ terraform apply
```

Notice that:
* This example will create resources that cost money.<br/>Run `terraform destroy` when you don't need them anymore
* All created resources will be created within the tags `product:sysdig-secure-for-cloud`, within the resource-group `sysdig-secure-for-cloud`

<br/>

## Best practices

For contributing to existing modules or adding new modules, below are some of the best practices recommended :-
* Module names referred and used in deployment snippets should be consistent with those in their source path.
* A module can fall into one of two categories - feature module or an integrations module.
* Every user-facing deployment snippet will,
- at the top level first call the feature module or integrations module from this repo. These modules deploy corresponding cloud resources and Sysdig component resources.
- the corresponding feature resource will be added as the last block and enabled from the module installed component resource reference.
See sample deployment snippets in `test/examples` for more.
* integrations modules are shared and could enable multiple features. Hence, one should be careful with changes to them.
* Module naming follows the pattern with "-" , resource and variable naming follows the pattern with "_".


## Troubleshooting

### Q: I'm not able to see Cloud Identity & Access Management (CIEM) results
A: Make sure you installed both [onboarding](https://github.com/draios/terraform-aws-secure/tree/master/modules/onboarding) and [event-bridge](https://github.com/draios/terraform-aws-secure/tree/master/modules/integrations/event-bridge) modules


## Authors

Module is maintained and supported by [Sysdig](https://sysdig.com).

## License

Apache 2 Licensed. See LICENSE for full details.
5 changes: 5 additions & 0 deletions modules/agentless-scanning/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,18 @@ No modules.
| [aws_cloudformation_stack_set_instance.primary_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_scanning_role](https://registry.terraform.io/providers/sysdiglabs/sysdig/latest/docs/resources/secure_cloud_auth_account_component) | resource |
| [sysdig_secure_cloud_auth_account_component.aws_crypto_key](https://registry.terraform.io/providers/sysdiglabs/sysdig/latest/docs/resources/secure_cloud_auth_account_component) | resource |
| [aws_cloudformation_stack_set.scanning_role_stackset](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudformation_stack_set) | resource |
| [aws_cloudformation_stack_set_instance.scanning_role_stackset_instance](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudformation_stack_set_instance) | resource |
| [aws_cloudformation_stack_set.ou_resources_stackset](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudformation_stack_set) | resource |
| [aws_cloudformation_stack_set_instance.ou_stackset_instance](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudformation_stack_set_instance) | resource |
| [aws_iam_policy_document.scanning](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.scanning_assume_role_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.kms_operations](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 |
| [aws_iam_session_context.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_session_context) | 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 |
| [aws_organizations_organization.org](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/organizations_organization) | data source |

## Inputs

Expand Down
51 changes: 37 additions & 14 deletions modules/agentless-scanning/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ resource "random_id" "suffix" {

# IAM Policy Document used by Stackset roles for the KMS operations policy
data "aws_iam_policy_document" "kms_operations" {
count = !var.auto_create_stackset_roles ? 0 : 1
# skip in org case if delegated_admin is used
count = (var.is_organizational && var.delegated_admin) || !var.auto_create_stackset_roles ? 0 : 1

statement {
sid = "KmsOperationsAccess"
Expand All @@ -84,9 +85,11 @@ data "aws_iam_policy_document" "kms_operations" {
}

resource "aws_iam_role" "scanning_stackset_admin_role" {
count = !var.auto_create_stackset_roles ? 0 : 1
name = "AWSCloudFormationStackSetAdministrationRoleForScanning"
tags = var.tags
# skip resource creation in org case if delegated_admin is used
count = (var.is_organizational && var.delegated_admin) || !var.auto_create_stackset_roles ? 0 : 1

name = "AWSCloudFormationStackSetAdministrationRoleForScanning"
tags = var.tags

assume_role_policy = <<EOF
{
Expand Down Expand Up @@ -118,9 +121,11 @@ EOF
#-----------------------------------------------------------------------------------------------------------------------------------------

resource "aws_iam_role" "scanning_stackset_execution_role" {
count = !var.auto_create_stackset_roles ? 0 : 1
name = "AWSCloudFormationStackSetExecutionRoleForScanning"
tags = var.tags
# skip resource creation in org case if delegated_admin is used
count = (var.is_organizational && var.delegated_admin) || !var.auto_create_stackset_roles ? 0 : 1

name = "AWSCloudFormationStackSetExecutionRoleForScanning"
tags = var.tags

assume_role_policy = <<EOF
{
Expand Down Expand Up @@ -152,6 +157,9 @@ EOF
#-----------------------------------------------------------------------------------------------------------------------------------------

data "aws_iam_policy_document" "scanning" {
# skip in org case if delegated_admin is used
count = var.is_organizational && var.delegated_admin ? 0 : 1

# General read permission, necessary for the discovery phase.
statement {
sid = "Read"
Expand Down Expand Up @@ -314,9 +322,12 @@ data "aws_iam_policy_document" "scanning" {
}

resource "aws_iam_policy" "scanning_policy" {
# skip resource creation in org case if delegated_admin is used
count = var.is_organizational && var.delegated_admin ? 0 : 1

name = local.scanning_resource_name
description = "Grants Sysdig Secure access to volumes and snapshots"
policy = data.aws_iam_policy_document.scanning.json
policy = data.aws_iam_policy_document.scanning[0].json
tags = var.tags
}

Expand All @@ -325,6 +336,8 @@ resource "aws_iam_policy" "scanning_policy" {
#-----------------------------------------------------------------------------------------------------------------------------------------

data "aws_iam_policy_document" "scanning_assume_role_policy" {
# skip resource creation in org case if delegated_admin is used
count = var.is_organizational && var.delegated_admin ? 0 : 1

statement {
sid = "SysdigSecureScanning"
Expand Down Expand Up @@ -354,15 +367,21 @@ data "aws_iam_policy_document" "scanning_assume_role_policy" {
#-----------------------------------------------------------------------------------------------------------------------------------------

resource "aws_iam_role" "scanning_role" {
# skip resource creation in org case if delegated_admin is used
count = var.is_organizational && var.delegated_admin ? 0 : 1

name = local.scanning_resource_name
tags = var.tags
assume_role_policy = data.aws_iam_policy_document.scanning_assume_role_policy.json
assume_role_policy = data.aws_iam_policy_document.scanning_assume_role_policy[0].json
}

resource "aws_iam_policy_attachment" "scanning_policy_attachment" {
# skip resource creation in org case if delegated_admin is used
count = var.is_organizational && var.delegated_admin ? 0 : 1

name = local.scanning_resource_name
roles = [aws_iam_role.scanning_role.name]
policy_arn = aws_iam_policy.scanning_policy.arn
roles = [aws_iam_role.scanning_role[0].name]
policy_arn = aws_iam_policy.scanning_policy[0].arn
}

#-----------------------------------------------------------------------------------------------------------------------------------------
Expand All @@ -374,6 +393,9 @@ resource "aws_iam_policy_attachment" "scanning_policy_attachment" {
#-----------------------------------------------------------------------------------------------------------------------------------------

resource "aws_cloudformation_stack_set" "primary_acc_stackset" {
# skip self managed stacksets in org case if delegated_admin is used
count = var.is_organizational && var.delegated_admin ? 0 : 1

name = join("-", [local.scanning_resource_name, "ScanningKmsPrimaryAcc"])
tags = var.tags
permission_model = "SELF_MANAGED"
Expand Down Expand Up @@ -403,7 +425,7 @@ Resources:
- Sid: "SysdigAllowKms"
Effect: "Allow"
Principal:
AWS: ["arn:aws:iam::${data.sysdig_secure_agentless_scanning_assets.assets.aws.account_id}:root", !Sub "arn:aws:iam::$${AWS::AccountId}:role/${local.scanning_resource_name}"]
AWS: ["arn:aws:iam::${data.sysdig_secure_agentless_scanning_assets.assets.aws.account_id}:root", "arn:aws:iam::${local.account_id}:role/${local.scanning_resource_name}"]
Action:
- "kms:Encrypt"
- "kms:Decrypt"
Expand Down Expand Up @@ -436,10 +458,11 @@ TEMPLATE

# stackset instance to deploy resources for agentless scanning, in all regions of given account
resource "aws_cloudformation_stack_set_instance" "primary_acc_stackset_instance" {
for_each = local.region_set
# skip self managed stackset instances in org case if delegated_admin is used
for_each = var.is_organizational && var.delegated_admin ? toset([]) : local.region_set
region = each.key

stack_set_name = aws_cloudformation_stack_set.primary_acc_stackset.name
stack_set_name = aws_cloudformation_stack_set.primary_acc_stackset[0].name
operation_preferences {
max_concurrent_percentage = 100
failure_tolerance_percentage = var.failure_tolerance_percentage
Expand Down
Loading

0 comments on commit a505838

Please sign in to comment.