Skip to content

Commit 36c7408

Browse files
author
iru
authored
docs: self-baked example library (#50)
* docs: small renaming and explanations * docs: clarify s3-sns-sqs use-case * docs: self-baked user-case
1 parent 1d73cd5 commit 36c7408

File tree

22 files changed

+197
-18
lines changed

22 files changed

+197
-18
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,28 @@ For other Cloud providers check: [GCP](https://github.com/sysdiglabs/terraform-g
1717

1818
<br/>
1919

20+
[comment]: <> (## Permissions)
21+
22+
[comment]: <> (Inspect `/module/infrastructure/permissions` subdirectories to understand the several)
23+
24+
[comment]: <> (permissions required.)
25+
26+
[comment]: <> (- `/iam-user` creates an IAM user + adds permissions for required modules &#40;general, cloud-connector, cloud-scanning&#41;<br/><br/>)
27+
28+
[comment]: <> (- `/general` concerns general permissions that apply to both threat-detection and image-scanning features)
29+
30+
[comment]: <> (- `/cloud-connector` for threat-detection features)
31+
32+
[comment]: <> (- `/cloud-scanning` for image-scanning features)
33+
34+
[comment]: <> (TODO review `/module/*/ permissions` vs. the ones in permissions folder)
35+
36+
[comment]: <> (TODO review)
37+
38+
[comment]: <> (- `/org-role-ecs`)
39+
40+
[comment]: <> (- `/org-role-eks`)
41+
2042
## Usage
2143

2244
There are several ways to deploy this in you AWS infrastructure:

examples-internal/organizational-k8s-threat-reuse_cloudtrail/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ Minimum requirements:
2121
```
2222
sysdig_secure_api_token=<SECURE_API_TOKEN>
2323
```
24-
4. S3 event-notification subscribed SNS topic(s).<br/>see `modules/infrastructure/cloudtrail_s3-sns-sqs` for guidance<br/><br/>
25-
5. **SQS topic** subscribed to the S3-SNS event notifications.<br/>The ARN of this SQS will be used as an input parameter to the module.<br/>
26-
see `modules/infrastructure/sqs-sns-subscription` for guidance`<br/><br/>
24+
4. **SQS topic** subscribed to the Cloudtrail-S3-SNS event notifications.<br/>
25+
This three-actor setup (S3-SNS-SQS) can be manually provisioned, or handled through `modules/infrastructure/cloudtrail_s3-sns-sqs` module<br/><br/>
26+
Client is responsible for provisioning the ARN of this SQS, which will be required as an input parameter.<br/>
2727
2828
2929
## Usage
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# ORG-S3-K8S-FILTERED
2+
3+
## Use-Case explanation
4+
5+
**Current User Setup**
6+
- [X] organizational setup
7+
- [ ] organizational cloudtrail
8+
- [X] centralized S3 bucket with cloudtrail-events
9+
- [ ] member account usage - all required resources (s3/sns/sqs, sysdig workload) in same account
10+
- [X] member account usage - all required resources are in scattered
11+
- [X] pre-existing k8s cluster we want to use to deploy Sysdig for Cloud workload
12+
13+
**Sysdig Secure For Cloud Requirements**
14+
- [X] account-specific threat-detection
15+
- [ ] account-specific/organizational? image scanning (WIP)
16+
- [ ] account-specific/organizational? benchmark (WIP)
17+
- [X] pre-existing kubernetes management vía service account (WIP)
18+
<br/>this has not been tested yet, we rely on an `accessKey` created specifically for Sysdig-For-Cloud.
19+
<!--
20+
Skip step 4 and remove `aws_access_key_id` and `aws_secret_access_key` parameters from `org_k8s_threat_reuse_cloudtrail` module
21+
-->
22+
23+
## Suggested building-blocks
24+
25+
1. Define different **AWS providers**
26+
1. Populate `_REGION_` and `_S3_REGION_`
27+
2. Because we are going to provision resources on multiple accounts, we're gonna need several AWS providers
28+
29+
2. `s3` for s3-sns-sqs resources to be deployed. IAM user-credentials, to be used for k8s must also be in S3 account
30+
3. `sfc` for secure-for-cloud utilitary resources to be deployed
31+
32+
33+
```terraform
34+
provider "aws" {
35+
alias = "s3"
36+
region = "_S3_REGION_"
37+
...
38+
}
39+
40+
provider "aws" {
41+
alias = "sfc"
42+
region = "_REGION_"
43+
...
44+
}
45+
46+
```
47+
48+
2. **Helm provider** definition
49+
50+
Sysdig workload will be deployed through its official **Helm** [cloud-connector chart](https://charts.sysdig.com/charts/cloud-connector/).
51+
<br/>Note: Configure [**Helm** Provider](https://registry.terraform.io/providers/hashicorp/helm/latest/docs) for **Kubernetes** cluster
52+
<br/>ex:.
53+
```terraform
54+
provider "helm" {
55+
kubernetes {
56+
config_path = "~/.kube/config"
57+
}
58+
}
59+
60+
```
61+
62+
3. **Cloudtrail-S3-SNS-SQS**
63+
64+
1. Populate `_CLOUDTRAIL_S3_NAME_`
65+
<br/>ex.:
66+
```text
67+
cloudtrail_s3_name=cloudtrail-logging-237944556329
68+
```
69+
2. Populate `_CLOUDTRAIL_S3_FILTER_PREFIX_` in order to ingest a specific-account. Otherwise just remove its assignation
70+
<br/>ex.:
71+
```text
72+
s3_event_notification_filter_prefix=cloudtrail/AWSLogs/237944556329
73+
```
74+
75+
```terraform
76+
module "cloudtrail_s3_sns_sqs" {
77+
providers = {
78+
aws = aws.s3
79+
}
80+
source = "sysdiglabs/secure-for-cloud/aws//modules/infrastructure/cloudtrail_s3-sns-sqs"
81+
cloudtrail_s3_name = _CLOUDTRAIL_S3_NAME_
82+
s3_event_notification_filter_prefix=_CLOUDTRAIL_S3_FILTER_PREFIX_
83+
}
84+
```
85+
86+
87+
4. Kubernetes Organizational **User Permissions** to be able to handle S3/SQS operations
88+
<br/>Because Helm Cloud-Connector chart require specific AWS credentials to be passed by parameter, a new user + access key will be created within account. See [`modules/infrastructure/permissions/iam-user`](https://github.com/sysdiglabs/terraform-aws-secure-for-cloud/blob/master/modules/infrastructure/permissions/iam-user)
89+
90+
```terraform
91+
module "org_user" {
92+
providers = {
93+
aws = aws.s3
94+
}
95+
source = "sysdiglabs/secure-for-cloud/aws//modules/infrastructure/permissions/iam-user"
96+
deploy_image_scanning = false
97+
cloudtrail_s3_bucket_arn = module.cloudtrail_s3_sns_sqs.cloudtrail_s3_arn
98+
cloudtrail_subscribed_sqs_arn = module.cloudtrail_s3_sns_sqs.cloudtrail_subscribed_sqs_arn
99+
}
100+
```
101+
102+
5. **Sysdig workload deployment on K8s**
103+
104+
* Populate `_SYSDIG_SECURE_ENDPOINT_` and `_SYSDID_SECURE_API_TOKEN_`
105+
106+
```terraform
107+
# force some waiting for org_user creation (eventual consistency)
108+
resource "time_sleep" "wait" {
109+
depends_on = [module.org_user]
110+
create_duration = "5s"
111+
}
112+
113+
module "org_k8s_threat_reuse_cloudtrail" {
114+
providers = {
115+
aws = aws.sfc
116+
}
117+
source = "sysdiglabs/secure-for-cloud/aws//examples-internal/organizational-k8s-threat-reuse_cloudtrail"
118+
name = "test-orgk8s"
119+
120+
sysdig_secure_endpoint = _SYSDIG_SECURE_ENDPOINT_
121+
sysdig_secure_api_token = _SYSDID_SECURE_API_TOKEN_
122+
cloudtrail_s3_sns_sqs_url = module.cloudtrail_s3_sns_sqs.cloudtrail_subscribed_sqs_url
123+
124+
aws_access_key_id = module.org_user.sfc_user_access_key_id
125+
aws_secret_access_key = module.org_user.sfc_user_secret_access_key
126+
127+
depends_on = [module.org_user.sfc_user_arn, time_sleep.wait]
128+
}
129+
```

examples/organizational/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Notice that:
9797
| <a name="module_ecs_fargate_cluster"></a> [ecs\_fargate\_cluster](#module\_ecs\_fargate\_cluster) | ../../modules/infrastructure/ecs-fargate-cluster | |
9898
| <a name="module_resource_group"></a> [resource\_group](#module\_resource\_group) | ../../modules/infrastructure/resource-group | |
9999
| <a name="module_resource_group_secure_for_cloud_member"></a> [resource\_group\_secure\_for\_cloud\_member](#module\_resource\_group\_secure\_for\_cloud\_member) | ../../modules/infrastructure/resource-group | |
100-
| <a name="module_secure_for_cloud_role"></a> [secure\_for\_cloud\_role](#module\_secure\_for\_cloud\_role) | ../../modules/infrastructure/permissions/ecs-org-role | |
100+
| <a name="module_secure_for_cloud_role"></a> [secure\_for\_cloud\_role](#module\_secure\_for\_cloud\_role) | ../../modules/infrastructure/permissions/org-role-ecs | |
101101
| <a name="module_ssm"></a> [ssm](#module\_ssm) | ../../modules/infrastructure/ssm | |
102102

103103
## Resources

examples/organizational/credentials.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module "resource_group_secure_for_cloud_member" {
88
}
99

1010
module "secure_for_cloud_role" {
11-
source = "../../modules/infrastructure/permissions/ecs-org-role"
11+
source = "../../modules/infrastructure/permissions/org-role-ecs"
1212
providers = {
1313
aws.member = aws.member
1414
}

modules/infrastructure/cloudtrail_s3-sns-sqs/README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
# Cloudtrail_S3 event notification handle through SNS-SQS
22

3-
Provisions the SNS-SQS event-notification on a pre-existing cloudtrail, based on it S3 bucket event-notifications
3+
Provision a cloud-connector cloudtrail input, based on an S3-SNS-SQS event-notification.
4+
5+
# How it works
6+
7+
- This module's output will be visible in the `S3` console, after entering a bucket, in it's `Properties`, `Event notifications` section.
8+
Besides, an SQS queue will be visible, which will gather the events coming from the Cloudtrail-S3-SNS topic notifications.
9+
- Creates the SNS-SQS link using the underlying module `modules/infrastructure/sqs-sns-subscription`<br/><br/>
10+
11+
## Recommended use-cases
12+
13+
Matches one of the following points:
14+
15+
- Accounts are organized in an AWS Organization, but there is NO [Organizational Cloudtrail](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/creating-trail-organization.html)
16+
- An existing cloudtrail is available, but it has NO
17+
[Cloudtrail-SNS notification configured](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/configure-sns-notifications-for-cloudtrail.html?icmpid=docs_console_unmapped)
18+
- An existing cloudtrail is available, but despite having Cloudtrail-SNS notification activated we want to make an
19+
EVENT FILTER/fine-tunning, regarding what we want to send to Sysdig Cloud-Connector for the thread-detection feature.
420

521
## Pre-requirements
22+
- Identify the Cloudtrail-S3 bucket name, for the `input_cloudtrail_s3_name` module input
23+
<!--
624
- SNS must be created in the same region as Cloudtrail. Adjust `var.region` or your aws credentials region.
7-
25+
-->
826

927

1028
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
@@ -42,7 +60,7 @@ Provisions the SNS-SQS event-notification on a pre-existing cloudtrail, based on
4260
|------|-------------|------|---------|:--------:|
4361
| <a name="input_cloudtrail_s3_name"></a> [cloudtrail\_s3\_name](#input\_cloudtrail\_s3\_name) | Name of the Cloudtrail S3 bucket | `string` | n/a | yes |
4462
| <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 |
45-
| <a name="input_s3_event_notification_filter_prefix"></a> [s3\_event\_notification\_filter\_prefix](#input\_s3\_event\_notification\_filter\_prefix) | S3 Path filter prefix for event notification | `string` | `""` | no |
63+
| <a name="input_s3_event_notification_filter_prefix"></a> [s3\_event\_notification\_filter\_prefix](#input\_s3\_event\_notification\_filter\_prefix) | S3 Path filter prefix for event notification. Limit the notifications to objects with key starting with specified characters | `string` | `""` | no |
4664
| <a name="input_tags"></a> [tags](#input\_tags) | sysdig secure-for-cloud tags | `map(string)` | <pre>{<br> "product": "sysdig-secure-for-cloud"<br>}</pre> | no |
4765

4866
## Outputs

modules/infrastructure/cloudtrail_s3-sns-sqs/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ variable "cloudtrail_s3_name" {
1010
variable "s3_event_notification_filter_prefix" {
1111
type = string
1212
default = ""
13-
description = "S3 Path filter prefix for event notification"
13+
description = "S3 Path filter prefix for event notification. Limit the notifications to objects with key starting with specified characters"
1414
}
1515

1616
#

modules/infrastructure/permissions/general/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Permissions :: General
22

3-
General permissions that apply to both threat-detection (cloud-connector) and image-scanning (cloud-scanning) features
3+
General permissions that apply to both cloud-connector and cloud-scanning modules
4+
- Currently this only applies to the capability of reading the Secure API Token from the Key Management Service
45

56
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
67
## Requirements

modules/infrastructure/permissions/iam-user/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Permissions :: Single-Account user credentials
22

3-
Will create an IAM user and add add permissions for required modules
3+
Creates an IAM user and adds permissions for required modules.
4+
<br/>Will use the `deploy_threat_detection` and `deploy_image_scanning` flags
45

56
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
67
## Requirements

modules/infrastructure/permissions/iam-user/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ resource "aws_iam_access_key" "this" {
1010

1111

1212

13-
1413
module "credentials_general" {
1514
source = "../general"
1615
name = var.name

modules/infrastructure/permissions/ecs-org-role/README.md renamed to modules/infrastructure/permissions/org-role-ecs/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
The aim of this module is to manage the organizational **managed account** required role and permissions for threat-detection and image scanning modules to work properly.
44

5-
1. Enables Cloudtrail SNS subscription permissions through a role specified within the Sysdig Secure workload **member account**
6-
2. Creates a role in the organizational **managed account** with the required permissions
5+
1. Enables Cloudtrail SNS subscription permissions through a role specified within the Sysdig Secure workload **member account**<br/><br/>
6+
2. Creates a role `sfc-SysdigSecureForCloudRole` (by default) in the organizational **managed account** with the required permissions
77

8-
* Threat-Detection
8+
9+
## Permissions
10+
* Threat-Detection feature
911
* S3 Get and List permissions in order to fetch the events
1012
* SNS Subscription permissions in order to subscribe a topic to it
1113

12-
* Image scanning
14+
* Image scanning feature
1315
* Enable this role to assumeRole to member accounts through the `organizational_role_per_account` role,
1416
in order to be able to fetch images that may be in member-account repositories
1517

test/fixtures/organizational-k8s/main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ module "cloudtrail_s3_sns_sqs" {
2626
providers = {
2727
aws = aws.admin
2828
}
29-
source = "../../../modules/infrastructure/cloudtrail_s3-sns-sqs"
30-
cloudtrail_s3_name = var.cloudtrail_s3_name
29+
source = "../../../modules/infrastructure/cloudtrail_s3-sns-sqs"
30+
cloudtrail_s3_name = var.cloudtrail_s3_name
31+
s3_event_notification_filter_prefix = var.s3_event_notification_filter_prefix
3132
}
3233

3334

test/fixtures/organizational-k8s/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ variable "sysdig_secure_api_token" {
1515
# provide variables for testing
1616
#---------------------------------
1717

18+
variable "s3_event_notification_filter_prefix" {
19+
type = string
20+
default = ""
21+
description = "S3 Path filter prefix for event notification. Limit the notifications to objects with key starting with specified characters"
22+
}
23+
1824
variable "org_profile" {
1925
type = string
2026
default = ""

0 commit comments

Comments
 (0)