| 1 | #!/usr/bin/env bash |
| 2 | . $builddir/tests/test_common.sh |
| 3 | |
| 4 | set -e |
| 5 | set -o pipefail |
| 6 | |
| 7 | profile="xccdf_moc.elpmaxe.www_profile_standard" |
| 8 | result_id="xccdf_org.open-scap_testresult_xccdf_moc.elpmaxe.www_profile_standard" |
| 9 | title="Standard System Security Profile" |
| 10 | description="This profile contains rules to ensure standard security baseline of your system." |
| 11 | benchmark="xccdf_moc.elpmaxe.www_benchmark_test" |
| 12 | version="1.0" |
| 13 | xccdf_version="1.2" |
| 14 | |
| 15 | name=$(basename $0 .sh) |
| 16 | results_arf=$(mktemp -t ${name}.out.XXXXXX) |
| 17 | stdout=$(mktemp -t ${name}.out.XXXXXX) |
| 18 | stderr=$(mktemp -t ${name}.out.XXXXXX) |
| 19 | script=$(mktemp -t ${name}.sh.XXXXXX) |
| 20 | playbook=$(mktemp -t ${name}.yml.XXXXXX) |
| 21 | |
| 22 | profile_header1a="# Bash Remediation Script for $title" |
| 23 | profile_header1b="# Ansible Playbook for $title" |
| 24 | profile_header2="# $description" |
| 25 | profile_header3="# Profile ID: $profile" |
| 26 | profile_header4="# Benchmark ID: $benchmark" |
| 27 | profile_header5="# Benchmark Version: $version" |
| 28 | profile_header6="# XCCDF Version: $xccdf_version" |
| 29 | |
| 30 | result_header1a="# Bash Remediation Script generated from evaluation of $title" |
| 31 | result_header1b="# Ansible Playbook generated from evaluation of $title" |
| 32 | result_header2="# XCCDF Version: $xccdf_version" |
| 33 | result_header3a="# $ oscap xccdf generate fix --result-id $result_id --fix-type bash xccdf-results.xml" |
| 34 | result_header3b="# $ oscap xccdf generate fix --result-id $result_id --fix-type ansible xccdf-results.xml" |
| 35 | |
| 36 | |
| 37 | # Create an ARF |
| 38 | $OSCAP xccdf eval --profile $profile --results-arf $results_arf $srcdir/$name.xccdf.xml >$stdout 2>$stderr || [ $? == 2 ] |
| 39 | [ -f $stdout ]; [ -s $stdout ]; rm $stdout |
| 40 | [ -f $stderr ]; [ ! -s $stderr ]; rm $stderr |
| 41 | |
| 42 | end_time="$(grep "end-time=" $results_arf | cut -d "\"" -f8)" |
| 43 | result_header5="# Evaluation End Time: $end_time" |
| 44 | |
| 45 | # Generate a bash script from an OpenSCAP profile |
| 46 | $OSCAP xccdf generate fix --profile $profile --output $script $srcdir/$name.xccdf.xml >$stdout 2>$stderr |
| 47 | [ -f $stdout ]; [ ! -s $stdout ]; rm $stdout |
| 48 | [ -f $stderr ]; [ ! -s $stderr ]; rm $stderr |
| 49 | grep "$profile_header1a" $script |
| 50 | grep "$profile_header2" $script |
| 51 | grep "$profile_header3" $script |
| 52 | grep "$profile_header4" $script |
| 53 | grep "$profile_header5" $script |
| 54 | grep "$profile_header6" $script |
| 55 | |
| 56 | # Generate a bash script based on scan results |
| 57 | $OSCAP xccdf generate fix --result-id $result_id --fix-type bash --output $script $results_arf >$stdout 2>$stderr |
| 58 | [ -f $stdout ]; [ ! -s $stdout ]; rm $stdout |
| 59 | [ -f $stderr ]; [ ! -s $stderr ]; rm $stderr |
| 60 | grep "$result_header1a" $script |
| 61 | grep "$result_header2" $script |
| 62 | grep "$result_header3a" $script |
| 63 | grep "$result_header5" $script |
| 64 | |
| 65 | |
| 66 | # Generate an Ansible playbook from an OpenSCAP profile |
| 67 | $OSCAP xccdf generate fix --profile $profile --fix-type ansible --output $playbook $srcdir/$name.xccdf.xml >$stdout 2>$stderr |
| 68 | [ -f $stdout ]; [ ! -s $stdout ]; rm $stdout |
| 69 | [ -f $stderr ]; [ ! -s $stderr ]; rm $stderr |
| 70 | grep "$profile_header1b" $playbook |
| 71 | grep "$profile_header2" $playbook |
| 72 | grep "$profile_header3" $playbook |
| 73 | grep "$profile_header4" $playbook |
| 74 | grep "$profile_header5" $playbook |
| 75 | grep "$profile_header6" $playbook |
| 76 | |
| 77 | # Generate an Ansible playbook based on scan results stored in ARF file |
| 78 | $OSCAP xccdf generate fix --result-id $result_id --fix-type ansible --output $playbook $results_arf >$stdout 2>$stderr |
| 79 | [ -f $stdout ]; [ ! -s $stdout ]; rm $stdout |
| 80 | [ -f $stderr ]; [ ! -s $stderr ]; rm $stderr |
| 81 | grep "$result_header1b" $playbook |
| 82 | grep "$result_header2" $playbook |
| 83 | grep "$result_header3b" $playbook |
| 84 | grep "$result_header5" $playbook |
| 85 | |
| 86 | rm $results_arf |
| 87 | rm $script |
| 88 | rm $playbook |