Giter Site home page Giter Site logo

hrizvi / serverless-monitor-for-unused-iam-roles Goto Github PK

View Code? Open in Web Editor NEW

This project forked from miztiik/serverless-monitor-for-unused-iam-roles

0.0 1.0 0.0 131 KB

Monitor Unused IAM Roles ๐ŸŽ“

Home Page: https://www.udemy.com/course/aws-cloud-development-kit-from-beginner-to-professional/?referralCode=E15D7FB64E417C547579&couponCode=AWS_4U_MAY

Python 100.00%

serverless-monitor-for-unused-iam-roles's Introduction

Monitor unused IAM roles with AWS Config Custom Rules

Identify IAM Roles that have not been used for x amount of time (for example, since last 30 days). We will use the role last used API and continuously monitor role activity using AWS Config. You can extend this solution to push the NON COMPLIANT information to SNS and get the necessary teams involved in the clean up operation.

Monitor unused IAM roles with AWS Config Custom Rules

Follow this article in Youtube

  1. Prerequisites

    This demo, instructions, scripts and cloudformation template is designed to be run in us-east-1. With few modifications you can try it out in other regions as well(Not covered here).

  2. SetUp Dev Environment

    Make sure you have AWS CLI profile configured. You should have at minimum these permissions before executing below commands

    # Clone the repo
    git clone https://github.com/miztiik/serverless-monitor-for-unused-iam-roles.git
    cd serverless-monitor-for-unused-iam-roles
    
    # Setup some global variables
    dir_name="mystique-infosec"
    custom_rule_name="monitor_unused_iam_roles"
    
    # If you dont have venv installed already
    # pip install virtualenv
    
    python3 -m venv ${dir_name}
    cd ${dir_name}
    source bin/activate
    pip3 install rdk
    
    # Configure AWS Profile
    rdk init
    
    # Lets create a LOCAL rule
    rdk create ${custom_rule_name} --runtime python3.7 --resource-types AWS::IAM::Role
  3. Copy the Config Rule code

    Copy the file under lambda_src to the directory ${custom_rule_name} directory that was created now. The custom_rule_name and this file-name should be the SAME.

  4. Deploy the custom rule

    rdk deploy ${custom_rule_name}
  5. Test the rule

    1. Create a new role(or ideally any pre-existing role, which has not been used for sometime is good enough)
    2. Wait for AWS Config to evaluate the role and identify it as โŒ Noncompliant
  6. Next Steps: Do Try This

    • update the lambda MAX_UNUSED_DAYS = 30 to different time period or make it a customizable variable
    • Integrate SNS notification
    • Quarantine old roles
    • Create exception list
  7. Resource Cleanup

    1. Delete CloudWatch Lambda LogGroups
    2. Delete the stack[s] - If you want to destroy all the resources created by the stack, Execute the below command to delete the stack, or you can delete the stack from console as well
    rdk undeploy ${custom_rule_name}

Buy me a coffee

Buy me a coffee โ˜• through Paypal, or You can reach out to get more details through here.

References

  1. Getting Started with Custom Rules
  2. AWS Config Rule Development Kit
  3. AWS Config RDK - Getting Started - Blog
  4. AWS Config RDK - Getting Started - Git
  5. Git Repo of Config Rules in Python-01
  6. Git Repo of Config Rules in Python-02

Metadata

Level: 200

serverless-monitor-for-unused-iam-roles's People

Contributors

miztiik avatar

Watchers

James Cloos avatar

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.