Skip to content

Commit

Permalink
log when store session fails
Browse files Browse the repository at this point in the history
  • Loading branch information
sechmann committed Jul 8, 2024
1 parent 8e01cd5 commit 4f6a22d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/apiserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func run(log *logrus.Entry, cfg config.Config) error {
return fmt.Errorf("fetch Azure jwks: %w", err)
}

authenticator = auth.NewAuthenticator(cfg.Azure, db, sessions)
authenticator = auth.NewAuthenticator(cfg.Azure, db, sessions, log.WithField("component", "azure-authenticator"))
log.Info("Azure OIDC authenticator configured to authenticate device sessions")
case "google":
log.Info("setting up Google OIDC configuration...")
Expand Down
8 changes: 6 additions & 2 deletions internal/apiserver/auth/auth_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/lestrrat-go/jwx/jwt"
"github.com/sirupsen/logrus"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/nais/device/internal/apiserver/database"
Expand All @@ -19,13 +20,15 @@ type azureAuth struct {
db database.Database
store SessionStore
Azure *auth.Azure
log logrus.FieldLogger
}

func NewAuthenticator(azureConfig *auth.Azure, db database.Database, store SessionStore) Authenticator {
func NewAuthenticator(azureConfig *auth.Azure, db database.Database, store SessionStore, log logrus.FieldLogger) Authenticator {
return &azureAuth{
db: db,
store: store,
Azure: azureConfig,
log: log,
}
}

Expand Down Expand Up @@ -70,7 +73,8 @@ func (s *azureAuth) Login(ctx context.Context, token, serial, platform string) (

err = s.store.Set(ctx, session)
if err != nil {
return nil, fmt.Errorf("persist session: %s", err)
s.log.WithError(err).WithField("device", device).WithField("session", session).Error("persist session")
return nil, fmt.Errorf("persist session: %w", err)
}

return session, nil
Expand Down

0 comments on commit 4f6a22d

Please sign in to comment.