Skip to content

Commit

Permalink
[v13] Use the most recent user object for the bot generation label. (#…
Browse files Browse the repository at this point in the history
…30996)

* Use the most recent user object for the bot generation label.

The bot generation label now uses the current user object instead of the
existing user state label.

* validateGenerationLabel uses username instead of passing in the user state.
  • Loading branch information
mdwn committed Aug 24, 2023
1 parent 5130961 commit 24e956d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/auth/auth_with_roles.go
Expand Up @@ -3125,7 +3125,7 @@ func (a *ServerWithRoles) generateUserCerts(ctx context.Context, req proto.UserC
// If the cert is renewable, process any certificate generation counter.
if certReq.renewable {
currentIdentityGeneration := a.context.Identity.GetIdentity().Generation
if err := a.authServer.validateGenerationLabel(ctx, user, &certReq, currentIdentityGeneration); err != nil {
if err := a.authServer.validateGenerationLabel(ctx, user.GetName(), &certReq, currentIdentityGeneration); err != nil {
return nil, trace.Wrap(err)
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/auth/bot.go
Expand Up @@ -371,16 +371,16 @@ func (s *Server) checkOrCreateBotToken(ctx context.Context, req *proto.CreateBot
}

// validateGenerationLabel validates and updates a generation label.
func (s *Server) validateGenerationLabel(ctx context.Context, userState services.UserState, certReq *certRequest, currentIdentityGeneration uint64) error {
func (s *Server) validateGenerationLabel(ctx context.Context, username string, certReq *certRequest, currentIdentityGeneration uint64) error {
// Fetch the user, bypassing the cache. We might otherwise fetch a stale
// value in case of a rapid certificate renewal.
user, err := s.Services.GetUser(userState.GetName(), false)
user, err := s.Services.GetUser(username, false)
if err != nil {
return trace.Wrap(err)
}

var currentUserGeneration uint64
label := userState.BotGenerationLabel()
label := user.BotGenerationLabel()
if label != "" {
currentUserGeneration, err = strconv.ParseUint(label, 10, 64)
if err != nil {
Expand Down Expand Up @@ -579,7 +579,7 @@ func (s *Server) generateInitialBotCerts(ctx context.Context, username string, p
generation: generation,
}

if err := s.validateGenerationLabel(ctx, userState, &certReq, 0); err != nil {
if err := s.validateGenerationLabel(ctx, userState.GetName(), &certReq, 0); err != nil {
return nil, trace.Wrap(err)
}

Expand Down

0 comments on commit 24e956d

Please sign in to comment.