inspec/libraries/aws_iam_user.rb

55 lines
1.3 KiB
Ruby
Raw Normal View History

# author: Alex Bedley
# author: Steffanie Freeman
# author: Simon Varlow
# author: Chris Redekop
class AwsIamUser < Inspec.resource(1)
name 'aws_iam_user'
desc 'Verifies settings for AWS IAM user'
example "
describe aws_iam_user(name: 'test_user') do
it { should have_mfa_enabled }
it { should_not have_console_password }
end
"
def initialize(
opts,
aws_user_provider = AwsIam::UserProvider.new,
Issue #46 Lazily load attributes in aws_iam_users (#89) * Initial Commit Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * aws_iam_user uses lazy loading Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * Disassociates convert call from list_users Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * A real-world working AwsIamUsers (#71) * Add aws_iam_users Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Adding Filter table and Collect User Details to aws_iam_users.rb Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Adding Filter table and Collect User Details to aws_iam_users.rb Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Adding Filter table and Collect User Details to aws_iam_users.rb Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Get an aws_iam_users integration test to pass Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Fix RuboCop issues and tests Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Improving code based on PR feedback Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * AWS IAM Users unit tests work with new lazy loading feature Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * Fixes tests Signed-off-by: aduric <adnan.duric@d2l.com> * Users should only hold the returned user references, transfering responsibility to each user to fetch any details Signed-off-by: aduric <adnan.duric@d2l.com> * Create user details provider class Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * Using details provider factory to delegate creation of detail providers, and updates tests Signed-off-by: aduric <adnan.duric@d2l.com> * Rubocop fixes Signed-off-by: aduric <adnan.duric@d2l.com> * Rename user details provider factory to initializer, and remove unnecessary instance variables Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com>
2017-10-26 19:22:15 +00:00
aws_user_details_provider_ini = AwsIam::UserDetailsProviderInitializer.new,
access_key_factory = AwsIamAccessKeyFactory.new
)
Issue #46 Lazily load attributes in aws_iam_users (#89) * Initial Commit Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * aws_iam_user uses lazy loading Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * Disassociates convert call from list_users Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * A real-world working AwsIamUsers (#71) * Add aws_iam_users Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Adding Filter table and Collect User Details to aws_iam_users.rb Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Adding Filter table and Collect User Details to aws_iam_users.rb Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Adding Filter table and Collect User Details to aws_iam_users.rb Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Get an aws_iam_users integration test to pass Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Fix RuboCop issues and tests Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Improving code based on PR feedback Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * AWS IAM Users unit tests work with new lazy loading feature Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * Fixes tests Signed-off-by: aduric <adnan.duric@d2l.com> * Users should only hold the returned user references, transfering responsibility to each user to fetch any details Signed-off-by: aduric <adnan.duric@d2l.com> * Create user details provider class Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * Using details provider factory to delegate creation of detail providers, and updates tests Signed-off-by: aduric <adnan.duric@d2l.com> * Rubocop fixes Signed-off-by: aduric <adnan.duric@d2l.com> * Rename user details provider factory to initializer, and remove unnecessary instance variables Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com>
2017-10-26 19:22:15 +00:00
user = opts[:user]
user = aws_user_provider.user(opts[:name]) if user.nil?
@aws_user_details_provider = aws_user_details_provider_ini.create(user)
@access_key_factory = access_key_factory
end
def has_mfa_enabled?
Issue #46 Lazily load attributes in aws_iam_users (#89) * Initial Commit Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * aws_iam_user uses lazy loading Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * Disassociates convert call from list_users Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * A real-world working AwsIamUsers (#71) * Add aws_iam_users Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Adding Filter table and Collect User Details to aws_iam_users.rb Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Adding Filter table and Collect User Details to aws_iam_users.rb Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Adding Filter table and Collect User Details to aws_iam_users.rb Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Get an aws_iam_users integration test to pass Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Fix RuboCop issues and tests Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Improving code based on PR feedback Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * AWS IAM Users unit tests work with new lazy loading feature Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * Fixes tests Signed-off-by: aduric <adnan.duric@d2l.com> * Users should only hold the returned user references, transfering responsibility to each user to fetch any details Signed-off-by: aduric <adnan.duric@d2l.com> * Create user details provider class Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * Using details provider factory to delegate creation of detail providers, and updates tests Signed-off-by: aduric <adnan.duric@d2l.com> * Rubocop fixes Signed-off-by: aduric <adnan.duric@d2l.com> * Rename user details provider factory to initializer, and remove unnecessary instance variables Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com>
2017-10-26 19:22:15 +00:00
@aws_user_details_provider.has_mfa_enabled?
end
def has_console_password?
Issue #46 Lazily load attributes in aws_iam_users (#89) * Initial Commit Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * aws_iam_user uses lazy loading Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * Disassociates convert call from list_users Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * A real-world working AwsIamUsers (#71) * Add aws_iam_users Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Adding Filter table and Collect User Details to aws_iam_users.rb Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Adding Filter table and Collect User Details to aws_iam_users.rb Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Adding Filter table and Collect User Details to aws_iam_users.rb Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Get an aws_iam_users integration test to pass Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Fix RuboCop issues and tests Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Improving code based on PR feedback Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * AWS IAM Users unit tests work with new lazy loading feature Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * Fixes tests Signed-off-by: aduric <adnan.duric@d2l.com> * Users should only hold the returned user references, transfering responsibility to each user to fetch any details Signed-off-by: aduric <adnan.duric@d2l.com> * Create user details provider class Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * Using details provider factory to delegate creation of detail providers, and updates tests Signed-off-by: aduric <adnan.duric@d2l.com> * Rubocop fixes Signed-off-by: aduric <adnan.duric@d2l.com> * Rename user details provider factory to initializer, and remove unnecessary instance variables Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com>
2017-10-26 19:22:15 +00:00
@aws_user_details_provider.has_console_password?
end
def access_keys
Issue #46 Lazily load attributes in aws_iam_users (#89) * Initial Commit Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * aws_iam_user uses lazy loading Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * Disassociates convert call from list_users Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * A real-world working AwsIamUsers (#71) * Add aws_iam_users Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Adding Filter table and Collect User Details to aws_iam_users.rb Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Adding Filter table and Collect User Details to aws_iam_users.rb Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Adding Filter table and Collect User Details to aws_iam_users.rb Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Get an aws_iam_users integration test to pass Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Fix RuboCop issues and tests Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Improving code based on PR feedback Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * AWS IAM Users unit tests work with new lazy loading feature Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * Fixes tests Signed-off-by: aduric <adnan.duric@d2l.com> * Users should only hold the returned user references, transfering responsibility to each user to fetch any details Signed-off-by: aduric <adnan.duric@d2l.com> * Create user details provider class Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * Using details provider factory to delegate creation of detail providers, and updates tests Signed-off-by: aduric <adnan.duric@d2l.com> * Rubocop fixes Signed-off-by: aduric <adnan.duric@d2l.com> * Rename user details provider factory to initializer, and remove unnecessary instance variables Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com>
2017-10-26 19:22:15 +00:00
@aws_user_details_provider.access_keys.map { |access_key|
@access_key_factory.create_access_key(access_key)
}
end
def name
Issue #46 Lazily load attributes in aws_iam_users (#89) * Initial Commit Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * aws_iam_user uses lazy loading Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * Disassociates convert call from list_users Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * A real-world working AwsIamUsers (#71) * Add aws_iam_users Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Adding Filter table and Collect User Details to aws_iam_users.rb Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Adding Filter table and Collect User Details to aws_iam_users.rb Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Adding Filter table and Collect User Details to aws_iam_users.rb Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Get an aws_iam_users integration test to pass Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Fix RuboCop issues and tests Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Improving code based on PR feedback Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * AWS IAM Users unit tests work with new lazy loading feature Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * Fixes tests Signed-off-by: aduric <adnan.duric@d2l.com> * Users should only hold the returned user references, transfering responsibility to each user to fetch any details Signed-off-by: aduric <adnan.duric@d2l.com> * Create user details provider class Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * Using details provider factory to delegate creation of detail providers, and updates tests Signed-off-by: aduric <adnan.duric@d2l.com> * Rubocop fixes Signed-off-by: aduric <adnan.duric@d2l.com> * Rename user details provider factory to initializer, and remove unnecessary instance variables Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com>
2017-10-26 19:22:15 +00:00
@aws_user_details_provider.name
end
def to_s
"IAM User #{name}"
end
class AwsIamAccessKeyFactory
def create_access_key(access_key)
AwsIamAccessKey.new({ access_key: access_key })
end
end
end