CyberCaius on Discord: S3 backup works, then every sync fails with
"the S3 server refused the access key ID or secret (HTTP 403
SignatureDoesNotMatch)", and edits to the S3 settings "won't save".
The keys work in other S3 clients, and switching to WebDAV and back
to S3 fixes it until the next time.
Cause: the SigV4 signer signs every header on the request, and
7ab91961d's conditional requests added If-None-Match (GET, the ETag
kept in sync-state.json) and If-Match (PUT). SigV4 needs only host
and x-amz-* signed. A server, or a proxy in front of it, that checks
the signature over a condition as it reads it back rather than as it
arrived refuses a signed one with SignatureDoesNotMatch. The first
sync has no ETag kept, so it passes; from the second on every sync is
conditional and refused. WebDAV and back changes stateKey, so the
state starts again with no ETag and one sync works. "Won't save" is
the same 403: /api/davsync/save writes the settings and then syncs,
and the form stays open with the sync's error.
Fix: sendTo signs every header except if-*, and sets the conditions
after signing. The docs page says so.
Test: TestS3ConditionsOutsideTheSignature, where the fake S3 rereads
an If-* header without its quotes before checking the signature. It
syncs three times, saves a second provider and syncs again, and
checks that the conditional GET and PUT reached the server.
On the old s3.go it fails with the reporter's text:
s3_test.go:612: sync 2: the S3 server refused the access key ID or
secret (HTTP 403 SignatureDoesNotMatch)
Run at this head (base e5dd86965), sandbox HOME, caches pinned:
- gofmt -l: clean. go vet (darwin), GOOS=linux go vet -tags nogui and
GOOS=windows go vet on internal/davsync; builds for darwin, linux
nogui and windows: ok.
- go test -tags nogui -count=1 ./internal/davsync ./internal/cli
./internal/gui (each package that imports davsync): davsync and cli
ok. gui had one red, TestRestartHandsTheGatewayOver ("9 of 10
requests during the restart answered", connection reset). That is
#3451, at load 50; it passes 3 of 3 alone. Commented on #3451.
- No full ./... suite: other sessions were running full suites on
this machine (gateway, agent).
Not tried: the reporter's own S3 vendor, which isn't known yet.