Cannot access composer registry in CI with $CI_JOB_TOKEN authentication

We are using GitLab Enterprise Edition 13.4.3-ee and the composer package registry. Publishing to the registry in a CI step with authentication via $CI_JOB_TOKEN works fine. However composer install on a depending project fails with “Invalid credentials”.

What I have done in the depending project:

Adding the registry to the repositories section with {servername} and {groupId} replaced by the actual values:

"repositories": [
    {
        "type": "composer",
        "url": "https://{servername}/api/v4/group/{groupId}/-/packages/composer/packages.json"
    },
    ...

Add the domain to the config section:

"config": {
    "gitlab-domains": ["{servername}"],
    ...

Add the JobToken in the .gitlab-ci.yaml before the composer install:

before_script:
    - composer config gitlab-token.{servername} $CI_JOB_TOKEN
    - composer install --no-progress -o

Am I missing anything? It works fine if I use a personal Access Token with exactly the same setup.

Same problem here. Did you fin a solution?

No, unfortunately not. I created a dedicated readonly API token instead that I pass to the CI.

If you do something like this:

composer config gitlab-token.gitlab.com gitlab-ci-token ${CI_JOB_TOKEN}

That should be what you need for composer specifically. Some of the others don’t need that username of gitlab-ci-token, but composer packages in gitlab do. You may also have to update your token access at Project/Settings/CI/CD/Token Access.

2 Likes

Try some solution, actually : Authentication on the composer download endpoint breaks user setups (#360644) · Issues · GitLab.org / GitLab · GitLab works

Same here … looks like there’s still no solution. :confused: