Skip to content
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

GitLab CI Trusted Publisher Docs Are Misleading in Regards to Workflow File Path #15897

Closed
crgwbr opened this issue May 2, 2024 · 2 comments · Fixed by #15921
Closed

GitLab CI Trusted Publisher Docs Are Misleading in Regards to Workflow File Path #15897

crgwbr opened this issue May 2, 2024 · 2 comments · Fixed by #15921

Comments

@crgwbr
Copy link

crgwbr commented May 2, 2024

The trusted publisher docs describe the workflow file path field for Gitlab as follows:

The file path of the publishing workflow, relative to the project's root. This file should exist in the project configured above (external workflows are not supported).

In the security considerations page, the docs add:

The claims defined in an OIDC token are bound to the workflow, meaning that a workflow defined at foo.yml in org/repo cannot impersonate a workflow defined at bar.yml in org/repo.
[…]
Trust the correct workflow: you shouldn't trust every workflow to upload to PyPI; instead, you should isolate responsibility to the smallest (and least-privileged) possible separate workflow. We recommend naming this workflow release.yml.

This makes it seem like the workflow file path field should be set to a the YML file that's included from the top-level .gitlab-ci.yml file. For example, if a project had .gitlab-ci.yml as the top-level CI config, and from that file included ci/release.yml, you would think that workflow file path should be set to ci/release.yml.

However, this isn't the case. The warehouse code compares workflow file path to the path in the ci_config_ref_uri field of the Gitlab CI JWT claim. This field is defined in Gitlab's documentation as follows:

ci_config_ref_uri: The ref path to the top-level pipeline definition, for example, gitlab.example.com/my-group/my-project//.gitlab-ci.yml@refs/heads/main. Introduced in GitLab 16.2. This claim is null unless the pipeline definition is located in the same project.

Thus, since the claim contains the path to the top-level pipeline definition, even if all the release steps are contained in the ci/release.yml, the workflow file path in PyPI must be set to .gitlab-ci.yml to actually work.

@crgwbr crgwbr added bug 🐛 requires triaging maintainers need to do initial inspection of issue labels May 2, 2024
@woodruffw
Copy link
Member

woodruffw commented May 5, 2024

Thanks for the report @crgwbr!

Yeah, this looks like a mistake in our documentation: ci_config_ref_uri is always going to reference the top-level CI definition (which is typically .gitlab-ci.yml, but can be configured to something different).

I think the docs there were probably copied over from GitHub Actions and its concept of multiple independent workflows in individual files. For GitLab, we should probably just suggest .gitlab-ci.yml as the default workflow path and remove the "minimal scoping" suggestion (since AFAIK GitLab is entirely YAML inclusion based and doesn't have the ability to separate permissions by include).

CC @facutuesca

@woodruffw woodruffw added documentation and removed requires triaging maintainers need to do initial inspection of issue labels May 5, 2024
crgwbr added a commit to crgwbr/asymmetric-jwt-auth that referenced this issue May 6, 2024
@facutuesca
Copy link
Contributor

PR open here: #15921

@di di closed this as completed in #15921 May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants