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

fix: Enforce policy checks for overridden apply reqs #3960

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions server/core/config/valid/global_cfg.go
Expand Up @@ -319,6 +319,11 @@ func (g GlobalCfg) MergeProjectCfg(log logging.SimpleLogging, repoID string, pro
if proj.ApplyRequirements != nil {
log.Debug("overriding server-defined %s with repo settings: [%s]", ApplyRequirementsKey, strings.Join(proj.ApplyRequirements, ","))
applyReqs = proj.ApplyRequirements

// Preserve policies_passed req if policy check is enabled
if policyCheck {
applyReqs = append(applyReqs, PoliciesPassedCommandReq)
}
}
case ImportRequirementsKey:
if proj.ImportRequirements != nil {
Expand Down
63 changes: 63 additions & 0 deletions server/core/config/valid/global_cfg_test.go
Expand Up @@ -920,6 +920,69 @@ repos:
CustomPolicyCheck: false,
},
},
"repo-side apply reqs should include non-overrideable 'policies_passed' req when overridden and policies enabled": {
gCfg: `
repos:
- id: /.*/
allowed_overrides: [apply_requirements]
apply_requirements: [approved]
policy_check: true
`,
repoID: "github.com/owner/repo",
proj: valid.Project{
Dir: ".",
Workspace: "default",
PlanRequirements: []string{},
ApplyRequirements: []string{"mergeable"},
ImportRequirements: []string{},
},
repoWorkflows: nil,
exp: valid.MergedProjectCfg{
PlanRequirements: []string{},
ApplyRequirements: []string{"mergeable", "policies_passed"},
ImportRequirements: []string{},
Workflow: defaultWorkflow,
RepoRelDir: ".",
Workspace: "default",
Name: "",
AutoplanEnabled: false,
PolicySets: emptyPolicySets,
RepoLocking: true,
CustomPolicyCheck: false,
PolicyCheck: true,
},
},
"repo-side apply reqs should not include non-overrideable 'policies_passed' req when overridden and policies disabled": {
gCfg: `
repos:
- id: /.*/
allowed_overrides: [apply_requirements]
apply_requirements: [approved]
`,
repoID: "github.com/owner/repo",
proj: valid.Project{
Dir: ".",
Workspace: "default",
PlanRequirements: []string{},
ApplyRequirements: []string{"mergeable"},
ImportRequirements: []string{},
},
repoWorkflows: nil,
exp: valid.MergedProjectCfg{
PlanRequirements: []string{},
ApplyRequirements: []string{"mergeable"},
ImportRequirements: []string{},
Workflow: defaultWorkflow,
RepoRelDir: ".",
Workspace: "default",
Name: "",
AutoplanEnabled: false,
PolicySets: emptyPolicySets,
RepoLocking: true,
CustomPolicyCheck: false,
PolicyCheck: false,
},
},
"repo-side import reqs win out if allowed": {
gCfg: `
repos:
Expand Down
2 changes: 1 addition & 1 deletion server/events/project_command_builder_internal_test.go
Expand Up @@ -1060,7 +1060,7 @@ workflows:
Pull: pull,
ProjectName: "",
PlanRequirements: []string{"policies_passed"},
ApplyRequirements: []string{},
ApplyRequirements: []string{"policies_passed"},
ImportRequirements: []string{"policies_passed"},
RepoConfigVersion: 3,
RePlanCmd: "atlantis plan -d project1 -w myworkspace -- flag",
Expand Down