scelint 0.6.2 → 0.8.0
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/.github/workflows/pr_tests.yml +1 -1
- data/.github/workflows/tag_deploy_rubygem.yml +2 -2
- data/CHANGELOG.md +17 -0
- data/Gemfile +2 -2
- data/lib/scelint/cli.rb +8 -3
- data/lib/scelint/version.rb +1 -1
- data/lib/scelint.rb +110 -8
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0fa4c86efdc5b8b53f3be73a0065a4c13bc0c7759e1886556c62fbb5a8a5d9eb
|
|
4
|
+
data.tar.gz: 8b3cdf888b0f474c91d53e2999e1b258d55c6269f6a20093cbf3840aaf14510a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e0af13652e213967a70272e1f34bee0664fc6a7b6aaf0bcc00271daedc8ca70d66035d1b2e22681605444db721de214932a0c83b500a9dbade4a07b766caebf6
|
|
7
|
+
data.tar.gz: '07856efc5a6e5d7fd71c48fcc294c98963b6595f2e8e8efe9a89923cd331f1040a61b19ff15b0fb89c22db58ef823c3830c5a03d88a301ed8485cdb725b64b1b'
|
|
@@ -92,7 +92,7 @@ jobs:
|
|
|
92
92
|
echo "release_command=$GEM_RELEASE_COMMAND" | tee -a "$GITHUB_OUTPUT"
|
|
93
93
|
- uses: ruby/setup-ruby@v1
|
|
94
94
|
with:
|
|
95
|
-
ruby-version: 4.0.
|
|
95
|
+
ruby-version: 4.0.10
|
|
96
96
|
bundler-cache: true
|
|
97
97
|
- name: Test build the package
|
|
98
98
|
run: "${{ steps.commands.outputs.build_command }}"
|
|
@@ -187,7 +187,7 @@ jobs:
|
|
|
187
187
|
clean: true
|
|
188
188
|
- uses: ruby/setup-ruby@v1
|
|
189
189
|
with:
|
|
190
|
-
ruby-version: 4.0.
|
|
190
|
+
ruby-version: 4.0.10
|
|
191
191
|
bundler-cache: true
|
|
192
192
|
- name: Build RubyGem
|
|
193
193
|
run: |
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
### 0.8.0 / 2026-11-24
|
|
2
|
+
* **BREAKING:** Report an error when a check's `value` is `null`. A `null`
|
|
3
|
+
overrides lower Hiera layers with the parameter's default. Remove the
|
|
4
|
+
check to leave the parameter alone, or use the module's removal value.
|
|
5
|
+
* Report a warning when a check's `value` contains a nested `null`
|
|
6
|
+
* Add `--allow-revision-drift PATTERN` (repeatable). Two files whose basenames
|
|
7
|
+
both match the same glob may name different revisions of the same DISA rule,
|
|
8
|
+
as when a manual and a SCAP benchmark for one release disagree on rule
|
|
9
|
+
revisions. A file from another release is still reported, as are different
|
|
10
|
+
rules. A pattern that matches no file is reported as a warning.
|
|
11
|
+
* Parse `.scelint` lines as a shell would, so quoted arguments work there
|
|
12
|
+
|
|
13
|
+
### 0.7.0 / 2026-11-02
|
|
14
|
+
* **BREAKING:** Report an error when files give a CE `oval-ids` for different
|
|
15
|
+
rules, as happens when two revisions of a benchmark ship together. Remove
|
|
16
|
+
the superseded files.
|
|
17
|
+
|
|
1
18
|
### 0.6.2 / 2026-11-02
|
|
2
19
|
* Report the file and check when data cannot be merged instead of crashing
|
|
3
20
|
* Report a `profiles`, `ce` or `checks` section that is not a hash, and a check's
|
data/Gemfile
CHANGED
|
@@ -7,10 +7,10 @@ gem 'rake', '~> 13.4.0'
|
|
|
7
7
|
|
|
8
8
|
group :tests do
|
|
9
9
|
gem 'rspec', '~> 3.13.1'
|
|
10
|
-
gem 'rubocop', '~> 1.
|
|
10
|
+
gem 'rubocop', '~> 1.93.0'
|
|
11
11
|
gem 'rubocop-performance', '~> 1.27.0'
|
|
12
12
|
gem 'rubocop-rake', '~> 0.7.1'
|
|
13
|
-
gem 'rubocop-rspec', '~> 3.
|
|
13
|
+
gem 'rubocop-rspec', '~> 3.11.0'
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
group :development do
|
data/lib/scelint/cli.rb
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require 'scelint'
|
|
4
4
|
require 'thor'
|
|
5
5
|
require 'logger'
|
|
6
|
+
require 'shellwords'
|
|
6
7
|
|
|
7
8
|
# SCELint CLI
|
|
8
9
|
class Scelint::CLI < Thor
|
|
@@ -13,12 +14,13 @@ class Scelint::CLI < Thor
|
|
|
13
14
|
DEFAULTS_FILE = '.scelint'
|
|
14
15
|
|
|
15
16
|
# Load default arguments from .scelint in the current directory.
|
|
16
|
-
# Each non-blank, non-comment line may contain one or more arguments
|
|
17
|
+
# Each non-blank, non-comment line may contain one or more arguments,
|
|
18
|
+
# split as a shell would, so quoted arguments work as on the command line.
|
|
17
19
|
def self.load_defaults
|
|
18
20
|
return [] unless File.exist?(DEFAULTS_FILE)
|
|
19
21
|
File.readlines(DEFAULTS_FILE, chomp: true)
|
|
20
22
|
.reject { |line| line.strip.empty? || line.strip.start_with?('#') }
|
|
21
|
-
.flat_map(
|
|
23
|
+
.flat_map { |line| Shellwords.split(line) }
|
|
22
24
|
end
|
|
23
25
|
|
|
24
26
|
# When the first argument is not a known subcommand or an option flag,
|
|
@@ -38,9 +40,12 @@ class Scelint::CLI < Thor
|
|
|
38
40
|
desc 'lint PATH', 'Lint all files in PATH'
|
|
39
41
|
option :strict, type: :boolean, aliases: '-s', default: false
|
|
40
42
|
option :allow_reserved_words, type: :boolean, default: false
|
|
43
|
+
option :allow_revision_drift, type: :string, repeatable: true, banner: 'PATTERN',
|
|
44
|
+
desc: 'Let two files whose names both match PATTERN name different revisions of the same DISA rule (repeatable)'
|
|
41
45
|
def lint(*paths)
|
|
42
46
|
paths = ['.'] if paths.nil? || paths.empty?
|
|
43
|
-
lint = Scelint::Lint.new(paths, logger: logger, allow_reserved_words: options[:allow_reserved_words]
|
|
47
|
+
lint = Scelint::Lint.new(paths, logger: logger, allow_reserved_words: options[:allow_reserved_words],
|
|
48
|
+
allow_revision_drift: options[:allow_revision_drift] || [])
|
|
44
49
|
|
|
45
50
|
count = lint.files.count
|
|
46
51
|
|
data/lib/scelint/version.rb
CHANGED
data/lib/scelint.rb
CHANGED
|
@@ -134,9 +134,13 @@ module Scelint
|
|
|
134
134
|
#
|
|
135
135
|
# @param paths [Array<String>] Paths to look for SCE data in. Defaults to ['.']
|
|
136
136
|
# @param logger [Logger] A logger to send messages to. Defaults to an instance of Logger with the log level set to INFO.
|
|
137
|
-
|
|
137
|
+
# @param allow_revision_drift [Array<String>] File name patterns (File.fnmatch globs,
|
|
138
|
+
# matched against each file's basename). Two files that both match the same pattern
|
|
139
|
+
# may name different revisions of the same rule. Defaults to none.
|
|
140
|
+
def initialize(paths = ['.'], logger: Logger.new(STDOUT, level: Logger::INFO), allow_reserved_words: false, allow_revision_drift: [])
|
|
138
141
|
@log = logger
|
|
139
142
|
@allow_reserved_words = allow_reserved_words
|
|
143
|
+
@allow_revision_drift = Array(allow_revision_drift)
|
|
140
144
|
@errors = []
|
|
141
145
|
@warnings = []
|
|
142
146
|
@notes = []
|
|
@@ -149,6 +153,8 @@ module Scelint
|
|
|
149
153
|
|
|
150
154
|
merged_data_lint
|
|
151
155
|
|
|
156
|
+
check_ce_oval_ids
|
|
157
|
+
|
|
152
158
|
validate
|
|
153
159
|
end
|
|
154
160
|
|
|
@@ -525,13 +531,19 @@ module Scelint
|
|
|
525
531
|
|
|
526
532
|
# Check a value
|
|
527
533
|
#
|
|
528
|
-
# @param
|
|
529
|
-
# @param
|
|
530
|
-
# @param
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
534
|
+
# @param file [String] The path to the file being checked
|
|
535
|
+
# @param check [String] The name of the check
|
|
536
|
+
# @param value [Object] The value to be validated
|
|
537
|
+
def check_value(file, check, value)
|
|
538
|
+
if value.nil?
|
|
539
|
+
errors << "#{file} (check '#{check}'): value is null, which overrides lower Hiera layers with the " \
|
|
540
|
+
"parameter's default; remove the check to leave the parameter alone, or use the module's removal value"
|
|
541
|
+
return
|
|
542
|
+
end
|
|
543
|
+
|
|
544
|
+
return unless nested_nil?(value)
|
|
545
|
+
|
|
546
|
+
warnings << "#{file} (check '#{check}'): value contains a nested null"
|
|
535
547
|
end
|
|
536
548
|
|
|
537
549
|
# Check settings
|
|
@@ -801,8 +813,98 @@ module Scelint
|
|
|
801
813
|
errors << "#{file}: #{e.message} (not a hash?)"
|
|
802
814
|
end
|
|
803
815
|
|
|
816
|
+
# Report CEs that resolve to more than one rule
|
|
817
|
+
#
|
|
818
|
+
# A CE identifies one rule. When two files give the same CE different
|
|
819
|
+
# oval-ids, the merged CE carries every one of them, and scan results
|
|
820
|
+
# can no longer be correlated back to a single rule with any confidence.
|
|
821
|
+
#
|
|
822
|
+
# In practice this is what a superseded benchmark file looks like from the
|
|
823
|
+
# inside: the old and new revisions both define the same CE keys, and the
|
|
824
|
+
# rule ids are where they diverge.
|
|
825
|
+
def check_ce_oval_ids
|
|
826
|
+
data.ces.each do |ce, component|
|
|
827
|
+
by_file = component.component[:fragments].each_with_object({}) do |(file, fragment), result|
|
|
828
|
+
next unless fragment.is_a?(Hash)
|
|
829
|
+
|
|
830
|
+
ids = Array(fragment['oval-ids']).select { |id| id.is_a?(String) && !id.empty? }
|
|
831
|
+
result[file] = ids unless ids.empty?
|
|
832
|
+
end
|
|
833
|
+
|
|
834
|
+
by_file.to_a.combination(2) do |(file_a, ids_a), (file_b, ids_b)|
|
|
835
|
+
next if same_rules?(ids_a, ids_b, ignore_revision: drift_allowed?(file_a, file_b))
|
|
836
|
+
|
|
837
|
+
errors << "CE '#{ce}': conflicting oval-ids (#{ids_a.inspect} in #{file_a}, #{ids_b.inspect} in #{file_b})"
|
|
838
|
+
end
|
|
839
|
+
end
|
|
840
|
+
|
|
841
|
+
@allow_revision_drift.each do |pattern|
|
|
842
|
+
next if files.any? { |file| File.fnmatch(pattern, File.basename(file)) }
|
|
843
|
+
|
|
844
|
+
warnings << "--allow-revision-drift pattern '#{pattern}' matches no file"
|
|
845
|
+
end
|
|
846
|
+
end
|
|
847
|
+
|
|
804
848
|
private
|
|
805
849
|
|
|
850
|
+
# Return true if two files may name different revisions of the same rule
|
|
851
|
+
#
|
|
852
|
+
# That is the case when one --allow-revision-drift pattern matches both
|
|
853
|
+
# files' basenames, as with a manual and a SCAP benchmark for the same
|
|
854
|
+
# release. A file from another release does not match the pair's pattern,
|
|
855
|
+
# so a superseded file left beside its replacement is still reported.
|
|
856
|
+
#
|
|
857
|
+
# @param file_a [String] Path to a file
|
|
858
|
+
# @param file_b [String] Path to another file
|
|
859
|
+
# @return [Boolean]
|
|
860
|
+
def drift_allowed?(file_a, file_b)
|
|
861
|
+
names = [File.basename(file_a), File.basename(file_b)]
|
|
862
|
+
|
|
863
|
+
@allow_revision_drift.any? { |pattern| names.all? { |name| File.fnmatch(pattern, name) } }
|
|
864
|
+
end
|
|
865
|
+
|
|
866
|
+
# Return true if two sets of oval-ids name the same rules
|
|
867
|
+
#
|
|
868
|
+
# The same rule is routinely written two ways in one data set: a manual
|
|
869
|
+
# benchmark uses the bare rule id and its SCAP counterpart prefixes it, as in
|
|
870
|
+
# 'SV-230221r1017040_rule' and
|
|
871
|
+
# 'xccdf_mil.disa.stig_rule_SV-230221r1017040_rule'. Those are not a
|
|
872
|
+
# disagreement, so the 'xccdf_<namespace>_rule_' prefix is ignored, and
|
|
873
|
+
# the remaining rule names are compared as sets. The namespace may be
|
|
874
|
+
# written with '.' or ':', as in 'xccdf_org.ssgproject.content_rule_foo'
|
|
875
|
+
# and 'xccdf_org:ssgproject:content_rule_foo'.
|
|
876
|
+
#
|
|
877
|
+
# With ignore_revision, the revision in a DISA rule id is ignored as well,
|
|
878
|
+
# so 'SV-230221r1017040_rule' and 'SV-230221r1017041_rule' name the same
|
|
879
|
+
# rule. DISA can publish a manual and a SCAP benchmark for one release
|
|
880
|
+
# whose rule revisions differ.
|
|
881
|
+
#
|
|
882
|
+
# @param ids_a [Array<String>] A set of oval-ids
|
|
883
|
+
# @param ids_b [Array<String>] A set of oval-ids
|
|
884
|
+
# @param ignore_revision [Boolean] Ignore DISA rule revisions
|
|
885
|
+
# @return [Boolean]
|
|
886
|
+
def same_rules?(ids_a, ids_b, ignore_revision: false)
|
|
887
|
+
rule_name = ->(id) {
|
|
888
|
+
name = id.sub(%r{\Axccdf_[^_]+_rule_}, '')
|
|
889
|
+
ignore_revision ? name.sub(%r{\A(SV-\d+)r\d+(_rule)\z}, '\1\2') : name
|
|
890
|
+
}
|
|
891
|
+
rule_names = ->(ids) { ids.map(&rule_name).uniq.sort }
|
|
892
|
+
|
|
893
|
+
rule_names.call(ids_a) == rule_names.call(ids_b)
|
|
894
|
+
end
|
|
895
|
+
|
|
896
|
+
# Whether a Hash or Array contains nil at any depth
|
|
897
|
+
#
|
|
898
|
+
# @param value [Object] The value to search
|
|
899
|
+
# @return [Boolean]
|
|
900
|
+
def nested_nil?(value)
|
|
901
|
+
case value
|
|
902
|
+
when Hash then value.values.any? { |v| v.nil? || nested_nil?(v) }
|
|
903
|
+
when Array then value.any? { |v| v.nil? || nested_nil?(v) }
|
|
904
|
+
else false
|
|
905
|
+
end
|
|
906
|
+
end
|
|
907
|
+
|
|
806
908
|
# Merge a ComplianceEngine::Collection object into a Hash
|
|
807
909
|
#
|
|
808
910
|
# Components that cannot be merged (usually because a fragment is
|