Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: use 403 for permission denied (#6150)
Danny Xu10a4c7e54718
diff --git a/backend/server/acl.go b/backend/server/acl.goindex 96895a4f32..f1d79ce3d4 100644--- a/backend/server/acl.go+++ b/backend/server/acl.go@@ -102,7 +102,7 @@ func aclMiddleware(s *Server, pathPrefix string, ce *casbin.Enforcer, next echo.}if !pass {- return echo.NewHTTPError(http.StatusUnauthorized).SetInternal(+ return echo.NewHTTPError(http.StatusForbidden).SetInternal(errors.Errorf("rejected by the ACL policy; %s %s u%d/%s", method, path, principalID, role))}@@ -196,11 +196,11 @@ func enforceWorkspaceDeveloperProjectRouteACL(plan api.PlanType, path string, me}if len(projectRoles) == 0 {- return echo.NewHTTPError(http.StatusUnauthorized, "is not a member of the project")+ return echo.NewHTTPError(http.StatusForbidden, "is not a member of the project")}if !api.ProjectPermission(permission, plan, projectRoles) {- return echo.NewHTTPError(http.StatusUnauthorized, permissionErrMsg)+ return echo.NewHTTPError(http.StatusForbidden, permissionErrMsg)}}@@ -230,11 +230,11 @@ func enforceWorkspaceDeveloperDatabaseRouteACL(plan api.PlanType, path string, m}if plan == api.ENTERPRISE {if _, ok := oldProjectRoles[common.ProjectOwner]; !ok {- return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("user is not project owner of project owns the database %d", databaseIDInt))+ return echo.NewHTTPError(http.StatusForbidden, fmt.Sprintf("user is not project owner of project owns the database %d", databaseIDInt))}} else {if len(oldProjectRoles) == 0 {- return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("user is not a project member of project owns the database %d", databaseIDInt))+ return echo.NewHTTPError(http.StatusForbidden, fmt.Sprintf("user is not a project member of project owns the database %d", databaseIDInt))}}@@ -251,11 +251,11 @@ func enforceWorkspaceDeveloperDatabaseRouteACL(plan api.PlanType, path string, m}if plan == api.ENTERPRISE {if _, ok := newProjectRoles[common.ProjectOwner]; !ok {- return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("user is not project owner of project want owns the database %d", databaseIDInt))+ return echo.NewHTTPError(http.StatusForbidden, fmt.Sprintf("user is not project owner of project want owns the database %d", databaseIDInt))}} else {if len(newProjectRoles) == 0 {- return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("user is not a project member of project want to owns the database %d", databaseIDInt))+ return echo.NewHTTPError(http.StatusForbidden, fmt.Sprintf("user is not a project member of project want to owns the database %d", databaseIDInt))}}}@@ -283,7 +283,7 @@ func enforceWorkspaceDeveloperSheetRouteACL(plan api.PlanType, path string, meth}switch sheet.Visibility {case api.PrivateSheet:- return echo.NewHTTPError(http.StatusUnauthorized, "not allowed to access private sheet created by other user")+ return echo.NewHTTPError(http.StatusForbidden, "not allowed to access private sheet created by other user")case api.PublicSheet:return nilcase api.ProjectSheet:@@ -293,11 +293,11 @@ func enforceWorkspaceDeveloperSheetRouteACL(plan api.PlanType, path string, meth}if len(projectRoles) == 0 {- return echo.NewHTTPError(http.StatusUnauthorized, "is not a member of the project containing the sheet")+ return echo.NewHTTPError(http.StatusForbidden, "is not a member of the project containing the sheet")}if !api.ProjectPermission(api.ProjectPermissionOrganizeSheet, plan, projectRoles) {- return echo.NewHTTPError(http.StatusUnauthorized, "not have permission to organize the project sheet")+ return echo.NewHTTPError(http.StatusForbidden, "not have permission to organize the project sheet")}}} else if matches := sheetRouteRegex.FindStringSubmatch(path); matches != nil {@@ -315,12 +315,12 @@ func enforceWorkspaceDeveloperSheetRouteACL(plan api.PlanType, path string, meth}switch sheet.Visibility {case api.PrivateSheet:- return echo.NewHTTPError(http.StatusUnauthorized, "not allowed to access private sheet created by other user")+ return echo.NewHTTPError(http.StatusForbidden, "not allowed to access private sheet created by other user")case api.PublicSheet:if method == "GET" {return nil}- return echo.NewHTTPError(http.StatusUnauthorized, "not allowed to change public sheet created by other user")+ return echo.NewHTTPError(http.StatusForbidden, "not allowed to change public sheet created by other user")case api.ProjectSheet:projectRoles, err := projectRolesFinder(sheet.ProjectID, principalID)if err != nil {@@ -328,7 +328,7 @@ func enforceWorkspaceDeveloperSheetRouteACL(plan api.PlanType, path string, meth}if len(projectRoles) == 0 {- return echo.NewHTTPError(http.StatusUnauthorized, "is not a member of the project containing the sheet")+ return echo.NewHTTPError(http.StatusForbidden, "is not a member of the project containing the sheet")}if method == "GET" {@@ -336,7 +336,7 @@ func enforceWorkspaceDeveloperSheetRouteACL(plan api.PlanType, path string, meth}if !api.ProjectPermission(api.ProjectPermissionAdminSheet, plan, projectRoles) {- return echo.NewHTTPError(http.StatusUnauthorized, "not have permission to change the project sheet")+ return echo.NewHTTPError(http.StatusForbidden, "not have permission to change the project sheet")}}}diff --git a/backend/server/member.go b/backend/server/member.goindex 0825cb02b0..a212df25db 100644--- a/backend/server/member.go+++ b/backend/server/member.go@@ -105,7 +105,7 @@ func (s *Server) registerMemberRoutes(g *echo.Group) {return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Server error to find user ID: %d", id)).SetInternal(err)}if user == nil {- return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Failed to find user ID: %d", id))+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to find user ID: %d", id))}memberPatch := &api.MemberPatch{diff --git a/backend/server/sheet.go b/backend/server/sheet.goindex 73994b5c3c..b2cbf4f077 100644--- a/backend/server/sheet.go+++ b/backend/server/sheet.go@@ -67,7 +67,7 @@ func (s *Server) registerSheetRoutes(g *echo.Group) {if role != api.Owner && role != api.DBA {// Non-workspace Owner or DBA can only create sheet into the project where she has the membership.if !isProjectOwnerOrDeveloper(currentPrincipalID, projectPolicy) {- return echo.NewHTTPError(http.StatusUnauthorized, "Must be a project owner or developer to create new sheet")+ return echo.NewHTTPError(http.StatusForbidden, "Must be a project owner or developer to create new sheet")}}diff --git a/backend/server/stage.go b/backend/server/stage.goindex 8396fad5e3..a77fd8e2a6 100644--- a/backend/server/stage.go+++ b/backend/server/stage.go@@ -89,7 +89,7 @@ func (s *Server) registerStageRoutes(g *echo.Group) {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to validate if the principal can change task status").SetInternal(err)}if !ok {- return echo.NewHTTPError(http.StatusUnauthorized, "Not allowed to change task status")+ return echo.NewHTTPError(http.StatusForbidden, "Not allowed to change task status")}if stageAllTaskStatusPatch.Status == api.TaskPending {diff --git a/backend/server/task.go b/backend/server/task.goindex 634640bfa2..b99e787563 100644--- a/backend/server/task.go+++ b/backend/server/task.go@@ -111,7 +111,7 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to update task").SetInternal(err)}if task == nil {- return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Task ID not found: %d", taskID))+ return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Task ID not found: %d", taskID))}issue, err := s.store.GetIssueV2(ctx, &store.FindIssueMessage{PipelineID: &task.PipelineID})@@ -191,7 +191,7 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to validate if the principal can change task status").SetInternal(err)}if !ok {- return echo.NewHTTPError(http.StatusUnauthorized, "Not allowed to change task status")+ return echo.NewHTTPError(http.StatusForbidden, "Not allowed to change task status")}if taskStatusPatch.Status == api.TaskPending {@@ -309,7 +309,7 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to update task status").SetInternal(err)}if task == nil {- return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Task not found with ID %d", taskID))+ return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Task not found with ID %d", taskID))}if err := s.TaskCheckScheduler.ScheduleCheck(ctx, task, c.Get(getPrincipalIDContextKey()).(int)); err != nil {