clairmon 0.0.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 +7 -0
- data/lib/clairmon.rb +88 -0
- metadata +45 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 7e1fae57f42b7f96a287d019a8346af77dbf775d
|
|
4
|
+
data.tar.gz: ff802be98f7e108218e050a0634890f5a8d1181d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 80ec430f016648559eaabb4605c5e24be13fb21ea580ead57a30581bf7cb8e4416b79a811c207dd6e7dc9cdea26032dedf87e500575e13f8f2f8cc7087a5aba1
|
|
7
|
+
data.tar.gz: 9598be151dce4c92b3c799d8b8e1f56c6830e799f0e2c62f6e0df1be5103afdcd55c98ded6404e8b04a8bb2540ee2423a4d34d1ab37c1cf206c987abed680c9b
|
data/lib/clairmon.rb
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'net/http'
|
|
4
|
+
require 'json'
|
|
5
|
+
|
|
6
|
+
class Clairmon
|
|
7
|
+
def initialize(tls=true, baseUrl, accesKey, accessSecret, imageIgnoreArray, clairctlBinary, clairctlConfigPath)
|
|
8
|
+
@TLS = tls
|
|
9
|
+
@BASE_URL = baseUrl
|
|
10
|
+
@ACCESS_KEY = accesKey
|
|
11
|
+
@ACCESS_SECRET = accessSecret
|
|
12
|
+
@IMAGE_IGNORE_ARRAY = imageIgnoreArray
|
|
13
|
+
@CLAIRCTL_CONFIG_PATH = clairctlConfigPath
|
|
14
|
+
@CLAIRCTL_BINARY = clairctlBinary
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def getRunningImages
|
|
18
|
+
if @TLS == false
|
|
19
|
+
uri = URI("http://#{@BASE_URL}/v2-beta/containers")
|
|
20
|
+
else
|
|
21
|
+
uri = URI("https://#{@BASE_URL}/v2-beta/containers")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
req = Net::HTTP::Get.new(uri)
|
|
25
|
+
req.basic_auth @ACCESS_KEY, @ACCESS_SECRET
|
|
26
|
+
|
|
27
|
+
res = Net::HTTP.start(uri.hostname, uri.port) {|http|
|
|
28
|
+
http.request(req)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
response_json = JSON.parse(res.body)
|
|
32
|
+
|
|
33
|
+
runningImages = []
|
|
34
|
+
|
|
35
|
+
response_json["data"].each do |con|
|
|
36
|
+
runningImages << con["imageUuid"].sub("docker:", "")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
return runningImages.uniq
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def scanImage(imageName)
|
|
43
|
+
value = %x[#{@CLAIRCTL_BINARY} analyze #{imageName} --config #{@CLAIRCTL_CONFIG_PATH}]
|
|
44
|
+
|
|
45
|
+
parsedValue = value.split("\n")
|
|
46
|
+
vulnerabilities = 0
|
|
47
|
+
|
|
48
|
+
parsedValue.each do |line|
|
|
49
|
+
if line.include? "Analysis"
|
|
50
|
+
parsedValueLine = parsedValue.to_a[4].split(" ").to_a
|
|
51
|
+
vulnerabilities += parsedValueLine[4].to_i
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
return vulnerabilities
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def createReport(imageName)
|
|
59
|
+
value = %x[#{@CLAIRCTL_BINARY} report #{imageName} --config #{@CLAIRCTL_CONFIG_PATH}]
|
|
60
|
+
|
|
61
|
+
return value
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def ignored(imageName)
|
|
65
|
+
skip = false
|
|
66
|
+
@IMAGE_IGNORE_ARRAY.each do |imageIgnore|
|
|
67
|
+
if imageName.include? imageIgnore
|
|
68
|
+
skip = true
|
|
69
|
+
break
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
return skip
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def getFullStatus
|
|
77
|
+
runningImagesArray = []
|
|
78
|
+
self.getRunningImages.each do |scan|
|
|
79
|
+
if self.ignored(scan) == false
|
|
80
|
+
vuns = self.scanImage(scan)
|
|
81
|
+
runningImagesArray << { 'image' => scan, 'vulnerabilities' => vuns }
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
return runningImagesArray
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: clairmon
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- paprickar
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-06-10 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Clairmon is a library which can be used with check_clairmon.rb to monitor
|
|
14
|
+
vulnerabilities in your docker containers
|
|
15
|
+
email:
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- lib/clairmon.rb
|
|
21
|
+
homepage:
|
|
22
|
+
licenses:
|
|
23
|
+
- Apache-2.0
|
|
24
|
+
metadata: {}
|
|
25
|
+
post_install_message:
|
|
26
|
+
rdoc_options: []
|
|
27
|
+
require_paths:
|
|
28
|
+
- lib
|
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
requirements: []
|
|
40
|
+
rubyforge_project:
|
|
41
|
+
rubygems_version: 2.6.10
|
|
42
|
+
signing_key:
|
|
43
|
+
specification_version: 4
|
|
44
|
+
summary: Clairmon a container monitoring library
|
|
45
|
+
test_files: []
|