Skip to content

Commit e4e8e85

Browse files
author
iru
authored
fix: region to cloud-connector (#80)
* fix: region to cloud-connector * chore(tests): force region change * docs: add forcing events section
1 parent 5ae2c2f commit e4e8e85

File tree

6 files changed

+46
-23
lines changed

6 files changed

+46
-23
lines changed

README.md

+33-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
# Sysdig Secure for Cloud in GCP
22

3-
Terraform module that deploys the **Sysdig Secure for Cloud** stack in **Google Cloud**.
3+
Terraform module that deploys the [**Sysdig Secure for Cloud** stack in **Google Cloud**](https://docs.sysdig.com/en/docs/installation/sysdig-secure-for-cloud/deploy-sysdig-secure-for-cloud-on-gcp/).
44
<br/>It provides unified threat detection, compliance, forensics and analysis.
55

66
There are three major components:
77

8-
* **Cloud Threat Detection**: Tracks abnormal and suspicious activities in your cloud environment based on Falco language. Managed through [cloud-connector module](https://github.com/sysdiglabs/terraform-google-secure-for-cloud/tree/master/modules/services/cloud-connector).
9-
<br/><br/>
108
* **CSPM/Compliance**: It evaluates periodically your cloud configuration, using Cloud Custodian, against some benchmarks and returns the results and remediation you need to fix. Managed through [cloud-bench module](https://github.com/sysdiglabs/terraform-google-secure-for-cloud/tree/master/modules/services/cloud-bench).
119
<br/><br/>
12-
* **Cloud Scanning**: Automatically scans all container images pushed to the registry or as soon a new task which involves a container is spawned in your account.Managed through [cloud-scanning module](https://github.com/sysdiglabs/terraform-google-secure-for-cloud/tree/master/modules/services/cloud-scanning).
10+
* **Cloud Threat Detection**: Tracks abnormal and suspicious activities in your cloud environment based on Falco language. Managed through [cloud-connector module](https://github.com/sysdiglabs/terraform-google-secure-for-cloud/tree/master/modules/services/cloud-connector).
11+
<br/><br/>
12+
* **Cloud Scanning**: Automatically scans all container images pushed to the registry or as soon a new task which involves a container is spawned in your account. Managed through [cloud-connector module](https://github.com/sysdiglabs/terraform-google-secure-for-cloud/tree/master/modules/services/cloud-connector).
1313
<br/><br/>
1414

1515
For other Cloud providers check: [AWS](https://github.com/sysdiglabs/terraform-aws-secure-for-cloud), [Azure](https://github.com/sysdiglabs/terraform-azurerm-secure-for-cloud)
1616

17-
<br/>
18-
1917
## Prerequisites
2018

2119
You **must** have following **roles** in your GCP credentials
@@ -106,6 +104,33 @@ Notice that:
106104

107105

108106
<br/><br/>
107+
108+
109+
## Forcing Events
110+
111+
**Threat Detection**
112+
113+
Choose one of the rules contained in the `GCP Best Practices` policy and execute it in your GCP account.
114+
ex.: Create an alert (Monitoring > Alerting > Create policy). Delete it to prompt the event.
115+
116+
Remember that in case you add new rules to the policy you need to give it time to propagate the changes.
117+
118+
In the `cloud-connector` logs you should see similar logs to these
119+
> An alert has been deleted (requesting user=..., requesting IP=..., resource name=projects/test/alertPolicies/3771445340801051512)
120+
121+
**Image Scanning**
122+
123+
Upload an image to a new Repository in a Artifact Registry. Follow repository `Setup Instructions` provided by GCP
124+
```bash
125+
$ docker tag REPO_REGION-docker.pkg.dev/PROJECT-ID/REPOSITORY/IMAGE:latest
126+
$ docker push REPO_REGION-docker.pkg.dev/PROJECT-ID/REPOSITORY/IMAGE:latest
127+
````
128+
129+
In the `cloud-connector` logs you should see similar logs to these
130+
> An image has been pushed to GCR registry (project=..., tag=europe-west2-docker.pkg.dev/test-repo/alpine/alpine:latest, digest=europe-west2-docker.pkg.dev/test-repo/alpine/alpine@sha256:be9bdc0ef8e96dbc428dc189b31e2e3b05523d96d12ed627c37aa2936653258c)
131+
132+
> Starting GCR scanning for 'europe-west2-docker.pkg.dev/test-repo/alpine/alpine:latest
133+
109134
## Troubleshooting
110135
111136
- Q1: Getting "Error creating WorkloadIdentityPool: googleapi: Error 409: Requested entity already exists"<br/>
@@ -127,7 +152,7 @@ Notice that:
127152
128153
- Q2: Scanning does not seem to work<br/>
129154
A2: Verify that `gcr` topic exists. If `create_gcr_topic` is set to false and `gcr` topic is not found, the GCR scanning is ommited and won't be deployed. For more info see GCR PubSub topic.
130-
155+
<br/><br/>
131156
- Q3: Scanning, I get an error saying:
132157
```
133158
error starting scan runner for image ****: rpc error: code = PermissionDenied desc = Cloud Build API has not been used in project *** before or it is disabled.
@@ -136,9 +161,7 @@ Notice that:
136161
If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry
137162
```
138163
A3: Do as the error says and activate CloudBuild API. Check the list of all the required APIs that need to be activated per feature module.
139-
140-
141-
<br/><br/><br/>
164+
<br/><br/>
142165
## Authors
143166
144167
Module is maintained and supported by [Sysdig](https://sysdig.com).

modules/services/cloud-connector/README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ A **Cloud Run** deployment that will detect events in your infrastructure.
55
## Usage
66

77
```hcl
8+
provider "google" {
9+
project = "<PROJECT_ID>"
10+
region = "<REGION_ID>; ex. us-central-1"
11+
}
12+
813
module "cloud_connector_gcp" {
914
source = "sysdiglabs/secure-for-cloud/google/services/cloud-connector"
1015
1116
sysdig_secure_api_token = "00000000-1111-2222-3333-444444444444"
1217
sysdig_secure_endpoint = "https://secure.sysdig.com"
1318
bucket_config_name = "cloud-connector-config-bucket"
14-
location = "us-central1"
1519
}
1620
```
1721

@@ -51,6 +55,7 @@ No modules.
5155
| [google_storage_bucket_iam_member.read_access](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/storage_bucket_iam_member) | resource |
5256
| [google_storage_bucket_object.config](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/storage_bucket_object) | resource |
5357
| [random_string.random](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) | resource |
58+
| [google_client_config.current](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/client_config) | data source |
5459
| [google_project.project](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/project) | data source |
5560

5661
## Inputs
@@ -68,7 +73,6 @@ No modules.
6873
| <a name="input_config_source"></a> [config\_source](#input\_config\_source) | Path to a file that contains the contents of the configuration file to be saved in the bucket | `string` | `null` | no |
6974
| <a name="input_extra_envs"></a> [extra\_envs](#input\_extra\_envs) | Extra environment variables for the Cloud Connector instance | `map(string)` | `{}` | no |
7075
| <a name="input_image_name"></a> [image\_name](#input\_image\_name) | Cloud Connector image to deploy | `string` | `"gcr.io/mateo-burillo-ns/cloud-connector:latest"` | no |
71-
| <a name="input_location"></a> [location](#input\_location) | Zone where the cloud connector will be deployed | `string` | `"us-central1"` | no |
7276
| <a name="input_max_instances"></a> [max\_instances](#input\_max\_instances) | Max number of instances for the Cloud Connector | `number` | `1` | no |
7377
| <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-cloudconnector"` | no |
7478
| <a name="input_verify_ssl"></a> [verify\_ssl](#input\_verify\_ssl) | Verify the SSL certificate of the Secure endpoint | `bool` | `true` | no |

modules/services/cloud-connector/cloud_run.tf

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ locals {
2525
},
2626
{
2727
name = "GCP_REGION"
28-
value = var.location
28+
value = data.google_client_config.current.region
2929
}
3030
], [
3131
for env_key, env_value in var.extra_envs :
@@ -38,7 +38,7 @@ locals {
3838
}
3939

4040
resource "google_cloud_run_service" "cloud_connector" {
41-
location = var.location
41+
location = data.google_client_config.current.region
4242
name = var.name
4343

4444
lifecycle {
@@ -95,7 +95,7 @@ resource "google_cloud_run_service" "cloud_connector" {
9595

9696
resource "google_eventarc_trigger" "trigger" {
9797
name = "${var.name}-trigger"
98-
location = var.location
98+
location = data.google_client_config.current.region
9999
service_account = var.cloud_connector_sa_email
100100
matching_criteria {
101101
attribute = "type"
@@ -104,7 +104,7 @@ resource "google_eventarc_trigger" "trigger" {
104104
destination {
105105
cloud_run_service {
106106
service = google_cloud_run_service.cloud_connector.name
107-
region = var.location
107+
region = data.google_client_config.current.region
108108
path = "/audit"
109109
}
110110
}
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
data "google_client_config" "current" {
2+
}

modules/services/cloud-connector/variables.tf

-6
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ variable "verify_ssl" {
4040
default = true
4141
}
4242

43-
variable "location" {
44-
type = string
45-
default = "us-central1"
46-
description = "Zone where the cloud connector will be deployed"
47-
}
48-
4943
variable "image_name" {
5044
type = string
5145
default = "gcr.io/mateo-burillo-ns/cloud-connector:latest"

test/fixtures/single-project/variables.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ variable "sysdig_secure_endpoint" {
1818

1919
variable "location" {
2020
type = string
21-
default = "us-central1"
21+
default = "asia-northeast1"
2222
description = "Zone where the stack will be deployed"
2323
}

0 commit comments

Comments
 (0)