セッションマネージャーでリモートホストにポートフォワード出来ない場合はSSMエージェントのバージョンを確認してみて欲しい

2022.06.01

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

はじめに

こんにちは。大阪オフィスの林です。

つい最近のアップデートでAWS System Managerセッションマネージャーがリモートホストのポートフォワードに対応したことは記憶に新しいと思います。

リモートホストのポートフォワードにはSSMエージェントのバージョン要件があり、お使いのSSMエージェントのバージョンによっては、SSMエージェントのアップデートが必要となります。

使用開始するには、ポートフォワーディングセッションを確立しようとしている管理対象インスタンスにバージョン 3.1.1374.0 以降の SSM エージェントをインストールします。

セッションマネージャーでリモートホストにポートフォワード出来ない場合の一つの原因切り分けとしてSSMエージェントのバージョン確認をお勧めします。

やってみた

SSMエージェントの要件を満たしていない場合

まずは前提となるSSMエージェントのバージョンを満たしていない状態でリモートホストにポートフォワーディングしてみます。

hayashi@HL00751:~$ aws ssm start-session \
--target i-02ac9318543a98b62 \
--document-name AWS-StartPortForwardingSessionToRemoteHost \
--parameters '{"host":["xxx.amazonaws.com"],"portNumber":["xxx"], "localPortNumber":["xxx"]}'

An error occurred (BadRequest) when calling the StartSession operation: The version of the SSM agent installed on this instance doesn't support port forwarding to remote hosts. Install the latest version of the SSM agent to use port forwarding sessions to remote hosts.

下記のエラーが返されます。
内容は読んで字のごとく「このSSMエージェントのバージョンはリモートホストへのフォワーディングをサポートしていない」という旨のメッセージです。

An error occurred (BadRequest) when calling the StartSession operation: The version of the SSM agent installed on this instance doesn't support port forwarding to remote hosts. Install the latest version of the SSM agent to use port forwarding sessions to remote hosts.

対象のEC2でSSMエージェントのバージョンを確認

対象のEC2にログインしSSMエージェントのバージョンを確認してみます。
SSMエージェントのバージョンが3.1.1374.0 以降を満たしていません。

[ec2-user@ip-172-31-78-88 ~]$ yum info amazon-ssm-agent
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Installed Packages
Name        : amazon-ssm-agent
Arch        : x86_64
Version     : 3.1.1188.0
Release     : 1.amzn2
Size        : 115 M
Repo        : installed
Summary     : Manage EC2 Instances using SSM APIs
URL         : http://docs.aws.amazon.com/ssm/latest/APIReference/Welcome.html
License     : ASL 2.0
Description : This package provides Amazon SSM Agent for managing EC2 Instances using SSM APIs

Systems Manager Run CommandでSSMエージェントをアップデート

Systems Managerのダッシュボードから「Run Command」を選択し「AWS-UpdateSSMAgent」を検索・選択します。
※「Run Command」を使うので、System ManagerでEC2インスタンスを管理できている前提です。 ※オプションでSSMエージェントのバージョンの指定をしていないので最新バージョンのSSMエージェントにアップデートされます。

「ターゲット」で対象のインスタンスを選択します。

その他は設定せず「実行」を選択します。

「進行中」となるので暫く待ちます。

「成功」となったことを確認します。

改めて対象のEC2でSSMエージェントのバージョンを確認

再度、対象のEC2にログインしSSMエージェントのバージョンを確認してみます。
SSMエージェントのバージョンが3.1.1374.0 以降を満たしています。

[ec2-user@ip-172-31-78-88 ~]$ yum info amazon-ssm-agent
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Installed Packages
Name        : amazon-ssm-agent
Arch        : x86_64
Version     : 3.1.1476.0
Release     : 1
Size        : 108 M
Repo        : installed
Summary     : Manage EC2 Instances using SSM APIs
URL         : http://docs.aws.amazon.com/ssm/latest/APIReference/Welcome.html
License     : Apache License, Version 2.0
Description : This package provides Amazon SSM Agent for managing EC2 Instances using SSM APIs

リモートホストにポートフォワーディング

それでは最後にリモートホストにポートフォワーディングしてみます。

hayashi@HL00751:~$ aws ssm start-session \
--target i-02ac9318543a98b62 \
--document-name AWS-StartPortForwardingSessionToRemoteHost \
--parameters '{"host":["xxx.amazonaws.com"],"portNumber":["xxx"], "localPortNumber":["xxx"]}'

Starting session with SessionId: my-test1-0252f71fff292a107
Port xxx opened for sessionId my-test1-0252f71fff292a107.
Waiting for connections...

まとめ

AWS System Managerセッションマネージャーでリモートホストにポートフォワードするためには、ご利用の環境によってはSSMエージェントのアップデートが必要なので手順をまとめさせていただきました。
セッションマネージャーでリモートホストにポートフォワード出来ない場合の一つの原因切り分けとしてどなたかの参考になりましたら幸いです。

以上、大阪オフィスの林がお送りしました!