scelint 0.6.1 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2a232f07d18ffa6a294a5c8664e5c32fed52810ece80035b6ddc385be96695c
4
- data.tar.gz: 1503e5f3c4a5e1a6c8c065b74b7c48c75efc5f081932e11f69a112c1b4bed08d
3
+ metadata.gz: a1e8f8d8e3eb96d5aa6bc36fb178f2b3cb283240ff04c37f469f4563693e94ee
4
+ data.tar.gz: d89de6916fd66be7a7572240e8d04606ce33201b964f58b455da8423e850d474
5
5
  SHA512:
6
- metadata.gz: bfe6c7bf98cbdd1364cf230c91faeae76bbfd5e71d7d17ba0a74f48a77c46ea5fd64e3474fb6f6841e92202174e73e34ce995899db9a5a5e0a896be8688ecede
7
- data.tar.gz: c95d7b1e13e5b025374cb51e87494b8e8b25dd48b90df841bbfc482bef7687acbc5af2ddf99898962db3eda4e1a0e89ba1d4b3093b30b0a0e18efd5a954c875e
6
+ metadata.gz: 29896aa3398ae2a5503f304ec68968bf4e2944084dbbee5eee3056eba57cb843d3cc9e39eb1660bb6d679485548fed575e5a027a38ce9c3f2ef0cf2d34bc0900
7
+ data.tar.gz: f34b1e846bd6a188af09b9b5e5fc4fed0510c068ed05c09488ed845ba8e83f0ab46738551a005daa5a34cc4d6aef587bc8ca0a75b6a2833cc3482da452cd9243
@@ -1,6 +1,5 @@
1
- # Add new issues to triage project board (https://github.com/orgs/simp/projects/11)
1
+ # Add newly opened issues and pull requests to the Org Triage board
2
2
  # ------------------------------------------------------------------------------
3
- #
4
3
  # NOTICE: **This file is maintained with puppetsync**
5
4
  #
6
5
  # This file is updated automatically as part of a puppet module baseline.
@@ -8,19 +7,35 @@
8
7
  # The next baseline sync will overwrite any local changes to this file!
9
8
  #
10
9
  # ==============================================================================
11
- # This pipeline uses the following GitHub Action Secrets:
12
10
  #
13
- # GitHub Secret variable Notes
14
- # ------------------------------- ---------------------------------------
15
- # AUTO_TRIAGE_TOKEN Token with appropriate permissions
11
+ # Board: https://github.com/orgs/simp/projects/11
16
12
  #
17
- # ------------------------------------------------------------------------------
13
+ # Intake is filtered (simp/puppetsync#97): automated traffic never needs a
14
+ # human to triage it, and letting it in buried the items that do.
15
+ #
16
+ # * Renovate (and Dependabot, pre-emptively) are matched by actor.
17
+ # * puppetsync's own sync PRs are matched by the `[puppetsync]` title prefix.
18
+ # That prefix is a CONVENTION set by the `commit_message` in each sync
19
+ # config, not something enforced -- a config that drops it would silently
20
+ # start adding sync PRs to the board again.
21
+ #
22
+ # PRs in general are deliberately NOT filtered: drive-by PRs from outside
23
+ # contributors are exactly what the board must catch.
24
+ #
25
+ # This workflow does not check out any code, which is what makes its use of
26
+ # `pull_request_target` safe. Keep it that way.
18
27
  #
28
+ # Labelling (`community` for outside contributions, `needs-attention` for
29
+ # stalled items) is NOT done here: the event payload's `author_association`
30
+ # reports private org members as CONTRIBUTOR, so a per-repo step would mislabel
31
+ # most of the team. It lives in the scheduled org job
32
+ # simp/gha-workflows/.github/workflows/org_reconcile_board_status.yml, which
33
+ # resolves membership from the org member list (simp/puppetsync#98, #99).
19
34
  #
20
35
  ---
21
36
  name: Add new issues to triage project
22
37
 
23
- 'on':
38
+ on:
24
39
  issues:
25
40
  types:
26
41
  - opened
@@ -33,6 +48,14 @@ jobs:
33
48
  add-to-project:
34
49
  name: Add issue to project
35
50
  runs-on: ubuntu-latest
51
+ # `github.event.pull_request` is null on `issues` events, so the title test
52
+ # is guarded by event_name rather than relying on startsWith(null, ...)
53
+ # evaluating false.
54
+ if: >-
55
+ github.actor != 'renovate[bot]' &&
56
+ github.actor != 'dependabot[bot]' &&
57
+ !(github.event_name == 'pull_request_target' &&
58
+ startsWith(github.event.pull_request.title, '[puppetsync]'))
36
59
  steps:
37
60
  - uses: actions/add-to-project@v2
38
61
  with:
@@ -17,7 +17,7 @@ jobs:
17
17
  - name: "Install Ruby"
18
18
  uses: ruby/setup-ruby@v1
19
19
  with:
20
- ruby-version: 4.0.6
20
+ ruby-version: 4.0.9
21
21
  bundler-cache: true
22
22
  - run: bundle exec rake rubocop
23
23
 
@@ -41,3 +41,21 @@ jobs:
41
41
  bundler-cache: true
42
42
  - name: Spec tests
43
43
  run: bundle exec rake spec
44
+
45
+ # The one check for branch protection to require: GitHub only blocks a
46
+ # merge on checks listed by name, and this job fails unless every job it
47
+ # needs succeeded. Add any new job in this workflow to `needs:`.
48
+ all-checks:
49
+ name: 'All checks'
50
+ if: always()
51
+ needs:
52
+ - ruby-style
53
+ - spec-tests
54
+ runs-on: ubuntu-latest
55
+ steps:
56
+ - name: 'Fail unless every needed job succeeded'
57
+ env:
58
+ NEEDS: ${{ toJSON(needs) }}
59
+ run: |
60
+ jq -r 'to_entries[] | "\(.key): \(.value.result)"' <<< "$NEEDS"
61
+ jq -e 'all(.[]; .result == "success")' <<< "$NEEDS" > /dev/null
@@ -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.6
95
+ ruby-version: 4.0.9
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.6
190
+ ruby-version: 4.0.9
191
191
  bundler-cache: true
192
192
  - name: Build RubyGem
193
193
  run: |
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ### 0.7.0 / 2026-11-02
2
+ * **BREAKING:** Report an error when files give a CE `oval-ids` for different
3
+ rules, as happens when two revisions of a benchmark ship together. Remove
4
+ the superseded files.
5
+
6
+ ### 0.6.2 / 2026-11-02
7
+ * Report the file and check when data cannot be merged instead of crashing
8
+ * Report a `profiles`, `ce` or `checks` section that is not a hash, and a check's
9
+ `settings`, `ces` or remediation section of the wrong type, instead of crashing
10
+ * Report a CE's `imported_data` that is not a hash instead of crashing
11
+ * Exit with a non-zero status when linting fails with an exception
12
+
1
13
  ### 0.6.1 / 2026-08-20
2
14
  * Support compliance_engine 1.x
3
15
 
data/Gemfile CHANGED
@@ -7,8 +7,8 @@ gem 'rake', '~> 13.4.0'
7
7
 
8
8
  group :tests do
9
9
  gem 'rspec', '~> 3.13.1'
10
- gem 'rubocop', '~> 1.89.0'
11
- gem 'rubocop-performance', '~> 1.26.0'
10
+ gem 'rubocop', '~> 1.92.0'
11
+ gem 'rubocop-performance', '~> 1.27.0'
12
12
  gem 'rubocop-rake', '~> 0.7.1'
13
13
  gem 'rubocop-rspec', '~> 3.10.0'
14
14
  end
@@ -16,5 +16,5 @@ end
16
16
  group :development do
17
17
  gem 'pry', '~> 0.16.0'
18
18
  gem 'pry-byebug', '~> 3.12.0'
19
- gem 'rdoc', '~> 8.0.0'
19
+ gem 'rdoc', '~> 8.1.0'
20
20
  end
data/lib/scelint/cli.rb CHANGED
@@ -81,6 +81,8 @@ class Scelint::CLI < Thor
81
81
  exit exit_code
82
82
  rescue => e
83
83
  logger.fatal e.message
