Skip to content

Commit

Permalink
Create a public ECR for Sbom scans (#499)
Browse files Browse the repository at this point in the history
* Adding files to create a public ECR Repository accessible only to accounts within our organization

* Adding plan action to pass the aws_org_id

* Adding changes as recommended by Pat

* Deleting old private ECR code
  • Loading branch information
sylviamclaughlin authored Oct 2, 2024
1 parent 6e1d173 commit ee110a5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 13 deletions.
1 change: 1 addition & 0 deletions .github/workflows/generate-sbom-terragrunt-apply.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ env:
CONFTEST_VERSION: 0.27.0
TERRAFORM_VERSION: 1.1.9
TERRAGRUNT_VERSION: 0.36.7
TF_VAR_aws_org_id: ${{ secrets.AWS_ORG_ID }}
TF_INPUT: false

permissions:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/generate-sbom-terragrunt-plan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ env:
CONFTEST_VERSION: 0.27.0
TERRAFORM_VERSION: 1.1.9
TERRAGRUNT_VERSION: 0.36.7
TF_VAR_aws_org_id: ${{ secrets.AWS_ORG_ID }}
TF_INPUT: false

permissions:
Expand Down
55 changes: 42 additions & 13 deletions terragrunt/aws/generate_sbom/ecr.tf
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
resource "aws_ecr_repository" "generate_sbom" {
name = "${var.product_name}/generate_sbom/trivy"
image_tag_mutability = "MUTABLE"

image_scanning_configuration {
scan_on_push = true
}

encryption_configuration {
encryption_type = "KMS"
}

resource "aws_ecrpublic_repository" "generate_sbom_public" {
provider = aws.us-east-1
repository_name = "${var.product_name}/generate_sbom/trivy"
tags = {
(var.billing_tag_key) = var.billing_tag_value
Terraform = true
Product = "${var.product_name}-${var.tool_name}"
}
}
}
data "aws_iam_policy_document" "sbom_public_policy_document" {
provider = aws.us-east-1
statement {
sid = "sbom_public_policy"
effect = "Allow"


principals {
type = "AWS"
identifiers = ["*"]
}
actions = [
"ecr:BatchCheckLayerAvailability",
"ecr:BatchDeleteImage",
"ecr:BatchGetImage",
"ecr:CompleteLayerUpload",
"ecr:DescribeImages",
"ecr:DescribeRepositories",
"ecr:GetDownloadUrlForLayer",
"ecr:GetRepositoryPolicy",
"ecr:InitiateLayerUpload",
"ecr:ListImages",
"ecr:PutImage",
"ecr:SetRepositoryPolicy",
"ecr:UploadLayerPart"
]
condition {
test = "StringEquals"
variable = "aws:PrincipalOrgID"
values = [var.aws_org_id]
}
}
}
resource "aws_ecrpublic_repository_policy" "sbom_public_policy" {
provider = aws.us-east-1
repository_name = aws_ecrpublic_repository.generate_sbom_public.repository_name
policy = sensitive(data.aws_iam_policy_document.sbom_public_policy_document.json)
}
5 changes: 5 additions & 0 deletions terragrunt/aws/generate_sbom/inputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "aws_org_id" {
description = "The AWS org account ID. Used to limit which accounts can access the public repository."
type = string
sensitive = true
}

0 comments on commit ee110a5

Please sign in to comment.