Fix bug in Ci::Pipeline#protected_ref? method
Why this MR ?
We have two related open issues caused by the same root cause that needs to be fixed. The values for CI_COMMIT_REF_PROTECTED predefined CI variable and value for ref_protected claim in CI JWT ID Token are wrongly set as false in one scenario when it is supposed to be true - i.e. in the scenario where a pipeline is run for an MR whose source branch is protected
- Incorrect value for CI_COMMIT_REF_PROTECTED predefined CI variable Issue
- Incorrect value for ref_protected claim in CI JWT ID Token
What does this MR do ?
This MR fixes the bug by implementing this proposal to Ci::Pipeline#protected_ref? method
-
Check if the source_ref_path of the pipeline is protected instead of the git_ref path of the pipeline
-
Note that the values of source_ref_path and git_ref is the same EXCEPT for the case of Merge Requests. In the case of Merge Requests, it returns the
refof thesource branchof the Merge Request - Refer here -
For easy review, I have written down the easily comparable simplified final logic versions of the methods -
git_refmethod that we are replacing andsource_ref_pathmethod which we are using instead below and we can see that the change is only for merge requests where we usesource_branchinstead ofref
def git_ref
if merge_request?
Gitlab::Git::BRANCH_REF_PREFIX + ref.to_s
elsif branch?
Gitlab::Git::BRANCH_REF_PREFIX + ref.to_s
elsif tag?
Gitlab::Git::TAG_REF_PREFIX + ref.to_s
end
end
def source_ref_path
if merge_request?
Gitlab::Git::BRANCH_REF_PREFIX + merge_request.source_branch
elsif branch?
Gitlab::Git::BRANCH_REF_PREFIX + ref.to_s
elsif tag?
Gitlab::Git::TAG_REF_PREFIX + ref.to_s
end
end
- For a pipeline that is run for a Merge Request, The
reffollows a special format:refs/merge-requests/X/head, where X is the merge request ID whereasmerge_request.source_branchis the name of thesource_branchof the merge request which is marked asprotected
References
Screenshots
| Before | After |
|---|---|
![]() |
![]() |
![]() |
![]() |




