Skip to content

Commit

Permalink
Convert lib/auth/sessions to use slog (#50524)
Browse files Browse the repository at this point in the history
  • Loading branch information
rosstimothy authored Dec 21, 2024
1 parent c82b7ff commit c4b5e9e
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions lib/auth/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"time"

"github.com/gravitational/trace"
"github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh"

"github.com/gravitational/teleport"
Expand Down Expand Up @@ -154,7 +153,7 @@ func (a *Server) augmentSessionForDeviceTrust(
})
switch {
case err != nil:
log.WithError(err).Warn("Failed to create DeviceWebToken for user")
a.logger.WarnContext(ctx, "Failed to create DeviceWebToken for user", "error", err)
case webToken != nil: // May be nil even if err==nil.
session.SetDeviceWebToken(&types.DeviceWebToken{
Id: webToken.Id,
Expand Down Expand Up @@ -210,7 +209,7 @@ func (a *Server) newWebSession(
}
if req.LoginIP == "" {
// TODO(antonam): consider turning this into error after all use cases are covered (before v14.0 testplan)
log.Debug("Creating new web session without login IP specified.")
a.logger.DebugContext(ctx, "Creating new web session without login IP specified")
}

clusterName, err := a.GetClusterName()
Expand Down Expand Up @@ -351,17 +350,15 @@ func (a *Server) newWebSession(
if tdr, err := a.calculateTrustedDeviceMode(ctx, func() ([]types.Role, error) {
return checker.Roles(), nil
}); err != nil {
log.
WithError(err).
Warn("Failed to calculate trusted device mode for session")
a.logger.WarnContext(ctx, "Failed to calculate trusted device mode for session", "error", err)
} else {
sess.SetTrustedDeviceRequirement(tdr)

if tdr != types.TrustedDeviceRequirement_TRUSTED_DEVICE_REQUIREMENT_UNSPECIFIED {
log.WithFields(logrus.Fields{
"user": req.User,
"trusted_device_requirement": tdr,
}).Debug("Calculated trusted device requirement for session")
a.logger.DebugContext(ctx, "Calculated trusted device requirement for session",
"user", req.User,
"trusted_device_requirement", tdr,
)
}
}

Expand Down Expand Up @@ -597,7 +594,7 @@ func (a *Server) CreateAppSessionFromReq(ctx context.Context, req NewAppSessionR
if err = a.UpsertAppSession(ctx, session); err != nil {
return nil, trace.Wrap(err)
}
log.Debugf("Generated application web session for %v with TTL %v.", req.User, req.SessionTTL)
a.logger.DebugContext(ctx, "Generated application web session", "user", req.User, "ttl", req.SessionTTL)
UserLoginCount.Inc()

// Extract the identity of the user from the certificate, this will include metadata from any actively assumed access requests.
Expand Down Expand Up @@ -643,7 +640,7 @@ func (a *Server) CreateAppSessionFromReq(ctx context.Context, req NewAppSessionR
},
})
if err != nil {
log.WithError(err).Warn("Failed to emit app session start event")
a.logger.WarnContext(ctx, "Failed to emit app session start event", "error", err)
}

return session, nil
Expand Down Expand Up @@ -784,7 +781,7 @@ func (a *Server) CreateSnowflakeSession(ctx context.Context, req types.CreateSno
if err = a.UpsertSnowflakeSession(ctx, session); err != nil {
return nil, trace.Wrap(err)
}
log.Debugf("Generated Snowflake web session for %v with TTL %v.", req.Username, ttl)
a.logger.DebugContext(ctx, "Generated Snowflake web session", "user", req.Username, "ttl", ttl)

return session, nil
}
Expand All @@ -808,7 +805,7 @@ func (a *Server) CreateSAMLIdPSession(ctx context.Context, req types.CreateSAMLI
if err = a.UpsertSAMLIdPSession(ctx, session); err != nil {
return nil, trace.Wrap(err)
}
log.Debugf("Generated SAML IdP web session for %v.", req.Username)
a.logger.DebugContext(ctx, "Generated SAML IdP web session", "user", req.Username)

return session, nil
}

0 comments on commit c4b5e9e

Please sign in to comment.