Patch a Bug that Prevents Kerberos Login via Vault Libraries or the Generic Vault "write" CLI #52
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
There is a bug in both HashiCorp maintained version of “vault-plugin-auth-kerberos” and Winton maintained version of “vault-plugin-auth-kerberos”. The bug prevents the Vault client from making a successful call to Kerberos Login API using Vault libraries or Vault generic “write” CLI. This is while the Vault client can successfully make a REST API call for Kerberos Login API.
Steps to Reproduce
curl --header "Authorization: Negotiate YIIFSw...sWw" --request POST http://127.0.0.1:8200/v1/auth/kerberos/login
vault write auth/kerberos/login authorization="Negotiate YIICng...gE="
Error writing data to auth/kerberos/login: Error making API request.
URL: PUT http://127.0.0.1:8200/v1/auth/kerberos/login
Code: 401. Errors:
strSPNEGOToken := "YIICngYGKw..."
vaultPath := "http://127.0.0.1:8200/v1/auth/kerberos/login"
vaultData := map[string]interface{}{ "authorization": "Negotiate " + strSPNEGOToken }
vaultResponse, err:=vaultClient.Logical().Write(vaultPath, vaultData)
URL: PUT http://0.0.0.0:8200/v1/auth/kerberos/login
Code: 401. Errors:
Solution
The PR addresses the bug.
Details of the Bug
The issue happens because although line 95 through 99 of the code checks whether the user provides the “Authorization: Negotiate ….” through the HTTP header or through the API’s body and fetches it accordingly, it does NOT set it part of the “req.Headers” once it is provided through the API’s body. This is while, “req.Headers” is referred in the line 164 to re-compose the raw request to execute the SPNEGO authentication check. Therefore, it should include the “Authorization: Negotiate ….” no matter it was originally provided through HTTP header or the API body.
In another word, we need to manually add the Authorization header with the negotiated SPNEGO Token to the request’s header in the cases it is provided through API’s body. Therefore, when the raw request is made later, "rebuiltReq" has as the header to properly execute the SPNEGO authentication check.
This change is