Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v13] Use the most recent user object for the bot generation label. #30996

Merged
merged 2 commits into from Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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