84
+ logger.debug e.backtrace.join("\n")
85
+ exit 1
84
86
  end
85
87
  default_task :lint
86
88
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Scelint
4
- VERSION = '0.6.1'
4
+ VERSION = '0.7.0'
5
5
  end
data/lib/scelint.rb CHANGED
@@ -149,6 +149,8 @@ module Scelint
149
149
 
150
150
  merged_data_lint
151
151
 
152
+ check_ce_oval_ids
153
+
152
154
  validate
153
155
  end
154
156
 
@@ -314,6 +316,11 @@ module Scelint
314
316
  def check_imported_data(file, file_data)
315
317
  ok = ['checktext', 'fixtext']
316
318
 
319
+ unless file_data.is_a?(Hash)
320
+ warnings << "#{file}: bad imported_data '#{file_data}'"
321
+ return
322
+ end
323
+
317
324
  file_data.each do |key, value|
318
325
  warnings << "#{file}: unexpected key '#{key}'" unless ok.include?(key)
319
326
 
@@ -337,7 +344,22 @@ module Scelint
337
344
  'benchmark_version',
338
345
  ]
339
346
 
347
+ unless file_data.is_a?(Hash)
348
+ errors << "#{file}: 'profiles' must be a hash, got #{file_data.class}"
349
+ return
350
+ end
351
+
340
352
  file_data.each do |profile, value|
353
+ if value.nil?
354
+ warnings << "#{file} (profile '#{profile}'): empty value"
355
+ next
356
+ end
357
+
358
+ unless value.is_a?(Hash)
359
+ errors << "#{file} (profile '#{profile}'): contains something other than a hash"
360
+ next
361
+ end
362
+
341
363
  value.each_key do |key|
342
364
  warnings << "#{file} (profile '#{profile}'): unexpected key '#{key}'" unless ok.include?(key)
343
365
  end
@@ -367,7 +389,22 @@ module Scelint
367
389
  'notes',
368
390
  ]
369
391
 
392
+ unless file_data.is_a?(Hash)
393
+ errors << "#{file}: 'ce' must be a hash, got #{file_data.class}"
394
+ return
395
+ end
396
+
370
397
  file_data.each do |ce, value|
398
+ if value.nil?
399
+ warnings << "#{file} (CE '#{ce}'): empty value"
400
+ next
401
+ end
402
+
403
+ unless value.is_a?(Hash)
404
+ errors << "#{file} (CE '#{ce}'): contains something other than a hash"
405
+ next
406
+ end
407
+
371
408
  value.each_key do |key|
372
409
  warnings << "#{file} (CE '#{ce}'): unexpected key '#{key}'" unless ok.include?(key)
373
410
  end
@@ -445,6 +482,11 @@ module Scelint
445
482
 
446
483
  if remediation_section.is_a?(Hash)
447
484
  remediation_section.each do |section, value|
485
+ if ['scan-false-positive', 'disabled', 'risk'].include?(section) && !value.is_a?(Array)
486
+ errors << "#{file} (check '#{check}'): malformed remediation section #{section}, expecting an array."
487
+ next
488
+ end
489
+
448
490
  case section
449
491
  when 'scan-false-positive', 'disabled'
450
492
  value.each do |reason|
@@ -512,6 +554,16 @@ module Scelint
512
554
  return false
513
555
  end
514
556
 
557
+ unless file_data.is_a?(Hash)
558
+ msg = "#{file} (check '#{check}'): settings must be a hash, got #{file_data.class}"
559
+ if file == 'merged data'
560
+ errors << msg
561
+ else
562
+ warnings << msg
563
+ end
564
+ return false
565
+ end
566
+
515
567
  if file_data.key?('parameter')
516
568
  check_parameter(file, check, file_data['parameter'])
517
569
  else
@@ -542,12 +594,16 @@ module Scelint
542
594
  # Check CEs in a check
543
595
  #
544
596
  # @param file [String] The path to the file being checked
597
+ # @param check [String] The name of the check
545
598
  # @param file_data [Array] The data to validate
