Skip to content

Commit f963830

Browse files
author
iru
authored
feat: enable ecr/ecs scanning optionals (#61)
1 parent 945e5d5 commit f963830

File tree

19 files changed

+207
-92
lines changed

19 files changed

+207
-92
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ repos:
1111
# create a custom terraform validate for the examples, as launching the validation in the root dir won't work and give
1212
# "Error: Provider configuration not present" error
1313
# https://github.com/hashicorp/terraform/issues/21416
14+
# https://discuss.hashicorp.com/t/how-to-run-terraform-validate-on-a-module-that-is-supplied-the-providers-via-an-alias/34664/2
1415
- repo: local
1516
hooks:
1617
- id: terraform_validate

.pre-commit-terraform-validate-examples.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
# ensure errexit + failfast
44
set -o errexit
55

6+
# cleanup
7+
bash ./resources/terraform-clean.sh
8+
69
for dir in examples*/*
710
do
811
echo validating example [$dir]
912
cd $dir
10-
terraform init --upgrade
13+
terraform init
1114
terraform validate
1215
cd ../..
1316
done

CONTRIBUTE.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
- [ ] **input/output** variables have been modified?
4040
- [ ] terraform-docs has been updated accordingly
4141
- [ ] if these inputs are mandatory, they've been changed on
42-
- [ ] examples
43-
- [ ] testing use-cases
44-
- [ ] snippets on README's
45-
- [ ] snippets on Secure Platform onboarding
42+
- [ ] examples, examples-internal and use-cases are updated accordingly
43+
- [ ] tests are updated accordingly
44+
- [ ] snippets on README's are updated accordingly
45+
- [ ] snippets on Secure Platform onboarding are updated accordingly
4646
- [ ] had any problems developing this PR? add it to the readme **troubleshooting** list! may come handy to someone
4747

4848

@@ -60,12 +60,7 @@ We're using **pre-commit** | https://pre-commit.com
6060
```
6161

6262
- If pre-commit fails on Github but not on your local, try cleaning-up `terraform` files with
63-
```bash
64-
-- resources/terraform-clean.sh
65-
$ find . -name ".terraform" -exec rm -fr {} \;
66-
$ find . -name "terraform.tfstate*" -exec rm -fr {} \;
67-
$ find . -name ".terraform.lock.hcl*" -exec rm -fr {} \;
68-
```
63+
`./resources/terraform-clean.sh` script
6964

7065

7166
## 2. Check::Integration tests

examples/organizational/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ Notice that:
119119
| <a name="input_cloudtrail_sns_arn"></a> [cloudtrail\_sns\_arn](#input\_cloudtrail\_sns\_arn) | ARN of a pre-existing cloudtrail\_sns. Used together with `cloudtrail_sns_arn`, `cloudtrail_s3_arn`. If it does not exist, it will be inferred from created cloudtrail. Providing an ARN requires permisision to SNS:Subscribe, check ./modules/infrastructure/cloudtrail/sns\_permissions.tf block | `string` | `"create"` | no |
120120
| <a name="input_connector_ecs_task_role_name"></a> [connector\_ecs\_task\_role\_name](#input\_connector\_ecs\_task\_role\_name) | Name for the ecs task role. This is only required to resolve cyclic dependency with organizational approach | `string` | `"organizational-ECSTaskRole"` | no |
121121
| <a name="input_deploy_benchmark"></a> [deploy\_benchmark](#input\_deploy\_benchmark) | Whether to deploy or not the cloud benchmarking | `bool` | `true` | no |
122+
| <a name="input_deploy_image_scanning_ecr"></a> [deploy\_image\_scanning\_ecr](#input\_deploy\_image\_scanning\_ecr) | true/false whether to deploy the image scanning on ECR pushed images | `bool` | `true` | no |
123+
| <a name="input_deploy_image_scanning_ecs"></a> [deploy\_image\_scanning\_ecs](#input\_deploy\_image\_scanning\_ecs) | true/false whether to deploy the image scanning on ECS running images | `bool` | `true` | no |
122124
| <a name="input_ecs_cluster_name"></a> [ecs\_cluster\_name](#input\_ecs\_cluster\_name) | Name of a pre-existing ECS (elastic container service) cluster. If defaulted, a new ECS cluster/VPC/Security Group will be created. For both options, ECS location will/must be within the `sysdig_secure_for_cloud_member_account_id` parameter accountID | `string` | `"create"` | no |
123125
| <a name="input_ecs_vpc_id"></a> [ecs\_vpc\_id](#input\_ecs\_vpc\_id) | ID of the VPC where the workload is to be deployed. Defaulted to be created when `ecs_cluster_name is not provided.` | `string` | `"create"` | no |
124126
| <a name="input_ecs_vpc_region_azs"></a> [ecs\_vpc\_region\_azs](#input\_ecs\_vpc\_region\_azs) | List of Availability Zones for ECS VPC creation. e.g.: ["apne1-az1", "apne1-az2"]. If defaulted, two of the default 'aws\_availability\_zones' datasource will be taken | `list(string)` | `[]` | no |

examples/organizational/main.tf

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ module "ssm" {
3737
}
3838

3939

40-
#
40+
#-------------------------------------
4141
# cloud-connector
42-
#
42+
#-------------------------------------
4343
module "codebuild" {
44+
count = var.deploy_image_scanning_ecr || var.deploy_image_scanning_ecs ? 1 : 0
45+
4446
providers = {
4547
aws = aws.member
4648
}
@@ -60,8 +62,8 @@ module "cloud_connector" {
6062
sysdig_secure_endpoint = var.sysdig_secure_endpoint
6163
secure_api_token_secret_name = module.ssm.secure_api_token_secret_name
6264

63-
build_project_arn = module.codebuild.project_arn
64-
build_project_name = module.codebuild.project_name
65+
deploy_image_scanning_ecr = var.deploy_image_scanning_ecr
66+
deploy_image_scanning_ecs = var.deploy_image_scanning_ecs
6567

6668
is_organizational = true
6769
organizational_config = {
@@ -70,6 +72,9 @@ module "cloud_connector" {
7072
connector_ecs_task_role_name = aws_iam_role.connector_ecs_task.name
7173
}
7274

75+
build_project_arn = length(module.codebuild) == 1 ? module.codebuild[0].project_arn : "na"
76+
build_project_name = length(module.codebuild) == 1 ? module.codebuild[0].project_name : "na"
77+
7378
sns_topic_arn = local.cloudtrail_sns_arn
7479

7580
ecs_cluster_name = local.ecs_cluster_name

examples/organizational/variables.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,23 @@ variable "cloudtrail_kms_enable" {
5858
description = "true/false whether cloudtrail delivered events to S3 should persist encrypted"
5959
}
6060

61+
#
62+
# scanning configuration
63+
#
64+
65+
variable "deploy_image_scanning_ecr" {
66+
type = bool
67+
description = "true/false whether to deploy the image scanning on ECR pushed images"
68+
default = true
69+
}
70+
71+
variable "deploy_image_scanning_ecs" {
72+
type = bool
73+
description = "true/false whether to deploy the image scanning on ECS running images"
74+
default = true
75+
}
76+
77+
6178
#
6279
# benchmark configuration
6380
#

examples/single-account-k8s/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ Notice that:
104104
| <a name="input_cloudtrail_kms_enable"></a> [cloudtrail\_kms\_enable](#input\_cloudtrail\_kms\_enable) | true/false whether s3 should be encrypted. testing/economization purpose. | `bool` | `true` | no |
105105
| <a name="input_cloudtrail_sns_arn"></a> [cloudtrail\_sns\_arn](#input\_cloudtrail\_sns\_arn) | ARN of a pre-existing cloudtrail\_sns. If it does not exist, it will be inferred from created cloudtrail | `string` | `"create"` | no |
106106
| <a name="input_deploy_benchmark"></a> [deploy\_benchmark](#input\_deploy\_benchmark) | Whether to deploy or not the cloud benchmarking | `bool` | `true` | no |
107-
| <a name="input_deploy_image_scanning"></a> [deploy\_image\_scanning](#input\_deploy\_image\_scanning) | true/false whether to deploy cloud\_scanning | `bool` | `true` | no |
107+
| <a name="input_deploy_image_scanning_ecr"></a> [deploy\_image\_scanning\_ecr](#input\_deploy\_image\_scanning\_ecr) | true/false whether to deploy the image scanning on ECR pushed images | `bool` | `true` | no |
108+
| <a name="input_deploy_image_scanning_ecs"></a> [deploy\_image\_scanning\_ecs](#input\_deploy\_image\_scanning\_ecs) | true/false whether to deploy the image scanning on ECS running images | `bool` | `true` | no |
108109
| <a name="input_deploy_threat_detection"></a> [deploy\_threat\_detection](#input\_deploy\_threat\_detection) | true/false whether to deploy cloud\_connector | `bool` | `true` | no |
109110
| <a name="input_name"></a> [name](#input\_name) | 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` | `"sfc"` | no |
110111
| <a name="input_sysdig_secure_endpoint"></a> [sysdig\_secure\_endpoint](#input\_sysdig\_secure\_endpoint) | Sysdig Secure API endpoint | `string` | `"https://secure.sysdig.com"` | no |

examples/single-account-k8s/cloud-connector.tf

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
locals {
2+
deploy_image_scanning = var.deploy_image_scanning_ecr || var.deploy_image_scanning_ecs
3+
}
4+
15
#-------------------------------------
26
# requirements
37
#-------------------------------------
@@ -11,7 +15,7 @@ module "cloud_connector_sqs" {
1115
}
1216

1317
module "codebuild" {
14-
count = var.deploy_image_scanning ? 1 : 0
18+
count = local.deploy_image_scanning ? 1 : 0
1519
source = "../../modules/infrastructure/codebuild"
1620

1721
name = var.name
@@ -69,18 +73,19 @@ resource "helm_release" "cloud_connector" {
6973
}
7074
}
7175
]
72-
scanners = var.deploy_image_scanning ? [
73-
{
76+
scanners = local.deploy_image_scanning ? [
77+
merge(var.deploy_image_scanning_ecr ? {
7478
aws-ecr = {
7579
codeBuildProject = module.codebuild[0].project_name
7680
secureAPITokenSecretName = module.ssm.secure_api_token_secret_name
7781
}
78-
79-
aws-ecs = {
80-
codeBuildProject = module.codebuild[0].project_name
81-
secureAPITokenSecretName = module.ssm.secure_api_token_secret_name
82-
}
83-
}
82+
} : {},
83+
var.deploy_image_scanning_ecs ? {
84+
aws-ecs = {
85+
codeBuildProject = module.codebuild[0].project_name
86+
secureAPITokenSecretName = module.ssm.secure_api_token_secret_name
87+
}
88+
} : {})
8489
] : []
8590
})
8691
]

examples/single-account-k8s/credentials.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ module "iam_user" {
33
name = var.name
44
ssm_secure_api_token_arn = module.ssm.secure_api_token_secret_arn
55
deploy_threat_detection = var.deploy_threat_detection
6-
deploy_image_scanning = var.deploy_image_scanning
6+
deploy_image_scanning = local.deploy_image_scanning
77
}

examples/single-account-k8s/variables.tf

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,6 @@ variable "sysdig_secure_api_token" {
88
# optionals - with defaults
99
#---------------------------------
1010

11-
variable "deploy_threat_detection" {
12-
type = bool
13-
description = "true/false whether to deploy cloud_connector"
14-
default = true
15-
}
16-
17-
variable "deploy_image_scanning" {
18-
type = bool
19-
description = "true/false whether to deploy cloud_scanning"
20-
default = true
21-
}
22-
23-
24-
#
25-
# benchmark configuration
26-
#
27-
variable "deploy_benchmark" {
28-
type = bool
29-
description = "Whether to deploy or not the cloud benchmarking"
30-
default = true
31-
}
32-
variable "benchmark_regions" {
33-
type = list(string)
34-
description = "List of regions in which to run the benchmark. If empty, the task will contain all aws regions by default."
35-
default = []
36-
}
37-
38-
39-
4011
#
4112
# cloudtrail configuration
4213
#
@@ -78,3 +49,44 @@ variable "tags" {
7849
"product" = "sysdig-secure-for-cloud"
7950
}
8051
}
52+
53+
#
54+
# threat-detection configuration
55+
#
56+
57+
variable "deploy_threat_detection" {
58+
type = bool
59+
description = "true/false whether to deploy cloud_connector"
60+
default = true
61+
}
62+
63+
#
64+
# scanning configuration
65+
#
66+
67+
variable "deploy_image_scanning_ecr" {
68+
type = bool
69+
description = "true/false whether to deploy the image scanning on ECR pushed images"
70+
default = true
71+
}
72+
73+
variable "deploy_image_scanning_ecs" {
74+
type = bool
75+
description = "true/false whether to deploy the image scanning on ECS running images"
76+
default = true
77+
}
78+
79+
80+
#
81+
# benchmark configuration
82+
#
83+
variable "deploy_benchmark" {
84+
type = bool
85+
description = "Whether to deploy or not the cloud benchmarking"
86+
default = true
87+
}
88+
variable "benchmark_regions" {
89+
type = list(string)
90+
description = "List of regions in which to run the benchmark. If empty, the task will contain all aws regions by default."
91+
default = []
92+
}

examples/single-account/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ No resources.
8383
| <a name="input_cloudtrail_kms_enable"></a> [cloudtrail\_kms\_enable](#input\_cloudtrail\_kms\_enable) | true/false whether cloudtrail delivered events to S3 should persist encrypted | `bool` | `true` | no |
8484
| <a name="input_cloudtrail_sns_arn"></a> [cloudtrail\_sns\_arn](#input\_cloudtrail\_sns\_arn) | ARN of a pre-existing cloudtrail\_sns. If defaulted, a new cloudtrail will be created | `string` | `"create"` | no |
8585
| <a name="input_deploy_benchmark"></a> [deploy\_benchmark](#input\_deploy\_benchmark) | Whether to deploy or not the cloud benchmarking | `bool` | `true` | no |
86+
| <a name="input_deploy_image_scanning_ecr"></a> [deploy\_image\_scanning\_ecr](#input\_deploy\_image\_scanning\_ecr) | true/false whether to deploy the image scanning on ECR pushed images | `bool` | `true` | no |
87+
| <a name="input_deploy_image_scanning_ecs"></a> [deploy\_image\_scanning\_ecs](#input\_deploy\_image\_scanning\_ecs) | true/false whether to deploy the image scanning on ECS running images | `bool` | `true` | no |
8688
| <a name="input_ecs_cluster_name"></a> [ecs\_cluster\_name](#input\_ecs\_cluster\_name) | Name of a pre-existing ECS (elastic container service) cluster. If defaulted, a new ECS cluster/VPC/Security Group will be created | `string` | `"create"` | no |
8789
| <a name="input_ecs_vpc_id"></a> [ecs\_vpc\_id](#input\_ecs\_vpc\_id) | ID of the VPC where the workload is to be deployed. Defaulted to be created when 'ecs\_cluster\_name' is not provided. | `string` | `"create"` | no |
8890
| <a name="input_ecs_vpc_region_azs"></a> [ecs\_vpc\_region\_azs](#input\_ecs\_vpc\_region\_azs) | List of Availability Zones for ECS VPC creation. e.g.: ["apne1-az1", "apne1-az2"]. If defaulted, two of the default 'aws\_availability\_zones' datasource will be taken | `list(string)` | `[]` | no |

examples/single-account/main.tf

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ module "ssm" {
1818
# cloud-connector
1919
#-------------------------------------
2020
module "codebuild" {
21+
count = var.deploy_image_scanning_ecr || var.deploy_image_scanning_ecs ? 1 : 0
22+
2123
source = "../../modules/infrastructure/codebuild"
2224
name = "${var.name}-codebuild"
2325
secure_api_token_secret_name = module.ssm.secure_api_token_secret_name
@@ -33,10 +35,14 @@ module "cloud_connector" {
3335

3436
sysdig_secure_endpoint = var.sysdig_secure_endpoint
3537
secure_api_token_secret_name = module.ssm.secure_api_token_secret_name
36-
is_organizational = false
3738

38-
build_project_arn = module.codebuild.project_arn
39-
build_project_name = module.codebuild.project_name
39+
deploy_image_scanning_ecr = var.deploy_image_scanning_ecr
40+
deploy_image_scanning_ecs = var.deploy_image_scanning_ecs
41+
42+
is_organizational = false
43+
44+
build_project_arn = length(module.codebuild) == 1 ? module.codebuild[0].project_arn : "na"
45+
build_project_name = length(module.codebuild) == 1 ? module.codebuild[0].project_name : "na"
4046

4147
sns_topic_arn = local.cloudtrail_sns_arn
4248

@@ -47,5 +53,4 @@ module "cloud_connector" {
4753

4854
tags = var.tags
4955
depends_on = [local.cloudtrail_sns_arn, module.ssm]
50-
5156
}

examples/single-account/variables.tf

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ variable "cloudtrail_kms_enable" {
3232
}
3333

3434

35-
#---------------------------------
35+
#
3636
# ecs, security group, vpc
37-
#---------------------------------
37+
#
3838

3939
variable "ecs_cluster_name" {
4040
type = string
@@ -54,14 +54,29 @@ variable "ecs_vpc_subnets_private_ids" {
5454
description = "List of VPC subnets where workload is to be deployed. Defaulted to be created when 'ecs_cluster_name' is not provided."
5555
}
5656

57-
5857
variable "ecs_vpc_region_azs" {
5958
type = list(string)
6059
description = "List of Availability Zones for ECS VPC creation. e.g.: [\"apne1-az1\", \"apne1-az2\"]. If defaulted, two of the default 'aws_availability_zones' datasource will be taken"
6160
default = []
6261
}
6362

6463

64+
#
65+
# scanning configuration
66+
#
67+
68+
variable "deploy_image_scanning_ecr" {
69+
type = bool
70+
description = "true/false whether to deploy the image scanning on ECR pushed images"
71+
default = true
72+
}
73+
74+
variable "deploy_image_scanning_ecs" {
75+
type = bool
76+
description = "true/false whether to deploy the image scanning on ECS running images"
77+
default = true
78+
}
79+
6580

6681
#
6782
# benchmark configuration
@@ -83,6 +98,7 @@ variable "benchmark_regions" {
8398
#
8499
# general
85100
#
101+
86102
variable "name" {
87103
type = string
88104
description = "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"

modules/services/cloud-connector/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ A task deployed on an **ECS deployment** will detect events in your infrastructu
7171
| <a name="input_sns_topic_arn"></a> [sns\_topic\_arn](#input\_sns\_topic\_arn) | ARN of a cloudtrail-sns topic | `string` | n/a | yes |
7272
| <a name="input_cloudwatch_log_retention"></a> [cloudwatch\_log\_retention](#input\_cloudwatch\_log\_retention) | Days to keep logs for CloudConnector | `number` | `5` | no |
7373
| <a name="input_connector_ecs_task_role_name"></a> [connector\_ecs\_task\_role\_name](#input\_connector\_ecs\_task\_role\_name) | Default ecs cloudconnector task role name | `string` | `"ECSTaskRole"` | no |
74+
| <a name="input_deploy_image_scanning_ecr"></a> [deploy\_image\_scanning\_ecr](#input\_deploy\_image\_scanning\_ecr) | true/false whether to deploy the image scanning on ECR pushed images | `bool` | `true` | no |
75+
| <a name="input_deploy_image_scanning_ecs"></a> [deploy\_image\_scanning\_ecs](#input\_deploy\_image\_scanning\_ecs) | true/false whether to deploy the image scanning on ECS running images | `bool` | `true` | no |
7476
| <a name="input_extra_env_vars"></a> [extra\_env\_vars](#input\_extra\_env\_vars) | Extra environment variables for the Cloud Connector deployment | `map(string)` | `{}` | no |
7577
| <a name="input_image"></a> [image](#input\_image) | Image of the cloud connector to deploy | `string` | `"quay.io/sysdig/cloud-connector:latest"` | no |
7678
| <a name="input_is_organizational"></a> [is\_organizational](#input\_is\_organizational) | whether secure-for-cloud should be deployed in an organizational setup | `bool` | `false` | no |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
locals {
2+
deploy_image_scanning = var.deploy_image_scanning_ecs || var.deploy_image_scanning_ecr
3+
}

0 commit comments

Comments
 (0)