-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Make the error and http code clearer when supplying wrong unseal key #17836
Conversation
@nsimons Thanks for submitting this PR. Copying my response from the linked issue:
Note that changing this now would be considered backwards incompatible. I am going to close this ticket for now. Please reopen this issue or open a new one for further discussions. |
@nsimons Thanks for contributing to Vault. We discussed the issue internally, and we would like to get the issue fixed. Would you please add a test (preferably a table test) to iterate through various cases to make sure the unseal behaviour is consistent? It would be good to see the same error code for all cases. |
The new case is triggered when key length is within valid range [16, 32], but it has uneven bytes, causing crypto/aes to return invalid key size.
Thanks for the guidance! Table test added, with some unseal cases. Is this more or less what you were after? The test uses single key shard threshold so that we get the errors out. With higher threshold the invalid keys are quite often "blindly" accepted (HTTP 200) and the unseal mechanism waits for next key shard. But I guess this is by design. Found one other return branch where it would make sense to have HTTP 400. The case is where key length is within the correct range, but the underlying AES cipher requires the length to be even. Two of the test cases tests for uneven byte length. |
Thanks for working on this issue. |
Thanks! I added test cases for multi key-shards and AutoUnseal seal config. The two code locations that you found are hit by those test cases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thanks for the contribution @nsimons
The error message inspection is the same as used elsewhere in the code (vault/barrier_aes_gcm.go).
ErrInvalidKey is already handled as a http 400 response in http/sys_seal.go, so we can simply use it in vault/seal.go to get http 400.
Regarding the error message, omitting the "message authentication failed" part, as it is printed to the end user.
Fixes #17792