Error some headers are not signed with version 0.7.0
immavalls opened this issue · comments
As reported in https://community.k6.io/t/s3serviceerror-using-s3client/5586, version 0.7.0
seems to have introduced an error.
ERRO[0000] S3ServiceError: There were headers present in the request which were not signed
running at value (webpack://k6-jslib-aws/./src/internal/s3.ts:289:16(55))
default at value (webpack://k6-jslib-aws/./src/internal/s3.ts:62:27(40))
at file:///Users/immavalls/Documents/grafana/github/k6-jslib-aws/examples/s3.js:23:20(3)
at native executor=per-vu-iterations scenario=default source=stacktrace
When following the s3 example, with the right credentials, it fails with the previous error.
The same example importing version 0.6.0
(before refactoring to support AWS signature v4 procedure, sign and pre-sign) works:
import { AWSConfig, S3Client } from 'https://jslib.k6.io/aws/0.6.0/s3.js';
After some digging, it seems that we need to add the host header in https://github.com/grafana/k6-jslib-aws/blob/main/src/internal/signature.ts#L102.
And we need to fix the test https://github.com/grafana/k6-jslib-aws/blob/main/tests/internal/new_signature.js#L82 adding delete request.hostname
. Otherwise, the request is adding the host
in the headers.
I've also spotted that we have accessKeyId: this.awsConfig.accessKeyID
in https://github.com/grafana/k6-jslib-aws/blob/main/src/internal/s3.ts#L27, and it should be accessKeyId: this.awsConfig.accessKeyId
. Otherwise, the AWS4-HMAC-SHA256 Credential
is missing the accessKeyId
.
Thanks a lot for reporting this @immavalls 🤝 It concurs with something pointed out by #27.
The change was initially made to align with the official node sdk's test suite, but it seems I must have missed something indeed and would have been better off trusting the docs instead🤦🏻
We need to bring back https://github.com/grafana/k6-jslib-aws/blob/main/src/internal/signature.ts#L102 and adjust the tests, indeed.
Regarding the accessKeyID
, good catch! I'll put a fix together, and see what I can do to help Typescript catch this earlier in the future.