使用 aws cli 时访问被拒绝,但在 Web 控制台中允许访问

abb*_*bbr 6 aws-cli

我的 IAM 帐户至少有“管理员”权限。据我所知,我可以在 Web 控制台中执行所有操作。例如, aws gui

最近我下载了 aws-cli 并通过提供访问密钥、默认区域和输出格式快速配置了它。然后我尝试发出一些命令,发现其中大部分(但不是全部)都有权限问题。例如

$ aws --version
aws-cli/1.16.243 Python/3.7.4 Windows/10 botocore/1.12.233
$ aws s3 ls s3://test-bucket

An error occurred (AccessDenied) when calling the ListObjectsV2 operation: Access Denied
$ aws ec2 describe-instances

An error occurred (UnauthorizedOperation) when calling the DescribeInstances operation: You are not authorized to perform this operation.
$ aws iam get-user
{
    "User": {
        "Path": "/",
        "UserName": "xxx@xxx.xxx",
        "UserId": "xxxxx",
        "Arn": "arn:aws:iam::nnnnnnnnnn:user/xxx@xxx.xxx",
        "CreateDate": "2019-08-21T17:09:25Z",
        "PasswordLastUsed": "2019-09-21T16:11:34Z"
    }
}
Run Code Online (Sandbox Code Playgroud)

在我看来,使用访问密钥进行身份验证的 cli 与使用 MFA 进行身份验证的 Web 控制台具有不同的权限集。

为什么 CLI 和 GUI 之间的权限不一致?如何使其一致?

abb*_*bbr 9

事实证明,由于缺乏 MFA,我的一项策略中的以下语句阻止了 CLI 访问。

{
      "Condition": {
        "BoolIfExists": {
          "aws:MultiFactorAuthPresent": "false"
        }
      },
      "Resource": "*",
      "Effect": "Deny",
      "NotAction": [
        "iam:CreateVirtualMFADevice",
        "iam:EnableMFADevice",
        "iam:GetUser",
        "iam:ListMFADevices",
        "iam:ListVirtualMFADevices",
        "iam:ResyncMFADevice",
        "sts:GetSessionToken"
      ],
      "Sid": "DenyAllExceptListedIfNoMFA"
},
Run Code Online (Sandbox Code Playgroud)


小智 5

如果要更换BoolIfExistsBool,它应该工作。您的 CLI 请求不会因为未使用 MFA 而被拒绝。

https://aws.amazon.com/premiumsupport/knowledge-center/mfa-iam-user-aws-cli/相对