我的IAM帐户有“管理”特权,至少应该如此。我可以在web控制台中尽我所能执行所有的操作。例如,
最近,我通过提供访问键、默认区域和输出格式下载了aws和快速配置。然后我尝试发出一些命令,发现大多数命令,但不是所有命令,都有权限问题。例如
$ 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"
}
}
在我看来,使用访问密钥进行身份验证的cli与使用MFA进行身份验证的web控制台具有不同的权限集。
为什么CLI和GUI之间的权限不一致?如何使它保持一致?
发布于 2019-09-24 00:20:13
结果发现,由于缺少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"
},
发布于 2020-07-16 12:59:01
如果您将BoolIfExists
替换为Bool
,那么它应该可以工作。您的CLI请求不会因为不使用MFA而被拒绝。
与https://aws.amazon.com/premiumsupport/knowledge-center/mfa-iam-user-aws-cli/相反
发布于 2021-04-01 19:51:00
要保持真正的安全,请检查以下好的解释:AWS CLI的MFA令牌
几步
aws sts get-session-token --serial-number arn:aws:iam::123456789012:mfa/user --token-code code-from-token
{
"Credentials": {
"SecretAccessKey": "secret-access-key",
"SessionToken": "temporary-session-token",
"Expiration": "expiration-date-time",
"AccessKeyId": "access-key-id"
}
}
[mfa]
aws_access_key_id = example-access-key-as-in-returned-output
aws_secret_access_key = example-secret-access-key-as-in-returned-output
aws_session_token = example-session-Token-as-in-returned-output
aws --profile mfa
Ps:不要像建议的那样做cron的工作,这又是安全问题。
https://stackoverflow.com/questions/58042096
复制相似问题