Skip to content

Add starboard_vulnerability endpoint

Brian Williams requested to merge bwill/starboard-vulnerability-api into master

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)

  1. Create a new KAS JWT using the rails console:

    JWT.encode({ 'iss' => Gitlab::Kas::JWT_ISSUER }, Gitlab::Kas.secret, 'HS256')
  2. Create a new gitlab project

  3. Create new agent:

    agent = Clusters::Agent.new(project_id: project.id, created_by_user: User.find(1), name: "test-agent")
    agent.save!
  4. 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
  5. 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"
       }
     }'
  6. Vulnerability now exists on your project (not currently visible on vulnerability report due to #339730 (closed)):

    Project.find(id).vulnerabilities

Screenshots

Screen_Shot_2021-08-30_at_1.02.01_PM

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Edited by Brian Williams

Merge request reports