dccscr 0.2.4 → 0.3.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: 19f7a39dba0aaf6a38390ec0231123337295fc09ed67688f2385570c7a0e2e68
4
- data.tar.gz: 2cb39e932916aa6f64c3e6bda49d7e92fdda67b3714172098db1a06bb3c09f05
3
+ metadata.gz: 753dc4edfd916f55efc0d2d533fa67835de1d8540f37b749304f208c3268ce0e
4
+ data.tar.gz: 03020aa7432733669621c0d318985e05a7a5c8a2f007143dc762e8cf12f70311
5
5
  SHA512:
6
- metadata.gz: a2beaade232b0aace980995067f07b0cf50791d640cac99ee6bec6151a0a09f2c1d937ae432ec04e64b66974853971b9ca2f32d5397df7f92f206c8ec0b4ea96
7
- data.tar.gz: 793bd0cf0c5d45a488e53e8c3382f87c3ad5428ccd7c3af31d6ff81fac57951d2c684e20e2b7d4ecdb6cf651c449b06e295e6dc2c978d3cd808338f3ae628a92
6
+ metadata.gz: 25e36706bda36da321fa36f2df0f415aebfeebe4a5d476408c8dc74738a300146edf890c6b6295e724369e924f939d4773c12ea7b53e8cc951ad508a2bb21942
7
+ data.tar.gz: a09fa390de7045f70fafb575bc7cb5ef91fedc40310b7f1f93cc5498f1c489fd7d90d91a3afd27cd34a85669e61b9194021743ad090e1d9bdafa8250e5bc4d32
data/.rubocop.yml CHANGED
@@ -11,6 +11,9 @@ Metrics/MethodLength:
11
11
  Naming/InclusiveLanguage:
12
12
  Enabled: false
13
13
 
14
+ Naming/MemoizedInstanceVariableName:
15
+ Enabled: false
16
+
14
17
  Naming/MethodParameterName:
15
18
  MinNameLength: 2
16
19
 
@@ -23,6 +26,9 @@ Style/ConditionalAssignment:
23
26
  Style/HashConversion:
24
27
  Enabled: false
25
28
 
29
+ Style/ClassAndModuleChildren:
30
+ Enabled: false
31
+
26
32
  Style/SpecialGlobalVars:
27
33
  Enabled: false
28
34
 
data/Gemfile CHANGED
@@ -9,6 +9,7 @@ gem 'rake', '~> 13.0'
9
9
  gem 'rubocop-rake'
10
10
 
11
11
  gem 'minitest', '~> 5.0'
12
+ gem 'minitest-ok', '~> 0.3.3'
12
13
  gem 'rubocop-minitest'
13
14
 
14
15
  gem 'rubocop', '~> 1.7'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dccscr (0.2.4)
4
+ dccscr (0.3.0)
5
5
  shellwords (~> 0.1)
6
6
 
7
7
  GEM
@@ -9,6 +9,8 @@ GEM
9
9
  specs:
10
10
  ast (2.4.2)
11
11
  minitest (5.14.4)
12
+ minitest-ok (0.3.3)
13
+ minitest
12
14
  parallel (1.20.1)
13
15
  parser (3.0.2.0)
14
16
  ast (~> 2.4.1)
@@ -41,6 +43,7 @@ PLATFORMS
41
43
  DEPENDENCIES
42
44
  dccscr!
43
45
  minitest (~> 5.0)
46
+ minitest-ok (~> 0.3.3)
44
47
  rake (~> 13.0)
45
48
  rubocop (~> 1.7)
46
49
  rubocop-minitest
@@ -1,74 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'dccscr/whitelist'
4
+ require 'dccscr/whitelist/update_allowlist_with_dccscr'
5
5
 
6
- def load_dccscr_whitelist
7
- DCCSCR::Whitelist.new.tap do |wl|
8
- # load wl entries for args
9
- # will load parents as well
10
- ARGV.each { |arg| wl[arg] }
11
- end
12
- end
13
-
14
- def load_gitlab_allowlist
15
- if File.exist?('local-vulnerability-allowlist.yml')
16
- warn 'Loading local-vulnerability-allowlist.yml'
17
- YAML.safe_load(File.read('local-vulnerability-allowlist.yml'))
18
- elsif File.exist?('vulnerability-allowlist.yml')
19
- warn 'Loading and renaming vulnerability-allowlist.yml'
20
- File.rename('vulnerability-allowlist.yml', 'local-vulnerability-allowlist.yml')
21
- YAML.safe_load(File.read('local-vulnerability-allowlist.yml'))
22
- else
23
- warn 'No [local-]vulnerability-allowlist.yml'
24
- {}
25
- end
26
- end
27
-
28
- def allow_list_dccscr(wl)
29
- warn 'Generating dccscr list in gitlab format'
30
-
31
- {
32
- 'generalallowlist' => Hash[
33
- wl.entries.map { |_, entry|
34
- entry.value['whitelisted_vulnerabilities'].map { |v|
35
- [v['vulnerability'], "dccscr-whitelists:\n#{v['justification']}"]
36
- }.compact
37
- }.flatten(1).sort
38
- ]
39
- }
40
- end
41
-
42
- def combined_list(dl, ll)
43
- warn 'Merging dccscr and local lists'
44
-
45
- dl.merge(ll) { |_, d, l|
46
- case d
47
- when Hash
48
- d.merge(l)
49
- else
50
- l
51
- end
52
- }
53
- end
54
-
55
- def update_allow_list_file(cl)
56
- warn 'Updating vulnerability-allowlist.yml'
57
-
58
- File.open('vulnerability-allowlist.yml', 'w') do |f|
59
- f << cl.to_yaml
60
- end
61
- end
62
-
63
- def run
64
- ll = load_gitlab_allowlist
65
-
66
- wl = load_dccscr_whitelist
67
- dl = allow_list_dccscr(wl)
68
-
69
- cl = combined_list(dl, ll)
70
-
71
- update_allow_list_file(cl)
72
- end
73
-
74
- run
6
+ DCCSCR::Whitelist::UpdateAllowlistWithDCCSCR.new(
7
+ images: ARGV
8
+ ).run
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DCCSCR
4
- VERSION = '0.2.4'
4
+ VERSION = '0.3.0'
5
5
  end
