This repository has been archived by the owner on Jun 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
Add rule_group defined type #59
Open
alexjfisher
wants to merge
1
commit into
kemra102:master
Choose a base branch
from
alexjfisher:rule_group
base: master
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.
+144
−0
Open
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# @summary Create a group of related rules with a comment header | ||
# | ||
# @example Creating 'watch' rules | ||
# auditd::rule_group { 'Tools to change group identifiers': | ||
# rules => [ | ||
# { | ||
# 'files' => ['/usr/sbin/groupadd','/usr/sbin/groupmod','/usr/sbin/addgroup'], | ||
# 'permissions' => ['x'], | ||
# 'keys' => ['group_modification'], | ||
# } | ||
# { | ||
# 'files' => ['/usr/sbin/useradd','/usr/sbin/usermod','/usr/sbin/adduser'], | ||
# 'permissions' => ['x'], | ||
# 'keys' => ['user_modification'], | ||
# } | ||
# ], | ||
# } | ||
# | ||
# @example Freeform syscall rules with default_keys set | ||
# auditd::rule_group { 'Kernel module loading and unloading': | ||
# rules => [ | ||
# '-a always,exit -F perm=x -F auid!=-1 -F path=/sbin/insmod', | ||
# '-a always,exit -F perm=x -F auid!=-1 -F path=/sbin/modprobe', | ||
# '-a always,exit -F perm=x -F auid!=-1 -F path=/sbin/rmmod', | ||
# ], | ||
# default_keys => ['modules'], | ||
# } | ||
# | ||
# @param rules An array of rules to include. | ||
# @param default_keys An array of keys you want added to every rule in this group | ||
# @param comment The comment to use as a header for this group of rules. Defaults to the `rule_group` title. | ||
# @param order Where in the audit rules file to place this group. | ||
define auditd::rule_group( | ||
Array[Variant[String[1],Auditd::WatchRule],1] $rules, | ||
Array[String[1]] $default_keys = [], | ||
String[1] $comment = $name, | ||
$order = 10, | ||
) | ||
{ | ||
concat::fragment{ "auditd_rule_group_fragment_${name}": | ||
target => $auditd::rules_file, | ||
order => $order, | ||
content => epp('auditd/rule_group.epp',{'comment' => $comment, 'rules' => $rules, 'default_keys' => $default_keys, }), | ||
} | ||
} |
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,68 @@ | ||
require 'spec_helper' | ||
|
||
describe 'auditd::rule_group' do | ||
let (:facts) {{ | ||
:osfamily => 'RedHat', | ||
:operatingsystem => 'RedHat', | ||
:operatingsystemrelease => '7', | ||
:concat_basedir => '/var/lib/puppet/concat', | ||
}} | ||
let :pre_condition do | ||
'class{"auditd": } ' | ||
end | ||
describe 'Reference example 1' do | ||
let(:title) { 'Tools to change group identifiers' } | ||
let(:params) {{ | ||
rules: [ | ||
{ | ||
'files' => ['/usr/sbin/groupadd','/usr/sbin/groupmod','/usr/sbin/addgroup'], | ||
'permissions' => ['x'], | ||
'keys' => ['group_modification'], | ||
}, | ||
{ | ||
'files' => ['/usr/sbin/useradd','/usr/sbin/usermod','/usr/sbin/adduser'], | ||
'permissions' => ['x'], | ||
'keys' => ['user_modification'], | ||
} | ||
], | ||
}} | ||
expected_content=<<-HEREDOC | ||
# Tools to change group identifiers | ||
-w /usr/sbin/groupadd -p x -k group_modification | ||
-w /usr/sbin/groupmod -p x -k group_modification | ||
-w /usr/sbin/addgroup -p x -k group_modification | ||
-w /usr/sbin/useradd -p x -k user_modification | ||
-w /usr/sbin/usermod -p x -k user_modification | ||
-w /usr/sbin/adduser -p x -k user_modification | ||
|
||
HEREDOC | ||
it { is_expected.to contain_concat_fragment('auditd_rule_group_fragment_Tools to change group identifiers'). | ||
with_target('/etc/audit/rules.d/puppet.rules'). | ||
with_content(expected_content). | ||
with_order(10) | ||
} | ||
end | ||
describe 'Reference example 2' do | ||
let(:title) { 'Kernel module loading and unloading' } | ||
let(:params) {{ | ||
rules: [ | ||
'-a always,exit -F perm=x -F auid!=-1 -F path=/sbin/insmod', | ||
'-a always,exit -F perm=x -F auid!=-1 -F path=/sbin/modprobe', | ||
'-a always,exit -F perm=x -F auid!=-1 -F path=/sbin/rmmod', | ||
], | ||
default_keys: ['modules'], | ||
}} | ||
expected_content=<<-HEREDOC | ||
# Kernel module loading and unloading | ||
-a always,exit -F perm=x -F auid!=-1 -F path=/sbin/insmod -k modules | ||
-a always,exit -F perm=x -F auid!=-1 -F path=/sbin/modprobe -k modules | ||
-a always,exit -F perm=x -F auid!=-1 -F path=/sbin/rmmod -k modules | ||
|
||
HEREDOC | ||
it { is_expected.to contain_concat_fragment('auditd_rule_group_fragment_Kernel module loading and unloading'). | ||
with_target('/etc/audit/rules.d/puppet.rules'). | ||
with_content(expected_content). | ||
with_order(10) | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<%- | | ||
String $comment, | ||
Array[Variant[String[1],Auditd::WatchRule],1] $rules, | ||
Array[String] $default_keys = [], | ||
| -%> | ||
# <%= $comment %> | ||
<% $rules.each |$rule| {-%> | ||
<%- | ||
case $rule { | ||
String: { | ||
$keys = $default_keys.map |$key| {" -k ${key}"}.join('') | ||
$rule_content = "${rule}${keys}" | ||
} | ||
Auditd::WatchRule: { $rule_content = epp('auditd/watch_rule.epp', {rule => $rule, default_keys => $default_keys } ).chomp } | ||
} | ||
-%> | ||
<%= $rule_content %> | ||
<% } -%> | ||
|
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,7 @@ | ||
<%- | | ||
Auditd::WatchRule $rule, | ||
Array[String] $default_keys, | ||
| -%> | ||
<% $rule['files'].each |$file| {-%> | ||
-w <%= $file %> <% if 'permissions' in $rule {-%> -p <%= $rule['permissions'].join('') %><% } -%><%= (pick($rule['keys'], []) + $default_keys).map |$key| {" -k ${key}"}.join('') %> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. given the |
||
<% } -%> |
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,5 @@ | ||
type Auditd::WatchRule = Struct[{ | ||
files => Array[Stdlib::Unixpath,1], | ||
Optional[permissions] => Array[Enum['r','w','x','a'],1], | ||
Optional[keys] => Array[String[1]], | ||
}] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is just wild! |
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.
concat_basedir is dead. IIRC since concat 2.0.