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

Update auditd_conf resource #16

Open
jburns12 opened this issue Aug 7, 2017 · 9 comments
Open

Update auditd_conf resource #16

jburns12 opened this issue Aug 7, 2017 · 9 comments
Assignees

Comments

@jburns12
Copy link
Owner

jburns12 commented Aug 7, 2017

This resource needs to be updated to match on specific flags per audit line.

@jburns12 jburns12 self-assigned this Aug 7, 2017
@jburns12
Copy link
Owner Author

jburns12 commented Aug 15, 2017

Updates to resource can be found here:
https://github.com/aaronlippold/inspec/tree/al/auditd_rules_updates

I did my best to update the resource to add functionality without taking anything away so that the resource can still be used in the same way by those that have code that previously used this resource.

Examples of usage of updated resource as follows:

For syscall audit rule

sys_call = "chown"

if os.arch == 'x86_64'
  describe auditd_rules.syscall("#{sys_call}") do
    its('action') { should eq ['always'] }
    its('list') { should eq ['exit']}
    its('fields_no_keys.flatten') { should match_array CHOWN_AUDIT_FIELDS_64 }
  end
else
  describe auditd_rules.syscall("#{sys_call}") do
    its('action') { should eq ['always'] }
    its('list') { should eq ['exit'] }
    its('fields_no_keys.flatten') { should match_array CHOWN_AUDIT_FIELDS_32 }
  end
end

For setsebool command:

  describe auditd_rules.file('/usr/sbin/setsebool') do
    its('action') { should eq ['always'] }
    its('list') { should eq ['exit'] }
    its('fields_no_keys.flatten') { should match_array SETSEBOOL_AUDIT_FIELDS }
  end

I can make a pull request for this resource and see how they feel about it if this style works for you @aaronlippold

@jburns12
Copy link
Owner Author

jburns12 commented Aug 16, 2017

Update: I also found that we can roll back a couple of changes I made and use this instead for commands like setsebool:

describe auditd_rules2.syscall('all').path('/usr/sbin/setsebool') do
  its('action') { should eq ['always'] }
  its('list') { should eq ['exit'] }
  its('fields_no_keys.flatten') { should match_array SETSEBOOL_AUDIT_FIELDS }
end

This might actually be preferable since it means less changes to the resource and better conveys that all sys calls to that particular command will be audited.

@aaronlippold
Copy link
Collaborator

describe auditd_rules.file('/usr/sbin/setsebool') do
    its('action') { should eq ['always'] }
    its('list') { should eq ['exit'] }
    its('fields') { should cmp  'a' }
    its('fields') { should cmp  'b' }
    its('key') { should cmp  'mykey' }
  end

@jburns12
Copy link
Owner Author

Adjusted to do active and passive testing. For setsebool command rule:

-a always, exit -F path=/usr/sbin/setsebool -F perm=x -F auid>=1000 -F auid!=4294967295 -F key=privileged

The inspec statements would be (active pulling from auditctl command and then passive from audit.rules file):

describe auditd_rules.file('/usr/sbin/setsebool') do
  its('action') { should eq ['always'] }
  its('list') { should eq ['exit'] }
  its('fields_nokey.flatten') { should match_array SETSEBOOL_AUDIT_FIELDS }
  its('key') { should cmp 'privileged' }
end

describe auditd_rules_conf.file('/usr/sbin/setsebool') do
  its('action') { should eq ['always'] }
  its('list') { should eq ['exit'] }
  its('fields_nokey.flatten') { should match_array SETSEBOOL_AUDIT_FIELDS_CONF }
  its('key') { should cmp 'privileged' }
end

@jburns12
Copy link
Owner Author

jburns12 commented Aug 16, 2017

And for a sys call rule:

-a always,exit -F arch=b32 -S chown -F auid>=1000 -F auid!=4294967295 -k perm_mod

The inspec statements would be:

