Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

normalize LDAP auth HTTP responses #21282

Merged
merged 3 commits into from
Jun 21, 2023

Conversation

raymonstah
Copy link
Contributor

@raymonstah raymonstah commented Jun 15, 2023

Attempts to fix #20923.

With this change, every combination of an invalid username or invalid password when authenticating against LDAP should return an HTTP 400 with the error message:

{
    "errors": [
        "ldap operation failed: failed to bind as user"
    ]
}

Demo:

LDAP.Auth.HTTP.Response.Codes.mp4

@raymonstah raymonstah requested a review from a team June 15, 2023 21:19
@raymonstah raymonstah marked this pull request as ready for review June 15, 2023 21:20
@raymonstah raymonstah requested a review from a team June 15, 2023 21:20
@raymonstah raymonstah changed the title normalize LDAP auth responses normalize LDAP auth HTTP responses Jun 15, 2023
Copy link
Member

@robmonte robmonte left a comment

Choose a reason for hiding this comment

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

Nice fix for information leakage 👍

Copy link
Member

@austingebauer austingebauer left a comment

Choose a reason for hiding this comment

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

LGTM! Might be worth exploring a bit on response behavior on a couple of different auth methods before merging.

@@ -1406,7 +1407,7 @@ func (c *Core) handleLoginRequest(ctx context.Context, req *logical.Request) (re
return nil, nil, err
}
}
return nil, nil, resp.Error()
return resp, nil, routeErr
Copy link
Member

Choose a reason for hiding this comment

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

Just gave this a test with a different auth method (userpass) to see if there are any undesirable side effects. I think this fixes other issues (good thing!). Interesting that userpass auth with an incorrect password returns a 500 before this change. Makes me wonder how long it's behaved like that 🤔 With the changes in this PR, both login attempts below return a 400.

$ vault auth enable userpass

$ vault write auth/userpass/users/test \
    password=password

$ vault login -method=userpass username=testt password=password
Error authenticating: Error making API request.

URL: PUT http://localhost:8200/v1/auth/userpass/login/testt
Code: 400. Errors:

* invalid username or password
$ vault login -method=userpass username=test password=passwordd
Error authenticating: Error making API request.

URL: PUT http://localhost:8200/v1/auth/userpass/login/test
Code: 500. Errors:

* invalid username or password

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for testing the userpass auth flow!

Copy link
Member

Choose a reason for hiding this comment

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

If the error is non-nil in this case (and scoped to be logical.ErrInvalidCredentials from the check above), is there a reason to return resp rather than nil?

Copy link
Member

Choose a reason for hiding this comment

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

I believe so that a 204 No Content isn't returned (reported in the GH issue) and the response has the errUserBindFailed contents included. @raymonstah can confirm this.

Copy link
Member

Choose a reason for hiding this comment

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

I see what's going -- the resp's Error is what fixes the 204 since the actual content is coming from there, and not the error's string value.

@@ -0,0 +1,3 @@
```release-note:bug
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should call this out as a change

change – A change in the product that may require action or review by the operator. Examples would be any kind of API change (as opposed to backwards compatible addition), a notable behavior change, or anything that might require attention before updating.

@raymonstah raymonstah added this to the 1.15 milestone Jun 21, 2023
@raymonstah raymonstah merged commit 5b41148 into main Jun 21, 2023
90 checks passed
@raymonstah raymonstah deleted the VAULT-17086/fix-ldap-auth-204-response-bug branch June 21, 2023 22:32
@mickael-hc
Copy link
Contributor

@raymonstah @austingebauer would it make sense to backport these changes?

@raymonstah
Copy link
Contributor Author

@raymonstah @austingebauer would it make sense to backport these changes?

Hey @mickael-hc, no objections here regarding a backport. I can't think of any reason not to.

@austingebauer
Copy link
Member

@raymonstah @mickael-hc - Sounds good on the backport. Looks like ErrInvalidCredentials was introduced in 1.13, so it probably makes sense to go back to 1.13.x. I believe applying the backport labels to this PR will still result in the backport PRs being created by the automation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vault LDAP Auth Method vulnerable to account fuzzing via response.
6 participants