Skip to content

Commit 79f700a

Browse files
feat(rbac): gate CI pipeline add/delete via patch on create/deletePipeline
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 6ca272e commit 79f700a

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

‎api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,27 @@ func (handler *PipelineConfigRestHandlerImpl) PatchCiPipelines(w http.ResponseWr
405405
return
406406
}
407407

408-
haveCiPatchAccess := handler.checkCiPatchAccess(token, resourceName, cdPipelines)
409-
if !haveCiPatchAccess {
410-
haveCiPatchAccess = handler.enforcer.Enforce(token, casbin.ResourceJobs, casbin.ActionCreate, resourceName) && handler.enforcer.Enforce(token, casbin.ResourceWorkflow, casbin.ActionCreate, workflowResourceName)
408+
// Pipeline lifecycle (add/delete a CI pipeline) is gated by the dedicated lifecycle actions,
409+
// independent of config/branch editing which keeps its existing access rules. Switch-CI is a
410+
// creation flow and is treated as create. The jobs fallback is unchanged for all arms.
411+
var haveCiPatchAccess bool
412+
switch {
413+
case patchRequest.Action == bean.CREATE || patchRequest.IsSwitchCiPipelineRequest():
414+
haveCiPatchAccess = handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionCreatePipeline, resourceName)
415+
if !haveCiPatchAccess {
416+
haveCiPatchAccess = handler.enforcer.Enforce(token, casbin.ResourceJobs, casbin.ActionCreate, resourceName) && handler.enforcer.Enforce(token, casbin.ResourceWorkflow, casbin.ActionCreate, workflowResourceName)
417+
}
418+
case patchRequest.Action == bean.DELETE:
419+
haveCiPatchAccess = handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionDeletePipeline, resourceName)
420+
if !haveCiPatchAccess {
421+
haveCiPatchAccess = handler.enforcer.Enforce(token, casbin.ResourceJobs, casbin.ActionCreate, resourceName) && handler.enforcer.Enforce(token, casbin.ResourceWorkflow, casbin.ActionCreate, workflowResourceName)
422+
}
423+
default:
424+
// UPDATE_PIPELINE / UPDATE_SOURCE: config/branch edit — existing access rules unchanged
425+
haveCiPatchAccess = handler.checkCiPatchAccess(token, resourceName, cdPipelines)
426+
if !haveCiPatchAccess {
427+
haveCiPatchAccess = handler.enforcer.Enforce(token, casbin.ResourceJobs, casbin.ActionCreate, resourceName) && handler.enforcer.Enforce(token, casbin.ResourceWorkflow, casbin.ActionCreate, workflowResourceName)
428+
}
411429
}
412430
if !haveCiPatchAccess {
413431
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)

0 commit comments

Comments
 (0)