mirror of
https://github.com/paralus/paralus.git
synced 2026-05-21 07:43:04 +00:00
Merge pull request #118 from RafayLabs/prompt-fixes
changes to support prompt
This commit is contained in:
@@ -9,24 +9,31 @@ import (
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
func GetProjectOrganization(ctx context.Context, db bun.IDB, name string) (string, string, error) {
|
||||
type projectOrg struct {
|
||||
Project string
|
||||
Organization string
|
||||
}
|
||||
var r projectOrg
|
||||
type ProjectOrg struct {
|
||||
Project string
|
||||
Organization string
|
||||
ProjectId string
|
||||
OrganizationId string
|
||||
PartnerId string
|
||||
}
|
||||
|
||||
func GetProjectOrganization(ctx context.Context, db bun.IDB, name string) (ProjectOrg, error) {
|
||||
var r ProjectOrg
|
||||
err := db.NewSelect().Table("authsrv_project").
|
||||
ColumnExpr("authsrv_project.name as project").
|
||||
ColumnExpr("authsrv_organization.name as organization").
|
||||
ColumnExpr("authsrv_project.id as project_id").
|
||||
ColumnExpr("authsrv_organization.id as organization_id").
|
||||
ColumnExpr("authsrv_organization.partner_id as partner_id").
|
||||
Join(`JOIN authsrv_organization ON authsrv_project.organization_id=authsrv_organization.id`).
|
||||
Where("authsrv_project.name = ?", name).
|
||||
Where("authsrv_project.trash = ?", false).
|
||||
Where("authsrv_organization.trash = ?", false).
|
||||
Scan(ctx, &r)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
return r, err
|
||||
}
|
||||
return r.Project, r.Organization, nil
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func GetFileteredProjects(ctx context.Context, db bun.IDB, account, partner, org uuid.UUID) ([]models.Project, error) {
|
||||
|
||||
1
main.go
1
main.go
@@ -585,6 +585,7 @@ func runRPC(wg *sync.WaitGroup, ctx context.Context) {
|
||||
ExcludeRPCMethods: []string{
|
||||
"/rafay.dev.sentry.rpc.Bootstrap/GetBootstrapAgentTemplate",
|
||||
"/rafay.dev.sentry.rpc.Bootstrap/RegisterBootstrapAgent",
|
||||
"/rafay.dev.sentry.rpc.KubeConfig/GetForClusterWebSession", //TODO: enable auth from prompt
|
||||
},
|
||||
ExcludeAuthzMethods: []string{
|
||||
"/rafay.dev.rpc.v3.User/GetUserInfo",
|
||||
|
||||
@@ -49,21 +49,21 @@ func (am *authMiddleware) ServeHTTP(rw http.ResponseWriter, r *http.Request, nex
|
||||
// Auth is primarily done via grpc endpoints, this is only used
|
||||
// for endoints which do not go through grpc As of now, it is just
|
||||
// prompt.
|
||||
var proj string
|
||||
var org string
|
||||
var poResp dao.ProjectOrg
|
||||
|
||||
if strings.HasPrefix(r.URL.String(), "/v2/debug/prompt/project/") {
|
||||
// /v2/debug/prompt/project/:project/cluster/:cluster_name
|
||||
splits := strings.Split(r.URL.String(), "/")
|
||||
if len(splits) > 5 {
|
||||
// we have to fetch the org info for casbin
|
||||
proj, org, err := dao.GetProjectOrganization(r.Context(), am.db, splits[5])
|
||||
res, err := dao.GetProjectOrganization(r.Context(), am.db, splits[5])
|
||||
if err != nil {
|
||||
_log.Errorf("Failed to authenticate: unable to find project")
|
||||
http.Error(rw, http.StatusText(http.StatusForbidden), http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
_log.Info("found project with organization %s %s", proj, org)
|
||||
_log.Info("found project with organization ", res.Organization)
|
||||
poResp = res
|
||||
}
|
||||
} else {
|
||||
// The middleware to only used with routes which does not have
|
||||
@@ -79,8 +79,8 @@ func (am *authMiddleware) ServeHTTP(rw http.ResponseWriter, r *http.Request, nex
|
||||
XSessionToken: r.Header.Get("X-Session-Token"),
|
||||
XApiKey: r.Header.Get("X-RAFAY-API-KEYID"),
|
||||
Cookie: r.Header.Get("Cookie"),
|
||||
Project: proj,
|
||||
Org: org,
|
||||
Project: poResp.Project,
|
||||
Org: poResp.Organization,
|
||||
}
|
||||
res, err := am.ac.IsRequestAllowed(r.Context(), r, req)
|
||||
if err != nil {
|
||||
@@ -92,6 +92,16 @@ func (am *authMiddleware) ServeHTTP(rw http.ResponseWriter, r *http.Request, nex
|
||||
s := res.GetStatus()
|
||||
switch s {
|
||||
case commonpbv3.RequestStatus_RequestAllowed:
|
||||
//udpate the session data response to be used within prompt
|
||||
res.SessionData.Organization = poResp.OrganizationId
|
||||
res.SessionData.Partner = poResp.PartnerId
|
||||
res.SessionData.Project = &commonpbv3.ProjectData{
|
||||
List: []*commonpbv3.ProjectRole{
|
||||
{
|
||||
ProjectId: poResp.ProjectId,
|
||||
},
|
||||
},
|
||||
}
|
||||
ctx := context.WithValue(r.Context(), common.SessionDataKey, res.SessionData)
|
||||
next(rw, r.WithContext(ctx))
|
||||
return
|
||||
|
||||
@@ -103,7 +103,7 @@ func getProjectsForAccount(ctx context.Context, accountID, orgID, partnerID stri
|
||||
}
|
||||
projects = append(projects, ap.ProjectID)
|
||||
projectsMap[ap.ProjectID] = ap.Scope
|
||||
if ap.Scope == "ORGANIZATION" {
|
||||
if ap.Scope == "organization" {
|
||||
isOrgScope = true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user