AWS Client VPNを試してみる

AWS Client VPNを試してみる:


はじめに

2018/12/18に発表になったAWS Client VPNを試してみます。

https://aws.amazon.com/jp/about-aws/whats-new/2018/12/introducing-aws-client-vpn-to-securely-access-aws-and-on-premises-resources/

認証は、Active Directory連携とクライアント証明書による認証が可能です。今回は、Getting Startedにならってクライアント証明書を使用します。

https://docs.aws.amazon.com/ja_jp/vpn/latest/clientvpn-admin/cvpn-getting-started.html

https://docs.aws.amazon.com/ja_jp/vpn/latest/clientvpn-admin/authentication-authrization.html#mutual



image.png


LinuxサーバやMacでeasy-rsaツールを使って、ルート証明書やサーバ証明書、サーバ秘密鍵、クライアント証明書、クライアント秘密鍵を作成します。作成したRootCAやサーバ証明書、サーバ秘密鍵をACMに登録して、Clinet VPCエンドポイントに登録します。

ネットワーク構成は、以下になります。



image.png



手順

  1. 接続テスト用のEC2インスタンスを作成して、Nginxを起動する
  2. easy-rsaでルート証明書、サーバ証明書、サーバ秘密鍵、クライアント証明書、クライアント秘密鍵作成し、ACMに登録する
  3. AWS Client VPNエンドポイントを作成する
  4. 接続確認する


ルート証明書、サーバ証明書、サーバ秘密鍵、クライアント証明書、クライアント秘密鍵作成、ACM登録

git clone https://github.com/OpenVPN/easy-rsa.git 
Cloning into 'easy-rsa'... 
remote: Enumerating objects: 1039, done. 
remote: Total 1039 (delta 0), reused 0 (delta 0), pack-reused 1039 
Receiving objects: 100% (1039/1039), 86 
初期化します。

cd easy-rsa/easyrsa3 
./easyrsa init-pki 
init-pki complete; you may now create a CA or requests. 
Your newly created PKI dir is: /easy-rsa/easyrsa3/pki 
CA作成時に、Common Nameを入力します。

./easyrsa build-ca nopass 
 
Using SSL: openssl OpenSSL 0.9.8zh 14 Jan 2016 
Generating RSA private key, 2048 bit long modulus 
...........+++ 
.............+++ 
e is 65537 (0x10001) 
You are about to be asked to enter information that will be incorporated 
into your certificate request. 
What you are about to enter is what is called a Distinguished Name or a DN. 
There are quite a few fields but you can leave some blank 
For some fields there will be a default value, 
If you enter '.', the field will be left blank. 
----- 
Common Name (eg: your user, host, or server name) [Easy-RSA CA]:sample 
 
CA creation complete and you may now import and sign cert requests. 
Your new CA certificate file for publishing is at: 
/easy-rsa/easyrsa3/pki/ca.crt 
サーバ証明書、秘密鍵を作成します。

./easyrsa build-server-full server nopass 
Using SSL: openssl OpenSSL 0.9.8zh 14 Jan 2016 
Generating a 2048 bit RSA private key 
.....+++ 
....................................+++ 
writing new private key to '/easy-rsa/easyrsa3/pki/private/server.key.To4RdoPhw4' 
----- 
Using configuration from /easy-rsa/easyrsa3/pki/safessl-easyrsa.cnf 
Check that the request matches the signature 
Signature ok 
The Subject's Distinguished Name is as follows 
commonName            :ASN.1 12:'server' 
Certificate is to be certified until Dec 22 05:18:37 2021 GMT (1080 days) 
 
Write out database with 1 new entr 
クライアント証明書、秘密鍵を作成する。

./easyrsa build-client-full client1 nopass 
 
Using SSL: openssl OpenSSL 0.9.8zh 14 Jan 2016 
Generating a 2048 bit RSA private key 
.........+++ 
......................................................................................................................+++ 
writing new private key to '/easy-rsa/easyrsa3/pki/private/client1.key.daPAVRFGmP' 
----- 
Using configuration from /easy-rsa/easyrsa3/pki/safessl-easyrsa.cnf 
Check that the request matches the signature 
Signature ok 
The Subject's Distinguished Name is as follows 
commonName            :ASN.1 12:'client1' 
Certificate is to be certified until Dec 22 05:19:31 2021 GMT (1080 days) 
 
Write out database with 1 new entries 
Data Base Updated 
ACMに登録するためにルート証明書、サーバ証明書、サーバ秘密鍵を任意のディレクトリをコピーする。

mkdir ./custom_folder 
cp pki/ca.crt ./custom_folder 
cp pki/issued/server.crt ./custom_folder 
cp pki/private/server.key ./custom_folder 
ACMにルート証明書、サーバ証明書、サーバ秘密鍵を登録する。

cd ./custom_folder 
aws acm import-certificate --certificate file://server.crt --private-key file://server.key --certificate-chain file://ca.crt --region us-east-1 
{ 
    "CertificateArn": "arn:aws:acm:us-east-1:******:certificate/27ec60c0-8937-4224-9c05-d88243239fde" 
} 


AWS Client VPNエンドポイント作成

VPC DashboardでClent VPN Endpointをクリックする。

Create Client VPN Endpointをクリックする。


image.png


Client IPv4 CIDRは、/22以上/16以下で指定する。

Server certificate ARNとClient certificate ARNは、どちらもサーバ証明書を指定する。

easy-rsaで作成するとサーバ証明書とクライアント証明書のルート証明書が同じなので。



image.png


ログ設定やその他パラメータは必要に応じて記入して、Create Client VPN Endpointをクリックする。


image.png




image.png


StateがPending-associateになります。VPC(Subnet)を関連付けることにより、Availableになります。


image.png


AssociationsタブをクリックしAssociateをクリックする。


image.png


VPCとSubnetをAssociateをクリックする。


image.png




image.png


AuthorizationタブをクリックしAuthorize Ingressをクリックする。
image.png

接続先ネットワークのCidrを入力して、Add authorization ruleをクリックする。


image.png




image.png


セキュリティグループ設定

ここまででClinet VPN設定は完了。


接続確認

セキュリティグループの設定を実施する。

関連するセキュリティグループは2つあります。VPN Endpointに紐付けられたセキュリティグループとテスト対象のEC2インスタンスに紐付けられたセキュリティグループです。

お試しなのでsource 0.0.0.0/0で設定します。

VPN Endpointに紐付けられたセキュリティグループ


image.png




image.png


テスト対象のEC2インスタンスに紐付けられたセキュリティグループ


image.png


OpenVPNクライアントのインストール。以下からdmgファイルをダウンロードして、インストールします。
https://tunnelblick.net/downloads.html

VPN EndpointからClient Configurationをダウンロードします。
image.png

ダウンロードしたディレクトリに最初に作成した、クライアント証明書とクライアント秘密鍵をコピーします。

$ pwd 
/easy-rsa/easyrsa 
$ cp pki/private/client1.key /Downloads/ 
$ cp pki/issued/client1.crt /Downloads/ 
ダウンロードしたClient Configurationに以下を追記する。

cert client1.crt 
key client1.key 
接続確認する。ブラウザにEC2インスタンスのPrivate IPアドレスを入力する。

接続できないことを確認する。



image.png



VPN接続を行う。

左のペインにconfigurationファイルをドラッグしてConnectをクリックする。


image.png


緑色になればOK。


image.png


ブラウザにEC2インスタンスのPrivate IPアドレスを入力する。

Welcomeページが表示されることを確認する。


image.png



お約束

投稿内容は私個人の意見であり、所属企業・部門見解を代表するものではありません。

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)