if os.arch == 'x86_64'
    describe auditd_rules.syscall("#{sys_call}") do
      its('action') { should eq ['always'] }
      its('list') { should eq ['exit']}
      its('fields_nokey.flatten') { should match_array CHOWN_AUDIT_FIELDS_64 }
      its('key) { should cmp 'perm_mod' }
    end
    describe auditd_rules_conf.syscall("#{sys_call}") do
      its('action') { should eq ['always'] }
      its('list') { should eq ['exit']}
      its('fields_nokey.flatten') { should match_array CHOWN_AUDIT_FIELDS_64_CONF }
      its('key) { should cmp 'perm_mod' }
    end
  else
    describe auditd_rules.syscall("#{sys_call}") do
      its('action') { should eq ['always'] }
      its('list') { should eq ['exit']}
      its('fields_nokey.flatten') { should match_array CHOWN_AUDIT_FIELDS_32 }
      its('key) { should cmp 'perm_mod' }
    end
    describe auditd_rules_conf.syscall("#{sys_call}") do
      its('action') { should eq ['always'] }
      its('list') { should eq ['exit']}
      its('fields_nokey.flatten') { should match_array CHOWN_AUDIT_FIELDS_32_CONF }
      its('key) { should cmp 'perm_mod' }
    end
  end

It seems lengthy, but it's because of the if/else depending on the architecture.

@aaronlippold
Copy link
Collaborator

We could always just set the CHOWN_AUDIT_FIELDS_32_CONF and CHOWN_AUDIT_FIELDS_64 on the outside:

chown_audit_fields = (inspec.os.arch == 'x86_64') ? CHOWN_AUDIT_FIELDS_64 : CHOWN_AUDIT_FIELDS_32
chow_audit_fields_conf =  (inspec.os.arch == 'x86_64') ? CHOWN_AUDIT_FIELDS_64 : CHOWN_AUDIT_FIELDS_32

describe auditd_rules.syscall("#{sys_call}") do
      its('action') { should eq ['always'] }
      its('list') { should eq ['exit']}
      its('fields_nokey.flatten') { should match_array chown_audit_fields }
      its('key) { should cmp 'perm_mod' }
    end
    describe auditd_rules_conf.syscall("#{sys_call}") do
      its('action') { should eq ['always'] }
      its('list') { should eq ['exit']}
      its('fields_nokey.flatten') { should match_array chown_audit_fields_conf }
      its('key) { should cmp 'perm_mod' }
    end

@jburns12
Copy link
Owner Author

Sure that makes sense. I'll switch to that format.

@aaronlippold
Copy link
Collaborator

assuming this returns a bool of true or false : (inspec.os.arch == 'x86_64')

It may need to be: (inspec.os.arch == 'x86_64').to_bol

etc.

@jburns12
Copy link
Owner Author

jburns12 commented Aug 17, 2017

That worked great...

sys_call = "chown"

chown_audit_fields = (inspec.os.arch == 'x86_64') ? CHOWN_AUDIT_FIELDS_64 : CHOWN_AUDIT_FIELDS_32
chown_audit_fields_conf = (inspec.os.arch == 'x86_64') ? CHOWN_AUDIT_FIELDS_64_CONF : CHOWN_AUDIT_FIELDS_32_CONF

describe auditd_rules2.syscall("#{sys_call}") do
  its('action') { should eq ['always'] }
  its('list') { should eq ['exit']}
  its('fields_nokey.flatten') { should match_array chown_audit_fields }
  its('key) { should cmp 'perm_mod' }
end
describe auditd_rules2.syscall("#{sys_call}") do
  its('action') { should eq ['always'] }
  its('list') { should eq ['exit']}
  its('fields_nokey.flatten') { should match_array chown_audit_fields_conf }
  its('key) { should cmp 'perm_mod' }
end

If this all seems reasonable at this point then I can do a PR before next Monday's meeting with the Inspec folk.

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

No branches or pull requests

2 participants