LoginSignup
0
0

More than 3 years have passed since last update.

AWS CloudFormation クライアントVPNエンドポイントの作成

Last updated at Posted at 2021-04-03

CloudFormation

これから使用するリソースをテンプレートと呼ばれるCloudFormationで用いるテキストファイルに記述することで、マネジメントコンソールやCLIを用いなくとも自動で作成してくれるサービス。例えば、VPCとサブネットを作成する場合、CIDRなどの必要事項を記述すれば、VPC → サブネットの順に依存関係まで考慮して作成してくれる。

特にクライアントVPNではACMを利用したりネットワークの関連付けをしたりするなど、あちこち行ったり来たりするのでリソースをまとめて管理するメリットは大きいと思われる。

また、削除も一括で行ってくれるのでリソースの消し忘れも防ぐことができる。

クライアントVPNエンドポイント

インターネットから分離したVPCに安全にアクセスするためのサービス。例えば、EC2インスタンスにログインするためには通常パブリックサブネットにインスタンスを置く必要があるが、その状況ではインターネットからの不特定なアクセスを許してしまう可能性がある。クライアントVPNエンドポイントを使うことで、プライベートサブネットに配置したインスタンスにアクセスすることが可能である。

テンプレートについての注意点

  • 今回のテンプレートではACMに証明書をあらかじめ用意しておき、そのARNを指定している
  • 認証方法には、相互認証・ディレクトリ認証を使用している

  • テンプレートは、JSONまたはyaml形式で作成する

今回はJSONで書いたがこれをyaml形式に変換するには次の手順を踏めばよい。

変換手順
1. スタックの作成をクリック

image.png

2. デザイナーでテンプレートを作成をクリック

image.png

3. YAMLを選択

image.png

変換できればメッセージに表示される。

image.png

テンプレート

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Resources": {
      "VPC": {
          "Type": "AWS::EC2::VPC",
          "Properties": {
              "CidrBlock": "10.0.0.0/16",
              "EnableDnsSupport": true,
              "EnableDnsHostnames": true
          }
      },
      "Subnet1": {
          "Type": "AWS::EC2::Subnet",
          "Properties": {
              "VpcId": {
                  "Ref": "VPC"
              },
              "CidrBlock": "10.0.0.0/24",
              "AvailabilityZone": "ap-northeast-1d"
          }
      },
      "Subnet2": {
          "Type": "AWS::EC2::Subnet",
          "Properties": {
              "VpcId": {
                  "Ref": "VPC"
              },
              "CidrBlock": "10.0.1.0/24",
              "AvailabilityZone": "ap-northeast-1c"
          }
      },
      "ClientVpnAuthorizationRule": {
          "Type": "AWS::EC2::ClientVpnAuthorizationRule",
          "Properties": {
              "ClientVpnEndpointId": {
                  "Ref": "ClientVpnEndpoint"
              },
              "AuthorizeAllGroups": true,
              "TargetNetworkCidr": "0.0.0.0/0"
          }
      },
      "ClientVpnEndpoint": {
          "Type": "AWS::EC2::ClientVpnEndpoint",
          "Properties": {
              "ServerCertificateArn": "arn:aws:acm:ap-northeast-1:012345678912:certificate/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
              "AuthenticationOptions": [
                  {
                      "MutualAuthentication": {
                          "ClientRootCertificateChainArn": "arn:aws:acm:ap-northeast-1:012345678912:certificate/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
                      },
                      "Type": "certificate-authentication"
                  },
                  {
                      "ActiveDirectory": {
                          "DirectoryId": {
                              "Ref": "SimpleAD"
                          }
                      },
                      "Type": "directory-service-authentication"
                  }
              ],
              "ClientCidrBlock": "10.1.0.0/22",
              "ConnectionLogOptions": {
                  "Enabled": false
              },
              "SplitTunnel": true
          }
      },
      "ClientVpnTargetNetworkAssociation": {
          "Type": "AWS::EC2::ClientVpnTargetNetworkAssociation",
          "Properties": {
              "ClientVpnEndpointId": {
                  "Ref": "ClientVpnEndpoint"
              },
              "SubnetId": {
                  "Ref": "Subnet1"
              }
          }
      },
      "SimpleAD": {
          "Type": "AWS::DirectoryService::SimpleAD",
          "Properties": {
              "Name": "example.com",
              "Password": "Ab12345!",
              "Size": "Small",
              "VpcSettings": {
                  "SubnetIds": [
                      {
                          "Ref": "Subnet1"
                      },
                      {
                          "Ref": "Subnet2"
                      }
                  ],
                  "VpcId": {
                      "Ref": "VPC"
                  }
              }
          }
      },
      "DHCPOptions": {
          "Type": "AWS::EC2::DHCPOptions",
          "Properties": {
              "DomainName": "example.com",
              "DomainNameServers": {
                  "Fn::GetAtt": [
                      "SimpleAD",
                      "DnsIpAddresses"
                  ]
              }
          }
      }
  }
}

参考記事

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0