Skip to content
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

[Issue #2472] allegedly setup a VPN #2558

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions infra/modules/vpn/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
locals {
vpn_cidr = "10.${var.second_octet}.0.0/20"
}

data "aws_vpc" "vpc" {
id = var.vpc_id
}

data "aws_acm_certificate" "cert" {
domain = "simpler.grants.gov"
}

data "aws_subnets" "subnets" {
filter {
name = "vpc-id"
values = [var.vpc_id]
}
tags = {
subnet_type = "private"
}
}

data "aws_subnet" "subnets" {
for_each = toset(data.aws_subnets.subnets.ids)
id = each.value
}

resource "aws_security_group" "vpn" {
vpc_id = var.vpc_id
description = "allow all ingress and egress to VPN"

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}

resource "aws_ec2_client_vpn_endpoint" "vpn" {
description = "vpn-${var.environment_name}"
server_certificate_arn = data.aws_acm_certificate.cert.arn
client_cidr_block = local.vpn_cidr
self_service_portal = "enabled"
vpc_id = var.vpc_id
security_group_ids = [aws_security_group.vpn.id]

authentication_options {
type = "federated-authentication"
saml_provider_arn = "arn:aws:iam::315341936575:saml-provider/AWSSSO_345521176bf03df0_DO_NOT_DELETE"
self_service_saml_provider_arn = "arn:aws:iam::315341936575:saml-provider/AWSSSO_345521176bf03df0_DO_NOT_DELETE"
}

connection_log_options {
enabled = true
cloudwatch_log_group = aws_cloudwatch_log_group.vpn.name
cloudwatch_log_stream = aws_cloudwatch_log_stream.vpn.name
}

tags = {
Name = "vpn-${var.environment_name}"
}
}

resource "aws_cloudwatch_log_group" "vpn" {
name_prefix = "/vpn/${var.environment_name}/"

# Conservatively retain logs for 5 years.
# Looser requirements may allow shorter retention periods
retention_in_days = 1827

# TODO(https://github.com/navapbc/template-infra/issues/164) Encrypt with customer managed KMS key
# checkov:skip=CKV_AWS_158:Encrypt service logs with customer key in future work
}

resource "aws_cloudwatch_log_stream" "vpn" {
name = "/vpn/${var.environment_name}/"
log_group_name = aws_cloudwatch_log_group.vpn.name
}

resource "aws_ec2_client_vpn_network_association" "vpn" {
for_each = toset(data.aws_subnets.subnets.ids)
client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.vpn.id
subnet_id = each.value
}

resource "aws_ec2_client_vpn_authorization_rule" "vpn" {
for_each = toset(data.aws_subnets.subnets.ids)
client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.vpn.id
target_network_cidr = data.aws_subnet.subnets[each.value].cidr_block
authorize_all_groups = true
}
14 changes: 14 additions & 0 deletions infra/modules/vpn/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
variable "environment_name" {
description = "The name of the environment"
type = string
}

variable "second_octet" {
description = "The second octet of the VPC CIDR block"
type = number
}

variable "vpc_id" {
description = "The ID of the VPC"
type = string
}
7 changes: 7 additions & 0 deletions infra/networks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,10 @@ module "dms_networking" {
our_cidr_block = module.network.vpc_cidr
grants_gov_oracle_cidr_block = module.project_config.network_configs[var.environment_name].grants_gov_oracle_cidr_block
}

module "vpn" {
source = "../modules/vpn"
environment_name = var.environment_name
second_octet = module.project_config.network_configs["vpn"].second_octet
vpc_id = module.network.vpc_id
}
3 changes: 3 additions & 0 deletions infra/project-config/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@ locals {
second_octet = 3 # The second octet our the VPC CIDR block
grants_gov_oracle_cidr_block = "10.250.0.0/16" # MicroHealth managed CIDR block where the prod origin Oracle database for Grants.gov is located
}
vpn = {
second_octet = 4
}
}
}
Loading