New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument must be of type string… #83
Comments
yes me too |
Thank you for your report. I am not able to reproduce your findings. I created a test script based on your excerpt above:
The output was this:
I also replaced Could you provide more details about your environment? Also, if you have a completely standalone script that produces the failure, that would be helpful. |
Okay… I use the docker image node@node:/usr/src/app$ node --version
v15.5.1 Positive caseInstall IBM-COS-SDK v1.0.9
Run testcase node@node:/usr/src/app$ export COS_KEY='<myKey>'
node@node:/usr/src/app$ export COS_CRN='<myCRN>'
node@node:/usr/src/app$ export COS_BUCKET='upload'
node@node:/usr/src/app$ npm list ibm-cos-sdk
app@1.0.0 /usr/src/app
`-- ibm-cos-sdk@1.9.0
node@node:/usr/src/app$ node issue1.mjs
Try…
Upload
Complete! Negative caseUpdate IBM-COS-SDK to version v1.10.0 node@node:/usr/src/app$ npm update ibm-cos-sdk
removed 1 package, changed 1 package, and audited 59 packages in 4s
3 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities Run testcase node@node:/usr/src/app$ npm list ibm-cos-sdk
app@1.0.0 /usr/src/app
`-- ibm-cos-sdk@1.10.0
node@node:/usr/src/app$ node issue1.mjs
Try…
Upload
TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument must be of type string or an instance of ArrayBuffer, Buffer, TypedArray, DataView, KeyObject, or CryptoKey. Received undefined
at new NodeError (node:internal/errors:278:15)
at prepareSecretKey (node:internal/crypto/keys:384:11)
at new Hmac (node:internal/crypto/hash:132:9)
at Object.createHmac (node:crypto:155:10)
at Object.hmac (/usr/src/app/node_modules/ibm-cos-sdk/lib/util.js:423:30)
at Object.getSigningKey (/usr/src/app/node_modules/ibm-cos-sdk/lib/signers/v4_credentials.js:62:8)
at V4.signature (/usr/src/app/node_modules/ibm-cos-sdk/lib/signers/v4.js:98:36)
at V4.authorization (/usr/src/app/node_modules/ibm-cos-sdk/lib/signers/v4.js:93:36)
at V4.addAuthorization (/usr/src/app/node_modules/ibm-cos-sdk/lib/signers/v4.js:35:12)
at /usr/src/app/node_modules/ibm-cos-sdk/lib/event_listeners.js:234:18 {
code: 'ERR_INVALID_ARG_TYPE',
retryDelay: 22.65398033442425
}
Complete! Testcaseimport ibm from 'ibm-cos-sdk'
async function main() {
const bucketName = process.env.COS_BUCKET
const svcInst = process.env.COS_CRN
const apiId = process.env.COS_KEY
const k = 'dir/file.text'
const cosBucket = new ibm.S3({
endpoint: 's3.eu-de.cloud-object-storage.appdomain.cloud',
apiKeyId: apiId,
ibmAuthEndpoint: 'https://iam.cloud.ibm.com/identity/token',
serviceInstanceId: svcInst,
computeChecksums: true
})
console.log('Try…')
try {
console.log('Upload')
const params = { Bucket: bucketName, Key: k, Body: 'bar' }
const options = { partSize: 10 * 2**20, queueSize: 10 }
const response = await cosBucket.upload(params, options).promise()
} catch (error) {
console.error(error)
}
console.log('Complete!')
}
main() |
@huineng Are you using IAM tokens? A different user shared an example that showed the stack trace going through a V4 signature path, but the user was providing an IAM API key. When I added |
I am able to reproduce the failure message using the test case above. Adding |
i'm using apiKeyId i can try that in the morning |
Adding the given option ( Thanks! |
ok, indeed solved, can i get an explanation ? Maybe some documentation needs to be updated |
I'll talk with the documentation team about an update. The short answer is the parameter you set specifically tells the client to look for IAM credentials. The credential handling code had been missing upstream updates going back almost four years. This release fixes a few compatibility bugs going back that far, and this appears to be a side effect of that. The error message is unfortunately confusing: |
Ok, one more thing, it was only happening for uploads, when doing queries or display the attachments, that error did not happen |
@IBMeric This is a breaking change which has been delivered in a minor version change. It doesn't seem like the change was intentional given that the README still says There needs to be a change here which either fixes the |
@jonesphi You're right that this is an unintentional regression. I just looked into this further and am going to re-open this ticket. We will fix this in an upcoming release, hopefully in the next week. |
@karl-otto Could you verify that 1.10.2 does not require you to set For @huineng's curiosity, upstream consolidated several signature version checks to all use the same source instead of using values in multiple data structures. The signature version was correctly reported when the signature checker had an actual request passed to it, but if it did not (common now because of the upstream change), it defaulted to a hardcoded value rather than doing detection. The fix does a check on the credentials available in |
Closing as resolved based on outside feedback. |
This is still an issue for me when using
|
not sure on this but looking at the code
|
@jhaaken Please open a new issue with a sample of the failing code. |
|
The new release (1.10.0) shows following error with our code:
This error is not shown with version 1.9.0.
Code excerpt related to above log:
The text was updated successfully, but these errors were encountered: