Skip to content

Commit a5e0a32

Browse files
author
iru
authored
chore: org+k8s+cloudtrail-s3-sqs+manual input roles (#32)
1 parent c18cbd0 commit a5e0a32

File tree

31 files changed

+1069
-9
lines changed

31 files changed

+1069
-9
lines changed

.github/workflows/ci-integration-tests.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ concurrency: terraform
1616

1717
jobs:
1818
integration_test_ecs:
19-
concurrency: terraform-account
19+
# concurrency: terraform-account
2020

2121
name: Test-Kitchen-ECS
2222
runs-on: ubuntu-latest
@@ -66,7 +66,7 @@ jobs:
6666
run: bundle exec kitchen destroy "organizational-aws"
6767

6868
integration_test-eks:
69-
concurrency: terraform-account
69+
# concurrency: terraform-account
7070
continue-on-error: true
7171

7272
name: Test-Kitchen-EKS
@@ -109,7 +109,7 @@ jobs:
109109
- name: Destroy single-account-k8s resources
110110
env:
111111
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_QA_CLOUDNATIVE_ACCESS_KEY_ID }}
112-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_QA_CLOUDNATIVE_SECRET_ACCESS_KEY }}}}
112+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_QA_CLOUDNATIVE_SECRET_ACCESS_KEY }}
113113
AWS_REGION: ${{ secrets.AWS_REGION }}
114114
if: ${{ failure() }}
115115
run: bundle exec kitchen destroy "single-account-k8s-aws"

.github/workflows/ci-test-cleanup.yaml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ jobs:
2222
with:
2323
ruby-version: 2.7
2424
bundler-cache: true
25-
25+
- name: Create kind cluster # this is not really needed but kitchen requires it
26+
uses: helm/kind-action@v1.2.0
27+
with:
28+
wait: 120s
2629
- name: Destroy resources
27-
run: bundle exec kitchen destroy
30+
run: bundle exec kitchen destroy single
2831

2932
cleanup-org:
3033
name: Test Cleanup Org
@@ -44,6 +47,9 @@ jobs:
4447
with:
4548
ruby-version: 2.7
4649
bundler-cache: true
47-
50+
- name: Create kind cluster # this is not really needed but kitchen requires it
51+
uses: helm/kind-action@v1.2.0
52+
with:
53+
wait: 120s
4854
- name: Destroy resources
49-
run: bundle exec kitchen destroy
55+
run: bundle exec kitchen destroy organizational

.kitchen.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ suites:
2020
- name: organizational
2121
driver:
2222
root_module_directory: test/fixtures/organizational
23+
- name: organizational-k8s
24+
driver:
25+
root_module_directory: test/fixtures/organizational-k8s

CONTRIBUTE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ $ bundle exec kitchen tests
6464
Because CI/CD sometimes fail, we setup the Terraform state to be handled in backend (s3+dynamo) within the Sysdig AWS backend (sysdig-test-account).
6565
In order to be able to use this Terraform backend AWS credentials are configured as Github project secret
6666

67-
If you need to handle the remote state on your local for any cleanup, please do it using `kitchen destroy`, not `terraform destroy`
68-
67+
If terraform state ends up in bad shape and not cleaned, use the action called `Test Cleanup` that should destroy any messed situation.
68+
If this does not work, try it from your local, but please do it using `kitchen destroy`, not `terraform destroy` unless you really know what you're doing :]
6969

7070
### Deployed infrastructure resources
7171

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Sysdig Secure for Cloud in AWS<br/>:: Organizational, threat-detection with pre-existing resources (EKS + cloudtrail through S3-SNS-SQS events)
2+
3+
4+
- Sysdig **Helm** chart will be used to deploy threat-detection
5+
- [Cloud-Connector Chart](https://charts.sysdig.com/charts/cloud-connector/)
6+
- This charts requires specific AWS credentials to be passed by parameter (accessKeyId and secretAccessKey)
7+
- An existing cloudtrail is used, but instead of sending events directly to an SNS topic (disabled), we will make use of a topic (SQS)
8+
which will be subscribed to the multiple possible SNS topics listening to the cloudtrail-S3 bucket changes.
9+
10+
![diagram](https://github.com/sysdiglabs/terraform-aws-secure-for-cloud/blob/master/examples-internal/organizational-k8s-threat-reuse_cloudtrail/diagram.png)
11+
12+
All the required resources and workloads will be run under the same AWS account, held in a member-account of the organization.
13+
14+
## Prerequisites
15+
16+
Minimum requirements:
17+
18+
1. **AWS** profile credentials configured within yor `aws` provider
19+
2. A **Kubernetes** cluster configured within your `helm` provider
20+
3. **Sysdig** Secure API token , as input variable value
21+
```
22+
sysdig_secure_api_token=<SECURE_API_TOKEN>
23+
```
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/>
27+
6. If the module is to be deployed on an AWS Organization **member account** which is not the same where the Cloudtrail-S3 events are located,
28+
the `organization_managed_role_arn` input variable must be used<br/>
29+
This will provide the **ARN of a role** that `cloud-connector` module will use to fetch the events from the S3 bucket.<br/>
30+
see `modules/infrastructure/permissions/eks-org-role` for guidance`<br/><br/>
31+
32+
## Usage
33+
34+
For quick testing, use this snippet on your terraform files.
35+
36+
```terraform
37+
provider "aws" {
38+
region = var.region
39+
...
40+
}
41+
42+
provider "helm" {
43+
...
44+
}
45+
46+
module "org_k8s_threat_reuse_cloudtrail" {
47+
source = "sysdiglabs/secure-for-cloud/aws//examples-internal/organizational-k8s-threat-reuse_cloudtrail"
48+
49+
sysdig_secure_api_token = "00000000-1111-2222-3333-444444444444"
50+
51+
region = "CLOUDTRAIL_SNS_SQS_REGION"
52+
cloudtrail_s3_sns_sqs_url = "SQS-URL"
53+
organization_managed_role_arn = "ARN_ROLE_FOR_MEMBER_ACCOUNT_PERMISSIONS"
54+
55+
aws_access_key_id = "AWS_ACCESSK_KEY"
56+
aws_secret_access_key = "AWS_SECRET_ACCESS_KEY"
57+
}
58+
59+
```
60+
61+
See [inputs summary](#inputs) or module module [`variables.tf`](https://github.com/sysdiglabs/terraform-aws-secure-for-cloud/blob/master/examples-internal/organizational-k8s-threat-reuse_cloudtrail/variables.tf) file for more optional configuration.
62+
63+
To run this example you need have your [aws account profile configured in CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) and to execute:
64+
```terraform
65+
$ terraform init
66+
$ terraform plan
67+
$ terraform apply
68+
```
69+
70+
Notice that:
71+
* This example will create resources that cost money.<br/>Run `terraform destroy` when you don't need them anymore
72+
* All created resources will be created within the tags `product:sysdig-secure-for-cloud`, within the resource-group `sysdig-secure-for-cloud`
73+
74+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
75+
## Requirements
76+
77+
| Name | Version |
78+
|------|---------|
79+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.15.0 |
80+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.50.0 |
81+
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | >=2.3.0 |
82+
83+
## Providers
84+
85+
| Name | Version |
86+
|------|---------|
87+
| <a name="provider_helm"></a> [helm](#provider\_helm) | >=2.3.0 |
88+
89+
## Modules
90+
91+
| Name | Source | Version |
92+
|------|--------|---------|
93+
| <a name="module_resource_group"></a> [resource\_group](#module\_resource\_group) | ../../modules/infrastructure/resource-group | |
94+
| <a name="module_ssm"></a> [ssm](#module\_ssm) | ../../modules/infrastructure/ssm | |
95+
96+
## Resources
97+
98+
| Name | Type |
99+
|------|------|
100+
| [helm_release.cloud_connector](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
101+
102+
## Inputs
103+
104+
| Name | Description | Type | Default | Required |
105+
|------|-------------|------|---------|:--------:|
106+
| <a name="input_aws_access_key_id"></a> [aws\_access\_key\_id](#input\_aws\_access\_key\_id) | cloud-connector. aws credentials in order to access required aws resources. aws.accessKeyId | `string` | n/a | yes |
107+
| <a name="input_aws_secret_access_key"></a> [aws\_secret\_access\_key](#input\_aws\_secret\_access\_key) | cloud-connector. aws credentials in order to access required aws resources. aws.secretAccessKey | `string` | n/a | yes |
108+
| <a name="input_cloudtrail_s3_sns_sqs_url"></a> [cloudtrail\_s3\_sns\_sqs\_url](#input\_cloudtrail\_s3\_sns\_sqs\_url) | Organization cloudtrail event notification S3-SNS-SQS URL to listen to | `string` | n/a | yes |
109+
| <a name="input_sysdig_secure_api_token"></a> [sysdig\_secure\_api\_token](#input\_sysdig\_secure\_api\_token) | Sysdig Secure API token | `string` | n/a | yes |
110+
| <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 |
111+
| <a name="input_organization_managed_role_arn"></a> [organization\_managed\_role\_arn](#input\_organization\_managed\_role\_arn) | `sysdig_secure_for_cloud_role_arn` for cloud-connector assumeRole in order to read cloudtrail s3 events</li><li>and the `connector_ecs_task_role_name` which has been granted trusted-relationship over the secure\_for\_cloud\_role | `string` | `"none"` | no |
112+
| <a name="input_region"></a> [region](#input\_region) | Default region for resource creation in both organization master and secure-for-cloud member account | `string` | `"eu-central-1"` | no |
113+
| <a name="input_sysdig_secure_endpoint"></a> [sysdig\_secure\_endpoint](#input\_sysdig\_secure\_endpoint) | Sysdig Secure API endpoint | `string` | `"https://secure.sysdig.com"` | no |
114+
| <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 |
115+
116+
## Outputs
117+
118+
No outputs.
119+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
120+
121+
122+
## Troubleshooting
123+
124+
- Q1: When I deploy it, cloud-connector gives an error saying `api error AWS.SimpleQueueService.NonExistentQueue: The specified queue does not exist for this wsdl version`
125+
S1: make use of the `var.region` to specify where the resources are on the organzation managed account (sqs)
126+
127+
## Authors
128+
129+
Module is maintained and supported by [Sysdig](https://sysdig.com).
130+
131+
## License
132+
133+
Apache 2 Licensed. See LICENSE for full details.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
resource "helm_release" "cloud_connector" {
2+
3+
provider = helm
4+
5+
name = "cloud-connector"
6+
7+
repository = "https://charts.sysdig.com"
8+
chart = "cloud-connector"
9+
10+
create_namespace = true
11+
namespace = var.name
12+
13+
set {
14+
name = "image.pullPolicy"
15+
value = "Always"
16+
}
17+
18+
set_sensitive {
19+
name = "sysdig.secureAPIToken"
20+
value = var.sysdig_secure_api_token
21+
}
22+
23+
set_sensitive {
24+
name = "aws.accessKeyId"
25+
value = var.aws_access_key_id
26+
}
27+
28+
set_sensitive {
29+
name = "aws.secretAccessKey"
30+
value = var.aws_secret_access_key
31+
}
32+
33+
set {
34+
name = "aws.region"
35+
value = var.region
36+
}
37+
38+
set {
39+
name = "sysdig.url"
40+
value = var.sysdig_secure_endpoint
41+
}
42+
43+
values = [
44+
<<CONFIG
45+
logging: info
46+
ingestors:
47+
- aws-cloudtrail-s3-sns-sqs:
48+
queueURL: ${var.cloudtrail_s3_sns_sqs_url}
49+
assumeRole: ${var.organization_managed_role_arn}
50+
CONFIG
51+
]
52+
}
Loading
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# diagrams as code vía https://diagrams.mingrammer.com
2+
from diagrams import Cluster, Diagram, Edge, Node
3+
from diagrams.aws.compute import EKS
4+
from diagrams.aws.general import General
5+
from diagrams.aws.integration import SNS, SQS
6+
from diagrams.aws.management import Cloudtrail
7+
from diagrams.aws.security import IAM, IAMRole
8+
from diagrams.aws.storage import S3
9+
from diagrams.custom import Custom
10+
11+
from diagrams.k8s.group import Namespace
12+
from diagrams.k8s.compute import Deployment
13+
14+
diagram_attr = {
15+
"pad":"0.25"
16+
}
17+
18+
role_attr = {
19+
"imagescale":"false",
20+
"height":"1.5",
21+
"width":"3",
22+
"fontsize":"9",
23+
}
24+
25+
color_event="firebrick"
26+
color_scanning = "dark-green"
27+
color_permission="red"
28+
color_creates="darkblue"
29+
color_non_important="gray"
30+
color_sysdig="lightblue"
31+
32+
33+
34+
with Diagram("Sysdig Secure for Cloud{}(org-threat_detection-k8s-cloudtrail_s3_sns_sqs-eks)".format("\n"), graph_attr=diagram_attr, filename="diagram", show=True, direction="TB"):
35+
36+
with Cluster("AWS account (sysdig)"):
37+
sds = Custom("Sysdig Secure", "../../resources/diag-sysdig-icon.png")
38+
39+
with Cluster("AWS organization"):
40+
41+
with Cluster("member accounts (main target)", graph_attr={"bgcolor":"lightblue"}):
42+
# resources = General("resources-1..n\n(events)")
43+
44+
with Cluster("sysdig-secure-for-cloud resources"):
45+
eks = EKS("EKS\n(pre-existing)")
46+
with Cluster("namespace: sfc"):
47+
cc_deployment = Deployment("cloud-connector")
48+
eks_deployments = [cc_deployment]
49+
50+
51+
with Cluster("management account"):
52+
# resources2 = General("resources-1..n\n(events)")
53+
54+
cloudtrail = Cloudtrail("cloudtrail\n(organizational)", shape="plaintext")
55+
cloudtrail_s3 = S3("cloudtrail-s3-events")
56+
sns = [SNS("sns /path-1"), SNS("sns /path-2"), SNS("sns /path-n")]
57+
sqs = SQS("sqs")
58+
cloudtrail >> Edge(color=color_event) >> cloudtrail_s3 >> Edge(color=color_event) >> sns << sqs
59+
# resources2 >> Edge(color=color_event, style="dashed") >> cloudtrail
60+
61+
management_credentials = IAM("credentials", fontsize="10")
62+
63+
cc_deployment >> Edge(color=color_event, style="dashed", label="subscribed") >> sqs
64+
# resources >> Edge(color=color_event, style="dashed") >> cloudtrail
65+
66+
cc_deployment >> Edge(color=color_sysdig) >> sds
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#-------------------------------------
2+
# general resources
3+
#-------------------------------------
4+
5+
module "resource_group" {
6+
source = "../../modules/infrastructure/resource-group"
7+
name = var.name
8+
tags = var.tags
9+
}
10+
11+
module "ssm" {
12+
source = "../../modules/infrastructure/ssm"
13+
name = var.name
14+
sysdig_secure_api_token = var.sysdig_secure_api_token
15+
}

examples-internal/organizational-k8s-threat-reuse_cloudtrail/outputs.tf

Whitespace-only changes.

0 commit comments

Comments
 (0)