azure-sdk-for-js icon indicating copy to clipboard operation
azure-sdk-for-js copied to clipboard

Partial document update fails with managed identity

Open mbhaskar opened this issue 3 years ago • 10 comments

fetchAll/upsert/create method are working fine. But .patch is throwing below error.

Trace:

97268cd7-4789-47fe-9dfe-2e8d42944e3f | ProductsCleaner | Error: Required Header authorization is missing. Ensure a valid Authorization token is passed. ActivityId: eff8dfcc-c5ee-43af-9f07-691cc6ecc66c, Microsoft.Azure.Documents.Common/2.14.0 at httpRequest (.../node_modules/@azure/cosmos/dist/index.js:7785:31) at runMicrotasks (anonymous) at processTicksAndRejections (internal/process/task_queues.js:95:5) at async execute ((.../node_modules/@azure/cosmos/dist/index.js:7620:26) at async ClientContext.patch (.../node_modules/@azure/cosmos/dist/index.js:8316:30) at async Item.patch (.../node_modules/@azure/cosmos/dist/index.js:4408:26) at async Promise.all (index 0) { code: 401, body: { code: 'Unauthorized', message: 'Required Header authorization is missing. Ensure a valid Authorization token is passed.\r\n' + 'ActivityId: eff8dfcc-c5ee-43af-9f07-691cc6ecc66c, Microsoft.Azure.Documents.Common/2.14.0' }, headers: { 'transfer-encoding': 'chunked', 'content-type': 'application/json', 'content-location': '/docs/', server: 'Microsoft-HTTPAPI/2.0', 'x-ms-activity-id': 'eff8dfcc-c5ee-43af-9f07-691cc6ecc66c', 'strict-transport-security': 'max-age=31536000', 'x-ms-gatewayversion': 'version=2.14.0', date: 'Wed, 02 Mar 2022 21:33:48 GMT', 'x-ms-throttle-retry-count': 0, 'x-ms-throttle-retry-wait-time-ms': 0 }, activityId: 'eff8dfcc-c5ee-43af-9f07-691cc6ecc66c' }

mbhaskar avatar Mar 07 '22 17:03 mbhaskar

Note: this could be related to https://github.com/Azure/azure-sdk-for-js/issues/20690

maorleger avatar Mar 07 '22 21:03 maorleger

I'm encountering the same thing. is it advised to try downgrading the @azure/core-http dependency?

EDIT: that didn't seem to help. My @azure/core-http was at 2.2.4 and I brought it down to 2.2.2. I'd hate to move away from managed identities to get patch to work.

wup-one avatar Apr 15 '22 17:04 wup-one

We have encountered the same issue, is there any updates on this?

Having done some investigation, I suspect the issue is that https://github.com/Azure/azure-sdk-for-js/blob/4e39a2adcb41d74d42bb37b5836200a20ca3c554/sdk/cosmosdb/cosmos/src/ClientContext.ts#L322 does not pass in the pipeline as pipeline: this.pipeline.

My logic behind this root cause, is that the pipeline uses the aadCredentials has a policy that applies the Authorization header with its bearer token value.

ghost avatar May 26 '22 10:05 ghost

We have verified the following fix works, using https://www.npmjs.com/package/patch-package:

diff --git a/node_modules/@azure/cosmos/dist/index.js b/node_modules/@azure/cosmos/dist/index.js
index d2b45fa..44f4e29 100644
--- a/node_modules/@azure/cosmos/dist/index.js
+++ b/node_modules/@azure/cosmos/dist/index.js
@@ -8302,6 +8302,7 @@ class ClientContext {
                 options,
                 plugins: this.cosmosClientOptions.plugins,
                 partitionKey,
+                pipeline: this.pipeline,
             };
             request$1.headers = await this.buildHeaders(request$1);
             this.applySessionToken(request$1);

ghost avatar May 30 '22 08:05 ghost

@asdaandrewhaigh Thanks for looking into this! We will investigate and make the changes!

sajeetharan avatar May 30 '22 15:05 sajeetharan

@sajeetharan we have encountered the same issue, any update on the changes?

JameelKhan9 avatar Aug 26 '22 01:08 JameelKhan9

Is there an ETA on this fix? Seems like this should be an urgent priority bug...

ChuckJonas avatar Sep 16 '22 23:09 ChuckJonas

@ChuckJonas we have tagged it for the milestone-september 28th

sajeetharan avatar Sep 18 '22 08:09 sajeetharan

Just checking in... did this go out? Struggling to find a changelog in this monorepo...

ChuckJonas avatar Oct 04 '22 15:10 ChuckJonas

hI @ChuckJonas Not yet, we are planning to release this with the next version 3.17.2 in couple of weeks time!

sajeetharan avatar Oct 07 '22 04:10 sajeetharan

@v1k1 tag the PR for the fix, we will be releasing this with the next release 3.17.2

sajeetharan avatar Nov 11 '22 03:11 sajeetharan

This is completed and released!

sajeetharan avatar Nov 29 '22 06:11 sajeetharan