-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resource updates #971
Draft
Amndeep7
wants to merge
16
commits into
inspec:main
Choose a base branch
from
mitre:resource_updates
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Resource updates #971
Changes from 4 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3fa020a
added the iam credential report as a resource
Amndeep7 db1b679
wip addition of the account as a resource
Amndeep7 3b9614d
implemented aws account resource
Amndeep7 f34e9ed
pass arguments properly to the get_alternate_contact function
Amndeep7 a09f972
iam_access_keys - use correct function call for list_access_keys
Amndeep7 821d360
iam_access_keys - assign correct values to user_created_date
Amndeep7 a558d8d
iam_access_keys - debugging + fixed last_used to stop using a global …
Amndeep7 8161d70
make sure to assign nil to attribute in row when it is nil
Amndeep7 64b9a70
adding new docs
aaronlippold edbf49e
added fix for presence error issue
aaronlippold a200543
Fixes and Linting
aaronlippold 5120750
fixed aws-backend to not throw errors when some account setting are n…
aaronlippold f40ab21
ran bundle exec chefstyle -A
aaronlippold 23b69d8
Merge remote-tracking branch 'upstream/main' into resource_updates
aaronlippold d0bfefa
Merge from upstream fix
aaronlippold e4b35ba
step 1: fixing autocorrect
aaronlippold File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require "aws_backend" | ||
|
||
class AwsAccount < AwsResourceBase | ||
name "aws_account" | ||
desc "Verifies contact information for an AWS Account." | ||
example " | ||
addr = { 'address_line_1' => '42 Wallaby Way', ... } | ||
describe aws_account.contact_information do | ||
it { should cmp addr } | ||
end | ||
" | ||
|
||
def initialize(opts = {}) | ||
super(opts) | ||
end | ||
|
||
def resource_id | ||
"AWS Account Contact Information" | ||
end | ||
|
||
def to_s | ||
"AWS Account Contact Information" | ||
end | ||
|
||
def contact_information | ||
@contact_information ||= catch_aws_errors do | ||
@aws.account_client.get_contact_information.contact_information.to_h.transform_keys(&:to_s) | ||
end | ||
end | ||
|
||
def billing_contact_information | ||
@billing_contact_information ||= catch_aws_errors do | ||
@aws.account_client.get_alternate_contact({alternate_contact_type: "BILLING"}).alternate_contact.to_h.transform_keys(&:to_s) | ||
end | ||
end | ||
|
||
def operations_contact_information | ||
@operations_contact_information ||= catch_aws_errors do | ||
@aws.account_client.get_alternate_contact({alternate_contact_type: "OPERATIONS"}).alternate_contact.to_h.transform_keys(&:to_s) | ||
end | ||
end | ||
|
||
def security_contact_information | ||
@security_contact_information ||= catch_aws_errors do | ||
@aws.account_client.get_alternate_contact({alternate_contact_type: "SECURITY"}).alternate_contact.to_h.transform_keys(&:to_s) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
require "csv" | ||
require "aws_backend" | ||
|
||
class AwsIamCredentialReport < AwsCollectionResourceBase | ||
name "aws_iam_credential_report" | ||
desc "Lists all users in the AWS account and the status of their credentials." | ||
|
||
example " | ||
describe aws_iam_credential_report.where(mfa_active: false) do | ||
it { should_not exist } | ||
end | ||
" | ||
|
||
attr_reader :table | ||
|
||
FilterTable.create | ||
.register_column(:user, field: :user) | ||
.register_column(:arn, field: :arn) | ||
.register_column(:user_creation_time, field: :user_creation_time) | ||
.register_column(:password_enabled, field: :password_enabled) | ||
.register_column(:password_last_used, field: :password_last_used) | ||
.register_column(:password_last_changed, field: :password_last_changed) | ||
.register_column(:password_next_rotation, field: :password_next_rotation) | ||
.register_column(:mfa_active, field: :mfa_active) | ||
.register_column(:access_key_1_active, field: :access_key_1_active) | ||
.register_column(:access_key_1_last_rotated, field: :access_key_1_last_rotated) | ||
.register_column(:access_key_1_last_used_date, field: :access_key_1_last_used_date) | ||
.register_column(:access_key_1_last_used_region, field: :access_key_1_last_used_region) | ||
.register_column(:access_key_1_last_used_service, field: :access_key_1_last_used_service) | ||
.register_column(:access_key_2_active, field: :access_key_2_active) | ||
.register_column(:access_key_2_last_rotated, field: :access_key_2_last_rotated) | ||
.register_column(:access_key_2_last_used_date, field: :access_key_2_last_used_date) | ||
.register_column(:access_key_2_last_used_region, field: :access_key_2_last_used_region) | ||
.register_column(:access_key_2_last_used_service, field: :access_key_2_last_used_service) | ||
.register_column(:cert_1_active, field: :cert_1_active) | ||
.register_column(:cert_1_last_rotated, field: :cert_1_last_rotated) | ||
.register_column(:cert_2_active, field: :cert_2_active) | ||
.register_column(:cert_2_last_rotated, field: :cert_2_last_rotated) | ||
.install_filter_methods_on_resource(self, :table) | ||
|
||
def initialize(opts = {}) | ||
super(opts) | ||
validate_parameters | ||
@table = fetch_data | ||
pp ["table", @table] | ||
end | ||
|
||
def to_s | ||
"IAM Credential Report" | ||
end | ||
|
||
private | ||
|
||
def fetch_data | ||
catch_aws_errors do | ||
@aws.iam_client.generate_credential_report | ||
begin | ||
attempts ||= 0 | ||
response = @aws.iam_client.get_credential_report | ||
rescue Aws::IAM::Errors::ReportInProgress => e | ||
if (attempts += 1) <= 5 | ||
Inspec::Log.warn "AWS IAM Credential Report still being generated - attempt #{attempts}/5." | ||
sleep 5 | ||
retry | ||
else | ||
Inspec::Log.warn "AWS IAM Credential Report was not generated quickly enough." | ||
raise e | ||
end | ||
end | ||
report = CSV.parse(response.content, headers: true, header_converters: :symbol, converters: [:date_time, -> field { field == 'true' ? true : field == 'false' ? false : field }]) | ||
report.map(&:to_h) | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inspec/train-aws#457 is merged.Please update Gemfile.