@@ -27,11 +27,7 @@ module DCCSCR
27
27
  @repo = UPSTREAM_REPO
28
28
  end
29
29
 
30
- if clone
31
- clone_options = Shellwords.join(Shellwords.split(clone_options).map { |w| Shellwords.escape(w) })
32
- system "git clone #{clone_options} -- #{@repo.inspect} #{@path.inspect}"
33
- $?.success? || fail('error cloning repo')
34
- end
30
+ clone_repo(clone_options) if clone
35
31
 
36
32
  @entries = {}
37
33
  end
@@ -51,5 +47,16 @@ module DCCSCR
51
47
  whitelist[@parent] unless (@parent = @value['image_parent_name'])&.empty?
52
48
  end
53
49
  end
50
+
51
+ private
52
+
53
+ def clone_repo(clone_options = '')
54
+ system Shellwords.join [].tap { |cmd|
55
+ cmd << %w[git clone]
56
+ cmd << Shellwords.split(clone_options).map { |w| Shellwords.escape(w) }
57
+ cmd << ['--', Shellwords.escape(@repo), Shellwords.escape(@path)]
58
+ }.flatten
59
+ $?.success? || fail('error cloning repo')
60
+ end
54
61
  end
55
62
  end
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../whitelist'
5
+
6
+ # Service class to update a GitLab vulnerability-allowlist.yml with
7
+ # whitelisted_vulnerabilities from the dccscr-whitelist for a set
8
+ # of images.
9
+ #
10
+ class DCCSCR::Whitelist::UpdateAllowlistWithDCCSCR
11
+ attr_reader :images, :allow_filename, :local_filename
12
+
13
+ def initialize(images: [], allow_filename: nil, local_filename: nil)
14
+ @images = images
15
+ @allow_filename = allow_filename || 'vulnerability-allowlist.yml'
16
+ @local_filename = local_filename || 'local-vulnerability-allowlist.yml'
17
+ end
18
+
19
+ def whitelist
20
+ @_whitelist ||= DCCSCR::Whitelist.new
21
+ end
22
+
23
+ def run
24
+ ll = load_gitlab_allowlist
25
+
26
+ wl = load_dccscr_whitelist
27
+ dl = allow_list_dccscr(wl)
28
+
29
+ cl = combined_list(dl, ll)
30
+
31
+ update_allow_list_file(cl)
32
+ end
33
+
34
+ private
35
+
36
+ def load_dccscr_whitelist
37
+ whitelist.tap do |wl|
38
+ # load wl entries for args
39
+ # will load parents as well
40
+ images.each { |arg| wl[arg] }
41
+ end
42
+ end
43
+
44
+ def load_gitlab_allowlist
45
+ if File.exist?(local_filename)
46
+ warn 'Loading local file'
47
+ load(local_filename)
48
+ elsif File.exist?(allow_filename)
49
+ warn 'Loading and renaming local allow file'
50
+ File.rename(allow_filename, local_filename)
51
+ load(local_filename)
52
+ else
53
+ warn 'No local allow file'
54
+ {}
55
+ end
56
+ end
57
+
58
+ def load(yml)
59
+ YAML.safe_load(File.read(yml))
60
+ end
61
+
62
+ def allow_list_dccscr(wl)
63
+ warn 'Generating dccscr list in gitlab format'
64
+
65
+ {
66
+ 'generalallowlist' => Hash[
67
+ wl.entries.map { |_, entry|
68
+ entry.value['whitelisted_vulnerabilities'].map { |v|
69
+ [v['vulnerability'], "dccscr-whitelists:\n#{v['justification']}"]
70
+ }.compact
71
+ }.flatten(1).sort
72
+ ]
73
+ }
74
+ end
75
+
76
+ def combined_list(dl, ll)
77
+ warn 'Merging dccscr and local lists'
78
+
79
+ dl.merge(ll) { |_, d, l|
80
+ case d
81
+ when Hash
82
+ d.merge(l)
83
+ else
84
+ l
85
+ end
86
+ }
87
+ end
88
+
89
+ def update_allow_list_file(cl)
90
+ warn 'Updating allow file'
91
+
92
+ File.open(allow_filename, 'w') do |f|
93
+ f << cl.to_yaml
94
+ end
95
+ end
96
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dccscr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank J. Cameron
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-08 00:00:00.000000000 Z
11
+ date: 2021-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shellwords
@@ -48,6 +48,7 @@ files:
48
48
  - lib/dccscr.rb
49
49
  - lib/dccscr/version.rb
50
50
  - lib/dccscr/whitelist.rb
51
+ - lib/dccscr/whitelist/update_allowlist_with_dccscr.rb
51
52
  homepage: https://gitlab.com/fjc/dccscr.rb
52
53
  licenses:
53
54
  - MIT