Skip to content

Fixing bug related rback #5109

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

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion api/externalLink/ExternalLinkRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (impl ExternalLinkRestHandlerImpl) roleCheckHelper(w http.ResponseWriter, r
common.WriteJsonResp(w, errors.New("Invalid request"), nil, http.StatusBadRequest)
return userId, "", fmt.Errorf("invalid request query param appId = %s", appId)
}
object := impl.enforcerUtil.GetAppRBACNameByAppId(id)
object, _ := impl.enforcerUtil.GetAppRBACNameByAppId(id)
if ok := impl.enforcer.Enforce(token, casbin.ResourceApplications, action, object); !ok {
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
return userId, "", fmt.Errorf("unauthorized error")
Expand Down
66 changes: 33 additions & 33 deletions api/restHandler/ConfigMapRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ func (handler ConfigMapRestHandlerImpl) CMGlobalAddUpdate(w http.ResponseWriter,

//RBAC START
token := r.Header.Get("token")
object := handler.enforcerUtil.GetAppRBACNameByAppId(configMapRequest.AppId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionCreate)
object, appType := handler.enforcerUtil.GetAppRBACNameByAppId(configMapRequest.AppId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionCreate, appType)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
Expand Down Expand Up @@ -148,8 +148,8 @@ func (handler ConfigMapRestHandlerImpl) CMEnvironmentAddUpdate(w http.ResponseWr

//RBAC START
token := r.Header.Get("token")
object := handler.enforcerUtil.GetAppRBACNameByAppId(configMapRequest.AppId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionCreate)
object, appType := handler.enforcerUtil.GetAppRBACNameByAppId(configMapRequest.AppId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionCreate, appType)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
Expand Down Expand Up @@ -189,8 +189,8 @@ func (handler ConfigMapRestHandlerImpl) CMGlobalFetch(w http.ResponseWriter, r *

//RBAC START
token := r.Header.Get("token")
object := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionGet)
object, appType := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionGet, appType)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
Expand Down Expand Up @@ -226,8 +226,8 @@ func (handler ConfigMapRestHandlerImpl) CMGlobalFetchForEdit(w http.ResponseWrit
return
}
token := r.Header.Get("token")
object := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionGet)
object, appType := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionGet, appType)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
Expand Down Expand Up @@ -269,8 +269,8 @@ func (handler ConfigMapRestHandlerImpl) CMEnvironmentFetchForEdit(w http.Respons
return
}
token := r.Header.Get("token")
object := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionGet)
object, appType := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionGet, appType)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
Expand Down Expand Up @@ -316,8 +316,8 @@ func (handler ConfigMapRestHandlerImpl) CMEnvironmentFetch(w http.ResponseWriter

//RBAC START
token := r.Header.Get("token")
object := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionGet)
object, appType := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionGet, appType)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
Expand Down Expand Up @@ -353,8 +353,8 @@ func (handler ConfigMapRestHandlerImpl) CSGlobalAddUpdate(w http.ResponseWriter,

//RBAC START
token := r.Header.Get("token")
object := handler.enforcerUtil.GetAppRBACNameByAppId(configMapRequest.AppId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionCreate)
object, appType := handler.enforcerUtil.GetAppRBACNameByAppId(configMapRequest.AppId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionCreate, appType)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
Expand Down Expand Up @@ -390,8 +390,8 @@ func (handler ConfigMapRestHandlerImpl) CSEnvironmentAddUpdate(w http.ResponseWr

//RBAC START
token := r.Header.Get("token")
object := handler.enforcerUtil.GetAppRBACNameByAppId(configMapRequest.AppId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionCreate)
object, appType := handler.enforcerUtil.GetAppRBACNameByAppId(configMapRequest.AppId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionCreate, appType)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
Expand Down Expand Up @@ -431,8 +431,8 @@ func (handler ConfigMapRestHandlerImpl) CSGlobalFetch(w http.ResponseWriter, r *

//RBAC START
token := r.Header.Get("token")
object := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionGet)
object, appType := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionGet, appType)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
return
Expand Down Expand Up @@ -470,8 +470,8 @@ func (handler ConfigMapRestHandlerImpl) CSEnvironmentFetch(w http.ResponseWriter

//RBAC START
token := r.Header.Get("token")
object := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionGet)
object, appType := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionGet, appType)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
return
Expand Down Expand Up @@ -511,8 +511,8 @@ func (handler ConfigMapRestHandlerImpl) CMGlobalDelete(w http.ResponseWriter, r

//RBAC START
token := r.Header.Get("token")
object := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionDelete)
object, appType := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionDelete, appType)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
return
Expand Down Expand Up @@ -558,8 +558,8 @@ func (handler ConfigMapRestHandlerImpl) CMEnvironmentDelete(w http.ResponseWrite

//RBAC START
token := r.Header.Get("token")
object := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionDelete)
object, appType := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionDelete, appType)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
return
Expand Down Expand Up @@ -607,8 +607,8 @@ func (handler ConfigMapRestHandlerImpl) CSGlobalDelete(w http.ResponseWriter, r

//RBAC START
token := r.Header.Get("token")
object := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionDelete)
object, appType := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionDelete, appType)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
return
Expand Down Expand Up @@ -654,8 +654,8 @@ func (handler ConfigMapRestHandlerImpl) CSEnvironmentDelete(w http.ResponseWrite

//RBAC START
token := r.Header.Get("token")
object := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionDelete)
object, appType := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionDelete, appType)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
return
Expand Down Expand Up @@ -703,8 +703,8 @@ func (handler ConfigMapRestHandlerImpl) CSGlobalFetchForEdit(w http.ResponseWrit

//RBAC START
token := r.Header.Get("token")
object := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionUpdate)
object, appType := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionUpdate, appType)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
return
Expand Down Expand Up @@ -750,8 +750,8 @@ func (handler ConfigMapRestHandlerImpl) CSEnvironmentFetchForEdit(w http.Respons

//RBAC START
token := r.Header.Get("token")
object := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionUpdate)
object, appType := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionUpdate, appType)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
return
Expand Down Expand Up @@ -905,7 +905,7 @@ func (handler ConfigMapRestHandlerImpl) GetEnvironmentsForJob(w http.ResponseWri
}
//AUTH - check from casbin db
token := r.Header.Get("token")
object := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
object, _ := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
if ok := handler.enforcer.Enforce(token, casbin.ResourceJobs, casbin.ActionGet, object); !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
Expand Down
2 changes: 1 addition & 1 deletion api/restHandler/CoreAppRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (handler CoreAppRestHandlerImpl) GetAppAllDetail(w http.ResponseWriter, r *

//rbac implementation for app (user should be admin)
token := r.Header.Get("token")
object := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
object, _ := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
if ok := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionUpdate, object); !ok {
handler.logger.Errorw("Unauthorized User for app update action", "err", err, "appId", appId)
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusForbidden)
Expand Down
20 changes: 10 additions & 10 deletions api/restHandler/DeploymentGroupRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (impl *DeploymentGroupRestHandlerImpl) CreateDeploymentGroup(w http.Respons
// RBAC enforcer applying
token := r.Header.Get("token")
for _, item := range bean.AppIds {
resourceName := impl.enforcerUtil.GetAppRBACNameByAppId(item)
resourceName, _ := impl.enforcerUtil.GetAppRBACNameByAppId(item)
if ok := impl.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionCreate, resourceName); !ok {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusForbidden)
return
Expand Down Expand Up @@ -133,7 +133,7 @@ func (impl *DeploymentGroupRestHandlerImpl) FetchParentCiForDG(w http.ResponseWr
// RBAC filter CI List
finalResp := make([]*deploymentGroup.CiPipelineResponseForDG, 0)
for _, item := range resp {
resourceName := impl.enforcerUtil.GetTeamRBACByCiPipelineId(item.CiPipelineId)
resourceName, _ := impl.enforcerUtil.GetTeamRBACByCiPipelineId(item.CiPipelineId)
if ok := impl.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionGet, resourceName); ok {
finalResp = append(finalResp, item)
}
Expand All @@ -160,7 +160,7 @@ func (impl *DeploymentGroupRestHandlerImpl) FetchEnvApplicationsForDG(w http.Res

// RBAC enforcer applying
token := r.Header.Get("token")
resourceName := impl.enforcerUtil.GetTeamRBACByCiPipelineId(ciPipelineId)
resourceName, _ := impl.enforcerUtil.GetTeamRBACByCiPipelineId(ciPipelineId)
if ok := impl.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionGet, resourceName); !ok {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusForbidden)
return
Expand All @@ -178,7 +178,7 @@ func (impl *DeploymentGroupRestHandlerImpl) FetchEnvApplicationsForDG(w http.Res
if ok := impl.enforcer.Enforce(token, casbin.ResourceGlobalEnvironment, casbin.ActionGet, item.EnvironmentIdentifier); ok {
passCount := 0
for _, app := range item.Apps {
resourceName := impl.enforcerUtil.GetAppRBACNameByAppId(app.Id)
resourceName, _ := impl.enforcerUtil.GetAppRBACNameByAppId(app.Id)
if ok := impl.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionGet, resourceName); ok {
passCount = passCount + 1
}
Expand Down Expand Up @@ -211,7 +211,7 @@ func (impl *DeploymentGroupRestHandlerImpl) FetchAllDeploymentGroups(w http.Resp
finalResp := make([]deploymentGroup.DeploymentGroupDTO, 0)
for _, item := range resp {
pass := 0
resourceName := impl.enforcerUtil.GetTeamRBACByCiPipelineId(item.CiPipelineId)
resourceName, _ := impl.enforcerUtil.GetTeamRBACByCiPipelineId(item.CiPipelineId)
if ok := impl.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionGet, resourceName); ok {
pass = 1
}
Expand Down Expand Up @@ -252,7 +252,7 @@ func (impl *DeploymentGroupRestHandlerImpl) DeleteDeploymentGroup(w http.Respons
}

// RBAC enforcer applying
resourceName := impl.enforcerUtil.GetTeamRBACByCiPipelineId(dg.CiPipelineId)
resourceName, _ := impl.enforcerUtil.GetTeamRBACByCiPipelineId(dg.CiPipelineId)
if ok := impl.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionDelete, resourceName); !ok {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusForbidden)
return
Expand Down Expand Up @@ -294,7 +294,7 @@ func (impl *DeploymentGroupRestHandlerImpl) TriggerReleaseForDeploymentGroup(w h

token := r.Header.Get("token")
// RBAC enforcer applying
object := impl.enforcerUtil.GetTeamRBACByCiPipelineId(dg.CiPipelineId)
object, _ := impl.enforcerUtil.GetTeamRBACByCiPipelineId(dg.CiPipelineId)
if ok := impl.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionTrigger, object); !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
Expand Down Expand Up @@ -340,7 +340,7 @@ func (impl *DeploymentGroupRestHandlerImpl) UpdateDeploymentGroup(w http.Respons

// RBAC enforcer applying
token := r.Header.Get("token")
resourceName := impl.enforcerUtil.GetTeamRBACByCiPipelineId(bean.CiPipelineId)
resourceName, _ := impl.enforcerUtil.GetTeamRBACByCiPipelineId(bean.CiPipelineId)
if ok := impl.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionUpdate, resourceName); !ok {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusForbidden)
return
Expand Down Expand Up @@ -373,7 +373,7 @@ func (impl *DeploymentGroupRestHandlerImpl) GetArtifactsByCiPipeline(w http.Resp
}
// RBAC enforcer applying
token := r.Header.Get("token")
resourceName := impl.enforcerUtil.GetTeamRBACByCiPipelineId(dg.CiPipelineId)
resourceName, _ := impl.enforcerUtil.GetTeamRBACByCiPipelineId(dg.CiPipelineId)
if ok := impl.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionGet, resourceName); !ok {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusForbidden)
return
Expand Down Expand Up @@ -406,7 +406,7 @@ func (impl *DeploymentGroupRestHandlerImpl) GetDeploymentGroupById(w http.Respon
}
// RBAC enforcer applying
token := r.Header.Get("token")
resourceName := impl.enforcerUtil.GetTeamRBACByCiPipelineId(dg.CiPipelineId)
resourceName, _ := impl.enforcerUtil.GetTeamRBACByCiPipelineId(dg.CiPipelineId)
if ok := impl.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionGet, resourceName); !ok {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusForbidden)
return
Expand Down
6 changes: 3 additions & 3 deletions api/restHandler/GlobalPluginRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (handler *GlobalPluginRestHandlerImpl) GetAllGlobalVariables(w http.Respons
//on atleast one app & we can't check this without iterating through every app
//TODO: update plugin as a resource in casbin and make rbac independent of appId
resourceName := handler.enforcerUtil.GetAppRBACName(app.AppName)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, resourceName, casbin.ActionCreate)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, resourceName, casbin.ActionCreate, app.AppType)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
Expand Down Expand Up @@ -183,7 +183,7 @@ func (handler *GlobalPluginRestHandlerImpl) ListAllPlugins(w http.ResponseWriter
//on atleast one app & we can't check this without iterating through every app
//TODO: update plugin as a resource in casbin and make rbac independent of appId
resourceName := handler.enforcerUtil.GetAppRBACName(app.AppName)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, resourceName, casbin.ActionCreate)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, resourceName, casbin.ActionCreate, app.AppType)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
Expand Down Expand Up @@ -217,7 +217,7 @@ func (handler *GlobalPluginRestHandlerImpl) GetPluginDetailById(w http.ResponseW
//on atleast one app & we can't check this without iterating through every app
//TODO: update plugin as a resource in casbin and make rbac independent of appId
resourceName := handler.enforcerUtil.GetAppRBACName(app.AppName)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, resourceName, casbin.ActionCreate)
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, resourceName, casbin.ActionCreate, app.AppType)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
Expand Down
Loading
Loading