Skip to content

Draft: Add a new vulnerabilities scope to SearchService

What does this MR do and why?

This MR is a proof of concept.

It implements a new scope for vulnerabilities in the SearchService. The new scope is available at global, group, and project level. It is based off Refactor issues search to make calls directly t... (!155516 - merged) which refactors how searches are implemented.

Note: This MR does not include the indexing implementation.

How to add data and test

Create the index manually

curl request
curl --request PUT \
  --url http://localhost:9200/test-vulnerabilities-index \
  --header 'Content-Type: application/json' \
  --data '{
	"settings": {
		"index": {
			"number_of_shards": 2,
			"number_of_replicas": 1
		}
	},
	"mappings": {
		"properties": {
			"id": {
				"type": "keyword",
				"index_options": "docs"
			},
			"type": {
				"type": "keyword"
			},
			"project_id": {
				"type": "integer"
			},
			"title": {
				"type": "text"
			},
			"description": {
				"type": "text"
			}
		}
	}
}'

Index data using client bulk requests

bulk_body = []

Vulnerability.where(project_id: 3).map do |v|
   bulk_body << { create: { _index: 'gitlab-vulnerabilities-test', _id: v.id } }
   bulk_body << { id: v.id, project_id: v.project_id, title: v.title, description: v.description, type: 'vulnerability' }
end

client = Gitlab::Elastic::Helper.default.client
client.bulk(body: bulk_body)

Test with Search service

search_service = ::SearchService.new(User.first, { search: 'cypher', scope: 'vulnerabilities', project_id: 3 })
search_service.search_objects
=> [#<Vulnerability id:61 [vulnerability:gitlab-org/gitlab-shell/61]>,
 #<Vulnerability id:62 [vulnerability:gitlab-org/gitlab-shell/62]>,
 #<Vulnerability id:63 [vulnerability:gitlab-org/gitlab-shell/63]>,
 #<Vulnerability id:64 [vulnerability:gitlab-org/gitlab-shell/64]>,
 #<Vulnerability id:65 [vulnerability:gitlab-org/gitlab-shell/65]>,
 #<Vulnerability id:66 [vulnerability:gitlab-org/gitlab-shell/66]>,
 #<Vulnerability id:67 [vulnerability:gitlab-org/gitlab-shell/67]>,
 #<Vulnerability id:68 [vulnerability:gitlab-org/gitlab-shell/68]>,
 #<Vulnerability id:69 [vulnerability:gitlab-org/gitlab-shell/69]>,
 #<Vulnerability id:70 [vulnerability:gitlab-org/gitlab-shell/70]>,
 #<Vulnerability id:71 [vulnerability:gitlab-org/gitlab-shell/71]>,
 #<Vulnerability id:72 [vulnerability:gitlab-org/gitlab-shell/72]>,
 #<Vulnerability id:73 [vulnerability:gitlab-org/gitlab-shell/73]>,
 #<Vulnerability id:74 [vulnerability:gitlab-org/gitlab-shell/74]>,
 #<Vulnerability id:75 [vulnerability:gitlab-org/gitlab-shell/75]>,
 #<Vulnerability id:76 [vulnerability:gitlab-org/gitlab-shell/76]>,
 #<Vulnerability id:77 [vulnerability:gitlab-org/gitlab-shell/77]>,
 #<Vulnerability id:78 [vulnerability:gitlab-org/gitlab-shell/78]>,
 #<Vulnerability id:79 [vulnerability:gitlab-org/gitlab-shell/79]>,
 #<Vulnerability id:80 [vulnerability:gitlab-org/gitlab-shell/80]>]

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Related to #461874 (closed)

Edited by Terri Chu

Merge request reports

Loading