mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Auth: Remove userauth service (#58941)
* Auth: remove userauth service * Use Revoke user tokens from UserAuthTokenService * Add function to delete user auth info to UserAuthInfo service
This commit is contained in:
parent
e37fc888c0
commit
b3406a8273
@ -239,13 +239,13 @@ func (hs *HTTPServer) AdminDeleteUser(c *models.ReqContext) response.Response {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
if err := hs.userAuthService.Delete(ctx, cmd.UserID); err != nil {
|
if err := hs.authInfoService.DeleteUserAuthInfo(ctx, cmd.UserID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
if err := hs.userAuthService.DeleteToken(ctx, cmd.UserID); err != nil {
|
if err := hs.AuthTokenService.RevokeAllUserTokens(ctx, cmd.UserID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/querylibrary"
|
"github.com/grafana/grafana/pkg/services/querylibrary"
|
||||||
"github.com/grafana/grafana/pkg/services/searchV2"
|
"github.com/grafana/grafana/pkg/services/searchV2"
|
||||||
"github.com/grafana/grafana/pkg/services/store/object/httpobjectstore"
|
"github.com/grafana/grafana/pkg/services/store/object/httpobjectstore"
|
||||||
"github.com/grafana/grafana/pkg/services/userauth"
|
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
@ -207,7 +206,6 @@ type HTTPServer struct {
|
|||||||
accesscontrolService accesscontrol.Service
|
accesscontrolService accesscontrol.Service
|
||||||
annotationsRepo annotations.Repository
|
annotationsRepo annotations.Repository
|
||||||
tagService tag.Service
|
tagService tag.Service
|
||||||
userAuthService userauth.Service
|
|
||||||
oauthTokenService oauthtoken.OAuthTokenService
|
oauthTokenService oauthtoken.OAuthTokenService
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,8 +248,7 @@ func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routi
|
|||||||
loginAttemptService loginAttempt.Service, orgService org.Service, teamService team.Service,
|
loginAttemptService loginAttempt.Service, orgService org.Service, teamService team.Service,
|
||||||
accesscontrolService accesscontrol.Service, dashboardThumbsService thumbs.DashboardThumbService, navTreeService navtree.Service,
|
accesscontrolService accesscontrol.Service, dashboardThumbsService thumbs.DashboardThumbService, navTreeService navtree.Service,
|
||||||
annotationRepo annotations.Repository, tagService tag.Service, searchv2HTTPService searchV2.SearchHTTPService,
|
annotationRepo annotations.Repository, tagService tag.Service, searchv2HTTPService searchV2.SearchHTTPService,
|
||||||
userAuthService userauth.Service, queryLibraryHTTPService querylibrary.HTTPService, queryLibraryService querylibrary.Service,
|
queryLibraryHTTPService querylibrary.HTTPService, queryLibraryService querylibrary.Service, oauthTokenService oauthtoken.OAuthTokenService,
|
||||||
oauthTokenService oauthtoken.OAuthTokenService,
|
|
||||||
) (*HTTPServer, error) {
|
) (*HTTPServer, error) {
|
||||||
web.Env = cfg.Env
|
web.Env = cfg.Env
|
||||||
m := web.New()
|
m := web.New()
|
||||||
@ -353,7 +350,6 @@ func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routi
|
|||||||
accesscontrolService: accesscontrolService,
|
accesscontrolService: accesscontrolService,
|
||||||
annotationsRepo: annotationRepo,
|
annotationsRepo: annotationRepo,
|
||||||
tagService: tagService,
|
tagService: tagService,
|
||||||
userAuthService: userAuthService,
|
|
||||||
QueryLibraryHTTPService: queryLibraryHTTPService,
|
QueryLibraryHTTPService: queryLibraryHTTPService,
|
||||||
QueryLibraryService: queryLibraryService,
|
QueryLibraryService: queryLibraryService,
|
||||||
oauthTokenService: oauthTokenService,
|
oauthTokenService: oauthTokenService,
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/google/wire"
|
"github.com/google/wire"
|
||||||
"github.com/grafana/grafana/pkg/services/auth/authimpl"
|
|
||||||
"github.com/grafana/grafana/pkg/tsdb/parca"
|
"github.com/grafana/grafana/pkg/tsdb/parca"
|
||||||
"github.com/grafana/grafana/pkg/tsdb/phlare"
|
"github.com/grafana/grafana/pkg/tsdb/phlare"
|
||||||
|
|
||||||
@ -53,6 +52,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/accesscontrol/ossaccesscontrol"
|
"github.com/grafana/grafana/pkg/services/accesscontrol/ossaccesscontrol"
|
||||||
"github.com/grafana/grafana/pkg/services/alerting"
|
"github.com/grafana/grafana/pkg/services/alerting"
|
||||||
"github.com/grafana/grafana/pkg/services/auth"
|
"github.com/grafana/grafana/pkg/services/auth"
|
||||||
|
"github.com/grafana/grafana/pkg/services/auth/authimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/auth/jwt"
|
"github.com/grafana/grafana/pkg/services/auth/jwt"
|
||||||
"github.com/grafana/grafana/pkg/services/cleanup"
|
"github.com/grafana/grafana/pkg/services/cleanup"
|
||||||
"github.com/grafana/grafana/pkg/services/comments"
|
"github.com/grafana/grafana/pkg/services/comments"
|
||||||
@ -129,7 +129,6 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/thumbs"
|
"github.com/grafana/grafana/pkg/services/thumbs"
|
||||||
"github.com/grafana/grafana/pkg/services/updatechecker"
|
"github.com/grafana/grafana/pkg/services/updatechecker"
|
||||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/userauth/userauthimpl"
|
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/grafana/grafana/pkg/tsdb/azuremonitor"
|
"github.com/grafana/grafana/pkg/tsdb/azuremonitor"
|
||||||
"github.com/grafana/grafana/pkg/tsdb/cloudmonitoring"
|
"github.com/grafana/grafana/pkg/tsdb/cloudmonitoring"
|
||||||
@ -327,7 +326,6 @@ var wireSet = wire.NewSet(
|
|||||||
userimpl.ProvideService,
|
userimpl.ProvideService,
|
||||||
orgimpl.ProvideService,
|
orgimpl.ProvideService,
|
||||||
teamimpl.ProvideService,
|
teamimpl.ProvideService,
|
||||||
userauthimpl.ProvideService,
|
|
||||||
ngmetrics.ProvideServiceForTest,
|
ngmetrics.ProvideServiceForTest,
|
||||||
notifications.MockNotificationService,
|
notifications.MockNotificationService,
|
||||||
objectdummyserver.ProvideFakeObjectServer,
|
objectdummyserver.ProvideFakeObjectServer,
|
||||||
|
@ -143,7 +143,6 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/thumbs/dashboardthumbsimpl"
|
"github.com/grafana/grafana/pkg/services/thumbs/dashboardthumbsimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/updatechecker"
|
"github.com/grafana/grafana/pkg/services/updatechecker"
|
||||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/userauth/userauthimpl"
|
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/grafana/grafana/pkg/tsdb/azuremonitor"
|
"github.com/grafana/grafana/pkg/tsdb/azuremonitor"
|
||||||
"github.com/grafana/grafana/pkg/tsdb/cloudmonitoring"
|
"github.com/grafana/grafana/pkg/tsdb/cloudmonitoring"
|
||||||
@ -368,7 +367,6 @@ var wireBasicSet = wire.NewSet(
|
|||||||
teamimpl.ProvideService,
|
teamimpl.ProvideService,
|
||||||
tempuserimpl.ProvideService,
|
tempuserimpl.ProvideService,
|
||||||
loginattemptimpl.ProvideService,
|
loginattemptimpl.ProvideService,
|
||||||
userauthimpl.ProvideService,
|
|
||||||
secretsMigrations.ProvideDataSourceMigrationService,
|
secretsMigrations.ProvideDataSourceMigrationService,
|
||||||
secretsMigrations.ProvideMigrateToPluginService,
|
secretsMigrations.ProvideMigrateToPluginService,
|
||||||
secretsMigrations.ProvideMigrateFromPluginService,
|
secretsMigrations.ProvideMigrateFromPluginService,
|
||||||
|
@ -13,6 +13,7 @@ type AuthInfoService interface {
|
|||||||
GetExternalUserInfoByLogin(ctx context.Context, query *models.GetExternalUserInfoByLoginQuery) error
|
GetExternalUserInfoByLogin(ctx context.Context, query *models.GetExternalUserInfoByLoginQuery) error
|
||||||
SetAuthInfo(ctx context.Context, cmd *models.SetAuthInfoCommand) error
|
SetAuthInfo(ctx context.Context, cmd *models.SetAuthInfoCommand) error
|
||||||
UpdateAuthInfo(ctx context.Context, cmd *models.UpdateAuthInfoCommand) error
|
UpdateAuthInfo(ctx context.Context, cmd *models.UpdateAuthInfoCommand) error
|
||||||
|
DeleteUserAuthInfo(ctx context.Context, userID int64) error
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -218,6 +218,14 @@ func (s *AuthInfoStore) DeleteAuthInfo(ctx context.Context, cmd *models.DeleteAu
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *AuthInfoStore) DeleteUserAuthInfo(ctx context.Context, userID int64) error {
|
||||||
|
return s.sqlStore.WithDbSession(ctx, func(sess *db.Session) error {
|
||||||
|
var rawSQL = "DELETE FROM user_auth WHERE user_id = ?"
|
||||||
|
_, err := sess.Exec(rawSQL, userID)
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (s *AuthInfoStore) GetUserById(ctx context.Context, id int64) (*user.User, error) {
|
func (s *AuthInfoStore) GetUserById(ctx context.Context, id int64) (*user.User, error) {
|
||||||
query := user.GetUserByIDQuery{ID: id}
|
query := user.GetUserByIDQuery{ID: id}
|
||||||
user, err := s.userService.GetByID(ctx, &query)
|
user, err := s.userService.GetByID(ctx, &query)
|
||||||
|
@ -197,6 +197,10 @@ func (s *Implementation) GetExternalUserInfoByLogin(ctx context.Context, query *
|
|||||||
return s.authInfoStore.GetExternalUserInfoByLogin(ctx, query)
|
return s.authInfoStore.GetExternalUserInfoByLogin(ctx, query)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Implementation) DeleteUserAuthInfo(ctx context.Context, userID int64) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Implementation) Run(ctx context.Context) error {
|
func (s *Implementation) Run(ctx context.Context) error {
|
||||||
s.logger.Debug("Started AuthInfo Metrics collection service")
|
s.logger.Debug("Started AuthInfo Metrics collection service")
|
||||||
return s.authInfoStore.RunMetricsCollection(ctx)
|
return s.authInfoStore.RunMetricsCollection(ctx)
|
||||||
|
@ -57,6 +57,10 @@ func (a *AuthInfoServiceFake) GetExternalUserInfoByLogin(ctx context.Context, qu
|
|||||||
return a.ExpectedError
|
return a.ExpectedError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *AuthInfoServiceFake) DeleteUserAuthInfo(ctx context.Context, userID int64) error {
|
||||||
|
return a.ExpectedError
|
||||||
|
}
|
||||||
|
|
||||||
type AuthenticatorFake struct {
|
type AuthenticatorFake struct {
|
||||||
ExpectedUser *user.User
|
ExpectedUser *user.User
|
||||||
ExpectedError error
|
ExpectedError error
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
package userauth
|
|
||||||
|
|
||||||
import "context"
|
|
||||||
|
|
||||||
type Service interface {
|
|
||||||
Delete(context.Context, int64) error
|
|
||||||
DeleteToken(context.Context, int64) error
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
package userauthimpl
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/infra/db"
|
|
||||||
)
|
|
||||||
|
|
||||||
type store interface {
|
|
||||||
Delete(context.Context, int64) error
|
|
||||||
DeleteToken(context.Context, int64) error
|
|
||||||
}
|
|
||||||
|
|
||||||
type sqlStore struct {
|
|
||||||
db db.DB
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ss *sqlStore) Delete(ctx context.Context, userID int64) error {
|
|
||||||
return ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
|
||||||
var rawSQL = "DELETE FROM user_auth WHERE user_id = ?"
|
|
||||||
_, err := sess.Exec(rawSQL, userID)
|
|
||||||
return err
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ss *sqlStore) DeleteToken(ctx context.Context, userID int64) error {
|
|
||||||
return ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
|
||||||
var rawSQL = "DELETE FROM user_auth_token WHERE user_id = ?"
|
|
||||||
_, err := sess.Exec(rawSQL, userID)
|
|
||||||
return err
|
|
||||||
})
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
package userauthimpl
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/infra/db"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestIntegrationUserAuthDataAccess(t *testing.T) {
|
|
||||||
if testing.Short() {
|
|
||||||
t.Skip("skipping integration test")
|
|
||||||
}
|
|
||||||
|
|
||||||
ss := db.InitTestDB(t)
|
|
||||||
userAuthStore := sqlStore{
|
|
||||||
db: ss,
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Run("delete user auth", func(t *testing.T) {
|
|
||||||
err := userAuthStore.Delete(context.Background(), 1)
|
|
||||||
require.NoError(t, err)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("delete user auth token", func(t *testing.T) {
|
|
||||||
err := userAuthStore.DeleteToken(context.Background(), 1)
|
|
||||||
require.NoError(t, err)
|
|
||||||
})
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
package userauthimpl
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/infra/db"
|
|
||||||
"github.com/grafana/grafana/pkg/services/userauth"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Service struct {
|
|
||||||
store store
|
|
||||||
}
|
|
||||||
|
|
||||||
func ProvideService(db db.DB) userauth.Service {
|
|
||||||
return &Service{
|
|
||||||
store: &sqlStore{
|
|
||||||
db: db,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Service) Delete(ctx context.Context, userID int64) error {
|
|
||||||
return s.store.Delete(ctx, userID)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Service) DeleteToken(ctx context.Context, userID int64) error {
|
|
||||||
return s.store.DeleteToken(ctx, userID)
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
package userauthimpl
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestUserAuthService(t *testing.T) {
|
|
||||||
userAuthStore := &FakeUserAuthStore{}
|
|
||||||
userAuthService := Service{
|
|
||||||
store: userAuthStore,
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Run("delete user", func(t *testing.T) {
|
|
||||||
err := userAuthService.Delete(context.Background(), 1)
|
|
||||||
require.NoError(t, err)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("delete token", func(t *testing.T) {
|
|
||||||
err := userAuthService.DeleteToken(context.Background(), 1)
|
|
||||||
require.NoError(t, err)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
type FakeUserAuthStore struct {
|
|
||||||
ExpectedError error
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FakeUserAuthStore) Delete(ctx context.Context, userID int64) error {
|
|
||||||
return f.ExpectedError
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FakeUserAuthStore) DeleteToken(ctx context.Context, userID int64) error {
|
|
||||||
return f.ExpectedError
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
package userauthtest
|
|
||||||
|
|
||||||
import "context"
|
|
||||||
|
|
||||||
type FakeUserAuthService struct {
|
|
||||||
ExpectedError error
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewFakeUserAuthService() *FakeUserAuthService {
|
|
||||||
return &FakeUserAuthService{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FakeUserAuthService) Delete(ctx context.Context, userID int64) error {
|
|
||||||
return f.ExpectedError
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FakeUserAuthService) DeleteToken(ctx context.Context, userID int64) error {
|
|
||||||
return f.ExpectedError
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user