在 AWS 中解码加密的授权/错误消息

问题描述 投票:0回答:3

某些涉及 IAM 权限的操作可能会返回 Client.UnauthorizedOperation 响应。

amazon-web-services amazon-ec2 amazon-iam aws-policies
3个回答
3
投票

您可以使用以下命令从 CLI 解密消息:

$> aws sts decode-authorization-message --encoded-message <encoded message from error>

这将为您提供如下所示的输出:

{"allowed":false,"explicitDeny":false,"matchedStatements":{"items":[]},"failures":{"items":[]},"context":{"principal":{"id":"APOZIAANAVSK6I6FK2RQI:i-66c78ee7","arn":"arn:aws:sts::<aws-account-id>:assumed-role/my-role-ec2/i-123456e7"},"action":"iam:PassRole","resource":"arn:aws:iam::<aws-account-id>:role/my-role-ec2","conditions":{"items":[]}}}

错误消息实际上是在

""
内部编码为JSON,默认情况下嵌入的引号(
"
)被转义为
\"
;为了方便阅读错误,请提取消息部分并使用文本编辑器将
\"
替换为
"


1
投票

为了使其更具可读性:

aws sts decode-authorization-message --encoded-message \
[the_message] | jq .DecodedMessage -r | jq

如果你没有jq,你可以拿它,例如从这里开始https://stedolan.github.io/jq


0
投票

运行下面的代码可以更轻松地读取 JSON 格式的错误。

aws sts decode-authorization-message --encoded-message  <encode_message> --query DecodedMessage --output text | jq '.'
© www.soinside.com 2019 - 2024. All rights reserved.