Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(vm, cloud-scan): single-project use-case #18

Merged
merged 21 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
- "secure_config_posture_identity_access/organization/main.tf"
- "secure_threat_detection/single/main.tf"
- "secure_threat_detection/organization/main.tf"
- "agentless-scan/single/main.tf"
marcuzzuu marked this conversation as resolved.
Show resolved Hide resolved
- "agentless-scan/organization/main.tf"
steps:
- name: Set up Go
Expand Down
32 changes: 32 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
- id: trailing-whitespace


- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.86.0
hooks:
- id: terraform_fmt
- id: terraform_docs
args:
- '--args=--sort-by required'
- id: terraform_tflint
args:
- '--args=--only=terraform_deprecated_interpolation'
- '--args=--only=terraform_deprecated_index'
- '--args=--only=terraform_unused_declarations'
- '--args=--only=terraform_comment_syntax'
- '--args=--only=terraform_documented_outputs'
- '--args=--only=terraform_documented_variables'
- '--args=--only=terraform_typed_variables'
- '--args=--only=terraform_module_pinned_source'
- '--args=--only=terraform_naming_convention'
- '--args=--only=terraform_required_version'
- '--args=--only=terraform_required_providers'
- '--args=--only=terraform_standard_module_structure'
- '--args=--only=terraform_workspace_remote'
- id: terrascan
6 changes: 3 additions & 3 deletions modules/services/agentless-scan/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ This module will deploy required resources for Sysdig to be able to scan hosts o


The following resources will be created on each instrumented project:
- For the **Resource Discovery**: Enable Sysdig to authenticate through a Workload Identity Pool (requires provider,
- For the **Resource Discovery**: Enable Sysdig to authenticate through a Workload Identity Pool (requires provider,
service account, role, and related bindings) in order to be able to discover the VPC/Instance/Volumes
- For the **Host Data Extraction**: Enable Sysdig to create a disk copy on our SaaS platform, to be able to extract
- For the **Host Data Extraction**: Enable Sysdig to create a disk copy on our SaaS platform, to be able to extract
the data required for security assessment.


Expand Down Expand Up @@ -103,4 +103,4 @@ Module is maintained by [Sysdig](https://sysdig.com).

## License

Apache 2 Licensed. See LICENSE for full details.
Apache 2 Licensed. See LICENSE for full details.
2 changes: 1 addition & 1 deletion modules/services/agentless-scan/controller_org.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ resource "google_organization_iam_binding" "controller_custom" {
members = [
"serviceAccount:${google_service_account.controller.email}",
]
}
}
2 changes: 1 addition & 1 deletion modules/services/agentless-scan/controller_single.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ resource "google_project_iam_binding" "controller_custom" {
members = [
"serviceAccount:${google_service_account.controller.email}",
]
}
}
2 changes: 1 addition & 1 deletion modules/services/agentless-scan/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ data "google_project" "project" {
data "google_organization" "org" {
count = local.is_organizational ? 1 : 0
domain = var.organization_domain
}
}
2 changes: 1 addition & 1 deletion modules/services/agentless-scan/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ locals {
resource "random_id" "suffix" {
count = var.suffix == null ? 1 : 0
byte_length = 3
}
}
12 changes: 10 additions & 2 deletions modules/services/agentless-scan/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
output "project_id" {
value = var.project_id
value = var.project_id
description = "Target project_id"
}

output "project_number" {
value = data.google_project.project.number
value = data.google_project.project.number
description = "Target project_number"
}

output "controller_service_account" {
value = google_service_account.controller.email

description = "Service Account (email) for Sysdig host Discovery to use"
}

output "workload_identity_pool_provider" {
Expand All @@ -16,6 +20,8 @@ output "workload_identity_pool_provider" {
condition = (var.sysdig_backend != null && var.sysdig_account_id == null) || (var.sysdig_backend == null && var.sysdig_account_id != null)
error_message = "Cannot provide both sysdig_backend or sysdig_account_id"
}

description = "Workload Identity Pool Provider URL for Sysdig host Discovery to use"
}

output "json_payload" {
Expand All @@ -29,4 +35,6 @@ output "json_payload" {
condition = (var.sysdig_backend != null && var.sysdig_account_id == null) || (var.sysdig_backend == null && var.sysdig_account_id != null)
error_message = "Cannot provide both sysdig_backend or sysdig_account_id"
}

description = "Deprecated. JSON Payload to internally provision customer on Sysdig VM Host scan on Sysdig"
}
2 changes: 1 addition & 1 deletion modules/services/agentless-scan/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ terraform {
version = ">= 3.1, < 4.0"
}
}
}
}
2 changes: 2 additions & 0 deletions modules/services/agentless-scan/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ variable "worker_identity" {
description = "Sysdig provided Identity for the Service Account in charge of performing the host disk analysis"
}

