Commit eed2bcf0 authored by Olivier Gonzalez's avatar Olivier Gonzalez

Fix container scanning parser

Add custom location object and use it to generate location_fingerprint
Remove dead code (metadata_version method)
Fix JSON indent (4 spaces => 2 spaces)
parent c7c63b2f
...@@ -51,26 +51,35 @@ module Gitlab ...@@ -51,26 +51,35 @@ module Gitlab
def format_vulnerability(vulnerability) def format_vulnerability(vulnerability)
{ {
'category' => 'container_scanning', 'category' => 'container_scanning',
'message' => name(vulnerability), 'message' => name(vulnerability),
'description' => vulnerability['description'], 'description' => vulnerability['description'],
'cve' => vulnerability['vulnerability'], 'cve' => vulnerability['vulnerability'],
'severity' => translate_severity(vulnerability['severity']), 'severity' => translate_severity(vulnerability['severity']),
'solution' => solution(vulnerability), 'solution' => solution(vulnerability),
'confidence' => 'Medium', 'confidence' => 'Medium',
'scanner' => { 'id' => 'clair', 'name' => 'Clair' }, 'location' => {
'identifiers' => [ 'operating_system' => vulnerability["namespace"],
{ 'dependency' => {
'type' => 'cve', 'package' => {
'name' => vulnerability['vulnerability'], 'name' => vulnerability["featurename"]
'value' => vulnerability['vulnerability'], },
'url' => vulnerability['link'] 'version' => vulnerability["featureversion"]
} }
], },
'links' => [{ 'url' => vulnerability['link'] }], 'scanner' => { 'id' => 'clair', 'name' => 'Clair' },
'priority' => 'Unknown', 'identifiers' => [
'url' => vulnerability['link'], {
'tool' => 'clair' 'type' => 'cve',
'name' => vulnerability['vulnerability'],
'value' => vulnerability['vulnerability'],
'url' => vulnerability['link']
}
],
'links' => [{ 'url' => vulnerability['link'] }],
'priority' => 'Unknown',
'url' => vulnerability['link'],
'tool' => 'clair'
} }
end end
...@@ -99,14 +108,8 @@ module Gitlab ...@@ -99,14 +108,8 @@ module Gitlab
"#{vulnerability['featurename']} - #{vulnerability['vulnerability']}" "#{vulnerability['featurename']} - #{vulnerability['vulnerability']}"
end end
def metadata_version(vulnerability)
'1.3'
end
def generate_location_fingerprint(location) def generate_location_fingerprint(location)
# Location is irrelevant for Clair vulnerabilities. Digest::SHA1.hexdigest("#{location['operating_system']}:#{location.dig('dependency', 'package', 'name')}")
# SHA1 value for 'clair'
'cb750fa5a7a31c527d5c15388a432c4ba3338457'
end end
end end
end end
......
...@@ -32,7 +32,9 @@ describe Gitlab::Ci::Parsers::Security::ContainerScanning do ...@@ -32,7 +32,9 @@ describe Gitlab::Ci::Parsers::Security::ContainerScanning do
end end
it "generates expected location fingerprint" do it "generates expected location fingerprint" do
expect(report.occurrences.first[:location_fingerprint]).to eq('cb750fa5a7a31c527d5c15388a432c4ba3338457') expected = Digest::SHA1.hexdigest('debian:9:glibc')
expect(report.occurrences.first[:location_fingerprint]).to eq(expected)
end end
it "generates expected metadata_version" do it "generates expected metadata_version" do
...@@ -55,6 +57,15 @@ describe Gitlab::Ci::Parsers::Security::ContainerScanning do ...@@ -55,6 +57,15 @@ describe Gitlab::Ci::Parsers::Security::ContainerScanning do
'url' => 'https://security-tracker.debian.org/tracker/CVE-2017-18269' 'url' => 'https://security-tracker.debian.org/tracker/CVE-2017-18269'
} }
], ],
'location' => {
'operating_system' => 'debian:9',
'dependency' => {
'package' => {
'name' => 'glibc'
},
'version' => '2.24-11+deb9u3'
}
},
'links' => [{ 'url' => 'https://security-tracker.debian.org/tracker/CVE-2017-18269' }], 'links' => [{ 'url' => 'https://security-tracker.debian.org/tracker/CVE-2017-18269' }],
'description' => 'SSE2-optimized memmove implementation problem.', 'description' => 'SSE2-optimized memmove implementation problem.',
'priority' => 'Unknown', 'priority' => 'Unknown',
......
{ {
"image": "registry.gitlab.com/bikebilly/auto-devops-10-6/feature-branch:e7315ba964febb11bac8f5cd6ec433db8a3a1583", "image": "registry.gitlab.com/bikebilly/auto-devops-10-6/feature-branch:e7315ba964febb11bac8f5cd6ec433db8a3a1583",
"unapproved": [ "unapproved": ["CVE-2017-15650"],
"CVE-2017-15650" "vulnerabilities": [
], {
"vulnerabilities": [ "featurename": "musl",
{ "featureversion": "1.1.14-r15",
"featurename": "musl", "vulnerability": "CVE-2017-15650",
"featureversion": "1.1.14-r15", "namespace": "alpine:v3.4",
"vulnerability": "CVE-2017-15650", "description": "",
"namespace": "alpine:v3.4", "link": "https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-15650",
"description": "", "severity": "Medium",
"link": "https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-15650", "fixedby": "1.1.14-r16"
"severity": "Medium", }
"fixedby": "1.1.14-r16" ]
}
]
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment