fix: fetchAndSetEntityDescriptor: return non-nil error if http status is not 200#38825
Conversation
fetchAndSetEntityDescriptor: return non-nil error regardless of http statusfetchAndSetEntityDescriptor: return non-nil error if http status is not 200
r0mant
left a comment
There was a problem hiding this comment.
In situation where remote endpoint would return HTTP status code above 200 and below 400, the fetchAndSetEntityDescriptor was returning early with a non-nil error, even it still failed to set the entity descriptor.
@flyinghermit I think in your PR description you wanted to say that it was returning early with a nil error, not with a non-nil error? It threw me off initially trying to understand the logic but I think it's just a typo in your description.
Haa Thanks for spotting that. Yeah I meant to write |
…EntityDescriptor() == check
|
Ping @fspmarshall, @atburke |
|
@flyinghermit See the table below for backport results.
|
Fixes a bug where
fetchAndSetEntityDescriptorreturned non-nil error when it failed to set entity descriptor.Background:
fetchAndSetEntityDescriptortries to fetch and set SAML service provider entity descriptor from given endpoint. It was implemented in a way that it should return error if it fails to fetch and set entity descriptor.If it fails to set entity descriptor, the
generateAndSetEntityDescriptorfunc will generate the entity descriptor with givenentity_idandacs_urlvalues.Bug: In situation where remote endpoint would return HTTP status code above
200and below400, thefetchAndSetEntityDescriptorwas returning early with a nil error, even when it still failed to set the entity descriptor. And since thegenerateAndSetEntityDescriptoris only called iffetchAndSetEntityDescriptorreturns error, we would never set the entity descriptor in such case.Root cause: incorrect use of
trace.ReadError().The
trace.ReadError()returns non-nil error ifstatusCode >= http.StatusOK && statusCode < http.StatusBadRequest. So in scenario where, say a redirect response was received,fetchAndSetEntityDescriptorwould return with non-nil error, without setting the entity descriptor, defeating the logic which follows.The existing test only included
404, empty message and a valid message so it failed to catch the302redirect case.Fix:
trace.BadParametererror regardless of HTTP status code except for200. We aren't interested in parsing error type as any error in this func means entity descriptor is not set.302redirect.changelog: Fixed an issue in SAML IdP entity descriptor generator process, which would fail to generate entity descriptor if the configured Entity ID endpoint would return HTTP status code above
200and below400.