Browse Source

Merge "Add new script for SELinux consolidation"

changes/79/809979/8
Zuul 7 months ago committed by Gerrit Code Review
parent
commit
74af58e957
  1. 5
      roles/collect_logs/defaults/main.yml
  2. 44
      roles/collect_logs/files/consolidate-avc.pl
  3. 6
      roles/collect_logs/tasks/collect.yml

5
roles/collect_logs/defaults/main.yml

@ -288,9 +288,12 @@ artcl_commands:
selinux_denials:
cmd: >
grep -i denied /var/log/audit/audit*
selinux_consolidated_avc:
cmd: >
/usr/bin/perl /usr/local/bin/consolidate-avc.pl /var/log/extra/selinux_denials.txt
selinux_denials_detail:
cmd: >
sealert -a /var/log/extra/selinux_denials.txt
sealert -S -a /var/log/extra/selinux_consolidated_avc.txt
seqfaults:
cmd: >
grep -v ansible-command /var/log/messages | grep segfault

44
roles/collect_logs/files/consolidate-avc.pl

@ -0,0 +1,44 @@
# Copyright 2021 Red Hat Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# Usage:
# will use /var/log/audit/audit.log as source
# ./consolidate-avc.pl
# Will use another input
# ./consolidate-avc.pl /var/log/extras/denials.txt
use strict;
use warnings;
use List::Util qw'first';
my $logfile = shift // '/var/log/audit/audit.log';
open(AUDIT_LOG, $logfile) or die("Could not open file '${logfile}'.");
my @denials = ();
while( my $line = <AUDIT_LOG>) {
my @matched = $line =~ m{type=AVC.* denied \{([\w\s]+)\}.* scontext=([\w:]+)(:[,c0-9]+)? tcontext=([\w:,]+) tclass=([\w]+) permissive=[01]};
if (@matched) {
my $action = $matched[0];
my $scontext = $matched[1];
my $tcontext = $matched[3];
my $tclass = $matched[4];
my $matcher = "${action}_${scontext}_${tcontext}_${tclass}";
if (!first {$matcher eq $_} @denials) {
push(@denials, $matcher);
print $line;
}
}
}
close(AUDIT_LOG);

6
roles/collect_logs/tasks/collect.yml

@ -36,6 +36,12 @@
- setroubleshoot
state: present
- name: install custom consolidation script
ansible.builtin.copy:
dest: /usr/local/bin/consolidate-avc.pl
src: consolidate-avc.pl
mode: 0555
- name: Run artcl_commands
# noqa 305
# noqa 102 :: No Jinja2 in when

Loading…
Cancel
Save