8000 Implement $CI_JOB_TOKEN support in releases by KundaPanda · Pull Request #1098 · python-semantic-release/python-semantic-release · GitHub
[go: up one dir, main page]

Skip to content

Implement $CI_JOB_TOKEN support in releases #1098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

KundaPanda
Copy link

Purpose

Implement support for the CI_JOB_TOKEN variable in Gitlab CI.

CI_JOB_TOKENs can now be used to push to repositories, and using them is both safer and easier.

Rationale

The CI_JOB_TOKEN should only complement the usage of GITLAB_TOKEN and respect its' value when used. When the values of GITLAB_TOKEN and CI_JOB_TOKEN match, or the remote token env name is set to CI_JOB_TOKEN, it is considered to be a job token. When GITLAB_TOKEN is not specified, the CI_JOB_TOKEN's valu 8000 e is used.

How did you test?

I added some parameters to the existing GitLab unit test that checks the usage of the environment variable. I also created an e2e test case that checks various combinations of personal token and job token usage in requests to the GitLab API.

How to Verify

  1. Enable usage of job tokens for pushing in the Gitlab repository configuration
  2. Set the tool.semantic_release.remote.token to { env = "CI_JOB_TOKEN" } or assign export GITLAB_TOKEN = $CI_JOB_TOKEN in a GitLab CI configuration.
  3. Trigger a release/version job in the pipeline

@codejedi365
Copy link
Contributor

@KundaPanda, this is a great contribution as you also included tests and documentation, Thank you! I just want to add a few things and we will get this merged in and released.

@jbnjohnathan
Copy link

Any update on this? From the comments it seemed pretty ready for merge

@codejedi365
Copy link
Contributor

I'll take a look at it again this weekend. It got majorly complicated because it was a bit premature to add this functionality without handling all the variations of GitLab installations.

After digging through GitLab's issue queue, I found that the CI_JOB_TOKEN support was only provided behind a feature flag that was turned off by default. Then I found that the official GitLab (gitlab.com) did not activate this feature flag because of a secondary issue ticket of infinite looping pipelines. This added undo complexity to attempting to determine what error states could happen.

The goal was to support GitLab proper, GitLab on-prem of multiple versions (no feature flag, feature flag disabled, and feature flag enabled). Each circumstance would provide some level of error message to the user of why it's not working otherwise I get a lot of issue tickets about why it isn't working.

@benedikt-bartscher
Copy link

Hi @codejedi365 thanks for trying to implement this properly and support all deployment variants. If you need any testing, we could test this on our gitlab instance or even provide you with a token/user to test it yourself.

After digging through GitLab's issue queue, I found that the CI_JOB_TOKEN support was only provided behind a feature flag that was turned off by default.

Can you refer to those issues/feature flags? In general, CI_JOB_TOKEN should be available in all environments afaik. Is it a specific permission which is missing?

@codejedi365
Copy link
Contributor

Hi @codejedi365 thanks for trying to implement this properly and support all deployment variants. If you need any testing, we could test this on our gitlab instance or even provide you with a token/user to test it yourself.

Wow, why thank you. I'll let you know if I need a testing environment. I do have a separate GitLab instance to test against when I get to that part but I appreciate the gesture.

Can you refer to those issues/feature flags? In general, CI_JOB_TOKEN should be available in all environments afaik. Is it a specific permission which is missing?

The job token has been available for a long time, but the problem has been permissions. It was restricted from writing to the repository. It has specific permissions hardcoded by GitLab. This is unlike GitHub which enabled users to define the permissions of the token per workflow or job. In GitLab v17.2 (see #977), it was provided as a feature flag that admins could enable but it was disabled by default. GitLab.com does not expose feature flag enablement to users and so it is disabled.

Original: https://gitlab.com/gitlab-org/gitlab/-/issues/389060
Roll-out plan: https://gitlab.com/gitlab-org/gitlab/-/issues/468320
Which then Scott Hampton mentions, it can't roll out until https://gitlab.com/gitlab-org/gitlab/-/issues/475705


Oddly enough even as this permission becomes available, previously you could write to the releases endpoint via the API and it will create the associated tag at a given commit sha. The problem is that PSR was not written to support this by the original maintainers. In this circumstance, you also must point the release at an existing commit in the remote which would require --no-commit to be set on PSR. Consequently how do we handle an updating changelog because we can't commit it with each release. I bring this up because GitLab has this issue but so does GitHub if you choose to add additional protections to your default branch. I feel we are in a no-win solution currently for better security and automated releases. Not to mention the importance of limiting subsequent pipelines via GitLab's workflow rules and GitHub's action event triggers which I get too many issues reported about. I digress.

Copy link

It has been 60 days since the last update on this confirmed PR. @python-semantic-release/team can you provide an update on the status of this PR?

@github-actions github-actions bot added the needs-update Needs status update from maintainers label May 19, 2025
@github-actions github-actions bot removed the needs-update Needs status update from maintainers label Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed Prevent from becoming stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support CI_JOB_TOKEN now that Gitlab added the option for it to push to its own repository which will be released in 17.2 (July 18th)
4 participants
0