BED-4931: Add Audit Logging for SAML Authentication Attempts #913
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR resolves an issue where successful SAML provider logins were not generating
LoginAttempt
entries in the/api/v2/audit
endpoint, despite being logged in the Elastic logs.Motivation and Context
This change addresses BED-4931.
For secret-based authentication, audit logging is handled within the
authenticator.LoginWithSecret()
method viaauditLogin()
, which createsLoginAttempt
entries visible in the/api/v2/audit
response body. However, in the SAML authentication flow, login attempts were not being audited, as the handler for the/api/v1/login/saml/{saml_provider_name}
endpoint did not create equivalent audit log entries.This PR resolves the issue by introducing audit logging in the SAML authentication handler and ensuring that all login attempts, including those using SAML, are properly logged in the audit trail.
The solution aligns with the existing audit logging pattern and provides a consistent and complete audit trail for SAML authentication attempts.
How Has This Been Tested?
The changes were tested by extending the existing test cases for the SAML login handler. A mock for
CreateAuditLog
was added to verify that audit log entries are created as expected. The mocking expectations were also updated to reflect the new code flow, including logging for both successful authentication attempts and failures.Screenshots (optional):
Types of changes
Checklist: