Add starboard_vulnerability endpoint
What does this MR do?
For: #330715 (closed)
This MR adds a new internal API endpoint to allow the GitLab Kubernetes agent to create vulnerabilities. This will support the new feature Cluster Image Scanning (Vulnerability Scans against Running Containers) by allowing the Kubernetes agent to sync Starboard vulnerabilities with GitLab.
How to setup and validate locally (strongly suggested)
-
Create a new KAS JWT using the rails console:
JWT.encode({ 'iss' => Gitlab::Kas::JWT_ISSUER }, Gitlab::Kas.secret, 'HS256')
-
Create a new gitlab project
-
Create new agent:
agent = Clusters::Agent.new(project_id: project.id, created_by_user: User.find(1), name: "test-agent") agent.save!
-
Create new agent token and retrieve the value
token = Clusters::AgentToken.new(agent: agent, created_by_user: User.find(1), name: "test-agent-token") token.save! token.token
-
Send the API request:
curl --request PUT --include \ --header "Gitlab-Kas-Api-Request: $KAS_JWT" \ --header "Authorization: Bearer $AGENT_TOKEN" --header "Content-Type: application/json" \ --url "http://localhost:3000/api/v4/internal/kubernetes/modules/starboard_vulnerability" \ --data '{ "vulnerability": { "name": "CVE-123-4567 in libc", "severity": "high", "confidence": "unknown", "location": { "kubernetes_resource": { "namespace": "production", "kind": "deployment", "name": "nginx", "container": "nginx" } }, "identifiers": [ { "type": "cve", "name": "CVE-123-4567", "value": "CVE-123-4567" } ] }, "scanner": { "id": "starboard_trivy", "name": "Trivy (via Starboard Operator)", "vendor": "GitLab" } }'
-
Vulnerability now exists on your project (not currently visible on vulnerability report due to #339730 (closed)):
Project.find(id).vulnerabilities
Screenshots
Does this MR meet the acceptance criteria?
Conformity
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
Edited by Brian Williams