Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access denied when using aws cli but allowed in web console

Tags:

aws-cli

My IAM account has "admin" privilege, at least supposedly. I can perform all operations as far as I can tell in web console. For example, aws gui

Recently I downloaded aws-cli and quickly configured it by supplying access keys, default region and output format. I then tried to issue some commands and found most of them, but not all, have permission issues. For example

$ 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": "[email protected]",
        "UserId": "xxxxx",
        "Arn": "arn:aws:iam::nnnnnnnnnn:user/[email protected]",
        "CreateDate": "2019-08-21T17:09:25Z",
        "PasswordLastUsed": "2019-09-21T16:11:34Z"
    }
}

It appears to me that cli, which is authenticated using access key, has a different permission set from web console, which is authenticated using MFA.

Why is permission inconsistent between CLI and GUI? How to make it consistent?

like image 958
abbr Avatar asked Sep 21 '19 16:09

abbr


People also ask

Why my AWS CLI is not working?

If the aws command cannot be found after first installing or updating the AWS CLI, you might need to restart your terminal for it to recognize any PATH updates. If the aws command cannot be found after first installing or updating the AWS CLI, it might not have been fully installed.

Why am I getting an access denied error when I open the link to an Amazon s3 object that I have access to?

If you're getting Access Denied errors on public read requests that are allowed, check the bucket's Amazon S3 Block Public Access settings. Review the S3 Block Public Access settings at both the account and bucket level. These settings can override permissions that allow public read access.

How do I give access to AWS command line?

To switch to a production role (AWS CLI)Open a command prompt and set up your AWS CLI installation to use the access key from your IAM user or from your federated role. For more information, see Configuring the AWS Command Line Interface in the AWS Command Line Interface User Guide.

Why am I getting an access denied error from the Amazon s3 console when I try to modify a bucket policy?

Short description. The "403 Access Denied" error can occur due to the following reasons: Your AWS Identity and Access Management (IAM) user or role doesn't have permissions for both s3:GetBucketPolicy and s3:PutBucketPolicy.


4 Answers

It turns out following statement in one of my policies blocked CLI access due to lacking MFA.

{
      "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"
},
like image 77
abbr Avatar answered Oct 16 '22 20:10

abbr


If you replace BoolIfExists with Bool, it should work. Your CLI requests would not be denied because of not using MFA.

Opposite of https://aws.amazon.com/premiumsupport/knowledge-center/mfa-iam-user-aws-cli/

like image 20
tushar1391 Avatar answered Oct 16 '22 19:10

tushar1391


I had this same issue and I fixed it by adding my user to a new group with administrator access in IAM.

to do this go to IAM, Users, click on your user and then [add permissions] in the next screen click [Create group] and then pick administrator access

enter image description here

like image 42
Hugo Avatar answered Oct 16 '22 19:10

Hugo


To remain really secure check this good explanation: MFA token for AWS CLI

In few steps

  1. Get a temporary 36 hours session token.
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"
    }
}
  1. Save these values in a mfa profile configuration.
    [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
  1. Call with the profile
aws --profile mfa

Ps: Don't do the cron job as suggested, it goes again the security.

like image 4
Martin P. Avatar answered Oct 16 '22 19:10

Martin P.