blob: 3cce34ab2fbfaddb5db49f2523ba20e6f4e9e550 [file] [log] [blame]
Ivan Suzdala40a91c2018-09-17 11:51:59 +04001package com.mirantis.mk
2
3/**
4 * Run salt oscap.eval xccdf
5 *
6 * @param target the target where the benchmark will be evaluated
7 * @param evaltype what to evaluate (xccdf or oval)
8 * @param benchmark the benchmark which will be evaluated by openscap
9 * @param results_dir the directory where artifacts will be moved
10 * @param profile the XCCDF profile name
11 * @param xccdf_version XCCDF benchmark version (default 1.2)
12 * @param tailoring_id The id of your tailoring data (from the corresponding pillar)
13 */
14def openscapEval(master, target, evaltype, benchmark, results_dir, profile='default', xccdf_version='1.2', tailoring_id='None') {
15 def salt = new com.mirantis.mk.Salt()
16 def common = new com.mirantis.mk.Common()
17 try {
18 salt.runSaltProcessStep(master, target, 'oscap.eval', [evaltype, benchmark, results_dir="$results_dir", profile="$profile", xccdf_version="$xccdf_version", tailoring_id="$tailoring_id"])
19 } catch (Throwable e) {
20 common.errorMsg("Opescap evaluation have failed")
21 }
22}
23
24/**
25 * Upload results to the security dashboard
26 *
27 * @param url the security dashboard url
28 * @param file the file to upload
29 * @param cloud_name the cloud_name
30 * @param nodename the scanned node name
31 */
32def uploadScanResultsToDashboard(url, file, cloud_name, nodename) {
33 def common = new com.mirantis.mk.Common()
34 try {
35 withCredentials([
36 [$class : 'UsernamePasswordMultiBinding',
37 credentialsId : 'dashboard',
38 passwordVariable : 'DASHBOARD_PASSWORD',
39 usernameVariable : 'DASHBOARD_LOGIN']
40 ]) {
41 sh "bash -c \"curl -X PUT -d@${file} -u ${DASHBOARD_LOGIN}:${DASHBOARD_PASSWORD} \'${url}\'\""
42 }
43 } catch (Throwable e) {
44 common.errorMsg("Can't upload scanning results to the security dashboard")
45 }
46}
47
48/**
49 * Copy evaluation results.xml to the master node
50 *
51 * @param master the salt master
52 * @param target the salt target
53 * @param source the target source directory
54 * @param destination the destination directory on the master
55 */
56def copyResultsXml(master, target, source, destination) {
57 def salt = new com.mirantis.mk.Salt()
58 def common = new com.mirantis.mk.Common()
59 try {
60 writeFile file: destination, text: salt.GetFileContent(master, target, source)
61 } catch (Throwable e) {
62 common.errorMsg("Can't upload scanning results to the security dashboard")
63 }
64}
65
66/**
67 * Archive evaluating results
68 *
69 * @param master the salt master
70 * @param target the salt target
71 * @param source the directory with scanning results
72 * @param destitation the archive output file
73 */
74def archiveScanResults(master, target, source, destination) {
75 def common = new com.mirantis.mk.Common()
76 def salt = new com.mirantis.mk.Salt()
77 def tempArchive = '/tmp/openscap-temp.tar'
78 try {
79 salt.runSaltProcessStep(master, target, 'file.remove', tempArchive)
80 salt.runSaltProcessStep(master, target, 'archive.tar', ['cf', tempArchive, source])
81
82 writeFile file: destination, text: salt.GetFileContent(master, target, tempArchive)
83
84 salt.runSaltProcessStep(master, target, 'file.remove', source)
85 salt.runSaltProcessStep(master, target, 'file.remove', tempArchive)
86 } catch (Throwable e) {
87 common.errorMsg("Can't archive results on ${target}")
88 }
89}
90
91/**
92 * Archive openscap scan results in Artifacts
93 *
94 * @param source the artifacts dir path
95 */
96def archiveOpenscapArtifacts(source) {
97 def common = new com.mirantis.mk.Common()
98 try {
99 archiveArtifacts artifacts: "${source}"
100 } catch (Throwable e) {
101 common.errorMsg("Can't archive artifacts")
102 }
103}
104