2021/05/27

AWS VPNのクライアント証明書とは?その基本情報や発行方法などを紹介!

 
  

AWS VPNのクライアント証明書とは?

AWS VPNのクライアント証明書とは、クライアントVPNエンドポイントに接続する許可を得るために必要な証明書のことを指します。 クライアント証明書は他の人と使い回すことも可能ですが、利用者ごとにクライアント証明書を持っていた方が便利です。

AWS VPNのクライアント証明書の基本情報

AWS VPNのクライアント証明書を使用することで、接続する際にサーバーが認証済みのクライアントかどうかを判断することができます。 AWS VPNでは他にもActive Directory認証やシングルサインオンなどの認証方法が提供されています。

AWS VPNのクライアント証明書の発行方法

ここでは、AWS VPNクライアント証明書の発行方法について紹介します。 クライアント証明書を発行する前のクライアントVPNの設定からクライアント証明書を発行した後の更新や失効の方法なども実際のコードを見ながら解説していきます。

クライアントVPNの設定

AWS VPNのクライアント証明書を発行する前にはクライアントVPNの設定を終わらせておかなければいけないので、その流れを説明していきます。 まずは、OpenVPN easy-rsaをインストールします。
$ wget https://github.com/OpenVPN/easy-rsa/releases/download/v3.0.7/EasyRSA-3.0.7.tgz
$ tar zxfv EasyRSA-3.0.7.tgz
$ cd EasyRSA-3.0.7
次に、PKI環境を初期化します。
$ ./easyrsa init-pki
そして、認証機関 (CA) を構築します。
$ ./easyrsa build-ca nopass
pki/ca.crtというのがCAの証明書となります。
$ openssl x509 -text -noout -in pki/ca.crt
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            ba:f6:6e:cf:78:74:62:2a
    Signature Algorithm: sha256WithRSAEncryption
        Issuer: CN=Easy-RSA CA
        Validity
            Not Before: May 18 06:48:58 2020 GMT
            Not After : May 16 06:48:58 2030 GMT
        Subject: CN=Easy-RSA CA
...
そして、サーバー/クライアント向けに証明書とキーを作成します。 サーバー向け
$ ./easyrsa build-server-full server nopass
クライアント向け
$ ./easyrsa build-client-full client1.domain.tld nopass
作成した証明書とキーをカスタムフォルダにコピーします。
$ mkdir ~/custom_folder/
$ cp pki/ca.crt ~/custom_folder/
$ cp pki/issued/server.crt ~/custom_folder/
$ cp pki/private/server.key ~/custom_folder/
$ cp pki/issued/client1.domain.tld.crt ~/custom_folder
$ cp pki/private/client1.domain.tld.key ~/custom_folder/
$ cd ~/custom_folder/
クライアント証明書とサーバー証明書は同じCAを使用しているため、クライアントVPNエンドポイントの作成前にACMにサーバー証明書を登録します。
$ aws acm import-certificate \
  --certificate file://server.crt \
  --private-key file://server.key \
  --certificate-chain file://ca.crt \
  --region region
{
    "CertificateArn": "arn:aws:acm:..."
}
これが終われば最後に、クライアントVPNエンドポイントを作成し、VPNの接続が確認できれば設定完了です。

クライアント証明書の発行

クライアントVPNの設定が終われば、さっそくAWS VPNのクライアント証明書の発行に移りましょう。 新規にクライアント証明書を発行するには名前を指定して、easyrsa build-client-fullを実行しましょう。
$ cd /path/to/easy-rsa/easyrsa3
$ ./easyrsa build-client-full client2.domain.tld nopass
...[snip]
The Subject's Distinguished Name is as follows
commonName            :ASN.1 12:'client2.domain.tld'
Certificate is to be certified until Aug 20 13:48:09 2022 GMT (825 days)

Write out database with 1 new entries
Data Base Updated

クライアント証明書の更新

AWS VPNのクライアント証明書には期限があるので、期限が切れる前に証明書を再発行する必要があります。 証明書を再発行するには$ ./easyrsa renew エンティティ nopassを実行します。
# 証明書を更新
$ ./easyrsa renew client1.domain.tld nopass

Note: using Easy-RSA configuration from: ./vars
Using SSL: openssl OpenSSL 1.0.2t  10 Sep 2019


Please confirm you wish to renew the certificate with the following subject:

subject=
    commonName                = client1.domain.tld


Type the word 'yes' to continue, or any other input to abort.
  Continue with renew: yes
Generating a RSA private key
...
The Subject's Distinguished Name is as follows
commonName            :ASN.1 12:'client1.domain.tld'
Certificate is to be certified until Jun 22 12:20:25 2021 GMT (400 days)

Write out database with 1 new entries
Data Base Updated
$
この操作を行うことにより、期限を400日延長することができます。

クライアント証明書の失効

自分のキー情報が漏れたり、クライアントVPNを利用しなくなった際はAWS VPNのクライアント証明書を失効させることが可能です。 失効させるには以下の手順を行ってください。
# 証明書を失効させる
$ ./easyrsa revoke client2.domain.tld

Note: using Easy-RSA configuration from: ./vars
Using SSL: openssl OpenSSL 1.0.2t  10 Sep 2019


Please confirm you wish to revoke the certificate with the following subject:

subject=
    commonName                = client2.domain.tld


Type the word 'yes' to continue, or any other input to abort.
  Continue with revocation: yes
Using configuration from /Users/jsmith/EasyRSA-3.0.7/pki/easy-rsa-90112.wfP0sa/tmp.jrFGwa
Revoking Certificate 0DACEEA5C11A6948B3C6E9AC3502CFA5.
Data Base Updated

IMPORTANT!!!

Revocation was successful. You must run gen-crl and upload a CRL to your
infrastructure in order to prevent the revoked cert from being accepted.


# 証明書失効リスト(CRL)を更新
$ ./easyrsa gen-crl

Note: using Easy-RSA configuration from: ./vars
Using SSL: openssl OpenSSL 1.0.2t  10 Sep 2019
Using configuration from /Users/jsmith/EasyRSA-3.0.7/pki/easy-rsa-90205.2q2Aak/tmp.poeCn8

An updated CRL has been created.
CRL file: /Users/jsmith/EasyRSA-3.0.7/pki/crl.pem

AWS VPNのクライアント証明書を実際に発行してみよう!

いかがだったでしょうか? 今回はAWS VPNのクライアント証明書の発行方法について解説しました。 証明書を発行するだけでなく発行前の設定、発行後の更新や失効する方法などもコードを使って詳しく解説しています。 ぜひこの記事を参考に、AWS VPNのクライアント証明書を実際に発行してみてください。]]>

ITエンジニアへのキャリアチェンジならキャリアチェンジアカデミー

この記事の監修者・著者

株式会社オープンアップITエンジニア
株式会社オープンアップITエンジニア
未経験からITエンジニアへのキャリアチェンジを支援するサイト「キャリアチェンジアカデミー」を運営。これまで4500人以上のITエンジニアを未経験から育成・排出してきました。
・AWS、salesforce、LPICの合計認定資格取得件数:2100以上(2023年6月時点)
・AWS Japan Certification Award 2020 ライジングスター of the Year 受賞

おすすめの動画

  • 【未経験からIT業界へ転職するなら】相談窓口とスキルの獲得はここで解決!IT転職が一気に有利に!【キャリアチェンジアカデミー】

  • 【費用一切不要】未経験からIT業界へ転職するならまずはここへ相談!【キャリアチェンジアカデミー】

  • 【何のエンジニアになれるのか?】未経験からITエンジニアを目指すとこんな道がある【キャリアチェンジアカデミー】