quayio-scanner 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ac34418a5b842f0d6bbd244f10c3e6ac380dce60
4
+ data.tar.gz: ea6508ad09cdcf7a9ecf24b08f777a95adb3a3ba
5
+ SHA512:
6
+ metadata.gz: 2333e2e65f928fc67ec24f3a1f4a3a03bb9178eecee85042c17be5fc3bac042f7a97be69fb9c1e7c33277fc4f2ce9e2a7d44489aa5bca0804321a67086fc4c2f
7
+ data.tar.gz: eecfcf7e3bd711d82607ad52cd937358b77ec3f45f3b4e5c51424e2f7de36e238f3fc7953690ccc29dc07b8fe71c889c464addf2d3fa6bbbb00cda4e8ae06047
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in quayio-scanner.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Benjamin Meichsner
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Quayio::Scanner
2
+
3
+ Scan quay.io for vulnerabilties in running docker containers. Implemented as sensu check.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'quayio-scanner'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install quayio-scanner
20
+
21
+ ## Contributing
22
+
23
+ Bug reports and pull requests are welcome on GitHub at https://github.com/aboutsource/quayio-scanner.
24
+
25
+
26
+ ## License
27
+
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+ task default: :spec
@@ -0,0 +1,49 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-container-vulnerabilities
4
+ #
5
+ # DESCRIPTION:
6
+ #
7
+ # This plugin attempts to fetch vulnerabilties for all running containers
8
+ #
9
+ # OUTPUT:
10
+ # plain text
11
+ #
12
+ # PLATFORMS:
13
+ # Linux
14
+ #
15
+ # DEPENDENCIES:
16
+ # gem: sensu-plugin
17
+ # gem: docker-api
18
+ # gem: rest-client
19
+ #
20
+ # USAGE:
21
+ # ./check-container-vulnerabilities.rb -d <docker-url> -t <quay-io-oauth-token>
22
+ #
23
+
24
+ require 'sensu-plugin/check/cli'
25
+ require 'quayio/scanner'
26
+
27
+ class CheckContainerVulnerabilities < Sensu::Plugin::Check::CLI
28
+ option :docker_url,
29
+ description: 'Docker URL',
30
+ short: '-d URL',
31
+ long: '--docker-url URL',
32
+ default: 'unix:///var/run/docker.sock'
33
+
34
+ option :quayio_token,
35
+ description: 'Quay.io oauth token',
36
+ short: '-t TOKEN',
37
+ long: '--quayio-token TOKEN'
38
+
39
+ def run
40
+ status, message = Quayio::Scanner::Check.new(config[:docker_url],
41
+ config[:quayio_token]).run
42
+
43
+ if status == :ok
44
+ ok message
45
+ else
46
+ critical message
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,26 @@
1
+ require 'quayio/scanner/image'
2
+ require 'docker'
3
+
4
+ module Quayio
5
+ module Scanner
6
+ class Check < Struct.new(:docker_url, :quayio_token)
7
+ def run
8
+ Docker.url = docker_url
9
+ containers = Docker::Container.all
10
+ .map { |dc| dc.json['Config']['Image'] }
11
+ .uniq
12
+
13
+ vulnerable_images = containers
14
+ .map { |container| Image.new(container, quayio_token) }
15
+ .select(&:vulnerable?)
16
+ .map(&:name)
17
+
18
+ if vulnerable_images.empty?
19
+ [:ok, "#{containers.size} Containers are ok"]
20
+ else
21
+ [:critical, "The images are insecure: #{vulnerable_images.join(', ')}"]
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,68 @@
1
+ require 'rest-client'
2
+
3
+ module Quayio
4
+ module Scanner
5
+ class Image < Struct.new(:name, :quayio_token)
6
+ RELEVANT_SEVERITIES = %w(High Critical)
7
+
8
+ def vulnerable?
9
+ quayio? && image_exists? && scanned? && high_vulnerabilities_present?
10
+ end
11
+
12
+ private
13
+
14
+ def quayio?
15
+ name.match(%r{^quay.io\/})
16
+ end
17
+
18
+ def image_exists?
19
+ raw_image
20
+ end
21
+
22
+ def scanned?
23
+ raw_scan['status'] == 'scanned'
24
+ end
25
+
26
+ def high_vulnerabilities_present?
27
+ raw_scan['data']['Layer']['Features'].detect do |f|
28
+ f['Vulnerabilities'] &&
29
+ f['Vulnerabilities']
30
+ .detect { |v| RELEVANT_SEVERITIES.include?(v['Severity']) }
31
+ end
32
+ end
33
+
34
+ def repo
35
+ name.split(':').first.gsub(%r{quay.io\/}, '')
36
+ end
37
+
38
+ def tag
39
+ name.split(':').last
40
+ end
41
+
42
+ def raw_image
43
+ return @raw_image if defined? @raw_image
44
+
45
+ @raw_image = begin
46
+ JSON.parse(
47
+ RestClient.get("https://quay.io/api/v1/repository/#{repo}/tag/#{tag}/images",
48
+ authorization: "Bearer #{quayio_token}", accept: :json)
49
+ )['images'].first
50
+ rescue RestClient::ExceptionWithResponse => err
51
+ return nil if err.http_code == 404 # ignore unknown repos
52
+ raise err
53
+ end
54
+ end
55
+
56
+ def raw_scan
57
+ return @raw_scan if defined? @raw_scan
58
+
59
+ @raw_scan = begin
60
+ JSON.parse(
61
+ RestClient.get("https://quay.io/api/v1/repository/#{repo}/image/#{raw_image['id']}/security?vulnerabilities=true",
62
+ authorization: "Bearer #{quayio_token}", accept: :json)
63
+ )
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,5 @@
1
+ module Quayio
2
+ module Scanner
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'quayio/scanner/version'
2
+ require 'quayio/scanner/check'
3
+
4
+ module Quayio
5
+ module Scanner
6
+ end
7
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'quayio/scanner/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'quayio-scanner'
9
+ spec.version = Quayio::Scanner::VERSION
10
+ spec.authors = ['Benjamin Meichsner']
11
+ spec.email = ['benjamin.meichsner@aboutsource.net']
12
+
13
+ spec.summary = 'Scan quay.io for vulnerabilties in running docker containers.'
14
+ spec.homepage = 'https://github.com/aboutsource/quayio-scanner'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.executables = Dir.glob('bin/**/*.rb').map { |file| File.basename(file) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'sensu-plugin', '~> 2.1'
24
+ spec.add_dependency 'docker-api', '~> 1.33'
25
+ spec.add_dependency 'rest-client', '~> 2.0'
26
+ spec.add_development_dependency 'bundler', '~> 1.14'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rubocop', '~> 0.49'
29
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quayio-scanner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Benjamin Meichsner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sensu-plugin
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: docker-api
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.33'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.33'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.49'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.49'
97
+ description:
98
+ email:
99
+ - benjamin.meichsner@aboutsource.net
100
+ executables:
101
+ - check-container-vulnerabilities.rb
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/check-container-vulnerabilities.rb
111
+ - lib/quayio/scanner.rb
112
+ - lib/quayio/scanner/check.rb
113
+ - lib/quayio/scanner/image.rb
114
+ - lib/quayio/scanner/version.rb
115
+ - quayio-scanner.gemspec
116
+ homepage: https://github.com/aboutsource/quayio-scanner
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.6.11
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Scan quay.io for vulnerabilties in running docker containers.
140
+ test_files: []