Giter Club home page Giter Club logo

inspec-aws-old's Introduction

This Repository Has Been Archived

You may continue to use this repo as an InSpec resource pack, but after February 15th, 2018, those resources will be available directly in InSpec 2.0

All code, issues, and pull requests are now available in the https://github.com/chef/inspec repository. Use the label 'aws' to find issues and PRs related to AWS.

This repository remains available for public reference.


InSpec for AWS

Roadmap

This repository is the development repository for InSpec for AWS. Once RFC Platforms is fully implemented in InSpec, this repository is going to be merged into core InSpec.

As of now, AWS resources are implemented as an InSpec resource pack. It will ship with the required resources to write your own AWS tests.

├── README.md - this readme
└── libraries - contains AWS resources

Get started

Before running the profile with InSpec, define environment variables with your AWS region and credentials. InSpec supports the following standard AWS variables:

  • AWS_REGION
  • AWS_DEFAULT_REGION
  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_SESSION_TOKEN (optional)

Those variables are defined in AWS CLI Docs

Use the resources

Since this is a InSpec resource pack, it only defines InSpec resources. It includes example tests only. You can easily use the AWS InSpec resources in your tests do the following:

Create a new profile

inspec init profile my-profile

Adapt the inspec.yml

name: my-profile
title: My own AWS profile
version: 0.1.0
depends:
  - name: aws
    url: https://github.com/chef/inspec-aws/archive/master.tar.gz

Add controls

Since your profile depends on the resource pack, you can use those resources in your own profile:

control "aws-1" do
  impact 0.7
  title 'Checks the machine is running'

  describe aws_ec2_instance('my-ec2-machine') do
    it { should be_running }
  end
end

Running your profile

Then use inspec exec my-profile to execute your new profile.

Our future intent is to support an aws target for InSpec/Train, so you may also pass credentials inspec exec my-profile -t aws://accesskey:secret@region.

Available Resources

  • aws_ec2_instance - This resource reads information about an ec2 instance
  • aws_iam_access_key - Verifies settings for AWS IAM access keys
  • aws_iam_password_policy - Verifies iam password policy
  • aws_iam_root_user - Verifies settings for AWS root account
  • aws_iam_user - Verifies settings for a specific AWS IAM user
  • aws_iam_users - Verifies settings for AWS IAM users

Roadmap

  • aws_ami
  • aws_s3bucket
  • aws_security_group
  • aws_iam_group
  • aws_iam_policy
  • aws_iam_role

Developing and Testing the AWS Resources Pack

Unit tests

To execute the unit tests, run:

bundle exec rake test

Integration tests

Please see TESTING_AGAINST_AWS.md for details on how to setup the needed AWS accounts to perform testing.

Kudos

This project was inspired by inspec-aws from arothian.

License

Author: Christoph Hartmann ([email protected])
Copyright: Copyright (c) 2017 Chef Software Inc.
License: Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

inspec-aws-old's People

Contributors

aaronlippold avatar chris-redekop avatar chris-rock avatar clintoncwolfe avatar dromazmj avatar hackershark avatar jerryaldrichiii avatar miah avatar mtjandra avatar nathenharvey avatar rx294 avatar samcornwell avatar stiffni avatar

Stargazers

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

Watchers

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

inspec-aws-old's Issues

CI Builds are Broken

The CI builds always fail. For example, see the failed builds on PR #4.

  • Figure out how to expose credentials to Travis CI
  • Ask Christoph re: AWS credentials
  • Make sure the build is green

Segregate integration-test runs

Currently, all our integration-test runs are in the same namespace and so can collide. As an example, I hit

Error applying plan:

2 error(s) occurred:

* aws_iam_user.mfa_not_enabled_user: Error creating IAM User mfa_not_enabled_user: EntityAlreadyExists: User with name mfa_not_enabled_user already exists.
        status code: 409, request id: c654263b-196e-11e7-9dbc-6dbf49504827
* aws_iam_user.console_password_enabled_user: Error creating IAM User console_password_enabled_user: EntityAlreadyExists: User with name console_password_enabled_user already exists.
        status code: 409, request id: c6570d4e-196e-11e7-b4b2-712691fb77d1

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

when I tried to run ubuntu@ubuntu-xenial:~/inspec-aws$ bundle exec rake test:setup_integration_tests.

Ideally, we can isolate environments with Terraform, like we can with CFn stacks...

SPIKE: Determine rules for resource/assertion grammar

