From c30494e7a071f3021344fa667cd89ef235fa9a8b Mon Sep 17 00:00:00 2001 From: Anders Eknert Date: Mon, 29 Nov 2021 13:18:46 +0100 Subject: [PATCH] plugins/rest/aws: debug log metadata error (#4061) A user on Slack is getting 500 responses from the AWS metadata API using a configuration like the below: ```yaml services: - name: svc-bundle url: https://opa-policies-dev.s3.amazonaws.com credentials: s3_signing: metadata_credentials: aws_region: us-east-1 iam_role: arn:aws:iam::1234:role/opa-bundles ``` It's really hard to know why this might be given how we currently only log the HTTP status code under this error condition. This tries to print the response body on debug level (if set). Signed-off-by: Anders Eknert --- plugins/rest/aws.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/rest/aws.go b/plugins/rest/aws.go index 6bba1a2385..cc5953f103 100644 --- a/plugins/rest/aws.go +++ b/plugins/rest/aws.go @@ -378,6 +378,12 @@ func doMetaDataRequestWithClient(req *http.Request, client *http.Client, desc st }).Debug("Received response from " + desc + " service.") if resp.StatusCode != 200 { + if logger.GetLevel() == logging.Debug { + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + logger.Debug("Error response with response body: %v", body) + } + } // could be 404 for role that's not available, but cover all the bases return nil, errors.New(desc + " HTTP request returned unexpected status: " + resp.Status) }