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

Ingress Urls User level access Issue #2659

Merged
merged 8 commits into from
Nov 19, 2022
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions api/restHandler/AppListingRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,20 @@ func (handler AppListingRestHandlerImpl) GetHostUrlsByBatch(w http.ResponseWrite
common.WriteJsonResp(w, fmt.Errorf("only one of the appId or installedAppId should be valid appId: %s installedAppId: %s", appIdParam, installedAppIdParam), nil, http.StatusBadRequest)
return
}
token := r.Header.Get("token")
if appIdParam != "" {
appId, err := strconv.Atoi(appIdParam)
if err != nil {
handler.logger.Errorw("error in parsing appId from request body", "appId", appIdParam, "err", err)
common.WriteJsonResp(w, fmt.Errorf("error in parsing appId : %s must be integer", envIdParam), nil, http.StatusBadRequest)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use appIdParam instead of envIdParam

return
}
object := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
if ok := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionGet, object); !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
return
}
}
var appDetail bean.AppDetailContainer
var appId, envId int
envId, err := strconv.Atoi(envIdParam)
Expand All @@ -595,7 +609,7 @@ func (handler AppListingRestHandlerImpl) GetHostUrlsByBatch(w http.ResponseWrite
common.WriteJsonResp(w, fmt.Errorf("error in parsing envId : %s must be integer", envIdParam), nil, http.StatusBadRequest)
return
}
appDetail, err = handler.getAppDetails(appIdParam, installedAppIdParam, envId)
appDetail, err, appId = handler.getAppDetails(appIdParam, installedAppIdParam, envId)
if err != nil {
handler.logger.Errorw("error occurred while getting app details", "appId", appIdParam, "installedAppId", installedAppIdParam, "envId", envId)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
Expand All @@ -610,11 +624,19 @@ func (handler AppListingRestHandlerImpl) GetHostUrlsByBatch(w http.ResponseWrite
return
}
//check user authorization for this app
token := r.Header.Get("token")
object := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
if ok := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionGet, object); !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
return
if installedAppIdParam != "" {
object, object2 := handler.enforcerUtil.GetHelmObjectByAppNameAndEnvId(appDetail.AppName, appDetail.EnvironmentId)
ok := handler.enforcer.Enforce(token, casbin.ResourceHelmApp, casbin.ActionGet, object) || handler.enforcer.Enforce(token, casbin.ResourceHelmApp, casbin.ActionGet, object2)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
return
}
} else {
object := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still need to check again??

if ok := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionGet, object); !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
return
}
}

if installedAppIdParam != "" {
Expand Down Expand Up @@ -649,23 +671,25 @@ func (handler AppListingRestHandlerImpl) GetHostUrlsByBatch(w http.ResponseWrite
common.WriteJsonResp(w, nil, result, http.StatusOK)
}

func (handler AppListingRestHandlerImpl) getAppDetails(appIdParam, installedAppIdParam string, envId int) (bean.AppDetailContainer, error) {
func (handler AppListingRestHandlerImpl) getAppDetails(appIdParam, installedAppIdParam string, envId int) (bean.AppDetailContainer, error, int) {
var appDetail bean.AppDetailContainer
if appIdParam != "" {
appId, err := strconv.Atoi(appIdParam)
if err != nil {
handler.logger.Errorw("error in parsing appId from request body", "appId", appIdParam, "err", err)
return appDetail, err
return appDetail, err, appId
}
return handler.appListingService.FetchAppDetails(appId, envId)
appDetail, err = handler.appListingService.FetchAppDetails(appId, envId)
return appDetail, err, appId
}

appId, err := strconv.Atoi(installedAppIdParam)
if err != nil {
handler.logger.Errorw("error in parsing installedAppId from request body", "installedAppId", installedAppIdParam, "err", err)
return appDetail, err
return appDetail, err, appId
}
return handler.installedAppService.FindAppDetailsForAppstoreApplication(appId, envId)
appDetail, err = handler.installedAppService.FindAppDetailsForAppstoreApplication(appId, envId)
return appDetail, err, appId
}

func (handler AppListingRestHandlerImpl) fetchResourceTree(w http.ResponseWriter, r *http.Request, appId int, envId int, appDetail bean.AppDetailContainer) bean.AppDetailContainer {
Expand Down