# mandatory; one of `sysdig_backend` or `sysdig_account_id`
variable "sysdig_backend" {
type = string
description = "Sysdig provided AWS Account designated for the host scan.<br/>One of `sysdig_backend` or `sysdig_account_id`must be provided"
Expand All @@ -29,6 +30,7 @@ variable "role_name" {
}



variable "suffix" {
type = string
description = "Optional. Suffix word to enable multiple deployments with different naming<br/>(Workload Identity Pool and Providers have a soft deletion on Google Platform that will disallow name re-utilization)<br/>By default a random value will be autogenerated."
Expand Down
2 changes: 1 addition & 1 deletion test/examples/agentless-scan/README
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ note;

- we test the cloud-scan module together with its dependencies on the minimal use-case
- cspm; for discovery + organizational setup (`secure-onboarding` component)
- sysdig provider `sysdig_secure_cloud_auth_account`; for authentication
- sysdig provider `sysdig_secure_cloud_auth_account`; for authentication
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# this is required for organizational setup (+cloud-host vm)

module "organization-posture" {
module "organization_posture" {
source = "sysdiglabs/secure/google//modules/services/service-principal"
project_id = "org-child-project-1"
service_account_name = "sysdig-secure-igm6"
is_organizational = true
organization_domain = "draios.com"
}
}
8 changes: 4 additions & 4 deletions test/examples/agentless-scan/organization/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
provider "google"{
project="mytestproject"
provider "google" {
project = "mytestproject"
}


Expand All @@ -9,6 +9,6 @@ module "cloud_host" {
sysdig_account_id = "012345678"
worker_identity = "foo@bar.com"

is_organizational = true
is_organizational = true
organization_domain = "myorg.com"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ resource "sysdig_secure_cloud_auth_account" "gcp_project" {
instance = "secure-onboarding"
service_principal_metadata = jsonencode({
gcp = {
key = module.organization-posture.service_account_key
key = module.organization_posture.service_account_key
}
})
}
Expand All @@ -40,10 +40,10 @@ resource "sysdig_secure_cloud_auth_account" "gcp_project" {
})
}

depends_on = [module.cloud_host, module.organization-posture]
depends_on = [module.cloud_host, module.organization_posture]
}

resource "sysdig_secure_organization" "gcp_organization_myproject" {
management_account_id = sysdig_secure_cloud_auth_account.gcp_project.id
depends_on = [module.organization-posture]
}
depends_on = [module.organization_posture]
}
Empty file.
11 changes: 11 additions & 0 deletions test/examples/agentless-scan/single/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
provider "google" {
project = "mytestproject"
region = "us-west1"
}

module "agentless_scan" {
source = "../../../..//modules/services/agentless-scan"
project_id = "mytestproject"
sysdig_account_id = "012345678"
worker_identity = "foo@bar.com"
}
18 changes: 18 additions & 0 deletions test/examples/agentless-scan/single/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
terraform {
required_version = ">=1.0"

required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.1, < 5.0"
}
random = {
source = "hashicorp/random"
version = ">= 3.1, < 4.0"
}
sysdig = {
source = "sysdiglabs/sysdig"
version = ">= 1.23.1"
}
}
}
31 changes: 31 additions & 0 deletions test/examples/agentless-scan/single/sysdig_provider.tf
marcuzzuu marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
provider "sysdig" {
sysdig_secure_url = "https://secure-staging.sysdig.com"
sysdig_secure_api_token = "12124235"
}

resource "sysdig_secure_cloud_auth_account" "gcp_project" {
enabled = true
provider_id = "mytestproject"
provider_type = "PROVIDER_GCP"

feature {
secure_agentless_scanning {
enabled = true
components = ["COMPONENT_SERVICE_PRINCIPAL/secure-scanning"]
}
}

component {
type = "COMPONENT_SERVICE_PRINCIPAL"
instance = "secure-scanning"
service_principal_metadata = jsonencode({
gcp = {
workload_identity_federation = {
pool_provider_id = module.agentless_scan.workload_identity_pool_provider
}
email = module.agentless_scan.controller_service_account
}
})
}
depends_on = [module.agentless_scan]
}
Loading