-
Notifications
You must be signed in to change notification settings - Fork 2
[NDR-213] Add mTLS api gateway #401
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 all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3e8511a
NDR-213 Add mTLS api gateway
megan-bower4 5e25358
NDR-213 Fix indexing
megan-bower4 3d98ee2
NDR-213 Add depends on for methods
megan-bower4 c1f350f
NDR-213 Fix indexing
megan-bower4 9a202f5
NDR-213 Remove indexing
megan-bower4 afa6ee7
NDR-213 Remove unessecary prefix var
megan-bower4 0d124c0
NDR-213 tf fmt
megan-bower4 8e4954d
NDR-213 Index truststore bucket
megan-bower4 73f5f1e
NDR-213 tf fmt
megan-bower4 888b014
NDR-213 typo
megan-bower4 43595a1
NDR-213 Fix reference
megan-bower4 17d428c
NDR-213 Fix reference
megan-bower4 5141d3d
NDR-213 Refactor conditional into locals
megan-bower4 4161788
NDR-213 Disable default endpoint
megan-bower4 908dad4
NDR-213 Set Api Gateway endpoint type to Regional
megan-bower4 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
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,133 @@ | ||
| # New API Gateway for mTLS | ||
| resource "aws_api_gateway_rest_api" "ndr_doc_store_api_mtls" { | ||
| name = "${terraform.workspace}_DocStoreApiMtls" | ||
| description = "Document store API with mTLS enabled" | ||
| disable_execute_api_endpoint = true | ||
|
|
||
| endpoint_configuration { | ||
| types = ["REGIONAL"] | ||
| } | ||
|
|
||
| tags = { | ||
| Name = "${terraform.workspace}_DocStoreApiMtls" | ||
| } | ||
megan-bower4 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| resource "aws_api_gateway_domain_name" "custom_api_domain_mtls" { | ||
| domain_name = local.mtls_api_gateway_full_domain_name | ||
| regional_certificate_arn = aws_acm_certificate_validation.mtls_api_gateway_cert.certificate_arn | ||
| security_policy = "TLS_1_2" | ||
|
|
||
| endpoint_configuration { | ||
| types = ["REGIONAL"] | ||
| } | ||
|
|
||
| mutual_tls_authentication { | ||
| truststore_uri = local.truststore_uri | ||
| truststore_version = data.aws_s3_object.truststore_ext_cert.version_id | ||
| } | ||
| } | ||
|
|
||
| resource "aws_api_gateway_base_path_mapping" "api_mapping_mtls" { | ||
| api_id = aws_api_gateway_rest_api.ndr_doc_store_api_mtls.id | ||
| stage_name = var.environment | ||
| domain_name = aws_api_gateway_domain_name.custom_api_domain_mtls.domain_name | ||
|
|
||
| depends_on = [aws_api_gateway_deployment.ndr_api_deploy_mtls] | ||
| } | ||
|
|
||
| resource "aws_api_gateway_deployment" "ndr_api_deploy_mtls" { | ||
| rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api_mtls.id | ||
|
|
||
| depends_on = [ | ||
| aws_api_gateway_rest_api.ndr_doc_store_api_mtls, | ||
| aws_api_gateway_resource.get_document_reference_mtls, | ||
| module.get-doc-fhir-lambda, | ||
| aws_api_gateway_integration.get_doc_fhir_lambda_integration, | ||
| aws_lambda_permission.lambda_permission_get_mtls_api, | ||
| module.post-document-references-fhir-lambda, | ||
| aws_api_gateway_integration.post_doc_fhir_lambda_integration, | ||
| aws_lambda_permission.lambda_permission_post_mtls_api, | ||
| module.search-document-references-fhir-lambda, | ||
| aws_api_gateway_integration.search_doc_fhir_lambda_integration, | ||
| aws_lambda_permission.lambda_permission_search_mtls_api, | ||
| ] | ||
|
|
||
| lifecycle { | ||
| create_before_destroy = true | ||
| } | ||
|
|
||
| variables = { | ||
| deployed_at = timestamp() | ||
| } | ||
| } | ||
|
|
||
| resource "aws_api_gateway_stage" "ndr_api_mtls" { | ||
| deployment_id = aws_api_gateway_deployment.ndr_api_deploy_mtls.id | ||
| rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api_mtls.id | ||
| stage_name = var.environment | ||
| xray_tracing_enabled = var.enable_xray_tracing | ||
| } | ||
|
|
||
| resource "aws_cloudwatch_log_group" "mtls_api_gateway_stage" { | ||
| name = "API-Gateway-Execution-Logs_${aws_api_gateway_rest_api.ndr_doc_store_api_mtls.id}/${var.environment}" | ||
| retention_in_days = 0 | ||
| depends_on = [ | ||
| aws_api_gateway_account.logging | ||
| ] | ||
| } | ||
|
|
||
| resource "aws_api_gateway_method_settings" "mtls_api_gateway_stage" { | ||
| rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api_mtls.id | ||
| stage_name = aws_api_gateway_stage.ndr_api_mtls.stage_name | ||
| method_path = "*/*" | ||
|
|
||
| settings { | ||
| logging_level = "INFO" | ||
| metrics_enabled = true | ||
| data_trace_enabled = true | ||
| } | ||
| } | ||
|
|
||
| resource "aws_api_gateway_gateway_response" "unauthorised_response_mtls" { | ||
| rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api_mtls.id | ||
| response_type = "DEFAULT_4XX" | ||
|
|
||
| response_templates = { | ||
| "application/json" = "{\"message\":$context.error.messageString}" | ||
| } | ||
|
|
||
| response_parameters = { | ||
| "gatewayresponse.header.Access-Control-Allow-Origin" = contains(["prod"], terraform.workspace) ? "'https://${var.domain}'" : "'https://${terraform.workspace}.${var.domain}'" | ||
| "gatewayresponse.header.Access-Control-Allow-Methods" = "'*'" | ||
| "gatewayresponse.header.Access-Control-Allow-Headers" = "'Content-Type,X-Amz-Date,Authorization,X-Auth,X-Api-Key,X-Amz-Security-Token,X-Auth-Cookie,Accept'" | ||
| "gatewayresponse.header.Access-Control-Allow-Credentials" = "'true'" | ||
| } | ||
| } | ||
|
|
||
| resource "aws_api_gateway_gateway_response" "bad_gateway_response_mtls" { | ||
| rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api_mtls.id | ||
| response_type = "DEFAULT_5XX" | ||
|
|
||
| response_templates = { | ||
| "application/json" = "{\"message\":$context.error.messageString}" | ||
| } | ||
|
|
||
| response_parameters = { | ||
| "gatewayresponse.header.Access-Control-Allow-Origin" = contains(["prod"], terraform.workspace) ? "'https://${var.domain}'" : "'https://${terraform.workspace}.${var.domain}'" | ||
| "gatewayresponse.header.Access-Control-Allow-Methods" = "'*'" | ||
| "gatewayresponse.header.Access-Control-Allow-Headers" = "'Content-Type,X-Amz-Date,Authorization,X-Auth,X-Api-Key,X-Amz-Security-Token,X-Auth-Cookie,Accept'" | ||
| "gatewayresponse.header.Access-Control-Allow-Credentials" = "'true'" | ||
| } | ||
| } | ||
|
|
||
| module "mtls_api_endpoint_url_ssm_parameter" { | ||
| source = "./modules/ssm_parameter" | ||
| name = "${terraform.workspace}_ApiEndpointMtls" | ||
| description = "mTLS api endpoint URL for ${var.environment}" | ||
| resource_depends_on = aws_api_gateway_deployment.ndr_api_deploy_mtls | ||
| value = "https://${aws_api_gateway_base_path_mapping.api_mapping_mtls.domain_name}" | ||
| type = "SecureString" | ||
| owner = var.owner | ||
| environment = var.environment | ||
| } | ||
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 |
|---|---|---|
|
|
@@ -128,6 +128,11 @@ module "ndr-truststore" { | |
| force_destroy = local.is_force_destroy | ||
| } | ||
|
|
||
| data "aws_s3_object" "truststore_ext_cert" { | ||
| bucket = local.truststore_bucket_id | ||
| key = var.ca_pem_filename | ||
| } | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This truststore object needs to be manually created and in place before deploying |
||
| # Lifecycle Rules | ||
| resource "aws_s3_bucket_lifecycle_configuration" "lg-lifecycle-rules" { | ||
| bucket = module.ndr-lloyd-george-store.bucket_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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| module "fhir_document_reference_mtls_gateway" { | ||
| source = "./modules/gateway" | ||
| api_gateway_id = aws_api_gateway_rest_api.ndr_doc_store_api_mtls.id | ||
| parent_id = aws_api_gateway_rest_api.ndr_doc_store_api_mtls.root_resource_id | ||
| http_methods = ["POST", "GET"] | ||
| authorization = "NONE" | ||
| api_key_required = true | ||
| gateway_path = "DocumentReference" | ||
| require_credentials = true | ||
| } |
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
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
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
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
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.