Skip to content

Commit

Permalink
fix: limit permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
mms2409 committed Mar 12, 2024
1 parent 4b749ec commit 1b78b95
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
6 changes: 1 addition & 5 deletions modules/services/workload-scanning/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ data "aws_iam_policy_document" "scanning" {
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
"ecr:BatchCheckLayerAvailability",
"ecr:GetRepositoryPolicy",
"ecr:DescribeRepositories",
"ecr:ListImages",
"ecr:DescribeImages",
"ecr:ListTagsForResource",
"ecr:GetAuthorizationToken",
]

Expand All @@ -49,7 +45,7 @@ resource "aws_iam_policy" "scanning" {
count = (var.deploy_global_resources || var.is_organizational) ? 1 : 0

name = var.name
description = "Grants Sysdig Secure access to volumes and snapshots"
description = "Grants Sysdig Secure access to ECR images"
policy = data.aws_iam_policy_document.scanning[0].json
tags = var.tags
}
Expand Down
4 changes: 0 additions & 4 deletions modules/services/workload-scanning/organizational.tf
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ Resources:
- "ecr:GetDownloadUrlForLayer"
- "ecr:BatchGetImage"
- "ecr:BatchCheckLayerAvailability"
- "ecr:GetRepositoryPolicy"
- "ecr:DescribeRepositories"
- "ecr:ListImages"
- "ecr:DescribeImages"
- "ecr:ListTagsForResource"
- "ecr:GetAuthorizationToken"
Resource: "*"
Expand Down
16 changes: 16 additions & 0 deletions modules/services/workload-scanning/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,19 @@ output "role_arn" {
description = "Role used by Sysdig Platform for Agentless Workload Scanning"
value = var.is_organizational ? null : var.deploy_global_resources ? aws_iam_role.scanning[0].arn : var.role_arn
}

output "validate_deploy_global_resources" {
value = null
precondition {
condition = (var.deploy_global_resources && var.external_id != null)
error_message = "Please provide external_id or set deploy_global_resources to false."
}
precondition {
condition = (var.deploy_global_resources && var.role_arn != null)
error_message = "Please provide ecr_role_name or set deploy_global_resources set to false."
}
precondition {
condition = (var.deploy_global_resources && var.trusted_identity != null)
error_message = "Please provide trusted_identity or set deploy_global_resources to false."
}
}
5 changes: 3 additions & 2 deletions modules/services/workload-scanning/variables.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
variable "external_id" {
description = "Random string generated unique to a customer"
description = "(Optional) This value should be provided by Sysdig. External ID is optional information that you can use in an IAM role trust policy to designate who in Sysdig can assume the role."
type = string
default = null
}

variable "trusted_identity" {
type = string
description = "The name of sysdig trusted identity"
description = "This value should be provided by Sysdig. The field refers to Sysdig's IAM role that will be authorized to pull ECR images"
}

variable "name" {
Expand Down
5 changes: 3 additions & 2 deletions modules/services/workload-scanning/versions.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
terraform {
required_version = ">= 1.2.0"
required_version = "~> 1.7"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.39.0"
version = "~> 5.0"
}
}
}

0 comments on commit 1b78b95

Please sign in to comment.