546
- def check_check_ces(file, file_data)
547
- warnings << "#{file}: bad ces '#{file_data}'" unless file_data.is_a?(Array)
599
+ def check_check_ces(file, check, file_data)
600
+ unless file_data.is_a?(Array)
601
+ warnings << "#{file} (check '#{check}'): bad ces '#{file_data}'"
602
+ return
603
+ end
548
604
 
549
605
  file_data.each do |key|
550
- warnings << "#{file}: bad ce '#{key}'" unless key.is_a?(String)
606
+ warnings << "#{file} (check '#{check}'): bad ce '#{key}'" unless key.is_a?(String)
551
607
  end
552
608
  end
553
609
 
@@ -567,6 +623,11 @@ module Scelint
567
623
  'remediation',
568
624
  ]
569
625
 
626
+ unless file_data.is_a?(Hash)
627
+ errors << "#{file}: 'checks' must be a hash, got #{file_data.class}"
628
+ return
629
+ end
630
+
570
631
  file_data.each do |check, value|
571
632
  if value.nil?
572
633
  warnings << "#{file} (check '#{check}'): empty value"
@@ -579,6 +640,7 @@ module Scelint
579
640
  end
580
641
  else
581
642
  errors << "#{file} (check '#{check}'): contains something other than a hash, this is most likely caused by a missing note or ce element under the check"
643
+ next
582
644
  end
583
645
 
584
646
  check_type(file, check, value['type']) if value['type'] || file == 'merged data'
@@ -589,7 +651,7 @@ module Scelint
589
651
  check_controls(file, value['controls']) unless value['controls'].nil?
590
652
  check_identifiers(file, value['identifiers']) unless value['identifiers'].nil?
591
653
  check_oval_ids(file, value['oval-ids']) unless value['oval-ids'].nil?
592
- check_check_ces(file, value['ces']) unless value['ces'].nil?
654
+ check_check_ces(file, check, value['ces']) unless value['ces'].nil?
593
655
  check_confine(file, value['confine']) unless value['confine'].nil?
594
656
  end
595
657
  end
@@ -672,7 +734,12 @@ module Scelint
672
734
 
673
735
  # Unconfined, verify that hiera data exists
674
736
  data.profiles.each_key do |profile|
675
- hiera = data.hiera([profile])
737
+ begin
738
+ hiera = data.hiera([profile])
739
+ rescue => e
740
+ errors << "Profile '#{profile}': unable to render Hiera data (#{e.message})"
741
+ next
742
+ end
676
743
  if hiera.nil?
677
744
  errors << "Profile '#{profile}': Invalid Hiera data (returned nil)"
678
745
  next
@@ -687,8 +754,20 @@ module Scelint
687
754
  # Again, this time confined
688
755
  confines.each do |confine|
689
756
  data.facts = confine
690
- data.profiles.select { |_, value| value.ces&.count&.positive? || value.controls&.count&.positive? }.each_key do |profile|
691
- hiera = data.hiera([profile])
757
+ eligible = data.profiles.select do |profile, value|
758
+ value.ces&.count&.positive? || value.controls&.count&.positive?
759
+ rescue => e
760
+ errors << "Profile '#{profile}': unable to render Hiera data (#{e.message}) with facts #{confine}"
761
+ false
762
+ end
763
+
764
+ eligible.each_key do |profile|
765
+ begin
766
+ hiera = data.hiera([profile])
767
+ rescue => e
768
+ errors << "Profile '#{profile}': unable to render Hiera data (#{e.message}) with facts #{confine}"
769
+ next
770
+ end
692
771
  if hiera.nil?
693
772
  errors << "Profile '#{profile}': Invalid Hiera data (returned nil) with facts #{confine}"
694
773
  next
@@ -724,22 +803,83 @@ module Scelint
724
803
  errors << "#{file}: #{e.message} (not a hash?)"
725
804
  end
726
805
 
