Skip to content
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

aide_conf resource: test configuration of the AIDE file integrity tool #2063

Merged
merged 6 commits into from
Aug 25, 2017

Conversation

jburns12
Copy link
Contributor

No description provided.

Jennifer Burns added 2 commits August 14, 2017 12:29
Signed-off-by: Jennifer Burns <[email protected]>
@adamleff adamleff changed the title New Resource - aide_conf aide_conf resource: test configuration of the AIDE file integrity tool Aug 15, 2017
Copy link
Contributor

@adamleff adamleff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jburns12 - thanks for the PR! I've left you some feedback.


An `aide_conf` resource block can be used to determine if the selection lines contain one (or more) directories whose files should be added to the aide database:

describe aide_conf('path')do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing space between ) and do

Use the where clause to match a selection_line to one or more rules found in the aide.conf file:

describe aide_conf.where { selection_line == '/bin' } do
its('rules.flatten') { should include 'r' }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any case where the rules shouldn't be flattened? Should the resource always flatten the rules value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is the case when you know the entire set of rules you want to match upon and the order of those rules. Hopefully lines 29-32 and 79-81 clear that up.

### Test whether selection line for /bin contains a particular rule

describe aide_conf.where { selection_line == '/bin' } do
its('rules.flatten') { should include 'r' }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question re: flatten as above. 🙂

desc 'Use the aide_conf InSpec audit resource to test the rules established for
the file integrity tool AIDE. Controlled by the aide.conf file typically at /etc/aide.conf.'
example "
describe aide_conf do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please indent lines 14-24 so it's clear it's part of the example method?


def all_have_rule(rule)
# Case when file didn't exist or perms didn't allow an open
if @content.instance_of?(String)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Ruby, testing an object for a given Class is generally seen as a stop-gap since a user/program could supply an object that looks/acts like a String, for example. It's generally better to see if it responds to a method with respond_to?

However, in this case, I think you just care if @content is nil or not, right? I'd probably just change 41-43 to be:

return false if @content.nil?

or...

return false unless defined?(@content)

def parse_line(line)
line_and_rules = {}
# Case when line is a rule line
if line.include? ' = '
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be consistent with our argument style and wrap it in parentheses:

if line.include?(' = ')

# Case when line is a rule line
if line.include? ' = '
parse_rule_line(line)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should 102-104 be an elsif? Is it possible for a line to be a "rule" line and a "selection" line at the same time?

@rules[rule_name] = rules_list.flatten
end

def normalize_dir(dir)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method appears to only be used in one place and it does one small thing. Should we perhaps just add this logic to #parse_selection_line directly?

it 'Verify aide_conf finds selection_line dirs' do
_(resource.selection_lines).must_include '/bin'
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's enough logic happening in some of the private methods (parse_rule_line, parse_selection_line, and check_multi_rule) that I'd like to see some unit test coverage for those.

if @rules.key?(rules_list[i])
rules_list[i] = @rules[rules_list[i]]
end
check_multi_rule(rules_list, i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge fan of passing an object to a method for it to be modified within that method. In this case, check_multi_rule actually modifies a value for a key in rules_list

Can we modify this to look like this:

rules_list[i] = handle_multi_rule(rules_list, i)

... and then handle_multi_rule returns whatever should be be in that hash value, which, in some cases, may simply be what's already there?

Signed-off-by: Jennifer Burns <[email protected]>
@jburns12 jburns12 requested a review from a team as a code owner August 21, 2017 19:11
Copy link
Contributor

@adamleff adamleff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks, @jburns12!

@adamleff adamleff requested a review from a team August 25, 2017 13:39
Copy link
Contributor

@arlimus arlimus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet work @jburns12 Thank you!! :D

Kudos Adam for the review as well

@arlimus arlimus merged commit 2cef15a into inspec:master Aug 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants