Skip to content

Commit

Permalink
Merge pull request #272 from ministryofjustice/feature/secure-code-an…
Browse files Browse the repository at this point in the history
…alysis-fixes

Secure code analysis fixes
  • Loading branch information
dms1981 authored Oct 17, 2023
2 parents 77e9522 + de1fd03 commit 5183a9c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ on:
branches:
- main

permissions: {}

jobs:
docs:
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ In order to prevent older versions from being retained forever, in addition to t

| Name | Source | Version |
|------|--------|---------|
| <a name="module_s3-bucket"></a> [s3-bucket](#module\_s3-bucket) | github.com/ministryofjustice/modernisation-platform-terraform-s3-bucket | v7.0.0 |
| <a name="module_s3-bucket"></a> [s3-bucket](#module\_s3-bucket) | github.com/ministryofjustice/modernisation-platform-terraform-s3-bucket | 8688bc15a08fbf5a4f4eef9b7433c5a417df8df1 |

## Resources

Expand All @@ -128,15 +128,17 @@ In order to prevent older versions from being retained forever, in addition to t
| [aws_iam_role_policy_attachment.bastion_s3](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
| [aws_kms_alias.bastion_s3_alias](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_alias) | resource |
| [aws_kms_key.bastion_s3](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource |
| [aws_kms_key_policy.bastion_s3](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key_policy) | resource |
| [aws_launch_template.bastion_linux_template](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template) | resource |
| [aws_s3_object.bucket_public_keys_readme](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_object) | resource |
| [aws_s3_object.user_public_keys](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_object) | resource |
| [aws_security_group.bastion_linux](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource |
| [aws_security_group_rule.basion_linux_egress_1](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
| [aws_security_group_rule.basion_linux_egress_2](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
| [aws_security_group_rule.bastion_linux_egress_1](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
| [aws_security_group_rule.bastion_linux_egress_2](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
| [aws_security_group_rule.bastion_linux_egress_3](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
| [random_string.random6](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) | resource |
| [aws_ami.linux_2_image](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) | data source |
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
| [aws_iam_policy_document.bastion_assume_policy_document](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.bastion_policy_document](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.bastion_ssm_s3_policy_document](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
Expand Down
41 changes: 37 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
data "aws_caller_identity" "current" {}

# get shared subnet-set vpc object
data "aws_vpc" "shared_vpc" {
# provider = aws.share-host
Expand Down Expand Up @@ -63,13 +65,44 @@ resource "aws_kms_alias" "bastion_s3_alias" {
target_key_id = aws_kms_key.bastion_s3.arn
}

resource "aws_kms_key_policy" "bastion_s3" {
key_id = aws_kms_key.bastion_s3.id
policy = jsonencode({
Id = "bastion-key-access"
Statement = [
{
"Sid" : "Enable IAM User Permissions",
"Effect" : "Allow",
"Principal" : {
"AWS" : "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
},
"Action" : "kms:*",
"Resource" : aws_kms_key.bastion_s3.arn
},
{
Action = [
"kms:Decrypt",
"kms:GenerateDataKey"
]
Effect = "Allow"
Principal = {
AWS = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/bastion_linux_ec2_role"
}

Resource = aws_kms_key.bastion_s3.arn
},
]
Version = "2012-10-17"
})
}

resource "random_string" "random6" {
length = 6
special = false
}

module "s3-bucket" {
source = "github.com/ministryofjustice/modernisation-platform-terraform-s3-bucket?ref=v7.0.0"
source = "github.com/ministryofjustice/modernisation-platform-terraform-s3-bucket?ref=8688bc15a08fbf5a4f4eef9b7433c5a417df8df1"

providers = {
# Since replication_enabled is false, the below provider is not being used.
Expand Down Expand Up @@ -177,7 +210,7 @@ resource "aws_security_group" "bastion_linux" {
)
}

resource "aws_security_group_rule" "basion_linux_egress_1" {
resource "aws_security_group_rule" "bastion_linux_egress_1" {
security_group_id = aws_security_group.bastion_linux.id

description = "bastion_linux_to_local_subnet_CIDRs"
Expand All @@ -188,10 +221,10 @@ resource "aws_security_group_rule" "basion_linux_egress_1" {
cidr_blocks = [for s in data.aws_subnet.local_account : s.cidr_block]
}

resource "aws_security_group_rule" "basion_linux_egress_2" {
resource "aws_security_group_rule" "bastion_linux_egress_2" {
security_group_id = aws_security_group.bastion_linux.id

description = "bastion_linux_egress_to_inteface_endpoints"
description = "bastion_linux_egress_to_interface_endpoints"
type = "egress"
from_port = "443"
to_port = "443"
Expand Down

0 comments on commit 5183a9c

Please sign in to comment.