-
Notifications
You must be signed in to change notification settings - Fork 6
Description
👋 Hi. This is a user error (as in I'm doing this wrong) question, so if there is a prefered different place to ask them please let me know and I'll move this.
Now that PyPI Trusted Publishers should be able to work with GitLab CI/CD @kratsg and myself are interested in using them for publication of tools being built on CERN's EE GitLab instance (https://gitlab.cern.ch/) (currently v16.9.4-ee and so should support id_tokens) as we've been using them with GitHub Actions and enjoying them.
However, though @kratsg has setup the PyPI package https://pypi.org/project/itkdb/ to support trusted publishers coming from GitLab CI/CD attempting to get a debug version of a .gitlab-ci.yml workflow to just get a OIDC token from id and then exchange it for a PyPI API token fails as
stages:
- deploy
variables:
# see https://docs.gitlab.com/ee/ci/caching/#cache-python-dependencies
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
cache:
paths:
- .cache/pip
- venv/
image: python:3.11-bullseye
before_script:
# want to set up a virtualenv to cache
- apt-get update
- apt-get install -y --no-install-recommends git jq
- python -V
- git config --global credential.helper 'cache'
- python -m venv venv
- source venv/bin/activate
- python -m pip install -U pip pipx id
- python -m pipx ensurepath
- python -m pip freeze --local
publish-job:
stage: deploy
id_tokens:
PYPI_ID_TOKEN:
aud: pypi
variables:
OIDC_MINT_TOKEN_URL: "https://pypi.org/_/oidc/mint-token"
script:
# Retrieve the OIDC token from GitLab CI/CD and exchange it for a PyPI API token
- oidc_token=$(python -m id PYPI)
- echo "OIDC MINT TOKEN URL ${OIDC_MINT_TOKEN_URL}"
- response=$(curl -X POST "${OIDC_MINT_TOKEN_URL}" -d "{\"token\":\"${oidc_token}\"}")
- echo "RESPONSE ${response}"
- api_token=$(jq --raw-output '.token' <<< "${response}")
- echo "TEST TOKEN ${api_token}"results in an invalid-payload error.
$ echo "RESPONSE ${response}"
RESPONSE {"errors":[{"code":"invalid-payload","description":"unknown trusted publishing issuer"}],"message":"Token request failed"}
As this error is indicating that python -m id PYPI is failing to retrieve a valid OIDC token in the current setup on CERN's GitLab do you have debugging advice, related to id?
Namespace aside (possibly main problem)
The project lives as an internal project at https://gitlab.cern.ch/atlas-itk/sw/db/itkdb/ so @kratsg selected a namespace of atlas-itk
as trying with the full namespace of atlas-itk/sw/db failed with
Invalid GitLab username of group/subgroup name
cc @henryiii as also somewhat related to scientific-python/cookie#411