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

Fix handling of username_as_alias during LDAP authentication #15525

Merged
merged 7 commits into from
May 20, 2022

Conversation

remilapeyre
Copy link
Contributor

There is a bug that was introduced in the LDAP authentication method by #11000.
It was thought to be backward compatible but has broken a number of users. Later
a new parameter username_as_alias was introduced in #14324
to make it possible for operators to restore the previous behavior.
The way it is currently working is not completely backward compatible thought
because when username_as_alias is set, a call to GetUserAliasAttributeValue() will
first be made, then this value is completely discarded in pathLogin() and replaced
by the username as expected.

This is an issue because it makes useless calls to the LDAP server and will break
backward compatibility if one of the constraints in GetUserAliasAttributeValue()
is not respected, even though the resulting value will be discarded anyway.

In order to maintain backward compatibility here we have to only call
GetUserAliasAttributeValue() if necessary.

Since this change of behavior was introduced in 1.9, this fix will need to be
backported to the 1.9, 1.10 and 1.11 branches.

There is a bug that was introduced in the LDAP authentication method by hashicorp#11000.
It was thought to be backward compatible but has broken a number of users. Later
a new parameter `username_as_alias` was introduced in hashicorp#14324
to make it possible for operators to restore the previous behavior.
The way it is currently working is not completely backward compatible thought
because when username_as_alias is set, a call to GetUserAliasAttributeValue() will
first be made, then this value is completely discarded in pathLogin() and replaced
by the username as expected.

This is an issue because it makes useless calls to the LDAP server and will break
backward compatibility if one of the constraints in GetUserAliasAttributeValue()
is not respected, even though the resulting value will be discarded anyway.

In order to maintain backward compatibility here we have to only call
GetUserAliasAttributeValue() if necessary.

Since this change of behavior was introduced in 1.9, this fix will need to be
backported to the 1.9, 1.10 and 1.11 branches.
@calvn
Copy link
Contributor

calvn commented May 19, 2022

Thanks for the PR to address this! Can you include a test case to cover this scenario?

will break backward compatibility if one of the constraints in GetUserAliasAttributeValue()
is not respected, even though the resulting value will be discarded anyway.

@remilapeyre
Copy link
Contributor Author

Hi @calvn, I added two tests, one for username_as_alias = true and the other for username_as_alias = false. I also ttok this opportunity to fix the error message at https://github.com/hashicorp/vault/blob/v1.9.6/sdk/helper/ldaputil/client.go#L247.

Can you please make a review?

@calvn calvn requested a review from jasonodonnell May 19, 2022 23:31
Co-authored-by: Calvin Leung Huang <1883212+calvn@users.noreply.github.com>
@remilapeyre
Copy link
Contributor Author

remilapeyre commented May 20, 2022

Hi @calvn do you think you will be able to do the review shortly? This is blocking one of our Vault enterprise client.

@jasonodonnell
Copy link
Contributor

Hi @remilapeyre, CI is failing due to a formatting error (please run make fmt), as well as an undefined error: https://app.circleci.com/pipelines/github/hashicorp/vault/34706/workflows/89abcf43-92ae-49d3-9b9e-6cbb56aa0374/jobs/450756.

Can you take a look at these?

changelog/15525.txt Outdated Show resolved Hide resolved
@remilapeyre remilapeyre requested a review from calvn May 20, 2022 20:50
Copy link
Contributor

@calvn calvn left a comment

Choose a reason for hiding this comment

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

Changes look good, though I'd like to hold off on the merge until @jasonodonnell is all good with some validation he is performing on his end.

@jasonodonnell jasonodonnell self-requested a review May 20, 2022 21:15
Copy link
Contributor

@jasonodonnell jasonodonnell left a comment

Choose a reason for hiding this comment

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

LGTM!

@calvn calvn merged commit 03d923c into hashicorp:main May 20, 2022
@calvn calvn added this to the 1.11.0-rc1 milestone May 20, 2022
calvn pushed a commit that referenced this pull request May 20, 2022
* Fix handling of username_as_alias during LDAP authentication

There is a bug that was introduced in the LDAP authentication method by #11000.
It was thought to be backward compatible but has broken a number of users. Later
a new parameter `username_as_alias` was introduced in #14324
to make it possible for operators to restore the previous behavior.
The way it is currently working is not completely backward compatible thought
because when username_as_alias is set, a call to GetUserAliasAttributeValue() will
first be made, then this value is completely discarded in pathLogin() and replaced
by the username as expected.

This is an issue because it makes useless calls to the LDAP server and will break
backward compatibility if one of the constraints in GetUserAliasAttributeValue()
is not respected, even though the resulting value will be discarded anyway.

In order to maintain backward compatibility here we have to only call
GetUserAliasAttributeValue() if necessary.

Since this change of behavior was introduced in 1.9, this fix will need to be
backported to the 1.9, 1.10 and 1.11 branches.

* Add changelog

* Add tests

* Format code

* Update builtin/credential/ldap/backend.go

Co-authored-by: Calvin Leung Huang <1883212+calvn@users.noreply.github.com>

* Format and fix declaration

* Reword changelog

Co-authored-by: Calvin Leung Huang <1883212+calvn@users.noreply.github.com>
# Conflicts:
#	builtin/credential/ldap/backend_test.go
calvn pushed a commit that referenced this pull request May 20, 2022
…#15556)

* Fix handling of username_as_alias during LDAP authentication

There is a bug that was introduced in the LDAP authentication method by #11000.
It was thought to be backward compatible but has broken a number of users. Later
a new parameter `username_as_alias` was introduced in #14324
to make it possible for operators to restore the previous behavior.
The way it is currently working is not completely backward compatible thought
because when username_as_alias is set, a call to GetUserAliasAttributeValue() will
first be made, then this value is completely discarded in pathLogin() and replaced
by the username as expected.

This is an issue because it makes useless calls to the LDAP server and will break
backward compatibility if one of the constraints in GetUserAliasAttributeValue()
is not respected, even though the resulting value will be discarded anyway.

In order to maintain backward compatibility here we have to only call
GetUserAliasAttributeValue() if necessary.

Since this change of behavior was introduced in 1.9, this fix will need to be
backported to the 1.9, 1.10 and 1.11 branches.

* Add changelog

* Add tests

* Format code

* Update builtin/credential/ldap/backend.go

Co-authored-by: Calvin Leung Huang <1883212+calvn@users.noreply.github.com>

* Format and fix declaration

* Reword changelog

Co-authored-by: Calvin Leung Huang <1883212+calvn@users.noreply.github.com>
# Conflicts:
#	builtin/credential/ldap/backend_test.go

Co-authored-by: Rémi Lapeyre <remi.lapeyre@lenstra.fr>
@remilapeyre
Copy link
Contributor Author

Hi @calvn @jasonodonnell, thanks for reviewing the PR. Do you know when 1.9.7 will be released? We can't build it ourselves because we are using the enterprise version.

@mladlow mladlow modified the milestones: 1.11.0-rc1, 1.9.7 May 23, 2022
@remilapeyre remilapeyre deleted the ldap-username_as_alias-fix branch May 28, 2022 13:26
Gabrielopesantos pushed a commit to Gabrielopesantos/vault that referenced this pull request Jun 6, 2022
…rp#15525)

* Fix handling of username_as_alias during LDAP authentication

There is a bug that was introduced in the LDAP authentication method by hashicorp#11000.
It was thought to be backward compatible but has broken a number of users. Later
a new parameter `username_as_alias` was introduced in hashicorp#14324
to make it possible for operators to restore the previous behavior.
The way it is currently working is not completely backward compatible thought
because when username_as_alias is set, a call to GetUserAliasAttributeValue() will
first be made, then this value is completely discarded in pathLogin() and replaced
by the username as expected.

This is an issue because it makes useless calls to the LDAP server and will break
backward compatibility if one of the constraints in GetUserAliasAttributeValue()
is not respected, even though the resulting value will be discarded anyway.

In order to maintain backward compatibility here we have to only call
GetUserAliasAttributeValue() if necessary.

Since this change of behavior was introduced in 1.9, this fix will need to be
backported to the 1.9, 1.10 and 1.11 branches.

* Add changelog

* Add tests

* Format code

* Update builtin/credential/ldap/backend.go

Co-authored-by: Calvin Leung Huang <1883212+calvn@users.noreply.github.com>

* Format and fix declaration

* Reword changelog

Co-authored-by: Calvin Leung Huang <1883212+calvn@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants