Variables from settings are not overwritten by PEP if a template is included.
Summary
CI/CD variables from group or project settings are not overwritten by pipeline execution policy if a templates is included.
For example with this CI config as the pipeline execution policy:
# policy-ci.yml
include:
- template: Jobs/SAST.gitlab-ci.yml
variables:
SAST_EXCLUDED_ANALYZERS: "none"
I expected it shouldn't be possible to overwrite the SAST_EXCLUDED_ANALYZERS variable via project settings but it was still possible. If the variable is used in a pipeline execution job directly, without using the template. It has the expected value of none.
Steps to reproduce
- Create a group
- Create a project in the group
- Add a simple
.groovyfile.// example.groovy class Example { static void main(String[] args) { println('Hello World'); } } - Create another project in the group.
- Add a policy CI/CD config file to the project.
# policy-ci.yml include: - template: Jobs/SAST.gitlab-ci.yml - Go back to the group.
- On the project's left sidebar, select Security & Compliance and Policies.
- Select New Policy
- Select Pipeline execution policy
- Choose a name for the policy
- In the Actions section, select
Overrideand select the project andpolicy-ci.ymlfile you created in step 5. - Select Update via Merge Request.
- Merge the MR.
- Go back to the first project and start a pipeline.
- The pipeline should contain a spotbugs-sast job.
- Go to Settings -> CI/CD and select Variables
- Select add variable and use
SAST_EXCLUDED_ANALYZERSas Key andspotbugsas Value. - Select Add variable to save the variable.
- Run a new pipeline.
- This time, the pipeline should not contain a spotbugs-sast job.
- Go to the security policy project and edit the
policy-ci.ymlfile to overwrite the project variable:# policy-ci.yml include: - template: Jobs/SAST.gitlab-ci.yml variables: SAST_EXCLUDED_ANALYZERS: "none" - Go back to the first project and start a new pipeline. The pipeline still not contains a spotbugs-sast job, but it should because
SAST_EXCLUDED_ANALYZERSshould be overwritten by the policy.
Example Project
https://gitlab.com/gitlab-org/govern/security-policies/andys-test-group/example-issue-479315/test/
Possible fixes
Edited by Andy Schoenen