-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding onboarding module for Agentless Lambda scanning
- Loading branch information
1 parent
c5926a7
commit b17f5a7
Showing
6 changed files
with
214 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
resource "google_service_account" "lambda" { | ||
project = var.project_id | ||
account_id = "sysdig-ws-${local.suffix}" | ||
display_name = "Sysdig Agentless Lambda Scanning" | ||
} | ||
|
||
resource "google_project_iam_custom_role" "lambda" { | ||
project = var.project_id | ||
role_id = "${var.role_name}LambdaScanning{title(local.suffix)}" | ||
title = "Role for Sysdig Agentless Lambda Scanning" | ||
permissions = [ | ||
# artifact registry reader permissions | ||
"artifactregistry.repositories.downloadArtifacts", | ||
"artifactregistry.repositories.get", | ||
"artifactregistry.repositories.list", | ||
"artifactregistry.dockerimages.get", | ||
"artifactregistry.dockerimages.list", | ||
"storage.objects.get", | ||
"storage.buckets.list", | ||
"storage.objects.list", | ||
|
||
# workload identity federation | ||
"iam.serviceAccounts.getAccessToken", | ||
"gcloudfunctions.list", | ||
"gcloudfunctions.get" | ||
] | ||
} | ||
|
||
resource "google_project_iam_binding" "lambda_custom" { | ||
project = var.project_id | ||
role = google_project_iam_custom_role.lambda.id | ||
|
||
members = [ | ||
"serviceAccount:${google_service_account.lambda.email}", | ||
] | ||
} | ||
|
||
resource "google_iam_workload_identity_pool" "lambda" { | ||
workload_identity_pool_id = "sysdig-wl-${local.suffix}" | ||
} | ||
|
||
resource "google_iam_workload_identity_pool_provider" "lambda" { | ||
count = var.sysdig_backend != null ? 1 : 0 | ||
|
||
lifecycle { | ||
precondition { | ||
condition = (var.sysdig_backend != null && var.sysdig_account_id == null) | ||
error_message = "Cannot provide both sysdig_backend or sysdig_account_id" | ||
} | ||
} | ||
|
||
workload_identity_pool_id = google_iam_workload_identity_pool.lambda.workload_identity_pool_id | ||
workload_identity_pool_provider_id = "sysdig-lambda-${local.suffix}" | ||
display_name = "Sysdig Lambda Scanning" | ||
description = "AWS identity pool provider for Sysdig Secure Agentless Lambda Scanning" | ||
disabled = false | ||
|
||
attribute_condition = "attribute.aws_account==\"${var.sysdig_backend}\"" | ||
|
||
attribute_mapping = { | ||
"google.subject" = "assertion.arn" | ||
"attribute.aws_account" = "assertion.account" | ||
"attribute.role" = "assertion.arn.extract(\"/assumed-role/{role}/\")" | ||
"attribute.session" = "assertion.arn.extract(\"/assumed-role/{role_and_session}/\").extract(\"/{session}\")" | ||
} | ||
|
||
aws { | ||
account_id = var.sysdig_backend | ||
} | ||
} | ||
|
||
resource "google_service_account_iam_member" "lambda_custom" { | ||
count = var.sysdig_backend != null ? 1 : 0 | ||
|
||
lifecycle { | ||
precondition { | ||
condition = (var.sysdig_backend != null && var.sysdig_account_id == null) | ||
error_message = "Cannot provide both sysdig_backend or sysdig_account_id" | ||
} | ||
} | ||
|
||
service_account_id = google_service_account.lambda.name | ||
role = "roles/iam.workloadIdentityUser" | ||
member = "principalSet://iam.googleapis.com/${google_iam_workload_identity_pool.lambda.name}/attribute.aws_account/${var.sysdig_backend}" | ||
} | ||
|
||
resource "google_iam_workload_identity_pool_provider" "lambda_gcp" { | ||
count = var.sysdig_account_id != null ? 1 : 0 | ||
|
||
lifecycle { | ||
precondition { | ||
condition = (var.sysdig_backend == null && var.sysdig_account_id != null) | ||
error_message = "Cannot provide both sysdig_backend or sysdig_account_id" | ||
} | ||
} | ||
|
||
workload_identity_pool_id = google_iam_workload_identity_pool.lambda.workload_identity_pool_id | ||
workload_identity_pool_provider_id = "sysdig-lambda-${local.suffix}-gcp" | ||
display_name = "Sysdig Agentless Lambda Scanning" | ||
description = "GCP identity pool provider for Sysdig Secure Agentless Lambda Scanning" | ||
disabled = false | ||
|
||
attribute_condition = "google.subject == \"${var.sysdig_account_id}\"" | ||
|
||
attribute_mapping = { | ||
"google.subject" = "assertion.sub" | ||
"attribute.sa_id" = "assertion.sub" | ||
} | ||
|
||
oidc { | ||
issuer_uri = "https://accounts.google.com" | ||
} | ||
} | ||
|
||
resource "google_service_account_iam_member" "lambda_custom_gcp" { | ||
count = var.sysdig_account_id != null ? 1 : 0 | ||
|
||
lifecycle { | ||
precondition { | ||
condition = (var.sysdig_backend == null && var.sysdig_account_id != null) | ||
error_message = "Cannot provide both sysdig_backend or sysdig_account_id" | ||
} | ||
} | ||
|
||
service_account_id = google_service_account.lambda.name | ||
role = "roles/iam.workloadIdentityUser" | ||
member = "principalSet://iam.googleapis.com/${google_iam_workload_identity_pool.lambda.name}/attribute.sa_id/${var.sysdig_account_id}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
data "google_project" "project" { | ||
project_id = var.project_id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
locals { | ||
suffix = var.suffix == null ? random_id.suffix[0].hex : var.suffix | ||
} | ||
|
||
resource "random_id" "suffix" { | ||
count = var.suffix == null ? 1 : 0 | ||
byte_length = 3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
output "project_id" { | ||
value = var.project_id | ||
} | ||
|
||
output "project_number" { | ||
value = data.google_project.project.number | ||
} | ||
|
||
output "controller_service_account" { | ||
value = google_service_account.lambda.email | ||
} | ||
|
||
output "workload_identity_pool_provider" { | ||
value = var.sysdig_backend != null ? google_iam_workload_identity_pool_provider.lambda[0].name : var.sysdig_account_id != null ? google_iam_workload_identity_pool_provider.lambda_gcp[0].name : null | ||
precondition { | ||
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" | ||
} | ||
} | ||
|
||
output "json_payload" { | ||
value = jsonencode({ | ||
"projectId" = var.project_id | ||
"projectNumber" = data.google_project.project.number | ||
"serviceAccount" = google_service_account.lambda.email | ||
"identityProvider" = var.sysdig_backend != null ? google_iam_workload_identity_pool_provider.lambda[0].name : var.sysdig_account_id != null ? google_iam_workload_identity_pool_provider.lambda_gcp[0].name : null | ||
}) | ||
precondition { | ||
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
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" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
variable "project_id" { | ||
type = string | ||
description = "GCP Project ID" | ||
} | ||
|
||
variable "sysdig_backend" { | ||
type = string | ||
description = "Sysdig provided AWS Account designated for the lambda scan.<br/>One of `sysdig_backend` or `sysdig_account_id`must be provided" | ||
default = null | ||
} | ||
|
||
variable "sysdig_account_id" { | ||
type = string | ||
description = "Sysdig provided GCP Account designated for the lambda scan.<br/>One of `sysdig_backend` or `sysdig_account_id`must be provided" | ||
default = null | ||
} | ||
|
||
# optionals | ||
variable "role_name" { | ||
type = string | ||
description = "Name for the Worker Role on the Customer infrastructure" | ||
default = "SysdigAgentlessLambdaRole" | ||
} | ||
|
||
variable "suffix" { | ||
type = string | ||
description = "By default a random value will be autogenerated.<br/>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)" | ||
default = null | ||
} |