Skip to content

Conversation

@TheoBrigitte
Copy link
Contributor

@TheoBrigitte TheoBrigitte commented Aug 4, 2025

What is this feature?

This PR adds a new setting in order to be able to disable the username based brute force login protection, which allow to use IP only brute force login protection.

Why do we need this feature?

The issue I am facing currently is due to brute force attacks trying to login in as admin user, which then results in the admin user account being blocked for 5 min. I would rather instead only have the attacker IP address being blocked and not the admin account.

Who is this feature for?

For DevOps people running and configuring Grafana.

Which issue(s) does this PR fix?:

Fixes #109138

Special notes for your reviewer:

Please check that:

@TheoBrigitte TheoBrigitte requested review from a team, irenerl24 and torkelo as code owners August 4, 2025 18:06
@TheoBrigitte TheoBrigitte requested review from cinaglia and linoman and removed request for a team August 4, 2025 18:06
@CLAassistant
Copy link

CLAassistant commented Aug 4, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added area/backend type/docs Flags the technical writing team for documentation support; auto adds to org-wide docs project labels Aug 4, 2025
Copy link
Member

@cinaglia cinaglia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution, @TheoBrigitte! I just have a minor comment to avoid unnecessary database calls. The PR should be good to go once that is addressed.


func (s *Service) Validate(ctx context.Context, username string) (bool, error) {
if s.cfg.DisableBruteForceLoginProtection {
if s.cfg.DisableUsernameLoginProtection {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should continue to skip the validation if s.cfg.DisableBruteForceLoginProtection is true to avoid unnecessary database calls.

Suggested change
if s.cfg.DisableUsernameLoginProtection {
if s.cfg.DisableBruteForceLoginProtection || s.cfg.DisableUsernameLoginProtection {

For completeness, we would probably want to do the same for Service.ValidateIPAddress().

We could go even a step further and update Service.Add() to skip adding in the scenario where s.cfg.DisableBruteForceLoginProtection || (s.cfg.DisableBruteForceLoginProtection && s.cfg.DisableBruteForceLoginProtection). You're welcome to make that change if you wish, otherwise we can probably create a separate PR for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. I think you meant s.cfg.DisableBruteForceLoginProtection || (s.cfg.DisableUsernameLoginProtection && s.cfg.DisableIPAddressLoginProtection)

I added that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, good catch. I did, indeed.

Copy link
Member

@cinaglia cinaglia Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheoBrigitte Looks great! I was wondering if you could add a couple of tests to exercise these new checks (for both Validate & ValidateIPAddress)?

I'd approved it before realizing that we needed to update the tests. I've removed my approval but will take another look soon. Thanks again for your contribution!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added couple of test cases to test all the settings combinations.

@cinaglia cinaglia changed the title Authentication: Add setting to disable username based brute force login protection Auth: Add setting to disable username based brute force login protection Aug 5, 2025
cinaglia
cinaglia previously approved these changes Aug 5, 2025
@cinaglia cinaglia self-requested a review August 5, 2025 19:05
@cinaglia cinaglia dismissed their stale review August 5, 2025 19:10

Removing approval until tests are updated. Will check back again!

@cinaglia cinaglia enabled auto-merge (squash) August 6, 2025 13:48
@cinaglia cinaglia merged commit 5c50fc6 into grafana:main Aug 6, 2025
98 of 100 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

add to changelog area/backend type/docs Flags the technical writing team for documentation support; auto adds to org-wide docs project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Authentication: Cannot use brute force login protection by IP address for same user login attempts

3 participants