Giter Site home page Giter Site logo

awsmfa's Introduction

awsmfa

Updates AWS credentials to allow MFA use with aws-cli

Usage

awsmfa --profile=profilename 000000

... where profilename is the name of a profile in your AWS credentials file which is protected by 2 factor authentication. And replace 000000 with the token from your MFA device.

Configuration:

For your IAM user, add the following policy to enforce 2FA on the CLI:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "DenyAllWhenMFAIsNotPresent",
            "Effect": "Deny",
            "NotAction": [
                "iam:ListMFADevices",
                "sts:GetSessionToken"
            ],
            "Resource": "*",
            "Condition": {
                "BoolIfExists": {
                    "aws:MultiFactorAuthPresent": false
                }
            }
        },
        {
            "Sid": "DenyAllWhenMFAIsOlderThanFourHours",
            "Effect": "Deny",
            "NotAction": [
                "iam:ListMFADevices",
                "sts:GetSessionToken"
            ],
            "Resource": "*",
            "Condition": {
                "NumericGreaterThanIfExists": {
                    "aws:MultiFactorAuthAge": "14400"
                }
            }
        }
    ]

}

iam.ListMFADevices is optional, since you can specify the MFA serial number in your credentials file (see below) if desired.

Adjust the MultiFactorAuthAge as desired. The expiration time in this policy is set to 4 hours. This policy will only allow access to the GetSessionToken and ListMFADevices API's unless credentials are used which have been provided through the MFA.

In your ~/.aws/credentials (or equivalent) file, create a new section called [{profile}mfa], where profile is the profilename you will use with the AWS SDK.

Just as with any profile to be used with the AWS SDK, you will need aws_access_key, and aws_secret_access_key parameters. You will also need a new parameter named mfa_serial, which should be set to the arn of your MFA device. The MFA arn can be found in the IAM console, under "Security credentials" for the user. Or via the aws iam list-mfa-devices command.

For instance, if your profile is "george", then the section will look something like this:

[georgemfa]
mfa_serial=arn:aws:iam::00000000000:mfa/georgeuser
aws_access_key_id=XXXXXXXXXXXXXXXXXXXXXXXX
aws_secret_access_key=XXXXXXXXXXXXXXXXXXXXXXXXX

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.