-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
go vault API (*client).Logical().ReadWithData() 404 handling issue #14099
Comments
Hello @eau-u4f and thanks for reaching out!
And I believe this code highlights that functionality. Let us know if I misunderstood your concern! |
Hey @VinnyHC ! Thank you for your reply, well the reason for my question is simple: I use Line 303 in c1495da
if buf.Len() == 0 then it returns nil, nil ) , which seems erroneous, I read an element that does NOT exist, it should return an error, no?
You end up using what you think is a valid This happens when for example you request a kv-v2 value for which the version does not exist, Why would an API call return both no pointer and no error? how do you know something went wrong ?! The rest of my comment/issue was proposing to simplify the code and remove cases that seems unclear/unfit in this whole call chain logic as well as solving what seems to be a bug, but maybe I miss something? |
I think there are a few things going on here and unfortunately, none of them are a perfect response. |
Thank you for your answer, I'll check the pointer as well from now on, since the error is not reliable (and dependent on resource type). |
Sorry, I think I mislead you a bit and I don't disagree that this behavior could likely lead to false assumptions but in Vault's API, the code is fairly consistent in that just because something isn't there it's not an error to look for it. An example of this pattern elsewhere is the storage system where again |
Hello Vault,
I am not sure, I use it for the first time on a small project, I have no knowledge of your products/projects or all the different use cases and/or exceptions, so bear with my humble understanding of your new (to me) codebase.
I am facing a simple issue, where
(*client).Logical().ReadWithData()
(and per extension(*client).Logical().Read()
) returnserr
== nil when requesting a kv-v2 secret that does not exist (http status code 404):vault/api/logical.go
Line 91 in c1495da
The logic in
ReadWithData()
for handling 404 seems to have a conflicting history:https://github.com/hashicorp/vault/blame/c1495da531a7bd9c6dda6b3a08a8cbc97c419ea3/api/logical.go#L79
Quickly simulating
(*client).Logical().Read()
independently calling(*client).RawRequest(req)
on a manually forged identical request reveals a 404 is returned anderr != nil
, but reading the function,err
is tested AFTER parsing the response body of the request, which seems erroneous? (dangerous?)It seems logical to test the error right after the request or I am missing something completely in this case that requires to Parse the body before error checking and especially with a 404 code? do you return secrets to parse when they don't exist?
May be this (simplifying a bit) ? :
and in
vault/api/secret.go
Line 303 in c1495da
handle the
io.EOF
, or leave the handling toencode/json
in yourjsonutil.DecodeJSONFromReader()
.Also, not related but in
ParseSecret()
you have anio.Reader
parameter and recreate anio.Reader
(bytes.Buffer
), to feed an API able to use anio.Reader
already, wouldn't this work (I have not verified but it seemsencoding/json
used injsonutil.DecodeJSONFromReader
handles it)?Did I miss something?
Please advice, thanks!
The text was updated successfully, but these errors were encountered: