Skip to content

A small lambda script that will disable access keys older than a given amount of days.

License

Notifications You must be signed in to change notification settings

te-papa/aws-key-disabler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS IAM Access Key Disabler

![Image of KeyIcon] (https://github.com/te-papa/aws-key-disabler/blob/3869f2a788d948fd962a51b51ff5389f3dbf5b3b/docs/images/GitHubTepapaKeyIcon.jpg)

The AWS Key disabler is a Lambda function that disables AWS access keys after a set amount of time in order to reduce the risk associated with old access keys.

AWS Lambda Architecture

![Image of Arch] (https://github.com/te-papa/aws-key-disabler/blob/master/docs/images/GitHubTepapaLambda.png)

SysOps Output for EndUser

![Image of iPhoneEmail] (https://github.com/te-papa/aws-key-disabler/blob/master/docs/images/GitHubTepapaOutput.png)

Developer Toolchain

![Image of Toolchain] (https://github.com/te-papa/aws-key-disabler/blob/master/docs/images/GitHubTepapaToolchain.png)

Current Limitations

  • A report containing the output (json) of scan will be sent to a single defined sysadmin account, refer to the report_to attribute in the /grunt/package.json build configuration file.
  • Keys are only disabled, not deleted nor replaced

Prerequisites

This script requires the following components to run.

It also assumes that you have an AWS account with SES enabled, ie domain verified and sandbox mode removed.

Installation instructions

These instructions are for OSX. Your mileage may vary on Windows and other *nix.

  1. Grab yourself a copy of this script
  2. Navigate into the /grunt folder
  3. Setup the Grunt task runner, e.g. install its deps: npm install
  4. Fill in the following information in /grunt/package.json
    1. Set the aws_account_number value to your AWS account id found on https://portal.aws.amazon.com/gp/aws/manageYourAccount
    2. Set the first_warning and last_warning to the age that the key has to be in days to trigger a warning. These limits trigger an email send to report_to
    3. Set the expiry to the age in days when the key expires. At this age the key is disabled and an email is triggered to report_to notifying this change
    4. Set the send_completion_report value to True to enable email delivery via SES
    5. Set the report_to value to the email address you'd like to receive deletion reports to
    6. Set the report_from value to the email address you'd like to use as the sender address for deletion reports. Note that the domain for this needs to be verified in AWS SES.
    7. Set the deployment_region to a region that supports Lambda and SES. Also ensure that the region has SES sandbox mode disabled.
  5. Ensure you can successfully connect to AWS from the CLI, eg run aws iam get-user to verify successful connection
  6. from the /grunt directory run grunt bumpup && grunt deployLambda to bump your version number and perform a build/deploy of the Lambda function to the selected region

Additional configuration option

  • You can choose to set the message used for each warning and the final disabling by changing the values under key_disabler.keystates.<state>.message
  • You can change the length of masking under key_disabler.mask_accesskey_length. The access keys are 20 characters in length.

Troubleshooting

This script is provided as is. We are happy to answer questions as time allows but can't give any promises.

If things don't work ensure that:

Bonus Points

Once the Lambda Function has been successfully deployed - the following commands can be performed:

  1. aws lambda list-functions
  2. openssl dgst -binary -sha256 ..\Releases\AccessKeyRotationPackage.1.0.18.zip | openssl base64
  3. aws lambda invoke --function-name AccessKeyRotation report.log --region us-east-1
  4. jq '.' report.log
  5. jq '.users[] | select(.username=="johndoe")' report.log
  6. jq '.' report.log | grep age | cut -d':' -f2 | sort -n

Bonus Bonus Points

  1. jq 'def maximal_by(f): (map(f) | max) as $mx | .[] | select(f == $mx); .users | maximal_by(.keys[].age)' report.log
  2. jq 'def minimal_by(f): (map(f) | min) as $mn | .[] | select(f == $mn); .users | minimal_by(.keys[].age)' report.log

About

A small lambda script that will disable access keys older than a given amount of days.

Resources

License

Stars

Watchers

Forks

Packages

No packages published