fix(auth): improve sign out handling (#2030)

* fix(auth): create index on token table

* only terminate active sessions

Co-authored-by: Livio Amstutz <livio.a@gmail.com>
This commit is contained in:
Silvan 2021-07-19 15:12:00 +02:00 committed by GitHub
parent 1b6fcebaa6
commit 3d865b3178
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 3 deletions

View File

@ -154,6 +154,9 @@ func (o *OPStorage) TerminateSession(ctx context.Context, userID, clientID strin
logging.Log("OIDC-Ghgr3").WithError(err).Error("error retrieving user sessions") logging.Log("OIDC-Ghgr3").WithError(err).Error("error retrieving user sessions")
return err return err
} }
if len(userIDs) == 0 {
return nil
}
err = o.command.HumansSignOut(ctx, userAgentID, userIDs) err = o.command.HumansSignOut(ctx, userAgentID, userIDs)
logging.Log("OIDC-Dggt2").OnError(err).Error("error signing out") logging.Log("OIDC-Dggt2").OnError(err).Error("error signing out")
return err return err

View File

@ -10,6 +10,7 @@ import (
"github.com/caos/zitadel/internal/api/authz" "github.com/caos/zitadel/internal/api/authz"
"github.com/caos/zitadel/internal/auth/repository/eventsourcing/view" "github.com/caos/zitadel/internal/auth/repository/eventsourcing/view"
"github.com/caos/zitadel/internal/config/systemdefaults" "github.com/caos/zitadel/internal/config/systemdefaults"
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/errors" "github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore/v1" "github.com/caos/zitadel/internal/eventstore/v1"
"github.com/caos/zitadel/internal/eventstore/v1/models" "github.com/caos/zitadel/internal/eventstore/v1/models"
@ -137,9 +138,11 @@ func (repo *UserRepo) UserSessionUserIDsByAgentID(ctx context.Context, agentID s
if err != nil { if err != nil {
return nil, err return nil, err
} }
userIDs := make([]string, len(userSessions)) userIDs := make([]string, 0, len(userSessions))
for i, session := range userSessions { for _, session := range userSessions {
userIDs[i] = session.UserID if session.State == int32(domain.UserSessionStateActive) {
userIDs = append(userIDs, session.UserID)
}
} }
return userIDs, nil return userIDs, nil
} }

View File

@ -0,0 +1 @@
CREATE INDEX IF NOT EXISTS user_user_agent_idx ON auth.tokens (user_id, user_agent_id);