abide_dev_utils 0.11.0 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +18 -31
- data/lib/abide_dev_utils/cem/benchmark.rb +335 -136
- data/lib/abide_dev_utils/cem/generate/coverage_report.rb +380 -0
- data/lib/abide_dev_utils/cem/generate/reference.rb +238 -35
- data/lib/abide_dev_utils/cem/generate.rb +5 -4
- data/lib/abide_dev_utils/cem/hiera_data/mapping_data/map_data.rb +110 -0
- data/lib/abide_dev_utils/cem/hiera_data/mapping_data/mixins.rb +46 -0
- data/lib/abide_dev_utils/cem/hiera_data/mapping_data.rb +146 -0
- data/lib/abide_dev_utils/cem/hiera_data/resource_data/control.rb +127 -0
- data/lib/abide_dev_utils/cem/hiera_data/resource_data/parameters.rb +90 -0
- data/lib/abide_dev_utils/cem/hiera_data/resource_data/resource.rb +102 -0
- data/lib/abide_dev_utils/cem/hiera_data/resource_data.rb +310 -0
- data/lib/abide_dev_utils/cem/hiera_data.rb +7 -0
- data/lib/abide_dev_utils/cem/mapping/mapper.rb +161 -34
- data/lib/abide_dev_utils/cem/validate/resource_data.rb +33 -0
- data/lib/abide_dev_utils/cem/validate.rb +10 -0
- data/lib/abide_dev_utils/cem.rb +0 -1
- data/lib/abide_dev_utils/cli/cem.rb +20 -2
- data/lib/abide_dev_utils/dot_number_comparable.rb +75 -0
- data/lib/abide_dev_utils/errors/cem.rb +10 -0
- data/lib/abide_dev_utils/ppt/class_utils.rb +1 -1
- data/lib/abide_dev_utils/ppt/code_gen/data_types.rb +64 -0
- data/lib/abide_dev_utils/ppt/code_gen/generate.rb +15 -0
- data/lib/abide_dev_utils/ppt/code_gen/resource.rb +59 -0
- data/lib/abide_dev_utils/ppt/code_gen/resource_types/base.rb +93 -0
- data/lib/abide_dev_utils/ppt/code_gen/resource_types/class.rb +17 -0
- data/lib/abide_dev_utils/ppt/code_gen/resource_types/manifest.rb +16 -0
- data/lib/abide_dev_utils/ppt/code_gen/resource_types/parameter.rb +16 -0
- data/lib/abide_dev_utils/ppt/code_gen/resource_types/strings.rb +13 -0
- data/lib/abide_dev_utils/ppt/code_gen/resource_types.rb +6 -0
- data/lib/abide_dev_utils/ppt/code_gen.rb +15 -0
- data/lib/abide_dev_utils/ppt/code_introspection.rb +102 -0
- data/lib/abide_dev_utils/ppt/hiera.rb +4 -1
- data/lib/abide_dev_utils/ppt/puppet_module.rb +2 -1
- data/lib/abide_dev_utils/ppt.rb +3 -0
- data/lib/abide_dev_utils/version.rb +1 -1
- data/lib/abide_dev_utils/xccdf/parser/helpers.rb +146 -0
- data/lib/abide_dev_utils/xccdf/parser/objects.rb +87 -144
- data/lib/abide_dev_utils/xccdf/parser.rb +5 -0
- data/lib/abide_dev_utils/xccdf/utils.rb +89 -0
- data/lib/abide_dev_utils/xccdf.rb +193 -63
- metadata +27 -3
- data/lib/abide_dev_utils/cem/coverage_report.rb +0 -348
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'abide_dev_utils/validate'
|
4
|
+
|
5
|
+
module AbideDevUtils
|
6
|
+
module XCCDF
|
7
|
+
module Utils
|
8
|
+
# Class for working with directories that contain XCCDF files
|
9
|
+
class FileDir
|
10
|
+
CIS_FILE_NAME_PARTS_PATTERN = /^CIS_(?<subject>[A-Za-z0-9._()-]+)_Benchmark_v(?<version>[0-9.]+)-xccdf$/.freeze
|
11
|
+
def initialize(path)
|
12
|
+
@path = File.expand_path(path)
|
13
|
+
AbideDevUtils::Validate.directory(@path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def files
|
17
|
+
@files ||= Dir.glob(File.join(@path, '*-xccdf.xml')).map { |f| FileNameData.new(f) }
|
18
|
+
end
|
19
|
+
|
20
|
+
def fuzzy_find(label, value)
|
21
|
+
files.find { |f| f.fuzzy_match?(label, value) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def fuzzy_select(label, value)
|
25
|
+
files.select { |f| f.fuzzy_match?(label, value) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def fuzzy_reject(label, value)
|
29
|
+
files.reject { |f| f.fuzzy_match?(label, value) }
|
30
|
+
end
|
31
|
+
|
32
|
+
def label?(label)
|
33
|
+
files.select { |f| f.has?(label) }
|
34
|
+
end
|
35
|
+
|
36
|
+
def no_label?(label)
|
37
|
+
files.reject { |f| f.has?(label) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Parses XCCDF file names into labeled parts
|
42
|
+
class FileNameData
|
43
|
+
CIS_PATTERN = /^CIS_(?<subject>[A-Za-z0-9._()-]+?)(?<stig>_STIG)?_Benchmark_v(?<version>[0-9.]+)-xccdf$/.freeze
|
44
|
+
|
45
|
+
attr_reader :path, :name, :labeled_parts
|
46
|
+
|
47
|
+
def initialize(path)
|
48
|
+
@path = path
|
49
|
+
@name = File.basename(path, '.xml')
|
50
|
+
@labeled_parts = File.basename(name, '.xml').match(CIS_PATTERN)&.named_captures
|
51
|
+
end
|
52
|
+
|
53
|
+
def subject
|
54
|
+
@subject ||= labeled_parts&.fetch('subject', nil)
|
55
|
+
end
|
56
|
+
|
57
|
+
def stig
|
58
|
+
@stig ||= labeled_parts&.fetch('subject', nil)
|
59
|
+
end
|
60
|
+
|
61
|
+
def version
|
62
|
+
@version ||= labeled_parts&.fetch('version', nil)
|
63
|
+
end
|
64
|
+
|
65
|
+
def has?(label)
|
66
|
+
val = send(label.to_sym)
|
67
|
+
!val.nil? && !val.empty?
|
68
|
+
end
|
69
|
+
|
70
|
+
def fuzzy_match?(label, value)
|
71
|
+
return false unless has?(label)
|
72
|
+
|
73
|
+
this_val = normalize_char_array(send(label.to_sym).chars)
|
74
|
+
other_val = normalize_char_array(value.chars)
|
75
|
+
other_val.each_with_index do |c, idx|
|
76
|
+
return false unless this_val[idx] == c
|
77
|
+
end
|
78
|
+
true
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def normalize_char_array(char_array)
|
84
|
+
char_array.grep_v(/[^A-Za-z0-9]/).map(&:downcase)[3..]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -16,6 +16,8 @@ module AbideDevUtils
|
|
16
16
|
case type.downcase
|
17
17
|
when 'cis'
|
18
18
|
Benchmark.new(xccdf_file).gen_map(**opts)
|
19
|
+
when 'stig'
|
20
|
+
Benchmark.new(xccdf_file).gen_map(**opts)
|
19
21
|
else
|
20
22
|
raise AbideDevUtils::Errors::UnsupportedXCCDFError, "XCCDF type #{type} is unsupported!"
|
21
23
|
end
|
@@ -51,25 +53,31 @@ module AbideDevUtils
|
|
51
53
|
module Common
|
52
54
|
XPATHS = {
|
53
55
|
benchmark: {
|
54
|
-
all: '
|
55
|
-
title: '
|
56
|
-
version: '
|
56
|
+
all: 'Benchmark',
|
57
|
+
title: 'Benchmark/title',
|
58
|
+
version: 'Benchmark/version'
|
57
59
|
},
|
58
60
|
cis: {
|
59
61
|
profiles: {
|
60
|
-
all: '
|
61
|
-
relative_title: './
|
62
|
-
relative_select: './
|
62
|
+
all: 'Benchmark/Profile',
|
63
|
+
relative_title: './title',
|
64
|
+
relative_select: './select'
|
63
65
|
}
|
64
66
|
}
|
65
67
|
}.freeze
|
66
68
|
CONTROL_PREFIX = /^[\d.]+_/.freeze
|
67
69
|
UNDERSCORED = /(\s|\(|\)|-|\.)/.freeze
|
70
|
+
CIS_TITLE_MARKER = 'CIS'
|
68
71
|
CIS_NEXT_GEN_WINDOWS = /[Nn]ext_[Gg]eneration_[Ww]indows_[Ss]ecurity/.freeze
|
69
72
|
CIS_CONTROL_NUMBER = /([0-9.]+[0-9]+)/.freeze
|
70
73
|
CIS_LEVEL_CODE = /(?:_|^)([Ll]evel_[0-9]|[Ll]1|[Ll]2|[NnBb][GgLl]|#{CIS_NEXT_GEN_WINDOWS})/.freeze
|
71
74
|
CIS_CONTROL_PARTS = /#{CIS_CONTROL_NUMBER}#{CIS_LEVEL_CODE}?_+([A-Za-z].*)/.freeze
|
72
75
|
CIS_PROFILE_PARTS = /#{CIS_LEVEL_CODE}[_-]+([A-Za-z].*)/.freeze
|
76
|
+
STIG_TITLE_MARKER = 'Security Technical Implementation Guide'
|
77
|
+
STIG_CONTROL_PARTS = /(V-[0-9]+)/.freeze
|
78
|
+
STIG_PROFILE_PARTS = /(MAC-\d+)_([A-Za-z].+)/.freeze
|
79
|
+
PROFILE_PARTS = /#{CIS_PROFILE_PARTS}|#{STIG_PROFILE_PARTS}/.freeze
|
80
|
+
CONTROL_PARTS = /#{CIS_CONTROL_PARTS}|#{STIG_CONTROL_PARTS}/.freeze
|
73
81
|
|
74
82
|
def xpath(path)
|
75
83
|
@xml.xpath(path)
|
@@ -119,19 +127,40 @@ module AbideDevUtils
|
|
119
127
|
end
|
120
128
|
|
121
129
|
def profile_parts(profile)
|
122
|
-
parts = control_profile_text(profile).match(
|
130
|
+
parts = control_profile_text(profile).match(PROFILE_PARTS)
|
123
131
|
raise AbideDevUtils::Errors::ProfilePartsError, profile if parts.nil?
|
124
132
|
|
125
|
-
parts[1]
|
126
|
-
|
133
|
+
if parts[1]
|
134
|
+
# CIS profile
|
135
|
+
parts[1].gsub!(/[Ll]evel_/, 'L')
|
136
|
+
parts[1..2]
|
137
|
+
elsif parts[3]
|
138
|
+
# STIG profile
|
139
|
+
parts[3..4]
|
140
|
+
else
|
141
|
+
raise AbideDevUtils::Errors::ProfilePartsError, profile
|
142
|
+
end
|
127
143
|
end
|
128
144
|
|
129
|
-
def control_parts(control
|
130
|
-
mdata = control_profile_text(control).match(
|
145
|
+
def control_parts(control)
|
146
|
+
mdata = control_profile_text(control).match(CONTROL_PARTS)
|
131
147
|
raise AbideDevUtils::Errors::ControlPartsError, control if mdata.nil?
|
132
148
|
|
133
|
-
mdata[
|
134
|
-
|
149
|
+
if mdata[1]
|
150
|
+
# CIS control
|
151
|
+
mdata[1..3]
|
152
|
+
elsif mdata[4]
|
153
|
+
# STIG control
|
154
|
+
vuln_id = mdata[4]
|
155
|
+
group = @benchmark.xpath("Group[@id='#{vuln_id}']")
|
156
|
+
if group.xpath('Rule').length != 1
|
157
|
+
raise AbideDevUtils::Errors::ControlPartsError, control
|
158
|
+
end
|
159
|
+
rule_id = group.xpath('Rule/@id').first.value
|
160
|
+
return [vuln_id, rule_id]
|
161
|
+
else
|
162
|
+
raise AbideDevUtils::Errors::ControlPartsError, control
|
163
|
+
end
|
135
164
|
end
|
136
165
|
|
137
166
|
def control_profile_text(item)
|
@@ -148,14 +177,6 @@ module AbideDevUtils
|
|
148
177
|
end
|
149
178
|
end
|
150
179
|
|
151
|
-
def sorted_control_classes(raw_select_list, sort_key: :number)
|
152
|
-
raw_select_list.map { |x| Control.new(x) }.sort_by(&sort_key)
|
153
|
-
end
|
154
|
-
|
155
|
-
def sorted_profile_classes(raw_profile_list, sort_key: :title)
|
156
|
-
raw_profile_list.map { |x| Profile.new(x) }.sort_by(&sort_key)
|
157
|
-
end
|
158
|
-
|
159
180
|
def ==(other)
|
160
181
|
diff_properties.map { |x| send(x) } == other.diff_properties.map { |x| other.send(x) }
|
161
182
|
end
|
@@ -169,14 +190,17 @@ module AbideDevUtils
|
|
169
190
|
class Benchmark
|
170
191
|
include AbideDevUtils::XCCDF::Common
|
171
192
|
|
172
|
-
|
193
|
+
CIS_MAP_INDICES = %w[title hiera_title hiera_title_num number].freeze
|
194
|
+
STIG_MAP_INDICES = %w[vulnid ruleid].freeze
|
173
195
|
|
174
|
-
attr_reader :xml, :title, :version, :diff_properties
|
196
|
+
attr_reader :xml, :title, :version, :diff_properties, :benchmark
|
175
197
|
|
176
198
|
def initialize(path)
|
177
199
|
@xml = parse(path)
|
178
|
-
@
|
179
|
-
@
|
200
|
+
@xml.remove_namespaces!
|
201
|
+
@benchmark = xpath('Benchmark')
|
202
|
+
@title = xpath('Benchmark/title').text
|
203
|
+
@version = xpath('Benchmark/version').text
|
180
204
|
@diff_properties = %i[title version profiles]
|
181
205
|
end
|
182
206
|
|
@@ -185,7 +209,7 @@ module AbideDevUtils
|
|
185
209
|
end
|
186
210
|
|
187
211
|
def profiles
|
188
|
-
@profiles ||= Profiles.new(xpath('
|
212
|
+
@profiles ||= Profiles.new(xpath('Benchmark/Profile'), @benchmark)
|
189
213
|
end
|
190
214
|
|
191
215
|
def profile_levels
|
@@ -197,7 +221,7 @@ module AbideDevUtils
|
|
197
221
|
end
|
198
222
|
|
199
223
|
def controls
|
200
|
-
@controls ||= Controls.new(xpath('//
|
224
|
+
@controls ||= Controls.new(xpath('//select'))
|
201
225
|
end
|
202
226
|
|
203
227
|
def controls_by_profile_level(level_code)
|
@@ -209,15 +233,22 @@ module AbideDevUtils
|
|
209
233
|
end
|
210
234
|
|
211
235
|
def gen_map(dir: nil, type: 'cis', parent_key_prefix: '', version_output_dir: false, **_)
|
212
|
-
|
236
|
+
case type
|
237
|
+
when 'cis'
|
238
|
+
os, ver = facter_platform
|
239
|
+
indicies = CIS_MAP_INDICES
|
240
|
+
when 'stig'
|
241
|
+
os, ver = facter_benchmark
|
242
|
+
indicies = STIG_MAP_INDICES
|
243
|
+
end
|
213
244
|
output_path = [type, os, ver]
|
214
245
|
output_path.unshift(File.expand_path(dir)) if dir
|
215
246
|
output_path << version if version_output_dir
|
216
247
|
mapping_dir = File.expand_path(File.join(output_path))
|
217
248
|
parent_key_prefix = '' if parent_key_prefix.nil?
|
218
|
-
|
249
|
+
indicies.each_with_object({}) do |idx, h|
|
219
250
|
map_file_path = "#{mapping_dir}/#{idx}.yaml"
|
220
|
-
h[map_file_path] = map_indexed(index: idx, framework: type, key_prefix: parent_key_prefix)
|
251
|
+
h[map_file_path] = map_indexed(indicies: indicies, index: idx, framework: type, key_prefix: parent_key_prefix)
|
221
252
|
end
|
222
253
|
end
|
223
254
|
|
@@ -237,10 +268,10 @@ module AbideDevUtils
|
|
237
268
|
}
|
238
269
|
end
|
239
270
|
|
240
|
-
def map_indexed(index: 'title', framework: 'cis', key_prefix: '')
|
271
|
+
def map_indexed(indicies: [], index: 'title', framework: 'cis', key_prefix: '')
|
241
272
|
c_map = profiles.each_with_object({}) do |profile, obj|
|
242
273
|
obj[profile.level.downcase] = {} unless obj[profile.level.downcase].is_a?(Hash)
|
243
|
-
obj[profile.level.downcase][profile.title.downcase] = map_controls_hash(profile, index).sort_by { |k, _| k }.to_h
|
274
|
+
obj[profile.level.downcase][profile.title.downcase] = map_controls_hash(profile, indicies, index).sort_by { |k, _| k }.to_h
|
244
275
|
end
|
245
276
|
|
246
277
|
c_map['benchmark'] = { 'title' => title, 'version' => version }
|
@@ -249,8 +280,13 @@ module AbideDevUtils
|
|
249
280
|
{ mappings.join('::') => c_map }.to_yaml
|
250
281
|
end
|
251
282
|
|
283
|
+
def facter_benchmark
|
284
|
+
id = xpath('Benchmark/@id').text
|
285
|
+
id.split('_')[0..-2]
|
286
|
+
end
|
287
|
+
|
252
288
|
def facter_platform
|
253
|
-
cpe = xpath('
|
289
|
+
cpe = xpath('Benchmark/platform')[0]['idref'].split(':')
|
254
290
|
if cpe.length > 4
|
255
291
|
product_name = cpe[4].split('_')
|
256
292
|
product_version = cpe[5].split('.') unless cpe[5].nil?
|
@@ -280,8 +316,8 @@ module AbideDevUtils
|
|
280
316
|
hash.to_yaml
|
281
317
|
end
|
282
318
|
|
283
|
-
def
|
284
|
-
xpath("//
|
319
|
+
def resolve_cis_control_reference(control)
|
320
|
+
xpath("//Rule[@id='#{control.reference}']")
|
285
321
|
end
|
286
322
|
|
287
323
|
private
|
@@ -291,15 +327,15 @@ module AbideDevUtils
|
|
291
327
|
when 'hiera_title_num'
|
292
328
|
control.hiera_title(number_format: true)
|
293
329
|
when 'title'
|
294
|
-
|
330
|
+
resolve_cis_control_reference(control).xpath('./title').text
|
295
331
|
else
|
296
332
|
control.send(index.to_sym)
|
297
333
|
end
|
298
334
|
end
|
299
335
|
|
300
|
-
def map_controls_hash(profile, index)
|
336
|
+
def map_controls_hash(profile, indicies, index)
|
301
337
|
profile.controls.each_with_object({}) do |ctrl, hsh|
|
302
|
-
control_array =
|
338
|
+
control_array = indicies.each_with_object([]) do |idx_sym, ary|
|
303
339
|
next if idx_sym == index
|
304
340
|
|
305
341
|
item = format_map_control_index(idx_sym, ctrl)
|
@@ -316,13 +352,9 @@ module AbideDevUtils
|
|
316
352
|
end
|
317
353
|
end
|
318
354
|
|
319
|
-
def sorted_profile_classes(raw_profile_list, sort_key: :level)
|
320
|
-
raw_profile_list.map { |x| Profile.new(x) }.sort_by(&sort_key)
|
321
|
-
end
|
322
|
-
|
323
355
|
def find_profiles
|
324
356
|
profs = {}
|
325
|
-
xpath('
|
357
|
+
xpath('Benchmark/Profile').each do |profile|
|
326
358
|
level_code, name = profile_parts(profile['id'])
|
327
359
|
profs[name] = {} unless profs.key?(name)
|
328
360
|
profs[name][level_code] = profile
|
@@ -349,11 +381,66 @@ module AbideDevUtils
|
|
349
381
|
end
|
350
382
|
end
|
351
383
|
|
352
|
-
class
|
384
|
+
class XccdfObject
|
353
385
|
include AbideDevUtils::XCCDF::Common
|
354
386
|
|
355
|
-
def initialize(
|
356
|
-
@
|
387
|
+
def initialize(benchmark)
|
388
|
+
@benchmark = benchmark
|
389
|
+
@benchmark_type = benchmark_type
|
390
|
+
end
|
391
|
+
|
392
|
+
def controls_class
|
393
|
+
case @benchmark_type
|
394
|
+
when :cis
|
395
|
+
CisControls
|
396
|
+
when :stig
|
397
|
+
StigControls
|
398
|
+
else
|
399
|
+
raise AbideDevUtils::Errors::UnsupportedXCCDFError
|
400
|
+
end
|
401
|
+
end
|
402
|
+
|
403
|
+
def control_sort_key
|
404
|
+
case @benchmark_type
|
405
|
+
when :cis
|
406
|
+
:number
|
407
|
+
when :stig
|
408
|
+
:vulnid
|
409
|
+
else
|
410
|
+
raise AbideDevUtils::Errors::UnsupportedXCCDFError
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
def control_class
|
415
|
+
case @benchmark_type
|
416
|
+
when :cis
|
417
|
+
CisControl
|
418
|
+
when :stig
|
419
|
+
StigControl
|
420
|
+
else
|
421
|
+
raise AbideDevUtils::Errors::UnsupportedXCCDFError
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
private
|
426
|
+
|
427
|
+
def benchmark_type
|
428
|
+
title = @benchmark.at_xpath('title').text
|
429
|
+
if title.include?(STIG_TITLE_MARKER)
|
430
|
+
return :stig
|
431
|
+
elsif title.include?(CIS_TITLE_MARKER)
|
432
|
+
return :cis
|
433
|
+
end
|
434
|
+
raise AbideDevUtils::Errors::UnsupportedXCCDFError, "XCCDF type is unsupported!"
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
class ObjectContainer < XccdfObject
|
439
|
+
include AbideDevUtils::XCCDF::Common
|
440
|
+
|
441
|
+
def initialize(list, object_creation_method, benchmark, *args, **kwargs)
|
442
|
+
super(benchmark)
|
443
|
+
@object_list = send(object_creation_method.to_sym, list, benchmark, *args, **kwargs)
|
357
444
|
@searchable = []
|
358
445
|
end
|
359
446
|
|
@@ -396,6 +483,14 @@ module AbideDevUtils
|
|
396
483
|
|
397
484
|
private
|
398
485
|
|
486
|
+
def sorted_control_classes(raw_select_list, benchmark)
|
487
|
+
raw_select_list.map { |x| control_class.new(x, benchmark) }.sort_by(&control_sort_key)
|
488
|
+
end
|
489
|
+
|
490
|
+
def sorted_profile_classes(raw_profile_list, benchmark)
|
491
|
+
raw_profile_list.map { |x| Profile.new(x, benchmark) }.sort_by(&:title)
|
492
|
+
end
|
493
|
+
|
399
494
|
def resolve_hash_key(obj)
|
400
495
|
return obj.send(:raw_title) unless defined?(@hash_key)
|
401
496
|
|
@@ -416,8 +511,8 @@ module AbideDevUtils
|
|
416
511
|
end
|
417
512
|
|
418
513
|
class Profiles < ObjectContainer
|
419
|
-
def initialize(list)
|
420
|
-
super(list, :sorted_profile_classes)
|
514
|
+
def initialize(list, benchmark)
|
515
|
+
super(list, :sorted_profile_classes, benchmark)
|
421
516
|
searchable! :level, :title
|
422
517
|
index! :title
|
423
518
|
hash_key! :level, :title
|
@@ -440,9 +535,34 @@ module AbideDevUtils
|
|
440
535
|
end
|
441
536
|
end
|
442
537
|
|
443
|
-
class
|
444
|
-
def initialize(list)
|
445
|
-
super(list, :sorted_control_classes)
|
538
|
+
class StigControls < ObjectContainer
|
539
|
+
def initialize(list, benchmark)
|
540
|
+
super(list, :sorted_control_classes, benchmark)
|
541
|
+
searchable! :vulnid, :ruleid
|
542
|
+
index! :vulnid
|
543
|
+
hash_key! :vulnid
|
544
|
+
end
|
545
|
+
|
546
|
+
def vulnids
|
547
|
+
@vulnids ||= @object_list.map(&:vulnid).sort
|
548
|
+
end
|
549
|
+
|
550
|
+
def ruleids
|
551
|
+
@ruleids ||= @object_list.map(&:ruleid).sort
|
552
|
+
end
|
553
|
+
|
554
|
+
def include_vulnid?(item)
|
555
|
+
@object_list.map(&:vulnid).include?(item)
|
556
|
+
end
|
557
|
+
|
558
|
+
def include_ruleid?(item)
|
559
|
+
@object_list.map(&:ruleid).include?(item)
|
560
|
+
end
|
561
|
+
end
|
562
|
+
|
563
|
+
class CisControls < ObjectContainer
|
564
|
+
def initialize(list, benchmark)
|
565
|
+
super(list, :sorted_control_classes, benchmark)
|
446
566
|
searchable! :level, :title, :number
|
447
567
|
index! :number
|
448
568
|
hash_key! :number
|
@@ -473,10 +593,11 @@ module AbideDevUtils
|
|
473
593
|
end
|
474
594
|
end
|
475
595
|
|
476
|
-
class XccdfElement
|
596
|
+
class XccdfElement < XccdfObject
|
477
597
|
include AbideDevUtils::XCCDF::Common
|
478
598
|
|
479
|
-
def initialize(element)
|
599
|
+
def initialize(element, benchmark)
|
600
|
+
super(benchmark)
|
480
601
|
@xml = element
|
481
602
|
@element_type = self.class.name.split('::').last.downcase
|
482
603
|
@raw_title = control_profile_text(element)
|
@@ -498,11 +619,12 @@ module AbideDevUtils
|
|
498
619
|
end
|
499
620
|
|
500
621
|
def reference
|
501
|
-
@reference ||= @element_type
|
622
|
+
@reference ||= @element_type.include?('control') ? @xml['idref'] : @xml['id']
|
502
623
|
end
|
503
624
|
|
504
625
|
def hiera_title(**opts)
|
505
|
-
|
626
|
+
e_type = @element_type.include?('control') ? 'control' : 'profile'
|
627
|
+
send("normalize_#{e_type}_name".to_sym, @xml, **opts)
|
506
628
|
end
|
507
629
|
|
508
630
|
private
|
@@ -524,19 +646,27 @@ module AbideDevUtils
|
|
524
646
|
end
|
525
647
|
|
526
648
|
class Profile < XccdfElement
|
527
|
-
def initialize(profile)
|
528
|
-
super(profile)
|
649
|
+
def initialize(profile, benchmark)
|
650
|
+
super(profile, benchmark)
|
529
651
|
@level, @title = profile_parts(control_profile_text(profile))
|
530
|
-
@plain_text_title = @xml.xpath('./
|
531
|
-
@controls =
|
652
|
+
@plain_text_title = @xml.xpath('./title').text
|
653
|
+
@controls = controls_class.new(xpath('./select'), benchmark)
|
532
654
|
properties :title, :level, :plain_text_title, controls: :to_h
|
533
655
|
end
|
534
656
|
end
|
535
657
|
|
536
|
-
class
|
537
|
-
def initialize(control,
|
538
|
-
super(control)
|
539
|
-
@
|
658
|
+
class StigControl < XccdfElement
|
659
|
+
def initialize(control, benchmark)
|
660
|
+
super(control, benchmark)
|
661
|
+
@vulnid, @ruleid = control_parts(control_profile_text(control))
|
662
|
+
properties :vulnid, :ruleid
|
663
|
+
end
|
664
|
+
end
|
665
|
+
|
666
|
+
class CisControl < XccdfElement
|
667
|
+
def initialize(control, benchmark)
|
668
|
+
super(control, benchmark)
|
669
|
+
@number, @level, @title = control_parts(control_profile_text(control))
|
540
670
|
properties :number, :level, :title
|
541
671
|
end
|
542
672
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abide_dev_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- abide-team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -360,10 +360,20 @@ files:
|
|
360
360
|
- lib/abide_dev_utils.rb
|
361
361
|
- lib/abide_dev_utils/cem.rb
|
362
362
|
- lib/abide_dev_utils/cem/benchmark.rb
|
363
|
-
- lib/abide_dev_utils/cem/coverage_report.rb
|
364
363
|
- lib/abide_dev_utils/cem/generate.rb
|
364
|
+
- lib/abide_dev_utils/cem/generate/coverage_report.rb
|
365
365
|
- lib/abide_dev_utils/cem/generate/reference.rb
|
366
|
+
- lib/abide_dev_utils/cem/hiera_data.rb
|
367
|
+
- lib/abide_dev_utils/cem/hiera_data/mapping_data.rb
|
368
|
+
- lib/abide_dev_utils/cem/hiera_data/mapping_data/map_data.rb
|
369
|
+
- lib/abide_dev_utils/cem/hiera_data/mapping_data/mixins.rb
|
370
|
+
- lib/abide_dev_utils/cem/hiera_data/resource_data.rb
|
371
|
+
- lib/abide_dev_utils/cem/hiera_data/resource_data/control.rb
|
372
|
+
- lib/abide_dev_utils/cem/hiera_data/resource_data/parameters.rb
|
373
|
+
- lib/abide_dev_utils/cem/hiera_data/resource_data/resource.rb
|
366
374
|
- lib/abide_dev_utils/cem/mapping/mapper.rb
|
375
|
+
- lib/abide_dev_utils/cem/validate.rb
|
376
|
+
- lib/abide_dev_utils/cem/validate/resource_data.rb
|
367
377
|
- lib/abide_dev_utils/cli.rb
|
368
378
|
- lib/abide_dev_utils/cli/abstract.rb
|
369
379
|
- lib/abide_dev_utils/cli/cem.rb
|
@@ -375,6 +385,7 @@ files:
|
|
375
385
|
- lib/abide_dev_utils/comply.rb
|
376
386
|
- lib/abide_dev_utils/config.rb
|
377
387
|
- lib/abide_dev_utils/constants.rb
|
388
|
+
- lib/abide_dev_utils/dot_number_comparable.rb
|
378
389
|
- lib/abide_dev_utils/errors.rb
|
379
390
|
- lib/abide_dev_utils/errors/base.rb
|
380
391
|
- lib/abide_dev_utils/errors/cem.rb
|
@@ -393,6 +404,17 @@ files:
|
|
393
404
|
- lib/abide_dev_utils/ppt.rb
|
394
405
|
- lib/abide_dev_utils/ppt/api.rb
|
395
406
|
- lib/abide_dev_utils/ppt/class_utils.rb
|
407
|
+
- lib/abide_dev_utils/ppt/code_gen.rb
|
408
|
+
- lib/abide_dev_utils/ppt/code_gen/data_types.rb
|
409
|
+
- lib/abide_dev_utils/ppt/code_gen/generate.rb
|
410
|
+
- lib/abide_dev_utils/ppt/code_gen/resource.rb
|
411
|
+
- lib/abide_dev_utils/ppt/code_gen/resource_types.rb
|
412
|
+
- lib/abide_dev_utils/ppt/code_gen/resource_types/base.rb
|
413
|
+
- lib/abide_dev_utils/ppt/code_gen/resource_types/class.rb
|
414
|
+
- lib/abide_dev_utils/ppt/code_gen/resource_types/manifest.rb
|
415
|
+
- lib/abide_dev_utils/ppt/code_gen/resource_types/parameter.rb
|
416
|
+
- lib/abide_dev_utils/ppt/code_gen/resource_types/strings.rb
|
417
|
+
- lib/abide_dev_utils/ppt/code_introspection.rb
|
396
418
|
- lib/abide_dev_utils/ppt/facter_utils.rb
|
397
419
|
- lib/abide_dev_utils/ppt/hiera.rb
|
398
420
|
- lib/abide_dev_utils/ppt/new_obj.rb
|
@@ -411,9 +433,11 @@ files:
|
|
411
433
|
- lib/abide_dev_utils/xccdf/diff/benchmark/property_existence.rb
|
412
434
|
- lib/abide_dev_utils/xccdf/diff/utils.rb
|
413
435
|
- lib/abide_dev_utils/xccdf/parser.rb
|
436
|
+
- lib/abide_dev_utils/xccdf/parser/helpers.rb
|
414
437
|
- lib/abide_dev_utils/xccdf/parser/objects.rb
|
415
438
|
- lib/abide_dev_utils/xccdf/parser/objects/digest_object.rb
|
416
439
|
- lib/abide_dev_utils/xccdf/parser/objects/numbered_object.rb
|
440
|
+
- lib/abide_dev_utils/xccdf/utils.rb
|
417
441
|
- new_diff.rb
|
418
442
|
homepage: https://github.com/puppetlabs/abide_dev_utils
|
419
443
|
licenses:
|