Scan packages from Artifact Central

  • Tier: Ultimate
  • Offering: GitLab.com
  • Status: Beta

Scan the npm and Maven packages your projects install from Artifact Central with dependency scanning. Dependency scanning reads your lockfile or dependency graph, not the registry. Packages from Artifact Central are scanned the same way as packages from any other registry.

After dependency scanning runs on the default branch, continuous vulnerability scanning checks the same packages again each time GitLab publishes a new security or malware advisory. You don’t need to run a new pipeline.

Findings appear in the project’s vulnerability report and dependency list.

Prerequisites

  • An npm or Maven remote or virtual repository that your project installs from.
  • The Developer role or higher in the project.

In the examples on this page, replace the following placeholders:

  • <registry_host>: Enter the hostname from your repository’s setup instructions. To find it, go to your repository and select Setup instructions.
  • <registry_handle>: Enter your organization’s registry handle.
  • <repository_name>: Enter the name of your npm or Maven repository.

Scan npm packages

Dependency scanning reads package-lock.json, pnpm-lock.yaml, or yarn.lock. It does not contact Artifact Central, so the scan job does not need a token.

To scan npm packages:

  1. Commit your lockfile to the repository.

  2. In .gitlab-ci.yml, include the dependency scanning template:

    yaml
    include:
      - template: Jobs/Dependency-Scanning.v2.gitlab-ci.yml

Create the lockfile in a pipeline

If you don’t commit a lockfile, create it in a job that installs from Artifact Central, and save it as an artifact for the scan job.

Prerequisites:

  • The Artifact Viewer role or higher on the repository for the user who runs the pipeline.
  • A hidden job named .artifact-registry that exchanges CI_JOB_TOKEN for an Artifact Central token. For more information, see exchange the job token.
  • A project in your Artifact Central organization.

To create the lockfile in a pipeline:

  • In .gitlab-ci.yml, add a job in a stage before test that installs the packages and saves the lockfile:

    yaml
    stages:
      - build
      - test
    
    include:
      - template: Jobs/Dependency-Scanning.v2.gitlab-ci.yml
    
    npm-install:
      extends: .artifact-registry
      stage: build
      image: node:22
      script:
        - |
          printf '%s\n' \
            'registry=https://<registry_host>/<registry_handle>/npm/<repository_name>/' \
            '//<registry_host>/<registry_handle>/npm/<repository_name>/:_authToken=${AR_TOKEN}' \
            > .npmrc
        - npm install --no-audit --no-fund
      artifacts:
        paths:
          - package-lock.json

Scan Maven packages

Create the dependency graph in a job that installs from Artifact Central, and turn off the automatic Maven resolution job. The resolution job has no Artifact Central token, so it can’t install from your repository.

Prerequisites:

  • The Artifact Viewer role or higher on the repository for the user who runs the pipeline.
  • A hidden job named .artifact-registry that exchanges CI_JOB_TOKEN for an Artifact Central token. For more information, see exchange the job token.
  • A project in your Artifact Central organization.

To scan Maven packages:

  1. Add a settings file to your project, for example ci-settings.xml, that sends every request to your repository:

    xml
    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0">
      <servers>
        <server>
          <id>artifact-central</id>
          <username>gitlab-ci-token</username>
          <password>${env.AR_TOKEN}</password>
        </server>
      </servers>
      <mirrors>
        <mirror>
          <id>artifact-central</id>
          <mirrorOf>*</mirrorOf>
          <url>https://<registry_host>/<registry_handle>/maven/<repository_name></url>
        </mirror>
      </mirrors>
    </settings>
  2. In .gitlab-ci.yml, add a job that creates the dependency graph, and turn off the resolution job:

    yaml
    stages:
      - build
      - test
    
    include:
      - template: Jobs/Dependency-Scanning.v2.gitlab-ci.yml
        inputs:
          disabled_resolution_jobs: "maven"
    
    maven-graph:
      extends: .artifact-registry
      stage: build
      image: maven:3.9-eclipse-temurin-17
      script:
        - mvn -B -ntp -s ci-settings.xml org.apache.maven.plugins:maven-dependency-plugin:3.8.1:tree -DoutputType=json -DoutputFile=maven.graph.json
      artifacts:
        paths:
          - "**/maven.graph.json"

If you already have a build job that installs from Artifact Central, add the mvn dependency:tree command from the example to that job instead, and save **/maven.graph.json as an artifact. The command reuses the packages the build already downloaded.

Known issues

  • Only packages that a pipeline installs are scanned. Packages that are in Artifact Central but that no pipeline uses are not scanned. Scanning in Artifact Central is proposed in issue 629881.
  • Findings are stored in the project that runs the pipeline, not on the package in Artifact Central. Artifact Central does not show scan results.
  • Dependency scanning matches public advisories. Packages that your organization publishes to Artifact Central have none, so they get no findings.
  • Packages installed outside a pipeline, such as on a laptop, are not scanned.