Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: cannot update the last active time (#10554)
ecmadaod69645516416
diff --git a/backend/api/auth/auth.go b/backend/api/auth/auth.goindex 342ca2b868..4ad0315043 100644--- a/backend/api/auth/auth.go+++ b/backend/api/auth/auth.go@@ -19,6 +19,7 @@ import (errs "github.com/pkg/errors""github.com/bytebase/bytebase/backend/common"+ "github.com/bytebase/bytebase/backend/component/config""github.com/bytebase/bytebase/backend/component/state"enterprise "github.com/bytebase/bytebase/backend/enterprise/api""github.com/bytebase/bytebase/backend/store"@@ -55,18 +56,25 @@ type APIAuthInterceptor struct {tokenDuration time.DurationlicenseService enterprise.LicenseServicestateCfg *state.State- mode common.ReleaseMode+ profile *config.Profile}// New returns a new API auth interceptor.-func New(store *store.Store, secret string, tokenDuration time.Duration, licenseService enterprise.LicenseService, stateCfg *state.State, mode common.ReleaseMode) *APIAuthInterceptor {+func New(+ store *store.Store,+ secret string,+ tokenDuration time.Duration,+ licenseService enterprise.LicenseService,+ stateCfg *state.State,+ profile *config.Profile,+) *APIAuthInterceptor {return &APIAuthInterceptor{store: store,secret: secret,tokenDuration: tokenDuration,licenseService: licenseService,stateCfg: stateCfg,- mode: mode,+ profile: profile,}}@@ -81,7 +89,7 @@ func (in *APIAuthInterceptor) AuthenticationInterceptor(ctx context.Context, reqreturn nil, status.Errorf(codes.Unauthenticated, err.Error())}- principalID, err := in.authenticate(ctx, accessTokenStr)+ principalID, err := in.getPrincipalID(ctx, accessTokenStr)if err != nil {if IsAuthenticationAllowed(serverInfo.FullMethod) {return handler(ctx, request)@@ -106,7 +114,7 @@ func (in *APIAuthInterceptor) AuthenticationStreamInterceptor(request any, ss grreturn status.Errorf(codes.Unauthenticated, err.Error())}- principalID, err := in.authenticate(ctx, accessTokenStr)+ principalID, err := in.getPrincipalID(ctx, accessTokenStr)if err != nil {if IsAuthenticationAllowed(serverInfo.FullMethod) {return handler(request, ss)@@ -153,11 +161,11 @@ func (in *APIAuthInterceptor) authenticate(ctx context.Context, accessTokenStr s}return 0, status.Errorf(codes.Unauthenticated, "failed to parse claim")}- if !audienceContains(claims.Audience, fmt.Sprintf(AccessTokenAudienceFmt, in.mode)) {+ if !audienceContains(claims.Audience, fmt.Sprintf(AccessTokenAudienceFmt, in.profile.Mode)) {return 0, status.Errorf(codes.Unauthenticated,"invalid access token, audience mismatch, got %q, expected %q. you may send request to the wrong environment",claims.Audience,- fmt.Sprintf(AccessTokenAudienceFmt, in.mode),+ fmt.Sprintf(AccessTokenAudienceFmt, in.profile.Mode),)}@@ -179,6 +187,17 @@ func (in *APIAuthInterceptor) authenticate(ctx context.Context, accessTokenStr sreturn principalID, nil}+func (in *APIAuthInterceptor) getPrincipalID(ctx context.Context, accessTokenStr string) (int, error) {+ principalID, err := in.authenticate(ctx, accessTokenStr)+ if err != nil {+ return 0, err+ }++ // Only update for authorized request.+ in.profile.LastActiveTs = time.Now().Unix()+ return principalID, nil+}+// GetUserIDFromMFATempToken returns the user ID from the MFA temp token.func GetUserIDFromMFATempToken(token string, mode common.ReleaseMode, secret string) (int, error) {claims := &claimsMessage{}diff --git a/backend/api/v1/debug_interceptor.go b/backend/api/v1/debug_interceptor.goindex 04d12f4e6b..587bdf6d0a 100644--- a/backend/api/v1/debug_interceptor.go+++ b/backend/api/v1/debug_interceptor.go@@ -14,7 +14,6 @@ import ("github.com/bytebase/bytebase/backend/common""github.com/bytebase/bytebase/backend/common/log"- "github.com/bytebase/bytebase/backend/component/config"api "github.com/bytebase/bytebase/backend/legacyapi""github.com/bytebase/bytebase/backend/metric"metricplugin "github.com/bytebase/bytebase/backend/plugin/metric"@@ -25,15 +24,13 @@ import (// DebugInterceptor is the v1 debug interceptor for gRPC server.type DebugInterceptor struct {errorRecordRing *api.ErrorRecordRing- profile *config.ProfilemetricReporter *metricreport.Reporter}// NewDebugInterceptor returns a new v1 API debug interceptor.-func NewDebugInterceptor(errorRecordRing *api.ErrorRecordRing, profile *config.Profile, metricReporter *metricreport.Reporter) *DebugInterceptor {+func NewDebugInterceptor(errorRecordRing *api.ErrorRecordRing, metricReporter *metricreport.Reporter) *DebugInterceptor {return &DebugInterceptor{errorRecordRing: errorRecordRing,- profile: profile,metricReporter: metricReporter,}}@@ -102,10 +99,6 @@ func (in *DebugInterceptor) debugInterceptorDo(ctx context.Context, fullMethod s}in.errorRecordRing.Ring = in.errorRecordRing.Ring.Next()}- if _, ok := ctx.Value(common.PrincipalIDContextKey).(int); ok {- // Only update for authorized request.- in.profile.LastActiveTs = time.Now().Unix()- }in.metricReporter.Report(ctx, &metricplugin.Metric{Name: metric.APIRequestMetricName,Value: 1,diff --git a/backend/server/init.go b/backend/server/init.goindex 5ae79d5d66..846adf7fa3 100644--- a/backend/server/init.go+++ b/backend/server/init.go@@ -213,7 +213,7 @@ func (s *Server) getInitSetting(ctx context.Context, datastore *store.Store) (st// initMetricReporter will initial the metric scheduler.func (s *Server) initMetricReporter() {- metricReporter := metricreport.NewReporter(s.store, s.licenseService, &s.profile, s.profile.EnableMetric)+ metricReporter := metricreport.NewReporter(s.store, s.licenseService, s.profile, s.profile.EnableMetric)metricReporter.Register(metric.InstanceCountMetricName, metriccollector.NewInstanceCountCollector(s.store))metricReporter.Register(metric.IssueCountMetricName, metriccollector.NewIssueCountCollector(s.store))metricReporter.Register(metric.ProjectCountMetricName, metriccollector.NewProjectCountCollector(s.store))diff --git a/backend/server/server.go b/backend/server/server.goindex 6ab6f0f999..5b4581162a 100644--- a/backend/server/server.go+++ b/backend/server/server.go@@ -84,7 +84,7 @@ type Server struct {licenseService enterprise.LicenseService- profile config.Profile+ profile *config.Profilee *echo.EchogrpcServer *grpc.ServerlspServer *lsp.Server@@ -119,7 +119,7 @@ type Server struct {// NewServer creates a server.func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {s := &Server{- profile: profile,+ profile: &profile,startedTs: time.Now().Unix(),errorRecordRing: api.NewErrorRecordRing(),}@@ -265,7 +265,7 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {s.s3Client = s3Client}- s.metricReporter = metricreport.NewReporter(s.store, s.licenseService, &s.profile, false)+ s.metricReporter = metricreport.NewReporter(s.store, s.licenseService, s.profile, false)s.schemaSyncer = schemasync.NewSyncer(storeInstance, s.dbFactory, s.stateCfg, profile, s.licenseService)if !profile.Readonly {s.slowQuerySyncer = slowquerysync.NewSyncer(storeInstance, s.dbFactory, s.stateCfg, profile)@@ -307,9 +307,9 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {}// Setup the gRPC and grpc-gateway.- authProvider := auth.New(s.store, s.secret, tokenDuration, s.licenseService, s.stateCfg, profile.Mode)- aclProvider := apiv1.NewACLInterceptor(s.store, s.secret, s.licenseService, s.iamManager, &profile)- debugProvider := apiv1.NewDebugInterceptor(&s.errorRecordRing, &profile, s.metricReporter)+ authProvider := auth.New(s.store, s.secret, tokenDuration, s.licenseService, s.stateCfg, s.profile)+ aclProvider := apiv1.NewACLInterceptor(s.store, s.secret, s.licenseService, s.iamManager, s.profile)+ debugProvider := apiv1.NewDebugInterceptor(&s.errorRecordRing, s.metricReporter)onPanic := func(p any) error {stack := stacktrace.TakeStacktrace(20 /* n */, 5 /* skip */)// keep a multiline stack@@ -355,7 +355,7 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {}return nil}- rolloutService, issueService, err := configureGrpcRouters(ctx, mux, s.grpcServer, s.store, s.dbFactory, s.licenseService, &s.profile, s.metricReporter, s.stateCfg, s.schemaSyncer, s.activityManager, s.iamManager, s.backupRunner, s.relayRunner, s.planCheckScheduler, postCreateUser, s.secret, &s.errorRecordRing, tokenDuration)+ rolloutService, issueService, err := configureGrpcRouters(ctx, mux, s.grpcServer, s.store, s.dbFactory, s.licenseService, s.profile, s.metricReporter, s.stateCfg, s.schemaSyncer, s.activityManager, s.iamManager, s.backupRunner, s.relayRunner, s.planCheckScheduler, postCreateUser, s.secret, &s.errorRecordRing, tokenDuration)if err != nil {return nil, err}