-
Notifications
You must be signed in to change notification settings - Fork 2
CCM-11586: Enable mTLS on API GW #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
aa25315
CCM-11586: initial truststore
masl2 9bca7cb
CCM-11586: group is invalid prop
masl2 6e1a983
CCM-11586: missing name
masl2 2b3ac47
CCM-11586: store ref not indexed
masl2 d3d31dc
CCM-11586: store ref not indexed
masl2 1193294
CCM-11586: cert references
masl2 bfe977e
CCM-11586: domain store refs
masl2 a54d726
CCM-11586: domain name lifecycles
masl2 20f4ec2
CCM-11586: more tf refs
masl2 94e1215
CCM-11586: domain name lifecycles
masl2 fdde815
CCM-11586: more sensible route53 config
masl2 235abc7
CCM-11586: correct name reference
masl2 4397b2c
CCM-11586: correct locals csis3 def
masl2 911df5d
CCM-11586: change csi to meet s3 naming convention
masl2 e29e8cc
CCM-11586: remove config variable, reference infra
masl2 6dbea64
CCM-11586: centralised bucket logging, define a bucket
masl2 27b2671
CCM-11586: try fix truststore uri
masl2 f02cafc
CCM-11586: Disable execute-api endpoint
masl2 1413b02
CCM-11586: secure logging bucket
masl2 108dfc1
CCM-11586: refine logging bucket policies
masl2 8d30c4b
CCM-11586: does consolidation make sonar happy
masl2 00faa97
CCM-11586: consolidation does make sonar happy
masl2 d3eb513
CCM-11586: forgot to save
masl2 a23d453
CCM-11586: version log bucket
masl2 d6a7c30
Merge branch 'main' into feature/CCM-11586_enable-gw-mtls
masl2 7112ad2
CCM-11586: use shared s3 module; always gen dummy certs
masl2 dc0ef78
CCM-11586: Correct references to new modules
masl2 7517345
CCM-11586: Correct references to new modules
masl2 381eb33
CCM-11586: Correct references to new modules
masl2 a7a6cae
CCM-11586: SSL module always present for dummies
masl2 706dbd0
CCM-11586: additional tags not needed
masl2 f2acd59
Merge branch 'main' into feature/CCM-11586_enable-gw-mtls
masl2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
infrastructure/terraform/components/api/api_gateway_base_path_mapping.tf
This file contains hidden or 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,5 +1,5 @@ | ||
| resource "aws_api_gateway_base_path_mapping" "main" { | ||
| api_id = aws_api_gateway_rest_api.main.id | ||
| stage_name = aws_api_gateway_stage.main.stage_name | ||
| domain_name = aws_api_gateway_domain_name.main.domain_name | ||
| domain_name = var.manually_configure_mtls_truststore ? aws_api_gateway_domain_name.main.0.domain_name : aws_api_gateway_domain_name.main_nonprod.0.domain_name | ||
| } |
38 changes: 38 additions & 0 deletions
38
infrastructure/terraform/components/api/api_gateway_domain.tf
This file contains hidden or 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,9 +1,47 @@ | ||
| resource "aws_api_gateway_domain_name" "main" { | ||
| count = var.manually_configure_mtls_truststore ? 1 : 0 | ||
| regional_certificate_arn = aws_acm_certificate_validation.main.certificate_arn | ||
| domain_name = local.root_domain_name | ||
| security_policy = "TLS_1_2" | ||
|
|
||
| endpoint_configuration { | ||
| types = ["REGIONAL"] | ||
| } | ||
|
|
||
| depends_on = [ | ||
| module.domain_truststore, | ||
| aws_s3_object.placeholder_truststore | ||
| ] | ||
|
|
||
| mutual_tls_authentication { | ||
| truststore_uri = "s3://${module.domain_truststore.id}/${aws_s3_object.placeholder_truststore[0].key}" | ||
| truststore_version = aws_s3_object.placeholder_truststore[0].version_id | ||
| } | ||
|
|
||
| lifecycle { | ||
| ignore_changes = [ | ||
| mutual_tls_authentication | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| resource "aws_api_gateway_domain_name" "main_nonprod" { | ||
| count = !var.manually_configure_mtls_truststore ? 1 : 0 | ||
| regional_certificate_arn = aws_acm_certificate_validation.main.certificate_arn | ||
| domain_name = local.root_domain_name | ||
| security_policy = "TLS_1_2" | ||
|
|
||
| endpoint_configuration { | ||
| types = ["REGIONAL"] | ||
| } | ||
|
|
||
| depends_on = [ | ||
| module.domain_truststore, | ||
| aws_s3_object.placeholder_truststore_nonprod | ||
| ] | ||
|
|
||
| mutual_tls_authentication { | ||
| truststore_uri = "s3://${module.domain_truststore.id}/${aws_s3_object.placeholder_truststore_nonprod[0].key}" | ||
| truststore_version = aws_s3_object.placeholder_truststore_nonprod[0].version_id | ||
| } | ||
| } |
This file contains hidden or 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
22 changes: 22 additions & 0 deletions
22
infrastructure/terraform/components/api/module_domain_truststore.tf
This file contains hidden or 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,22 @@ | ||
| module "domain_truststore" { | ||
| source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/s3bucket?ref=v2.0.17" | ||
|
|
||
| name = "truststore" | ||
| aws_account_id = var.aws_account_id | ||
| component = var.component | ||
| environment = var.environment | ||
| project = var.project | ||
| region = var.region | ||
|
|
||
| default_tags = merge(local.default_tags, { "Enable-Backup" = var.enable_backups }, { "Enable-S3-Continuous-Backup" = var.enable_backups }, { "SKIP_S3_AUDIT" = "true" }) | ||
| kms_key_arn = module.kms.key_id | ||
|
|
||
| bucket_logging_target = { | ||
| bucket = module.logging_bucket.bucket | ||
| prefix = "truststore/" | ||
| } | ||
|
|
||
| policy_documents = [ | ||
| ] | ||
|
|
||
| } | ||
35 changes: 35 additions & 0 deletions
35
infrastructure/terraform/components/api/module_logging_bucket.tf
This file contains hidden or 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,35 @@ | ||
| module "logging_bucket" { | ||
| source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/s3bucket?ref=v2.0.17" | ||
|
|
||
| name = "bucket-logs" | ||
| aws_account_id = var.aws_account_id | ||
| component = var.component | ||
| environment = var.environment | ||
| project = var.project | ||
| region = var.region | ||
|
|
||
| default_tags = merge(local.default_tags, { "Enable-Backup" = var.enable_backups }, { "Enable-S3-Continuous-Backup" = var.enable_backups }, { "SKIP_S3_AUDIT" = "true" }) | ||
masl2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| kms_key_arn = module.kms.key_id | ||
|
|
||
| policy_documents = [ | ||
| data.aws_iam_policy_document.logging.json | ||
| ] | ||
| } | ||
|
|
||
| data "aws_iam_policy_document" "logging" { | ||
| statement { | ||
| sid = "s3-log-delivery" | ||
| effect = "Allow" | ||
|
|
||
| principals { | ||
| type = "Service" | ||
| identifiers = ["logging.s3.amazonaws.com"] | ||
| } | ||
|
|
||
| actions = ["s3:PutObject"] | ||
|
|
||
| resources = [ | ||
| "${module.logging_bucket.arn}/*", | ||
| ] | ||
| } | ||
| } | ||
12 changes: 12 additions & 0 deletions
12
infrastructure/terraform/components/api/module_supplier_ssl.tf
This file contains hidden or 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,12 @@ | ||
| module "supplier_ssl" { | ||
| source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/ssl?ref=v2.0.17" | ||
|
|
||
| name = "sapi_trust" | ||
| aws_account_id = var.aws_account_id | ||
| default_tags = local.default_tags | ||
| component = var.component | ||
| environment = var.environment | ||
| project = var.project | ||
| region = var.region | ||
| subject_common_name = local.root_domain_name | ||
| } |
This file contains hidden or 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
32 changes: 32 additions & 0 deletions
32
infrastructure/terraform/components/api/s3_object_placeholder_truststore.tf
This file contains hidden or 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,32 @@ | ||
| # In manually configured (e.g. dev main, nonprod main, prod main) add lifecycle policy to permit manual management of cert | ||
| resource "aws_s3_object" "placeholder_truststore" { | ||
| count = var.manually_configure_mtls_truststore ? 1 : 0 | ||
| bucket = module.domain_truststore.bucket | ||
| key = "truststore.pem" | ||
| content = module.supplier_ssl.cacert_pem | ||
|
|
||
| depends_on = [ | ||
| module.domain_truststore, | ||
| module.supplier_ssl | ||
| ] | ||
|
|
||
| lifecycle { | ||
| ignore_changes = [ | ||
| content | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| # In non-manually configured env (e.g. PR) exclude lifecycle policy so resources are managed | ||
| # Requires duplicate block as lifecycle policies cannot be dynamic | ||
| resource "aws_s3_object" "placeholder_truststore_nonprod" { | ||
| count = !var.manually_configure_mtls_truststore ? 1 : 0 | ||
| bucket = module.domain_truststore.bucket | ||
| key = "truststore.pem" | ||
| content = module.supplier_ssl.cacert_pem | ||
|
|
||
| depends_on = [ | ||
| module.domain_truststore, | ||
| module.supplier_ssl | ||
| ] | ||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.