-
Notifications
You must be signed in to change notification settings - Fork 192
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
add attributes to exclude fstypes and paths from suid_check find #94
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,21 +4,44 @@ class SUIDCheck < Inspec.resource(1) | |
name 'suid_check' | ||
desc 'Use the suid_check resource to verify the current SUID/SGID against a blacklist' | ||
example " | ||
describe suid_check(blacklist) do | ||
describe suid_check(blacklist, exclude_fstypes: %w[nfs nfs4], exclude_paths: %w[/proc]) do | ||
its('diff') { should be_empty } | ||
end | ||
" | ||
|
||
def initialize(blacklist = nil) | ||
blacklist = default if blacklist.nil? | ||
def initialize(blacklist = nil, exclude_fstypes: nil, exclude_paths: nil) | ||
@blacklist = blacklist | ||
@exclude_fstypes = exclude_fstypes || default_exclude_fstypes | ||
@exclude_paths = exclude_paths || default_exclude_paths | ||
end | ||
|
||
def default_exclude_fstypes | ||
%w[nfs nfs4 cifs smp nbd ceph] | ||
end | ||
|
||
def default_exclude_paths | ||
%w[/sys /proc /var/lib/lxd/containers] | ||
end | ||
|
||
def permissions | ||
output = inspec.command('find / -perm -4000 -o -perm -2000 -type f ! -path \'/proc/*\' ! -path \'/var/lib/lxd/containers/*\' -print 2>/dev/null | grep -v \'^find:\'') | ||
exclude_opts = exclude_paths.map { |p| "-path #{p} -prune" }.join(' -o ') | ||
output = inspec.command("find / \\( #{exclude_opts} \\) -o -perm -4000 -perm -2000 -type f -print 2>/dev/null " \ | ||
"| grep -v '^find:'") | ||
output.stdout.split(/\r?\n/) | ||
end | ||
|
||
def exclude_fstype_paths | ||
mounts = inspec.command('mount') | ||
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. Should we open a ticket in inspec to expose their point parsing? https://github.com/inspec/inspec/blob/master/lib/resources/mount.rb 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. It appears they're just inspecting files to see if they are mounts and getting their options from mount if so (https://github.com/inspec/inspec/blob/master/lib/resources/file.rb#L94), rather than parsing all mounts. I don't think the two are really compatible. Individual objects vs. "walking" mounts. |
||
mounts.stdout.split("\n").map do |m| | ||
match = m.match(/ on (?<mount_path>.*) type (?<fstype>\w+) /) | ||
match['mount_path'] if !match.nil? && @exclude_fstypes.include?(match['fstype']) | ||
end.compact | ||
end | ||
|
||
def exclude_paths | ||
exclude_fstype_paths + @exclude_paths | ||
end | ||
|
||
def diff | ||
permissions & @blacklist | ||
end | ||
|
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.
By adding those, we change the default behaviour, which results in a breaking change. @arlimus @atomic111 we have two options:
What do you think?
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.
My $0.02 is that it should be the default behavior and have a major version bump because the current default of walking network filesystems is prohibitively expensive and redundant when you have a lot of nodes mounting the same share. If you're using the audit cookbook to run this profile in that scenario, some nodes could take longer than the Chef run interval to even complete. If you're using push jobs on large groups, the job will take as long as the longest node, so using the current version of this profile has increased deploy times as well. IMO, if you want to check network shares for SUID, that should be done by a single ad-hoc process somewhere.