-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8b095d
commit 4caf283
Showing
16 changed files
with
630 additions
and
145 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
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 |
---|---|---|
|
@@ -11,22 +11,28 @@ jobs: | |
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: setup go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.19 | ||
|
||
- name: setup python | ||
uses: actions/setup-python@v2 | ||
|
||
- name: pre-commit-cache | ||
uses: actions/cache@v2 | ||
env: | ||
cache-name: pre-commit-dot-cache | ||
with: | ||
path: ~/.cache/pre-commit | ||
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/.pre-commit-config.yaml') }} | ||
|
||
- name: run pre-commit | ||
uses: pre-commit/[email protected] | ||
|
||
- name: run go tests | ||
run: go test -v ./pkg/... | ||
|
||
- name: build the Docker image | ||
run: docker build . --file Dockerfile |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
bin/ | ||
dist/ | ||
manual_test_team_map.json | ||
.terraform |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,72 @@ | ||
locals { | ||
principal_arns = [for item in var.ecr_read_aws_accounts : format("arn:aws:iam::%s:root", item)] | ||
} | ||
|
||
resource "aws_ecr_repository" "this" { | ||
name = "security-hub-collector" | ||
image_scanning_configuration { | ||
scan_on_push = true | ||
} | ||
} | ||
|
||
resource "aws_ecr_lifecycle_policy" "this" { | ||
repository = aws_ecr_repository.this.name | ||
policy = <<EOF | ||
{ | ||
"rules": [ | ||
{ | ||
"action": { | ||
"type": "expire" | ||
}, | ||
"description": "Keep last 500 images", | ||
"rulePriority": 10, | ||
"selection": { | ||
"countNumber": 500, | ||
"countType": "imageCountMoreThan", | ||
"tagStatus": "any" | ||
} | ||
} | ||
] | ||
} | ||
EOF | ||
} | ||
|
||
resource "aws_ecr_repository_policy" "this" { | ||
repository = aws_ecr_repository.this.name | ||
policy = data.aws_iam_policy_document.cross_account_readonly.json | ||
} | ||
|
||
data "aws_iam_policy_document" "cross_account_readonly" { | ||
statement { | ||
sid = "CrossAccountReadOnly" | ||
|
||
effect = "Allow" | ||
|
||
actions = [ | ||
"ecr:BatchCheckLayerAvailability", | ||
"ecr:GetAuthorizationToken", | ||
"ecr:GetDownloadUrlForLayer", | ||
"ecr:ListImages", | ||
"ecr:DescribeImages", | ||
"ecr:BatchGetImage", | ||
] | ||
|
||
principals { | ||
identifiers = local.principal_arns | ||
type = "AWS" | ||
} | ||
} | ||
|
||
statement { | ||
sid = "" | ||
|
||
effect = "Allow" | ||
|
||
actions = ["ecr:GetAuthorizationToken"] | ||
|
||
principals { | ||
identifiers = local.principal_arns | ||
type = "AWS" | ||
} | ||
} | ||
} |
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,53 @@ | ||
data "aws_caller_identity" "current" {} | ||
|
||
data "aws_iam_openid_connect_provider" "github_actions" { | ||
url = "https://token.actions.githubusercontent.com" | ||
} | ||
|
||
module "iam_github_oidc_role_github_actions_runner" { | ||
source = "terraform-aws-modules/iam/aws//modules/iam-github-oidc-role" | ||
|
||
name = "security-hub-collector-github-oidc" | ||
|
||
path = "/delegatedadmin/developer/" | ||
permissions_boundary_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:policy/cms-cloud-admin/developer-boundary-policy" | ||
|
||
subjects = [ | ||
"Enterprise-CMCS/mac-fc-security-hub-collector:*", | ||
] | ||
|
||
policies = { | ||
github_actions_runner = aws_iam_policy.github_actions_permissions.arn | ||
} | ||
} | ||
|
||
data "aws_iam_policy_document" "github_actions_permissions" { | ||
statement { | ||
actions = [ | ||
"ecr:GetAuthorizationToken" | ||
] | ||
resources = ["*"] | ||
} | ||
|
||
statement { | ||
actions = [ | ||
"ecr:CompleteLayerUpload", | ||
"ecr:GetAuthorizationToken", | ||
"ecr:UploadLayerPart", | ||
"ecr:InitiateLayerUpload", | ||
"ecr:BatchCheckLayerAvailability", | ||
"ecr:BatchGetImage", | ||
"ecr:PutImage", | ||
"ecr:TagResource" | ||
] | ||
resources = ["arn:aws:ecr:us-east-1:${data.aws_caller_identity.current.account_id}:repository/security-hub-collector"] | ||
} | ||
} | ||
|
||
resource "aws_iam_policy" "github_actions_permissions" { | ||
name = "github-actions-permissions" | ||
policy = data.aws_iam_policy_document.github_actions_permissions.json | ||
path = "/delegatedadmin/developer/" | ||
description = "Permissions for GitHub Actions OIDC" | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,4 @@ | ||
ecr_read_aws_accounts = [ | ||
"666736308865", # MACPro DevSecOps/aws-cms-oit-iusg-acct222 | ||
"358534743481" # TODO remove | ||
] |
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 |
---|---|---|
@@ -1,22 +1,4 @@ | ||
variable "lifecycle_policy" { | ||
type = string | ||
description = "ECR repository lifecycle policy document. Used to override the default policy." | ||
default = "" | ||
} | ||
|
||
variable "tags" { | ||
type = map(any) | ||
description = "Additional tags to apply." | ||
default = {} | ||
} | ||
|
||
variable "scan_on_push" { | ||
type = bool | ||
description = "Scan image on push to repo." | ||
default = true | ||
} | ||
|
||
variable "allowed_read_principals" { | ||
variable "ecr_read_aws_accounts" { | ||
type = list(any) | ||
description = "External principals that are allowed to read from the ECR repository" | ||
description = "AWS accounts that are allowed to read from the ECR repository" | ||
} |
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 |
---|---|---|
@@ -1,10 +1,33 @@ | ||
terraform { | ||
required_version = ">= 0.13" | ||
required_version = "= 1.5.2" | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 3.0" | ||
version = "~>5.30.0" | ||
} | ||
} | ||
backend "s3" { | ||
bucket = "security-hub-collector-dev-tfstate" | ||
key = "account/state" | ||
region = "us-east-1" | ||
dynamodb_table = "security-hub-collector-dev-lock-table" | ||
encrypt = true | ||
} | ||
} | ||
|
||
provider "aws" { | ||
allowed_account_ids = ["037370603820"] | ||
|
||
default_tags { | ||
tags = { | ||
Maintainer = "[email protected]" | ||
Owner = "[email protected]" | ||
Environment = "dev" | ||
Application = "mac-fc-security-hub-collector" | ||
Business = "MACBIS" | ||
Automated = "Terraform" | ||
stack = "dev" | ||
} | ||
} | ||
} |
Oops, something went wrong.