Azure / azure-cli

Azure Command-Line Interface
MIT License
4.03k stars 3.01k forks source link

Use Read Write Consistency (RWC) Token to call Microsoft Graph API #21674

Open jiasli opened 2 years ago

jiasli commented 2 years ago

Symptom

As reported in IcM 294491919, even though az ad sp create-for-rbac has retry logic to create service principal after the application creation replication/propagation is done:

https://github.com/Azure/azure-cli/blob/f8ea47cd3330d1125b322f6c54e3da947596c1c7/src/azure-cli/azure/cli/command_modules/role/custom.py#L1451-L1469

It is still be possible that after _RETRY_TIMES (whose value is 36), the replication is not complete, leading to service principal creation failure:

The appId 'c807447b-5118-4756-a6c5-90dbdf919d22' of the service principal does not reference a valid application object.

Possible solution

AAD has a mechanism called Read Write Consistency (RWC) Token to solve this:

Problems

Alternative solutions

Increase _RETRY_TIMES to higher value or use exponential backoff in order to increase the max totally retry time (currently 36*5s=180s).

yonzhan commented 2 years ago

Use Read Write Consistency (RWC)