Auth: Reduce restriction with non-user accounts (#74397)
* Reduce restrictions with non-user accounts * Revert restrictions on anonymous accounts * Change log level from warning to debug * Change log messages to upper case
This commit is contained in:
@@ -22,7 +22,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -207,15 +206,16 @@ func (dr *DashboardServiceImpl) BuildSaveDashboardCommand(ctx context.Context, d
|
||||
}
|
||||
|
||||
func resolveUserID(user identity.Requester, log log.Logger) (int64, error) {
|
||||
userID := int64(0)
|
||||
namespaceID, identifier := user.GetNamespacedID()
|
||||
if namespaceID != identity.NamespaceUser && namespaceID != identity.NamespaceServiceAccount {
|
||||
return 0, errutil.BadRequest("account doesn't belong to the user or service namespace")
|
||||
log.Debug("User does not belong to a user or service account namespace", "namespaceID", namespaceID, "userID", identifier)
|
||||
}
|
||||
|
||||
userID, err := identity.IntIdentifier(namespaceID, identifier)
|
||||
|
||||
if err != nil {
|
||||
log.Warn("failed to parse user ID", "namespaceID", namespaceID, "userID", identifier, "error", err)
|
||||
log.Debug("failed to parse user ID", "namespaceID", namespaceID, "userID", identifier, "error", err)
|
||||
}
|
||||
return userID, nil
|
||||
}
|
||||
|
||||
@@ -281,14 +281,17 @@ func (s *Service) Create(ctx context.Context, cmd *folder.CreateFolderCommand) (
|
||||
dashFolder.SetUID(trimmedUID)
|
||||
|
||||
user := cmd.SignedInUser
|
||||
|
||||
userID := int64(0)
|
||||
var err error
|
||||
namespaceID, userIDstr := user.GetNamespacedID()
|
||||
if namespaceID == identity.NamespaceAPIKey {
|
||||
s.log.Warn("namespace API key detected, using 0 as user ID", "namespaceID", namespaceID, "userID", userIDstr)
|
||||
userIDstr = "0"
|
||||
}
|
||||
userID, err := identity.IntIdentifier(namespaceID, userIDstr)
|
||||
if err != nil {
|
||||
s.log.Warn("failed to parse user ID", "namespaceID", namespaceID, "userID", userIDstr, "error", err)
|
||||
if namespaceID != identity.NamespaceUser && namespaceID != identity.NamespaceServiceAccount {
|
||||
s.log.Debug("User does not belong to a user or service account namespace, using 0 as user ID", "namespaceID", namespaceID, "userID", userIDstr)
|
||||
} else {
|
||||
userID, err = identity.IntIdentifier(namespaceID, userIDstr)
|
||||
if err != nil {
|
||||
s.log.Debug("failed to parse user ID", "namespaceID", namespaceID, "userID", userIDstr, "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
if userID == 0 {
|
||||
@@ -773,14 +776,15 @@ func (s *Service) BuildSaveDashboardCommand(ctx context.Context, dto *dashboards
|
||||
}
|
||||
}
|
||||
|
||||
userID := int64(0)
|
||||
namespaceID, userIDstr := dto.User.GetNamespacedID()
|
||||
if namespaceID == identity.NamespaceAPIKey {
|
||||
s.log.Warn("namespace API key detected, using 0 as user ID", "namespaceID", namespaceID, "userID", userIDstr)
|
||||
userIDstr = "0"
|
||||
}
|
||||
userID, err := identity.IntIdentifier(namespaceID, userIDstr)
|
||||
if err != nil {
|
||||
s.log.Warn("failed to parse user ID", "namespaceID", namespaceID, "userID", userIDstr, "error", err)
|
||||
if namespaceID != identity.NamespaceUser && namespaceID != identity.NamespaceServiceAccount {
|
||||
s.log.Warn("User does not belong to a user or service account namespace, using 0 as user ID", "namespaceID", namespaceID, "userID", userIDstr)
|
||||
} else {
|
||||
userID, err = identity.IntIdentifier(namespaceID, userIDstr)
|
||||
if err != nil {
|
||||
s.log.Warn("failed to parse user ID", "namespaceID", namespaceID, "userID", userIDstr, "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
cmd := &dashboards.SaveDashboardCommand{
|
||||
|
||||
@@ -300,15 +300,11 @@ func ProvideService(plugCtxProvider *plugincontext.Provider, cfg *setting.Cfg, r
|
||||
|
||||
g.websocketHandler = func(ctx *contextmodel.ReqContext) {
|
||||
user := ctx.SignedInUser
|
||||
namespaceID, userID := user.GetNamespacedID()
|
||||
|
||||
if namespaceID != identity.NamespaceUser {
|
||||
return // Only users can connect to Live
|
||||
}
|
||||
_, identifier := user.GetNamespacedID()
|
||||
|
||||
// Centrifuge expects Credentials in context with a current user ID.
|
||||
cred := ¢rifuge.Credentials{
|
||||
UserID: userID,
|
||||
UserID: identifier,
|
||||
}
|
||||
newCtx := centrifuge.SetCredentials(ctx.Req.Context(), cred)
|
||||
newCtx = livecontext.SetContextSignedUser(newCtx, user)
|
||||
|
||||
@@ -59,11 +59,12 @@ func (u *SignedInUser) ToUserDisplayDTO() *UserDisplayDTO {
|
||||
|
||||
// Static function to parse a requester into a UserDisplayDTO
|
||||
func NewUserDisplayDTOFromRequester(requester identity.Requester) (*UserDisplayDTO, error) {
|
||||
userID := int64(0)
|
||||
namespaceID, identifier := requester.GetNamespacedID()
|
||||
if namespaceID != identity.NamespaceUser && namespaceID != identity.NamespaceServiceAccount {
|
||||
identifier = "0"
|
||||
if namespaceID == identity.NamespaceUser || namespaceID == identity.NamespaceServiceAccount {
|
||||
userID, _ = identity.IntIdentifier(namespaceID, identifier)
|
||||
}
|
||||
userID, _ := identity.IntIdentifier(namespaceID, identifier)
|
||||
|
||||
return &UserDisplayDTO{
|
||||
ID: userID,
|
||||
Login: requester.GetLogin(),
|
||||
|
||||
Reference in New Issue
Block a user