rework session updates to use new patch method (#4705)

Update the AccessTracker, WebAuthn handlers, and identity manager
refresh loop to perform their session record updates using the
databroker Patch() method.

This should prevent any of these updates from conflicting.
This commit is contained in:
Kenneth Jenkins 2023-11-06 09:43:07 -08:00 committed by GitHub
parent 2771a5ae87
commit ab104a643a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 88 additions and 15 deletions

View file

@ -2,11 +2,13 @@ package authorize
import (
"context"
"fmt"
"sync/atomic"
"time"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/fieldmaskpb"
"google.golang.org/protobuf/types/known/timestamppb"
"github.com/pomerium/pomerium/internal/log"
@ -158,13 +160,12 @@ func (tracker *AccessTracker) updateSession(
ctx, clearTimeout := context.WithTimeout(ctx, accessTrackerUpdateTimeout)
defer clearTimeout()
s, err := session.Get(ctx, client, sessionID)
if status.Code(err) == codes.NotFound {
return nil
} else if err != nil {
return err
s := &session.Session{Id: sessionID, AccessedAt: timestamppb.Now()}
m, err := fieldmaskpb.New(s, "accessed_at")
if err != nil {
return fmt.Errorf("internal error: %w", err)
}
s.AccessedAt = timestamppb.Now()
_, err = session.Put(ctx, client, s)
_, err = session.Patch(ctx, client, s, m)
return err
}