Something that came up while @vix633 was working on the policy resource: assertion grammar. (I think this is an important part of InSpec usability, so I want us to get this right/consistent.) For boolean properties, at least, I think we want to lead with a third person verb: exists?, has_console_password?, and has_mfa_enabled?.

This gets interesting/weird with InSpec's assertion grammar: for the ec2 resource, we can say either it { should exist } OR its('exists?') { should be true }. The former is more usable but

  • I am not clear how/why this works (Does Ruby/InSpec understand English grammar?),
  • I do not know if/how this translates to other methods, like has_console_password?.

@chris-rock , is this worth a live discussion/tutorial, and are you available? I ask because we have more methods coming in now, and the sooner we get this right, the less rework we need to do.

Fix Terraform Env Name

PR #57 .

Instead of generating a random environment identifier during the setup of our integration tests, use a fixed one based on an input. (Consider defaulting the environment identifier to the hostname, or not defaulting it.)

The idea is that it should be possible to imbue these IDs with human-level meaning, so we can link a Terraform environment identifier--which appears in the AWS console--to a person or a task.

[SPIKE] Consider a "IamPolicyEntities" resource

... to look for groups, roles, and users that have a policy. For recommendation 1.22.

Is the resource too abstract? What are the alternatives?

describe PolicyEntities.where(policy_name="AWSSupport") do
  it {should exist}
end

aws_iam_users for Recommendation 1.2

Now that we have a single aws_iam_user, add the ability to query for users with a new aws_iam_users resource.

Existing query logic for InSpec's core user resource is at

https://github.com/chef/inspec/blob/master/lib/resources/users.rb#L72-L89 and

https://github.com/chef/inspec/blob/master/lib/resources/users.rb#L103-L105

Example usage:

describe aws_iam_users.where(:has_console_password? => true) do
  its('has_mfa_enabled?') { should_not include false }
end

user_provider

  • create aws_user_provider.rb - master...Issue9-UserProvider
  • make aws_iam_user use aws_user_provider
  • fix aws_iam_user unit tests
  • add aws_user_provider unit tests
  • merge changes above

get_users

  • add get_users to aws_user_provider (and unit tests)
  • investigate potential paging of users by aws
  • run manual integration test
  • merge changes above

aws_am_users

  • add aws_iam_users.rb which will call get_users to populate the filter table
  • aws_iam_users unit tests
  • aws_iam_users integration tests

Circular reference in password-policy unit tests

When running the unit tests, the following warning appears:

/home/ubuntu/inspec-aws/test/unit/resources/aws_iam_password_policy_test.rb:78: warning: circular argument reference - value

Fix the warning.

RFC:`aws_s3bucket` and `aws_s3buckets` resources for vpc and or iam_groups??

Examples of Questions of Concerns:

i.e. ensure users didn't open an S3 bucket to the world
i.e. ensure that s3 only open to particular users
i.e. ensure that only a particular service, port, and or IAM
i.e. ensure that I can pass a list of IAMs to the resource and that it can validate that the S3 bucket has or has_not access.
i.e. ensure the S3 bucket is only accessible form https, or a known uri etc.
i.e. ensure that the S3 bucket has logging enabled, set, reporting to the 'known' location
i.e. ensure that the 'POLICY SETTINGS' for S3 is set or not set

[SPIKE] EC2 instance roles for recommendation 1.21

One option for checking instance roles is to explicitly name the instances to check. In this case, we can just add a 'has_instance_role?' property to our existing EC2 resource.

We'd like to search for instances that "should" have roles, and check those; but we don't see any reliable way to identify such instances--we might need to leave instance identification to the user.

@aduric and @Stiffni , what do you think?

aws_iam_password_policy for recomendation 1.5-1.11

Implement ability to get iam password policy and validate it's properties based on AWS_CIS recommendations 1.5 through 1.11.

  • 1.5 Ensure IAM password policy requires at least one uppercase letter - @vix633

  • 1.6 Ensure IAM password policy require at least one lowercase letter

  • 1.7 Ensure IAM password policy require at least one symbol

  • 1.8 Ensure IAM password policy require at least one number

  • 1.9 Ensure IAM password policy requires minimum length of 14 or greater

  • 1.10 Ensure IAM password policy prevents password reuse

  • 1.11 Ensure IAM password policy expires passwords within 90 days or less

SPIKE: aws_iam_user for Recommendation 1.3

Recommendation 1.3 looks for passwords or API keys that

  1. are enabled and
  2. haven't been used in 90 days.

