Skip to content

Commit 0d07d93

Browse files
authored
feat: adding override-variables policy (#334)
* feat: adding override-variables policy * fix severity and threat
1 parent 0cea8da commit 0d07d93

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

e2e/gitlab.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,9 @@ var testCasesGitLab = []testCase{
6969
path: "data.member.two_factor_authentication_is_disabled_for_an_external_collaborator",
7070
skippedEntity: "legitify-test",
7171
},
72+
{
73+
path: "data.repository.overriding_defined_variables_isnt_restricted",
74+
failedEntity: "failed_repo",
75+
passedEntity: "passed_repo",
76+
},
7277
}

policies/gitlab/repository.rego

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,22 @@ default repository_dismiss_stale_reviews := true
344344
repository_dismiss_stale_reviews := false {
345345
input.approval_configuration.reset_approvals_on_push
346346
}
347+
348+
# METADATA
349+
# scope: rule
350+
# title: The ability to override predefined variables should be limited only to users with at least Maintainer role.
351+
# description: It’s recommended to restrict users with low privileges from overriding predefined variables, as doing so could compromise the security and integrity of the CI/CD pipeline.
352+
# custom:
353+
# remediationSteps:
354+
# - 1. Make sure you have owner or maintainer permissions
355+
# - 2. The remediation is available through the project's API (e.g., 'https://gitlab.com/api/v4/projects/<your-project-ID>')
356+
# - 3. Set the 'restrict_user_defined_variables' attribute to TRUE (this attribute is FALSE by default)
357+
# - 4. When 'restrict_user_defined_variables' is enabled, you can specify which role can override variables. This is done by setting the 'ci_pipeline_variables_minimum_override_role' attribute to one of: owner, maintainer, developer or no_one_allowed.
358+
# - 5. For more information, you can check out gitlab's API documentation: https://docs.gitlab.com/ee/api/projects.html
359+
# severity: LOW
360+
# threat: Allowing overrides of predefined variables can result in unintentional misconfigurations of the CI/CD pipeline or deliberate tampering.
361+
default overriding_defined_variables_isnt_restricted := true
362+
363+
overriding_defined_variables_isnt_restricted := false {
364+
input.restrict_user_defined_variables
365+
}

test/repository_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,3 +751,20 @@ func TestGitlabRepositoryDismissStaleReviews(t *testing.T) {
751751
repositoryTestTemplate(t, name, makeMockData(flag), testedPolicyName, expectFailure, scm_type.GitLab)
752752
}
753753
}
754+
755+
func TestGitlabRepositoryRestrictsOverrideVariables(t *testing.T) {
756+
name := "Restrict Override Of Defined Variables"
757+
testedPolicyName := "overriding_defined_variables_isnt_restricted"
758+
759+
makeMockData := func(flag bool) gitlabcollected.Repository {
760+
return gitlabcollected.Repository{Project: &gitlab2.Project{RestrictUserDefinedVariables: flag}}
761+
}
762+
options := map[bool]bool{
763+
false: true,
764+
true: false,
765+
}
766+
for _, expectFailure := range bools {
767+
flag := options[expectFailure]
768+
repositoryTestTemplate(t, name, makeMockData(flag), testedPolicyName, expectFailure, scm_type.GitLab)
769+
}
770+
}

0 commit comments

Comments
 (0)