Skip to content

Commit

Permalink
Enhance logging for authentication providers (#4880)
Browse files Browse the repository at this point in the history
An INFO level message is emitted upon successful login, with details
about the user and provider used. An ERROR level message is emitted upon
authentication failure, with the username that was tried.

(cherry-picked from a994851)
Signed-off-by: Cyril Cressent <[email protected]>
  • Loading branch information
ccressent committed Sep 30, 2022
1 parent c09e03c commit bae0c0a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG-7.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ and this project adheres to [Semantic
Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Breaking
- Embedded etcd is no longer supported, all related configuration has been
removed.
Expand All @@ -26,7 +25,9 @@ migrated from Etcd.
- Added configuration store selector to sensu-backend.
- Added postgresql state store.
- GlobalResource interface in core/v3 allows core/v3 resources to
be marked as global resources.
be marked as global resources.
- The authentication module now logs successful (INFO) and unsuccessful (ERROR)
login attempts.

### Fixed
- Fixed an issue where multi-expression exclusive "Deny" filters were not
Expand Down
11 changes: 11 additions & 0 deletions backend/authentication/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"sync"

"github.com/sirupsen/logrus"

corev2 "github.com/sensu/sensu-go/api/core/v2"
)

Expand Down Expand Up @@ -33,11 +35,20 @@ func (a *Authenticator) Authenticate(ctx context.Context, username, password str
continue
}

logger.WithFields(logrus.Fields{
"subject": claims.Subject,
"groups": claims.Groups,
"provider_id": claims.Provider.ProviderID,
"provider_type": claims.Provider.ProviderType,
"provider_userid": claims.Provider.UserID,
}).Info("login successful")
return claims, nil
}

// TODO(palourde): We might want to return a more meaningful and actionnable
// error message, but we don't want to leak sensitive information.

logger.WithField("username", username).Error("authentication failed")
return nil, errors.New("authentication failed")
}

Expand Down

0 comments on commit bae0c0a

Please sign in to comment.