如何排查 AWS Systems Manager 会话管理器的问题?

3 分钟阅读
0

在尝试使用 AWS Systems Manager 会话管理器时,我的会话失败了。

解决方法

当会话由于 Amazon Elastic Compute Cloud (Amazon EC2) 实例不可用作托管实例而失败时,请对托管实例可用性进行故障排查

如果会话失败且 Amazon EC2 实例可用作托管实例,请对会话管理器进行故障排查以解决以下问题:

  • 会话管理器没有启动会话的权限。
  • 会话管理器没有更改会话首选项的权限。
  • 托管节点不可用或者未为会话管理器配置托管节点。
  • 会话管理器插件未添加到命令行路径(Windows)。
  • 系统发送 TargetNotConnected 错误。
  • 在启动会话时,会话管理器会显示空白屏幕。

当会话失败并且显示以下一种错误消息时,请遵循相应的故障排查指南。

"Your session has been terminated for the following reasons: ----------ERROR------- Encountered error while initiating handshake.Fetching data key failed: Unable to retrieve data key, Error when decrypting data key AccessDeniedException: The ciphertext refers to a AWS KMS key that does not exist, does not exist in this region, or you are not allowed to access. status code: 400, request id: nnnnnnnnnnnn"

当账户中的用户和 EC2 实例不具有所需的 AWS Key Management Service (AWS KMS) 密钥权限时,会收到此错误。如需解决此错误,请为会话数据启用 AWS KMS 加密,然后执行下面的步骤:

  1. 向启动会话的用户和会话所连接的实例授予必需的 AWS KMS 密钥权限。
  2. 配置 AWS Identity and Access Management(IAM),为用户和实例提供通过会话管理器使用 AWS KMS 密钥的权限:
    要为用户添加 AWS KMS 密钥权限,请参阅会话管理器示例 IAM 策略
    要为实例添加 AWS KMS 密钥权限,请参阅验证或添加 Session Manager 的实例权限
    对于默认主机管理配置,请向提供 AWS KMS 密钥权限的 IAM 角色添加策略

**注意:**从 AWS Systems Manager Agent (SSM Agent) 版本 3.2.582.0 开始,默认主机管理配置会自动管理没有 IAM 实例配置文件的 EC2 实例。该实例必须使用实例元数据服务版本 2(IMDSv2)。

"Error - Fleet Manager is unable to start the session because the WebSocket connection closed unexpectedly during the handshake.Verify that your instance profile has sufficient Sessions Manager and AWS KMS permissions.For a more detailed message, visit the Session Manager console"

当目标实例附加的实例配置文件角色缺少以下权限时,可能会遇到此错误。要将 AWS Systems Manager 与 AWS KMS 配合使用,需要 kms:Decrypt 权限才能允许对会话数据进行客户密钥加密和解密。

{
    "Effect":   "Allow",
    "Action":  [
          "kms:Decrypt"
    ],
    "Resource": "key-name"
}

要解决此错误,请更新附加到实例的实例配置文件角色的权限。有关会话管理器权限的示例,请参阅向现有 IAM 角色添加会话管理器权限

“Your session has been terminated for the following reasons: Couldn't start the session because we are unable to validate encryption on Amazon S3 bucket.Error: AccessDenied: Access Denied status code: 403”

在会话管理器首选项中为 S3 日志记录选择仅允许加密的 S3 存储桶时,会收到此错误。要解决此错误,请完成以下步骤:

  1. 打开 AWS Systems Manager 控制台
  2. 选择会话管理器首选项,然后选择编辑
  3. S3 日志记录下,清除仅允许加密的 S3 存储桶,然后保存您所做的更改。
    有关详细信息,请参阅 使用 Amazon S3(控制台)记录会话数据
  4. 对于使用 IAM 实例配置文件管理的实例,请向实例配置文件添加一个策略,以提供将加密日志上传到 Amazon S3 的权限。有关说明,请参阅创建具有 Session Manager、Amazon S3 和 Amazon CloudWatch Logs 权限的 IAM 角色(控制台)
  5. 对于使用默认主机管理配置管理的实例,请向 IAM 角色添加一个策略,以提供将加密的日志上传到 Amazon S3 的权限。有关说明,请参阅 创建具有 Session Manager、Amazon S3 和 CloudWatch Logs权限的 IAM 角色(控制台)

“Your session has been terminated for the following reasons: We couldn't start the session because encryption is not set up on the selected CloudWatch Logs log group.Either encrypt the log group or choose an option to enable logging without encryption"

当在会话管理器首选项中为 CloudWatch 日志记录选择仅允许加密的 CloudWatch 日志组时,会收到此错误。要解决此错误,请完成以下步骤:

  1. 打开 AWS Systems Manager 控制台
  2. 选择会话管理器首选项,然后选择编辑
  3. CloudWatch 日志记录下,清除仅允许加密的 CloudWatch 日志组,然后保存您所做的更改。
    有关详细信息,请参阅使用 Amazon CloudWatch Logs 记录会话数据(控制台)
  4. 对于使用 IAM 实例配置文件管理的实例,请向实例配置文件添加一个策略,以提供将加密的日志上传到 Amazon CloudWatch 的权限。有关说明,请参阅创建具有 Session Manager、Amazon S3 和 CloudWatch Logs 权限的 IAM 角色(控制台)
  5. 对于使用默认主机管理配置管理的实例,请向 IAM 角色添加一个策略,以提供将加密的日志上传到 CloudWatch 的权限。有关说明,请参阅创建具有 Session Manager、Amazon S3 和 CloudWatch Logs 权限的 IAM 角色(控制台)

"Your session has been terminated for the following reasons: ----------ERROR------- Unable to start command: Failed to create user ssm-user: Instance is running active directory domain controller service.Disable the service to continue to use session manager"

使用适用于 Windows Server 的 AWS Systems Manager 时,可能会遇到这个错误。此错误的原因取决于实例上运行的 SSM 代理的版本。

相关信息

如何在 Amazon EC2 实例上附加或替换实例配置文件?

启用和禁用会话记录

设置会话管理器

AWS 官方
AWS 官方已更新 5 个月前