ARTIFACTORY: Implementing Basic OIDC Integration with GitLab CI/CD for Secure Authentication via REST API

ARTIFACTORY: Implementing Basic OIDC Integration with GitLab CI/CD for Secure Authentication via REST API

Products
Frog_Artifactory
Content Type
Integrations
AuthorFullName__c
Jeremy Leopold
articleNumber
000006431
FirstPublishedDate
2025-04-28T05:52:53Z
lastModifiedDate
2025-04-27
VersionNumber
2
Introduction

This article provides a quick step-by-step guide to integrating Artifactory with GitLab OIDC (OpenID Connect) using the JFrog OIDC Token Exchange REST API.


Configure Artifactory

Here, we use the Generic OIDC provider type with the following values and Identity Mapping Claims JSON, focusing solely on the issuer: 

User-added image 

Configure the Gitlab Pipeline

We create a new Pipeline using the following script in the .gitlab-ci.yml:

before_script:
  - apt-get -qq update
  - apt-get install -y jq

exchange_token:
  stage: build
  id_tokens: # Gitlab Id Tokens and their include claims are documented at      

    # https://docs.gitlab.com/ci/secrets/id_token_authentication/
    FIRST_ID_TOKEN:
      aud: https://gitlab.com
  script:
    - |
      ACCESS_TOKEN=$(curl -XPOST "${JF_CLOUD_URL}/access/api/v1/oidc/token" -H "Content-Type: application/json" -d "{\"grant_type\": \"urn:ietf:params:oauth:grant-type:token-exchange\", \"subject_token_type\":\"urn:ietf:params:oauth:token-type:id_token\", \"subject_token\": \"$FIRST_ID_TOKEN\", \"provider_name\": \"jeremyl-gitlab\"}" | jq -r '.access_token')
      echo "TOKEN=${ACCESS_TOKEN}" > build.env
      cat build.env
      # Use $ACCESS_TOKEN directly in subsequent commands if needed
      curl -XPUT -H "Authorization: Bearer $ACCESS_TOKEN" "${JF_CLOUD_URL}/artifactory/jeremyl-generic/test2.txt" -d "This is content of the test2.txt file deployed from our gitlab-oidc test pipeline"

  artifacts:
    reports: 
      dotenv: build.env
  environment: production
* We bring jq into the environment and then we extract the ACCESS_TOKEN by piping the OIDC exchange response through jq -r '.access_token' .
* JF_CLOUD_URL is a configured Variable pointing to our JFrog Host machine.
* The ACCESS_TOKEN is written to the build.env file, which can then be used as an artifact and passed to subsequent jobs in the pipeline

View the Results

In the pipeline output, we can see the successful token exchange and file deployment: 

User-added image