Design the example usages for a single user. Some questions to answer:

  1. Do we want to hang these properties off the user resource, or do we want separate users, console passwords, and access keys?
  2. How do we want to address each of the two access keys which each user can have?
  3. How do we test the date? (i.e. 'time since last use' < 90 days)

AC:

  1. We have a new story, with example usages, on how to implement Recommendation 1.3.

[SPIKE] Plan remaining work for Milestone #1

Some recommendations don't make sense in a pass/fail environment, while others are not (practically) implementable with the AWS API. Which recommendations won't we implement?

Milestone #1 demo - Recommendations 1.5-1.11

We want to create an InSpec profile that clearly demonstrates each of the recommendations. When run against an account, the profile should fail if the account does not follow the recommendations.

Start with the password policy, which should all be in master and ready to go.

If 1.5-1.11 are not yet demoable, then create follow-up issues.

configure_test_environment should fail if env exists

Currently, the configure_test_environment creates a new environment on each run, regardless if one has already been created (and has running resources). This "hides" the old environment, making it more difficult to track/manage.

Before creating a new Terraform env, check to see if the previous one exists and fail if it does. (This might be hard to do until #52 and might have to wait for that fix.)

aws_iam_user for Recommendation 1.2

  • Create an empty IAM aws_iam_user resource that does nothing
  • Add the ability to choose a user by username
  • Add "has MFA enabled" member
  • Add "has console password" member
  • Unit tests (@JeffreyLyonsD2L, @Rugbyte)
  • Integration tests that specifically demonstrate (a single-user version of) recommendation 1.2
    • Any dev can run integration tests locally
    • We can use Terraform to create IAM users with MFA

Notes:

  • Similar to core InSpec, we will differentiate between a single user (the resource described here) and a set of users (a resource which we have not planned yet).
  • As discussed on Slack, let's call the user resource aws_iam_user.

Example usage:

describe aws_iam_user('mfa_test_user') do
  its('is_mfa_enabled?') { should be true }
end

https://github.com/chef/inspec-aws/compare/issue6

Ec2#exists returns false positives

Ec2#exists checks for a non-nil id; because the id can be set during construction without any check against AWS, Ec2#exists sometimes reports true when the instance does not actually exist.

See the failing integration test in the issue13 branch.

Profile: inspec-aws-integration-tests
Version: unknown
Target:  local://


  EC2 Instance
     ✔  Example should exist
     ✔  Example image_id should eq "ami-0d729a60"
     ✔  Example instance_type should eq "t2.micro"
  EC2 Instance
     ∅  i-missing should not exist
     expected EC2 Instance i-missing not to exist


Profile: InSpec AWS Resource Pack (inspec-aws)
Version: 1.0.0
Target:  local://

     No tests executed.

Test Summary: 3 successful, 1 failures, 0 skipped
rake aborted!
Command failed with status (1): [bundle exec inspec exec test/integration/v...]
/home/ubuntu/inspec-aws/Rakefile:35:in `block (2 levels) in <top (required)>'
/var/lib/gems/2.3.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
Tasks: TOP => test:integration
(See full trace by running task with --trace)

To fix the issue, consider checking for a non-nil instance (as returned by Ec2#instance) instead.

[SPIKE] Consider a Policies resource for recommendation 1.24

Challenges:

  1. How do we query for policies based on their content? See aws iam get-policy-version for an example of querying and AWS's query syntax.
  2. How do we express our query in InSpec Policies.where(???) what does FilterTable support here?
  3. See more info in the CIS recommendation.

Determine Integration Tests for the IAM Password Policy

See #47. It would be good to have a deterministic integration test to cover the following case:

describe aws_iam_password_policy do
  its('prevent_password_reuse?') { should be true }
end


describe aws_iam_password_policy do
  its('number_of_passwords_to_remember') { should eq 1 }
end

Once the test is complete the account should be reverted to its previous state.

Determine Integration Tests for Root User Access Key Count

See #49 . It would be good to have a deterministic integration test to cover the following case:

describe aws_iam_root_user do
  its('access_key_count') { should eq 0 }
end

Once the test is complete the account should be reverted to its previous state.

Ensure AWS Resources are Destroyed for CI Usage

PR #56 .

Currently when you run bundle exec rake test:integration AWS resources are not destroyed if the integration tests fail. There should be an option to ensure the cleanup of AWS resources regardless of the results from the integration tests.

For example you might run bundle exec rake test:integration --force-cleanup

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.