-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #817 from ministryofjustice/feature/workflow-for-o…
…rg-sec Add OIDC provider and pipelines
- Loading branch information
Showing
15 changed files
with
302 additions
and
43 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,38 @@ | ||
name: terraform apply (organisation-security) | ||
|
||
on: | ||
push: | ||
paths: | ||
- 'organisation-security/terraform/**' | ||
- 'modules/**' | ||
- '.github/workflows/organisation-security-plan.yml' | ||
- '.github/workflows/organisation-security-apply.yml' | ||
branches: | ||
- main | ||
|
||
jobs: | ||
apply: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write | ||
contents: read | ||
defaults: | ||
run: | ||
working-directory: ./organisation-security/terraform | ||
steps: | ||
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 | ||
- uses: aws-actions/configure-aws-credentials@5fd3084fc36e372ff1fff382a39b10d03659f355 # v2.2.0 | ||
with: | ||
role-to-assume: arn:aws:iam::${{secrets.AWS_SECURITY_ACCOUNT_ID}}:role/github-actions-apply | ||
role-session-name: GitHubActions | ||
aws-region: eu-west-2 | ||
- uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 # v2.0.3 | ||
with: | ||
terraform_version: 1.5.2 | ||
- run: terraform fmt -check | ||
continue-on-error: true | ||
- run: terraform init | ||
- run: terraform validate -no-color | ||
- run: terraform plan -no-color | ||
- run: terraform apply -auto-approve | ||
if: github.event.ref == 'refs/heads/main' |
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,36 @@ | ||
name: terraform plan (organisation-security) | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- 'organisation-security/terraform/**' | ||
- 'modules/**' | ||
- '.github/workflows/organisation-security-plan.yml' | ||
- '.github/workflows/organisation-security-apply.yml' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
plan: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write | ||
contents: read | ||
defaults: | ||
run: | ||
working-directory: ./organisation-security/terraform | ||
steps: | ||
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 | ||
- uses: aws-actions/configure-aws-credentials@5fd3084fc36e372ff1fff382a39b10d03659f355 # v2.2.0 | ||
with: | ||
role-to-assume: arn:aws:iam::${{secrets.AWS_SECURITY_ACCOUNT_ID}}:role/github-actions-plan | ||
role-session-name: GitHubActions | ||
aws-region: eu-west-2 | ||
- uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 # v2.0.3 | ||
with: | ||
terraform_version: 1.5.2 | ||
- run: terraform fmt -check | ||
continue-on-error: true | ||
- run: terraform init | ||
- run: terraform validate -no-color | ||
- run: terraform plan -no-color | ||
|
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,39 @@ | ||
# State bucket key | ||
|
||
resource "aws_kms_key" "terraform_state_s3_bucket" { | ||
policy = data.aws_iam_policy_document.terraform_state_s3_bucket_kms.json | ||
is_enabled = true | ||
enable_key_rotation = true | ||
} | ||
|
||
resource "aws_kms_alias" "terraform_state_s3_bucket" { | ||
name = "alias/terraform-state-s3-bucket" | ||
target_key_id = aws_kms_key.terraform_state_s3_bucket.id | ||
} | ||
|
||
data "aws_iam_policy_document" "terraform_state_s3_bucket_kms" { | ||
statement { | ||
effect = "Allow" | ||
actions = ["kms:*"] | ||
resources = ["*"] | ||
|
||
principals { | ||
type = "AWS" | ||
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"] | ||
} | ||
} | ||
|
||
statement { | ||
effect = "Allow" | ||
actions = [ | ||
"kms:GenerateDataKey", | ||
"kms:Decrypt" | ||
] | ||
resources = ["*"] | ||
|
||
principals { | ||
type = "AWS" | ||
identifiers = ["arn:aws:iam::${resource.aws_organizations_account.organisation_security.id}:root"] | ||
} | ||
} | ||
} |
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
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,7 @@ | ||
output "bucket_name" { | ||
value = aws_s3_bucket.default.id | ||
} | ||
|
||
output "bucket" { | ||
value = aws_s3_bucket.default | ||
} |
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
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
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#################################### | ||
# OIDC Provider for GitHub actions # | ||
#################################### | ||
|
||
module "github_oidc" { | ||
source = "github.com/ministryofjustice/modernisation-platform-github-oidc-provider?ref=82f546bd5f002674138a2ccdade7d7618c6758b3" # v3.0.0 | ||
role_name = "github-actions-plan" | ||
additional_permissions = data.aws_iam_policy_document.oidc_assume_role_plan.json | ||
github_repositories = ["ministryofjustice/aws-root-account:pull_request"] | ||
tags_common = { "Name" = "GitHub Actions Plan" } | ||
tags_prefix = "" | ||
} | ||
|
||
data "aws_iam_policy_document" "oidc_assume_role_plan" { | ||
statement { | ||
sid = "AllowOIDCToDecryptKMS" | ||
effect = "Allow" | ||
resources = ["*"] | ||
actions = ["kms:Decrypt"] | ||
} | ||
|
||
statement { | ||
sid = "AllowOIDCReadState" | ||
effect = "Allow" | ||
resources = ["arn:aws:s3:::moj-aws-root-account-terraform-state/*", "arn:aws:s3:::moj-aws-root-account-terraform-state/"] | ||
actions = ["s3:Get*", | ||
"s3:List*"] | ||
} | ||
} | ||
|
||
module "github_actions_apply_role" { | ||
|
||
source = "github.com/ministryofjustice/modernisation-platform-github-oidc-role?ref=9d9a2d23cf569348cbdb665c979fcbaed76bb2f4" # v3.1.0 | ||
|
||
github_repositories = ["ministryofjustice/aws-root-account:ref:refs/heads/main"] | ||
role_name = "github-actions-apply" | ||
policy_arns = ["arn:aws:iam::aws:policy/AdministratorAccess"] | ||
policy_jsons = [data.aws_iam_policy_document.oidc_assume_role_apply.json] | ||
subject_claim = "pull_request" | ||
tags = { "Name" = "GitHub Actions Apply" } | ||
|
||
} | ||
|
||
data "aws_iam_policy_document" "oidc_assume_role_apply" { | ||
statement { | ||
effect = "Allow" | ||
actions = [ | ||
"account:*AlternateContact", | ||
"apigateway:*", | ||
"budgets:*", | ||
"ce:*", | ||
"cloudtrail:*", | ||
"config:*", | ||
"cur:DescribeReportDefinitions", | ||
"events:*", | ||
"fms:*", | ||
"guardduty:*", | ||
"iam:*", | ||
"identitystore:ListGroups", | ||
"identitystore:GetGroupId", | ||
"identitystore:DescribeGroup", | ||
"kms:Decrypt", | ||
"lambda:*", | ||
"license-manager:*", | ||
"logs:*", | ||
"organizations:Describe*", | ||
"organizations:List*", | ||
"route53:*", | ||
"s3:*", | ||
"secretsmanager:*", | ||
"securityhub:*", | ||
"sns:*", | ||
] | ||
resources = ["*"] | ||
} | ||
} |
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
Oops, something went wrong.