Giter Club home page Giter Club logo

iamspec's Introduction

IAMSpec

RSpec Tests for AWS IAM using the AWS Policy Simulator - inspired by serverspec.

Caution: WIP and proof of concept: Don't expect everything to work perfectly, make sense or be maintained going forward - However, I'm interested in feedback, drop me a line if this feels useful to you!

Why?

The other day, after making some changes to our projects IAM configuration, I told my colleague: "It should work now". When he tried it, it didn't. No worries, I found the mistake, fixed it and on second try, it worked.

But something kept nagging me: As a developer, I don't usually tell people "it should work". I write tests, I know it works. But somehow, I didn't do that in an area that counts, identity and access management. IAMSpec is my attempt in filling this gap.

FAQ

What does it do?

It automates dealing with the AWS Policy Simulator. It allows you to write tests against your IAM configuration

Does it support everything I can do in IAM?

No. It uses the AWS Policy Simulator in the background so iamspec can only check what's supported by the Policy Simulator.

For example, assume role policies seem to be ignored.

Does it support Terraform/CloudFormation/...?

IAMSpec runs your tests against the state in IAM, therefore it is independent from some tool. It is meant to run after you applied your changes in your favorite tool.

So it will only tell me after I broke something?

Yes, unless you set up a separate "staging accounts" where you test your IAM config before rolling it out. Support for testing policy-files separately might be added in the future to at least partly solve this issue.

Can I extend it?

Sure, you can write your own syntactic sugar based on GenericAction and GenericType. And if you think others can profit from your extension, why not send in a pull request?

Installation

Add this line to your application's Gemfile:

gem 'iamspec',:git => 'https://github.com/flosell/iamspec.git'

And then execute:

$ bundle

Or install it yourself as:

$ gem install iamspec

Then add it to your spec_helper

require "iamspec"

Usage

Write your first test:

describe('Using syntactic sugar') do
  describe iam_user('some_user_with_admin_permissions') do
      it { should be_allowed_to assume_role('Administrator') }
  end
end
# OR 
describe("Using a generic resource") do
  describe generic_policy_source("arn:aws:iam::#{SOME_ACCOUNT_ID}:user/some_user_with_admin_permissions") do
    it { should be_allowed_to perform_action('sts:AssumeRole').with_resource("arn:aws:iam::#{SOME_ACCOUNT_ID}:role/Administrator") }
  end
end

See integration_spec.rb for more examples

TODO

  • clean things up
  • add documentation
  • release on RubyGems
  • more syntactic sugar
  • spec directly against policy JSON

Development

The go-script is your central entrypoint. Call it without arguments to see what's available.

The integration-tests require an AWS account with certain IAM resources set up. Use the go script to apply the example_infra terraform code to do this (don't use a production account!)

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/flosell/iamspec.

iamspec's People

Contributors

flosell avatar imriz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

iamspec's Issues

picking up?

Wow, I really like the sound of this. Would you be interested in creating couple of issues I can work on? Something not big to get into the flow ;)

Show additional information on match-failures

For explicit allow or deny, IAM gives us more information than we show at the moment, e.g. which policy and which statement in the policy allowed it

#<struct Aws::IAM::Types::EvaluationResult eval_action_name="iam:CreateUser", eval_resource_name="*", eval_decision="allowed", matched_statements=[#<struct Aws::IAM::Types::Statement source_policy_id="AdministratorAccess", source_policy_type=nil, start_position=#<struct Aws::IAM::Types::Position line=3, column=17>, end_position=#<struct Aws::IAM::Types::Position line=8, column=6>>], missing_context_values=[], organizations_decision_detail=nil, eval_decision_details={}, resource_specific_results=[]>

We could display more detail in such a case, e.g.

Credential self service IAM Group "administrators" should not be allowed to iam:CreateUser
     Failure/Error: it {should not_be_allowed_to perform_action('iam:CreateUser')}
       iam:CreateUser was allowed because of allowed for iam:CreateUser in policy AdministratorAccess line 8, column 6

We could even extend this to get the policy and show the actual lines

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.