806
+ # Report CEs that resolve to more than one rule
807
+ #
808
+ # A CE identifies one rule. When two files give the same CE different
809
+ # oval-ids, the merged CE carries every one of them, and scan results
810
+ # can no longer be correlated back to a single rule with any confidence.
811
+ #
812
+ # In practice this is what a superseded benchmark file looks like from the
813
+ # inside: the old and new revisions both define the same CE keys, and the
814
+ # rule ids are where they diverge.
815
+ def check_ce_oval_ids
816
+ data.ces.each do |ce, component|
817
+ by_file = component.component[:fragments].each_with_object({}) do |(file, fragment), result|
818
+ next unless fragment.is_a?(Hash)
819
+
820
+ ids = Array(fragment['oval-ids']).select { |id| id.is_a?(String) && !id.empty? }
821
+ result[file] = ids unless ids.empty?
822
+ end
823
+
824
+ by_file.to_a.combination(2) do |(file_a, ids_a), (file_b, ids_b)|
825
+ next if same_rules?(ids_a, ids_b)
826
+
827
+ errors << "CE '#{ce}': conflicting oval-ids (#{ids_a.inspect} in #{file_a}, #{ids_b.inspect} in #{file_b})"
828
+ end
829
+ end
830
+ end
831
+
727
832
  private
728
833
 
834
+ # Return true if two sets of oval-ids name the same rules
835
+ #
836
+ # The same rule is routinely written two ways in one data set: a manual
837
+ # benchmark uses the bare rule id and its SCAP counterpart prefixes it, as in
838
+ # 'SV-230221r1017040_rule' and
839
+ # 'xccdf_mil.disa.stig_rule_SV-230221r1017040_rule'. Those are not a
840
+ # disagreement, so the 'xccdf_<namespace>_rule_' prefix is ignored, and
841
+ # the remaining rule names are compared as sets. The namespace may be
842
+ # written with '.' or ':', as in 'xccdf_org.ssgproject.content_rule_foo'
843
+ # and 'xccdf_org:ssgproject:content_rule_foo'.
844
+ #
845
+ # @param ids_a [Array<String>] A set of oval-ids
846
+ # @param ids_b [Array<String>] A set of oval-ids
847
+ # @return [Boolean]
848
+ def same_rules?(ids_a, ids_b)
849
+ rule_names = ->(ids) { ids.map { |id| id.sub(%r{\Axccdf_[^_]+_rule_}, '') }.uniq.sort }
850
+
851
+ rule_names.call(ids_a) == rule_names.call(ids_b)
852
+ end
853
+
729
854
  # Merge a ComplianceEngine::Collection object into a Hash
730
855
  #
856
+ # Components that cannot be merged (usually because a fragment is
857
+ # malformed) are reported as errors and left out of the result rather
858
+ # than aborting the entire lint run.
859
+ #
731
860
  # @param collection [ComplianceEngine::Collection] A collection object
861
+ # @param type [String] The type of component in the collection, used in error messages
732
862
  # @return [Hash] The merged data
733
- def merge(collection)
734
- collection.to_h.reduce({}) { |result, value| result.merge!(value[0] => value[1].to_h) }
863
+ def merge(collection, type)
864
+ collection.to_h.each_with_object({}) do |(key, value), result|
865
+ result[key] = value.to_h
866
+ rescue => e
867
+ errors << "merged data: unable to merge #{type} '#{key}': #{e.message}"
868
+ end
735
869
  end
736
870
 
737
871
  # Perform lint checks on merged data
872
+ #
873
+ # @note Unlike #lint, this has no file to attribute a failure to, so any
874
+ # unexpected exception is reported against 'merged data' rather than
875
+ # escaping to the caller.
738
876
  def merged_data_lint
739
- check_profiles('merged data', merge(data.profiles))
740
- check_ce('merged data', merge(data.ces))
741
- check_checks('merged data', merge(data.checks))
742
- check_controls('merged data', merge(data.controls))
877
+ check_profiles('merged data', merge(data.profiles, 'profile'))
878
+ check_ce('merged data', merge(data.ces, 'CE'))
879
+ check_checks('merged data', merge(data.checks, 'check'))
880
+ check_controls('merged data', merge(data.controls, 'control'))
881
+ rescue => e
882
+ errors << "merged data: #{e.message}"
743
883
  end
744
884
  end
745
885
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scelint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Pritchard
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  requirements: []
97
- rubygems_version: 4.0.16
97
+ rubygems_version: 4.0.20
98
98
  specification_version: 4
99
99
  summary: Linter SIMP Compliance Engine data
100
100
  test_files: []