[MAMIP] Monitor AWS Managed IAM Policies

This Article was created posted in September 2019. Updated in February 2020.

Disclaimer

Thanks to @0xdabbad00 from SummitRoute for the original idea and jq parsing.

Purpose

When your production workloads rely on AWS IAM Managed Policies (don’t do this), you will need to be notified when changes occur behind the scene. It’s also interesting to monitor new AWS services releases prior announcements to get spoiled.

This pet project automates the retrieval (every 4 hours) of new AWS Managed IAM Policies to make it easier to monitor and get alerted when changes occur (by AWS) using “Watch” feature from Github, RSS or dedicated Twitter Account.

twitter pics

Link: MAMIP - Monitor AWS Managed IAM Policies

Usage

Three options

  1. Activate Releases Only notifications of Github

setup

  1. Subscribe to the Github RSS Feed (master branch)

How it works behind the scene

Schema

schema

Managed Policies are acquired as follows:

aws iam list-policies > list-policies.json

cat list-policies.json | jq -cr '.Policies[] | select(.Arn | contains("iam::aws"))|.Arn +" "+ .DefaultVersionId+" "+.PolicyName' | xargs -n3 sh -c 'aws iam get-policy-version --policy-arn $1 --version-id $2 > "policies/$3"' sh

This does the following (the magic):

  • Gets the list of all policies in the AWS Account
  • Finds the ones with an ARN containing iam::aws, so that only the AWS managed policies are grabbed.
  • Gets the ARN, current version id, and policy name (needed so we don’t have a slash as the ARN does for writing a file)
  • Calls aws iam get-policy-version with those values, and writes the output to a file using the policy name.

Automation Steps

  1. Clone the mamip repository
  2. Run the magic (previous command)
  3. Commit changes if any
  4. Push (with tags for release) to Github
  5. Send message to a SQS queue (qTweet)
  6. A Lambda function is triggered on SQS message, then push message to Twitter

Schedule

  • Every 4 hours

That’s all folks!

zoph.


comments powered by Disqus