0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AWS Client VPNでEC2へセキュアにアクセスする環境の構築

Posted at

はじめに

VPNを使って社外の経路からVPC内のEC2へ安全にアクセスしたい、そんな件についてAWSで実装する場合、AWS Client VPN が最適です。

本記事は、VPNを使って社内端末からEC2へセキュアにアクセスする構成を一通り構築した手順を整理したメモとなります。


構成図

下記は実際に構築した構成図です。
vpnアーキテクチャ_qiita.drawio.png

ポイント:

  • VPC: 10.99.0.0/16
  • VPN Client CIDR: 172.30.0.0/22
  • Private Subnet: 10.99.1.0/24
  • 認証は証明書(証明書ベース)

構築ステップ概要

  1. VPC / Subnet の作成
  2. OpenSSL で証明書(サーバー/クライアント) 生成
  3. ACM への手動インポート
  4. Client VPN Endpoint 作成
  5. 承認ルール & ルーテ設定
  6. Security Group の設計
  7. client-config.ovpn の作成
  8. AWS VPN Client で接続確認

1. VPC / Subnet の作成

CIDRブロック:
VPC: 10.99.0.0/16
Subnet: 10.99.1.0/24 (Private)

2. OpenSSL で証明書生成

# 作業ディレクトリ
mkdir ~/vpn-certs && cd ~/vpn-certs
mkdir certs private requests && chmod 700 private

# Root CA 生成
openssl req -x509 -newkey rsa:4096 -days 3650 \
  -keyout private/ca.key -out certs/ca.crt \
  -subj "/CN=MyVPN-RootCA" -nodes

# Server Cert
openssl req -newkey rsa:4096 -nodes \
  -keyout private/server.key -out requests/server.csr \
  -subj "/CN=cvpn-endpoint-xxxxxxx.prod.clientvpn.ap-northeast-1.amazonaws.com"

openssl x509 -req -in requests/server.csr \
  -CA certs/ca.crt -CAkey private/ca.key -CAcreateserial \
  -out certs/server.crt -days 3650

# Client Cert
openssl req -newkey rsa:4096 -nodes \
  -keyout private/client.key -out requests/client.csr \
  -subj "/CN=vpn-user"

openssl x509 -req -in requests/client.csr \
  -CA certs/ca.crt -CAkey private/ca.key -CAcreateserial \
  -out certs/client.crt -days 3650

3. ACM への証明書手動インポート

コンソールから「Certificate Manager」 を開き、「Import」 を選択:

  • Certificate Body: server.crt
  • Private Key: server.key
  • Certificate Chain: ca.crt

server.crtca.crt を追加するとエラーになります。別体で入力しましょう。


4. Client VPN Endpoint 作成

コンソール -> VPC -> Client VPN Endpoints -> 「Create」

  • Server certificate: ACMに登録した証明書
  • Authentication: Certificate-based
  • Client IPv4 CIDR: 172.30.0.0/22
  • Security group: VPC内との通信用 (SG)
  • VPC: 10.99.0.0/16
  • Subnet: 10.99.1.0/24

5. 承認ルール & ルート

  • Authorization rule:

    • Destination: 10.99.1.0/24
    • Grant access to: All clients
  • Route table:

    • 172.30.0.0/22 から VPC へのルート

6. SG(セキュリティグループ)

  • Client VPN Endpoint SG:

    • Outbound: Allow to 10.99.0.0/16 (VPC)
    • Inbound: Not required
  • EC2用 SG:

    • Inbound: Allow from 172.30.0.0/22 (client CIDR)

7. client-config.ovpn の作成

  • クライアント用証明書 (.crt/.key/.ca)
  • VPNエンドポイントからテンプレートDL
  • <cert>, <key>, <ca> セクションに埋め込み

8. AWS VPN Client で接続

  1. AWS VPN Client アプリをダウンロード
  2. client.ovpn を読み込み
  3. 接続を実行 -> 成功

おわりに

AWS Client VPN を使って社外からのセキュアなEC2接続を実現できた。

この構成は証明書証明で管理されるため、未承認のユーザーのアクセスを削減できる上、専用CIDRによる分離でVPC側のセキュリティも簡潔に管理できます。


記事が役に立ったら、LGTM やフォローしてもらえると嬉しいです!

0
0
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?