From b7748841f5e98ae933deb7dc146370a27498a580 Mon Sep 17 00:00:00 2001 From: Nikolay Date: Fri, 30 Sep 2022 06:43:44 +0200 Subject: [PATCH] lib/awsapi: fixes sign encoding (#3183) * lib/awsapi: fixes sign encoding previously white spaces at filter were incorrectly encoded encoding tip was copied from aws signing lib For example, the space character must be encoded as %20 (not using '+', as some encoding schemes do) https://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3171 * Update lib/awsapi/sign.go Co-authored-by: Aliaksandr Valialkin --- docs/CHANGELOG.md | 1 + lib/awsapi/sign.go | 3 +++ 2 files changed, 4 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 8adac5fa5..de851637d 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -19,6 +19,7 @@ The following tip changes can be tested by building VictoriaMetrics components f * BUGFIX: do not export stale metrics via [/federate api](https://docs.victoriametrics.com/#federation) after the staleness markers. Previously such metrics were exported with `NaN` values. this could break some setups. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3185). * BUGFIX: [vmauth](https://docs.victoriametrics.com/vmauth.html): properly handle request paths ending with `/` such as `/vmui/`. Previously `vmui` was dropping the traling `/`, which could prevent from using `vmui` via `vmauth`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1752). +* BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): properly encode query params for aws signed requests, use `%20` instead of `+` as api requires. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3171). ## [v1.79.3](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.79.3) diff --git a/lib/awsapi/sign.go b/lib/awsapi/sign.go index d56890f12..88d182374 100644 --- a/lib/awsapi/sign.go +++ b/lib/awsapi/sign.go @@ -41,6 +41,9 @@ func signRequestWithTime(req *http.Request, service, region, payloadHash string, datestamp := t.Format("20060102") canonicalURL := uri.Path canonicalQS := uri.Query().Encode() + // Replace "%20" with "+" according to AWS requirements. + // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3171 + canonicalQS = strings.ReplaceAll(canonicalQS, "+", "%20") canonicalHeaders := fmt.Sprintf("host:%s\nx-amz-date:%s\n", uri.Host, amzdate) signedHeaders := "host;x-amz-date"