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

auditd resource: test active auditd configuration against the audit daemon #2133

Merged
merged 5 commits into from
Sep 18, 2017

Conversation

jburns12
Copy link
Contributor

This is a new version of the auditd_rules resource, renamed auditd, that implements Filter Tables as a means of creating params based upon the lines that are returned upon executing the command 'auditctl -l'.

New features include the ability to filter rules based on path, match on all fields sans the key field, match on single permissions values individually, and match on file watch rules written in a syscall syntax by means of the file name or the syscall field.

Jennifer Burns added 3 commits September 8, 2017 16:15
… match new entries in auditctl

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

@jburns12 and I just chatted and she's going to remove some of the legacy stuff and ping us here when she's ready for a new review. At quick glance, this looks like a great improvement over the existing resource. Thanks, Jen!

]
end

it 'auditd_rules syscall interface' do
resource = MockLoader.new(:centos7).load_resource('auditd_rules')
_(resource.send('syscall', 'open').send('rules')).must_equal [
{:syscall=>"open", :list=>"exit", :action=>"always", :fields=>["arch=b64", "exit=-EACCES", "key=access"], :arch=>"b64", :exit=>"-EACCES", :key=>"access"}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately I had to update the test file of the auditd_rules resource since the new and old both use the same command auditctl -l and therefore the same mock command.

@jburns12
Copy link
Contributor Author

Thanks for the chat, @adamleff ! I yanked all of the legacy code and added updates to the documentation to explain that support is for audit >= 2.3.

As a reminder, the reason I had to change the auditd_rules_test file was due to the new and old resource both needing to use the same mock cmd based on auditctl -l.

@adamleff adamleff changed the title New Auditd Resource auditd resource: test active auditd configuration against the audit daemon Sep 11, 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.

@jburns12 this looks really good. Thank you! Just a few things to tidy up.

Also, many Ruby programmers will tell you that prefixing methods with get_ or set_ is not great practice. Setters will usually end with an = and getters are usually self-defining. I'd encourage you to rethink some of your method names... for example I'd rename get_syscall_rules(line) to syscall_rules_for(line). It's not a blocking issue but it's something I would recommend addressing.

Lemme know when you've made another pass and I think we're pretty close to a final review on this one. Thank you for your contribution!

end

def get_file_syscall_syntax_rules(line)
file = get_file_syscall_syntax line
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry @jburns12 if I wasn't clear. The standard is to use parens rather than remove them, so can you update these lines as such?

file = get_file_syscall_syntax(line)
action, list = get_action_list(line)
... etc ...

... and throughout the resource, please? Thank you! 🙂

end

def to_s
'Audit Daemon Rules'
Copy link
Contributor

Choose a reason for hiding this comment

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

Because of our silly CLI parser, I'd recommend we keep this to two space-separate words. Otherwise, Rules will get pushed down to the next line. It's a long-standing bug and we'll fix it eventually :)

I'd recommend auditd rules for now.

@@ -0,0 +1,236 @@
# encoding: utf-8
# copyright: 2015, Vulcano Security GmbH
Copy link
Contributor

Choose a reason for hiding this comment

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

We can remove this line - the copyright and license are covered at a project-level.


if @content =~ /^LIST_RULES:/
return skip_resource 'The version of audit is outdated. The `auditd` resource supports versions of audit >= 2.3.'
else
Copy link
Contributor

Choose a reason for hiding this comment

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

Since there's a return on line 41, you can get rid of the else on 42 and end on 45, and outdent 43 and 44.

return skip_resource 'The version of audit is outdated. The `auditd` resource supports versions of audit >= 2.3.'
else
parse_content
@legacy = nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this needed anymore?

filter.connect(self, :params)

def status(name = nil)
return @legacy.status(name) if @legacy
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be removed now, right?

@jburns12
Copy link
Contributor Author

Thanks so much for the info and feedback, @adamleff !

I just made a commit/push that addresses the issues, including the naming of "get" methods. Hopefully the name changes are in the vein of what you expressed, but if not let me know. :)

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.

Looks great to me. Nice work, @jburns12!

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.

Fantastic addition, thank you @jburns12 !!

@arlimus arlimus merged commit ec18dce into inspec:master Sep 18, 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