-
Notifications
You must be signed in to change notification settings - Fork 516
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
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
23ff15d
urls hot fix
gireesh-naidu 09308fe
rbac added for installed apps
gireesh-naidu 83e5aee
Merge branch 'urls_hot_fix' into demo_latest
gireesh-naidu b669442
Merge remote-tracking branch 'origin/urls_hot_fix' into urls_hot_fix
gireesh-naidu 5041d7b
added rbac check before fetching appdetails
gireesh-naidu 05c8e21
nil check fix
gireesh-naidu 000ffbf
nil fix
gireesh-naidu 1752740
added review checks
gireesh-naidu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
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) | ||
|
@@ -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) | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 != "" { | ||
|
@@ -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 { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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