Fix scopes mutation by cloning original array (#37981) (#37996)

(cherry picked from commit c6356c5bba)

Co-authored-by: Sergey Kostrukov <sekost@microsoft.com>
This commit is contained in:
Grot (@grafanabot)
2021-08-18 10:36:41 +02:00
committed by GitHub
co-authored by Sergey Kostrukov
parent 3baec71cce
commit 1fe8b3a7b0
@@ -140,6 +140,12 @@ func (c *managedIdentityTokenRetriever) Init() error {
}
func (c *managedIdentityTokenRetriever) GetAccessToken(ctx context.Context, scopes []string) (*AccessToken, error) {
// Workaround for a bug in Azure SDK which mutates the passed array of scopes
// See details https://github.com/Azure/azure-sdk-for-go/issues/15308
arr := make([]string, len(scopes))
copy(arr, scopes)
scopes = arr
accessToken, err := c.credential.GetToken(ctx, azcore.TokenRequestOptions{Scopes: scopes})
if err != nil {
return nil, err