Skip to content

eanselmi/terraform-aws-client-vpn-multiple-users

Repository files navigation

This Terraform module provides a convenient solution for deploying AWS client vpn solution with the ability to manage multuple users using self-signed certificated. Latest Release

image


How does it work?

This module will facilitate the deployment of the following resources:

  • AWS Client vpn endpoint
  • Subnet associations
  • Certificates for each user stored in aws parameter store
  • ACM certificates
  • S3 bucket for storing the Openvpn config files
  • Openvpn config file for each user

Inputs

| Name | Description | Type | Default | Required | | ---------------------- | ------------------------------------------------------------------------------------------------------ | ------------------- | ------- | :------: | --- | ------------------------------------------- | --------- | ---- | --- | | organization_name | Name of the organization | string | {} | yes | | project-name | Name of the project | string | {} | yes | | aws-vpn-client-list | Set of users (example "john"), the firrst item of the list will be the certificate of the server | set(string) | {} | yes | | vpc_id | Id of the VPC | string | {} | yes | | subnets_id | List of the subnets to deploy the vpn endpoint | list(string) | {} | yes | | client_cidr_block | CIDR block for vpn users | string | {} | yes | | split_tunnel | Flag to indicate if split tunnel must be used | bool | {} | yes | | vpn_inactive_period | Flag to indicate (in minutes) when a user should be disconnected if there is no activity in the tunnel | numeric | {} | yes | | session_timeout_hours | Flag to indicate (in hours) the session timeout | numeric | {} | yes | | logs_retention_in_days | Retention perior for vpn logs in cloudwatch | numeric | {} | yes | | additional_routes | List of additional routes | list(map(string)) | {} | yes | | Retention perior for vpn logs in cloudwatch | numeric | {} | yes |

Example

locals {
  cliet_vpn = {
    organization_name      = "mycompany"
    project-name           = "client-vpn"
    aws-vpn-client-list    = ["root", "john", "michael", "clara"]
    client_cidr_block      = "172.24.0.0/22"
    split_tunnel           = true
    vpn_inactive_period    = 1800
    session_timeout_hours  = 8
    logs_retention_in_days = 7
    additional_routes = [{
      destination_cidr = "10.100.0.0/16"
      description      = "strging"
      subnet_id        = subnet-0b509a1c548112f26
    }]
  }
}
module "client-vpn" {
  source  = "eanselmi/client-vpn-multiple-users/aws"
  version = "1.0.2"
  organization_name      = local.cliet_vpn.organization_name
  project-name           = local.cliet_vpn.project-name
  aws-vpn-client-list    = local.cliet_vpn.aws-vpn-client-list
  vpc_id                 = vpc-0a959fbbb6e218299
  subnets_id             = [subnet-0b509a1c548112f30]
  client_cidr_block      = local.cliet_vpn.client_cidr_block
  split_tunnel           = local.cliet_vpn.split_tunnel
  vpn_inactive_period    = local.cliet_vpn.vpn_inactive_period
  session_timeout_hours  = local.cliet_vpn.session_timeout_hours
  logs_retention_in_days = local.cliet_vpn.logs_retention_in_days
  additional_routes      = local.cliet_vpn.additional_routes
}

How to remove/revoke users

An important part is how to delete or revoke a user; it is not enough to remove them from the list and delete their certificate. The certificate must be revoked, and this must be done outside of Terraform, and the VPN must be updated. These are the steps:

  1. From AWS-Parameter-Store, download the certificate and private key of the CA
  2. From AWS-Parameter-Store, download the certificate that we want to revoke
  3. We open a terminal and go to the directory where we are going to manage the downloaded certificates
  4. Adjust the default_crl_days variable in your openssl.cnf config file (default value is 30 days, you can find the file with openssl version -d )
  5. To revoke the certificate, please execute "openssl ca -revoke user.cer -keyfile ca.key -cert ca.cer"
  6. Now update the CRL "openssl ca -gencrl -out revocations.crl -keyfile ca.key -cert ca.cer"
  7. We import the CRL to our VPN endpoint "aws ec2 import-client-vpn-client-certificate-revocation-list --certificate-revocation-list file://revocations.crl --client-vpn-endpoint-id endpoint_id --region region" We can import the CRL using the AWS console
  8. Validate CRL expiration date using "openssl crl -in revocations.crl -text"

Requirements

Name Version
terraform >= 1.1.7
aws >= 4.4.0
tls 3.1.0

Providers

Name Version
aws >= 4.4.0
tls 3.1.0

Modules

No modules.

Resources

Name Type
aws_acm_certificate.ca resource
aws_acm_certificate.client resource
aws_acm_certificate.server resource
aws_cloudwatch_log_group.vpn-logs resource
aws_cloudwatch_log_stream.vpn-logs-stream resource
aws_ec2_client_vpn_authorization_rule.vpn-client resource
aws_ec2_client_vpn_endpoint.vpn-client resource
aws_ec2_client_vpn_network_association.vpn-client resource
aws_ec2_client_vpn_route.routes resource
aws_s3_bucket.vpn-config-files resource
aws_s3_bucket_policy.vpn-config-files resource
aws_s3_bucket_public_access_block.vpn-config-files resource
aws_s3_object.vpn-config-file resource
aws_security_group.vpn resource
aws_ssm_parameter.vpn_ca_cert resource
aws_ssm_parameter.vpn_ca_key resource
aws_ssm_parameter.vpn_client_cert resource
aws_ssm_parameter.vpn_client_key resource
aws_ssm_parameter.vpn_server_cert resource
aws_ssm_parameter.vpn_server_key resource
tls_cert_request.client resource
tls_cert_request.server resource
tls_locally_signed_cert.client resource
tls_locally_signed_cert.server resource
tls_private_key.ca resource
tls_private_key.client resource
tls_private_key.server resource
tls_self_signed_cert.ca resource
aws_iam_policy_document.vpn-config-files data source
aws_region.current data source

Inputs

Name Description Type Default Required
additional_routes Additional Routes list(map(string)) [] no
aws-vpn-client-list VPN client list set(string) n/a yes
client_cidr_block AWS VPN client cidr block string n/a yes
logs_retention_in_days VPN client list number n/a yes
organization_name Organization name string n/a yes
project-name Project name string n/a yes
session_timeout_hours Session timeout hours number n/a yes
split_tunnel Split tunnel traffic bool n/a yes
subnets_id Subnet list for client vpn network association list(string) n/a yes
vpc_id VPC ID string n/a yes
vpn_inactive_period VPN inactive period in seconds number n/a yes

Outputs

No outputs.


image

If you find this module useful, please consider helping me with a coffee so I can keep creating more modules like this one :)

We welcome any ideas, corrections, or feedback you may have. Your input is greatly appreciated and will contribute to further improving our module.


About

Terraform module to deploy AWS client vpn and manage multiple users with cetificates

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages