[アップデート] Amazon Lightsail でディストリビューションの最低 TLS バージョンを設定出来るようになりました

2024.04.03

いわさです。

Amazon Lightsail には CDN ディストリビューションをフロントに配置する機能があります。要は CloudFront みたいなものです。

その場合、SSL/TLS 接続が必要になるのですがsslscanで確認してみると次のような TLS バージョンポリシーとなっています。

% sslscan https://d2quankv56jss3.cloudfront.net/

:

  SSL/TLS Protocols:
SSLv2     disabled
SSLv3     disabled
TLSv1.0   enabled
TLSv1.1   enabled
TLSv1.2   enabled
TLSv1.3   enabled

:

  Supported Server Cipher(s):
Preferred TLSv1.3  128 bits  TLS_AES_128_GCM_SHA256        Curve 25519 DHE 253
Accepted  TLSv1.3  256 bits  TLS_AES_256_GCM_SHA384        Curve 25519 DHE 253
Accepted  TLSv1.3  256 bits  TLS_CHACHA20_POLY1305_SHA256  Curve 25519 DHE 253
Preferred TLSv1.2  128 bits  ECDHE-RSA-AES128-GCM-SHA256   Curve 25519 DHE 253
Accepted  TLSv1.2  128 bits  ECDHE-RSA-AES128-SHA256       Curve 25519 DHE 253
Accepted  TLSv1.2  128 bits  ECDHE-RSA-AES128-SHA          Curve 25519 DHE 253
Accepted  TLSv1.2  256 bits  ECDHE-RSA-AES256-GCM-SHA384   Curve 25519 DHE 253
Accepted  TLSv1.2  256 bits  ECDHE-RSA-CHACHA20-POLY1305   Curve 25519 DHE 253
Accepted  TLSv1.2  256 bits  ECDHE-RSA-AES256-SHA384       Curve 25519 DHE 253
Accepted  TLSv1.2  256 bits  ECDHE-RSA-AES256-SHA          Curve 25519 DHE 253
Accepted  TLSv1.2  128 bits  AES128-GCM-SHA256            
Accepted  TLSv1.2  256 bits  AES256-GCM-SHA384            
Accepted  TLSv1.2  128 bits  AES128-SHA256                
Accepted  TLSv1.2  256 bits  AES256-SHA                   
Accepted  TLSv1.2  128 bits  AES128-SHA                   
Accepted  TLSv1.2  112 bits  TLS_RSA_WITH_3DES_EDE_CBC_SHA
Preferred TLSv1.1  128 bits  ECDHE-RSA-AES128-SHA          Curve 25519 DHE 253
Accepted  TLSv1.1  256 bits  ECDHE-RSA-AES256-SHA          Curve 25519 DHE 253
Accepted  TLSv1.1  256 bits  AES256-SHA                   
Accepted  TLSv1.1  128 bits  AES128-SHA                   
Accepted  TLSv1.1  112 bits  TLS_RSA_WITH_3DES_EDE_CBC_SHA
Preferred TLSv1.0  128 bits  ECDHE-RSA-AES128-SHA          Curve 25519 DHE 253
Accepted  TLSv1.0  256 bits  ECDHE-RSA-AES256-SHA          Curve 25519 DHE 253
Accepted  TLSv1.0  256 bits  AES256-SHA                   
Accepted  TLSv1.0  128 bits  AES128-SHA                   
Accepted  TLSv1.0  112 bits  TLS_RSA_WITH_3DES_EDE_CBC_SHA

:

なるほど。
現在は非推奨の TLSv1.0 や TLSv1.1 がサポートされていたり、あるいは TLSv1.2 でも脆弱性のある暗号スイートが利用可能な状態です。
広くレガシークライアントもサポート出来ると見ることも出来るのですが、推奨される暗号スイート・ポリシーのみのクライアントに制限したい場合も最近は多いと思います。

先日のアップデートで、AWS API 経由にはなるのですがこのディストリビューションに対してセキュリティポリシーを選択して最低 TLS バージョンをコントロール出来るようになったようです。

アナウンスがまだ出ておらず、ひょっとすると数日中にコンソールでも操作出来るようになる可能性がありますが、先に AWS CLI を使って検証を行ってみましたので紹介します。

適当な Web サイトとディストリビューションを用意する

まずはデフォルトのディストリビューションを用意したいので、Lightsail インスタンスで LAMP あたりをオリジンとして選択します。

数秒で動作確認できる Web サイトがデプロイ出来るので、サクッと使いたい時に Lightsail 本当に良いなといつも思ってます。良いですよ。

オリジンとして適当なインスタンスを用意出来たら次にディストリビューションを作成します。
ディストリビューションのオリジンとして利用するにあたって、前提としてインスタンスに静的 IP アドレスをアタッチしておく必要があります。

ディストリビューション経由で Web サイトへアクセス出来ましたね。
ここでsslscanを行うと、冒頭のデフォルトの TLS バージョンが確認出来る感じです。

アップデートされた API で最低 TLS バージョンと証明書を指定出来るようになった

今回のアップデートでは次の API が更新されており、AWS CLI v1.34.75 以上で利用出来ます。

update-distributionからリファレンスをちょっと確認してみますが、次のように最低 TLS バージョンと証明書を指定するオプションが追加されました。

UPDATE-DISTRIBUTION()                                    UPDATE-DISTRIBUTION()

NAME
       update-distribution -

DESCRIPTION
       Updates an existing Amazon Lightsail content delivery network (CDN)
       distribution.

       Use this action to update the configuration of your existing
       distribution.

       See also: AWS API Documentation

SYNOPSIS

            update-distribution
          --distribution-name <value>
          [--origin <value>]
          [--default-cache-behavior <value>]
          [--cache-behavior-settings <value>]
          [--cache-behaviors <value>]
          [--is-enabled | --no-is-enabled]
          [--viewer-minimum-tls-protocol-version <value>]
          [--certificate-name <value>]
          [--use-default-certificate | --no-use-default-certificate]
          [--cli-input-json <value>]
          [--generate-cli-skeleton <value>]
          [--debug]
          [--endpoint-url <value>]
          [--no-verify-ssl]
          [--no-paginate]
          [--output <value>]
          [--query <value>]
          [--profile <value>]
          [--region <value>]
          [--version <value>]
          [--color <value>]
          [--no-sign-request]
          [--ca-bundle <value>]
          [--cli-read-timeout <value>]
          [--cli-connect-timeout <value>]

OPTIONS
       --distribution-name (string)
          The name of the distribution to update.

          Use the GetDistributions action to get a list of distribution names
          that you can specify.

       --origin (structure)

:

       --default-cache-behavior (structure)
 
 :

       --cache-behavior-settings (structure)
          An object that describes the cache behavior settings for the
          distribution.

:

       --cache-behaviors (list)

:

       --is-enabled | --no-is-enabled (boolean)
          Indicates whether to enable the distribution.

       --viewer-minimum-tls-protocol-version (string)
          Use this parameter to update the minimum TLS protocol version for
          the SSL/TLS certificate that's attached to the distribution.

          Possible values:

          o TLSv1.1_2016

          o TLSv1.2_2018

          o TLSv1.2_2019

          o TLSv1.2_2021

       --certificate-name (string)
          The name of the SSL/TLS certificate that you want to attach to the
          distribution.

          Only certificates with a status of ISSUED can be attached to a
          distribution.

          Use the GetCertificates action to get a list of certificate names
          that you can specify.

       --use-default-certificate | --no-use-default-certificate (boolean)
          Indicates whether the default SSL/TLS certificate is attached to the
          distribution. The default value is true . When true , the
          distribution uses the default domain name such as
          d111111abcdef8.cloudfront.net .

          Set this value to false to attach a new certificate to the
          distribution.

:

証明書のアタッチが必要

まず、ここまで準備した状態で試したところどうやらデフォルト証明書だとダメなようです。
次のようにバージョンを指定してみたところ、先に証明書をアタッチしろと言われました。

% cat hoge.json
{
    "distributionName": "Distribution-1",
    "viewerMinimumTlsProtocolVersion": "TLSv1.2_2021",
    "useDefaultCertificate": true
}
% aws-v1 lightsail update-distribution --cli-input-json file://hoge.json --profile hogeadmin --region us-east-1

An error occurred (InvalidInputException) when calling the UpdateDistribution operation: There is no attached certificate of this distribution, please attach certificate first.

そこで、適当なドメインを割り当てて証明書を発行してみます。
Lightsail DNS ゾーンのサブドメインを割り当てます。

証明書を作成します。create-certificateコマンドを使いました。
ちなみに ACM の場合だと作成時にキーアルゴリズムを指定するオプションがありますが、Lightsail 証明書の場合は本日時点でその機能は提供されていないようです。

% cat hoge-cert.json 
{
    "certificateName": "hoge0402cert",
    "domainName": "hoge0402.lightsail.tak1wa.com"
}
% aws-v1 lightsail create-certificate --cli-input-json file://hoge-cert.json --profile hogeadmin --region us-east-1
{
    "certificate": {
        "certificateArn": "arn:aws:lightsail:us-east-1:123456789012:Certificate/0f83e128-749a-47e5-b8ca-1eabf47a8693",
        "certificateName": "hoge0402cert",
        "domainName": "hoge0402.lightsail.tak1wa.com",
        "tags": []
    },
    "operations": [
        {
            "id": "a3ec180b-56ff-49e5-bd4d-d7e1edfd49ac",
            "resourceName": "hoge0402cert",
            "resourceType": "Certificate",
            "createdAt": 1712057764.42,
            "location": {
                "availabilityZone": "ALL",
                "regionName": "us-east-1"
            },
            "isTerminal": false,
            "operationDetails": "hoge0402cert",
            "operationType": "CreateCertificate",
            "status": "Started",
            "statusChangedAt": 1712057764.42
        }
    ]
}

この証明書を指定して再度試してみたところ API の実行には成功したようです。

アタッチできたっぽいか?

% cat hoge.json
{
    "distributionName": "Distribution-1",
    "viewerMinimumTlsProtocolVersion": "TLSv1.2_2021",
    "certificateName": "hoge0402cert",
    "useDefaultCertificate": false
}
% aws-v1 lightsail update-distribution --cli-input-json file://hoge.json --profile hogeadmin --region us-east-1
{
    "operation": {
        "id": "2841d271-3224-4dad-a0bd-c7e8a2cca4b5",
        "resourceName": "Distribution-1",
        "resourceType": "Distribution",
        "createdAt": 1712058075.216,
        "location": {
            "availabilityZone": "all",
            "regionName": "global"
        },
        "isTerminal": false,
        "operationType": "UpdateDistribution",
        "status": "Started"
    }
}

sslscanで確認してみると、次のように TLSv1.0 と TLSv1.1 も無効化され、暗号スイートも限定されるようになりました。

% sslscan https://hoge0402.lightsail.tak1wa.com/

:

  SSL/TLS Protocols:
SSLv2     disabled
SSLv3     disabled
TLSv1.0   disabled
TLSv1.1   disabled
TLSv1.2   enabled
TLSv1.3   enabled

:

  Supported Server Cipher(s):
Preferred TLSv1.3  128 bits  TLS_AES_128_GCM_SHA256        Curve 25519 DHE 253
Accepted  TLSv1.3  256 bits  TLS_AES_256_GCM_SHA384        Curve 25519 DHE 253
Accepted  TLSv1.3  256 bits  TLS_CHACHA20_POLY1305_SHA256  Curve 25519 DHE 253
Preferred TLSv1.2  128 bits  ECDHE-RSA-AES128-GCM-SHA256   Curve 25519 DHE 253
Accepted  TLSv1.2  256 bits  ECDHE-RSA-AES256-GCM-SHA384   Curve 25519 DHE 253
Accepted  TLSv1.2  256 bits  ECDHE-RSA-CHACHA20-POLY1305   Curve 25519 DHE 253

:

さいごに

本日は Amazon Lightsail でディストリビューションの TLS バージョンポリシーをコントロール出来るようになったので確認してみました。

コンソールで使えるようになるのかはまだわからないですが、Lightsail でも最低 TLS バージョンを制限したかったという方には嬉しいアップデートではないでしょうか。