ManagedServiceIdentity managedIdentity =
new ManagedServiceIdentity(ManagedServiceIdentityType.UserAssigned);
managedIdentity.UserAssignedIdentities.Add(
userIdentity.Id, null);
RedisPatch patch = new RedisPatch()
{
Identity = managedIdentity
};
RedisResource resource = redisCollection.GetAsync(clusterName).GetResult();
resource.UpdateAsync(WaitUntil.Completed, patch).GetResult();
我正在从托管身份切换回基于连接字符串的 Redis 缓存身份验证。但我无法从缓存中删除现有的用户分配的托管身份
错误
ERROR: Content:
ERROR: {"error":{"code":"FailedIdentityOperation","message":"Identity operation for resource '/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Cache/Redis/xxx' failed with error 'Failed to perform resource identity operation.
Status: 'BadRequest'.
Response: '{\"error\":{\"code\":\"BadRequest\",\"message\":
\"Removal of all user-assigned identities assigned to resource '/subscriptions/xxx/resourcegroups/TEstRGSandBox1/providers/Microsoft.Cache/Redis/xxx'
with type 'UserAssigned' is invalid.\"}}'.'."}}
您可以使用
Azure Rest API
Redis
更新托管身份类型:-***
Rest API文档:-
PATCH https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cache/redis/{cacheName}?api-version=2023-08-01
Content-Type: application/json
Authorization: Bearer <your_access_token>
{
"properties": {
"enableNonSslPort": true,
"replicasPerPrimary": 2,
"identity": {
"type": "SystemAssigned"
}
}
}
C# code:-
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Redis;
using Azure.ResourceManager.Redis.Models;
using Azure.ResourceManager.Resources;
class Program
{
static async Task Main(string[] args)
{
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "bxxxxxxxxx2xxxxf";
string resourceGroupName = "rg-name";
string name = "siliconredis";
ResourceIdentifier redisResourceId = RedisResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, name);
RedisResource redis = client.GetRedisResource(redisResourceId);
RedisPatch patch = new RedisPatch()
{
Identity = null
};
ArmOperation<RedisResource> lro = await redis.UpdateAsync(WaitUntil.Completed, patch);
RedisResource result = lro.Value;
RedisData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
}
}
输出:-
参考源代码.