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

fix(agentless-scanning): fix org onboarding for vm workload scanning #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
18 changes: 6 additions & 12 deletions modules/vm-workload-scanning/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,14 @@ data "aws_iam_policy_document" "functions" {
}

resource "aws_iam_policy" "ecr_scanning" {
count = var.is_organizational ? 0 : 1

name = "${local.ecr_role_name}-ecr"
description = "Grants Sysdig Secure access to ECR images"
policy = data.aws_iam_policy_document.scanning.json
tags = var.tags
}

resource "aws_iam_policy" "functions_scanning" {
count = var.lambda_scanning_enabled && !var.is_organizational? 1 : 0
count = var.lambda_scanning_enabled ? 1 : 0

name = "${local.ecr_role_name}-functions"
description = "Grants Sysdig Secure access to AWS Lambda"
Expand Down Expand Up @@ -108,26 +106,22 @@ data "aws_iam_policy_document" "scanning_assume_role_policy" {
}

resource "aws_iam_role" "scanning" {
count = var.is_organizational ? 0 : 1

name = local.ecr_role_name
tags = var.tags
assume_role_policy = data.aws_iam_policy_document.scanning_assume_role_policy.json
}

resource "aws_iam_policy_attachment" "scanning" {
count = var.is_organizational ? 0 : 1

name = local.ecr_role_name
roles = [aws_iam_role.scanning[0].name]
policy_arn = aws_iam_policy.ecr_scanning[0].arn
roles = [aws_iam_role.scanning.name]
policy_arn = aws_iam_policy.ecr_scanning.arn
}

resource "aws_iam_policy_attachment" "functions" {
count = var.lambda_scanning_enabled && !var.is_organizational ? 1 : 0
count = var.lambda_scanning_enabled ? 1 : 0

name = local.ecr_role_name
roles = [aws_iam_role.scanning[0].name]
roles = [aws_iam_role.scanning.name]
policy_arn = aws_iam_policy.functions_scanning[0].arn
}

Expand All @@ -145,7 +139,7 @@ resource "sysdig_secure_cloud_auth_account_component" "vm_workload_scanning_acco
version = "v0.1.0"
trusted_role_metadata = jsonencode({
aws = {
role_name = aws_iam_role.scanning[0].name
role_name = aws_iam_role.scanning.name
}
})

Expand Down
2 changes: 1 addition & 1 deletion modules/vm-workload-scanning/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
output "role_arn" {
description = "Role used by Sysdig Platform for Agentless Workload Scanning"
value = var.is_organizational ? null : aws_iam_role.scanning[0].arn
value = var.is_organizational ? null : aws_iam_role.scanning.arn
depends_on = [aws_iam_role.scanning]
}

Expand Down