針對 Azure 自動化帳戶停用系統指派受控識別

您可以使用 Azure 入口網站或使用 REST API,在 Azure 自動化中停用系統指派的受控識別。

使用 Azure 入口網站停用

無論您當初如何設定系統指派的受控識別,您都可以從 Azure 入口網站停用系統指派的受控識別。

  1. 登入 Azure 入口網站

  2. 瀏覽至您的自動化帳戶,然後在 [帳戶設定] 下方選取 [身分識別]

  3. 從 [系統指派] 索引標籤的 [狀態] 按鈕下,選取 [關閉],然後選取 [儲存]。 系統提示您確認時,選取 [是]

系統指派的受控識別已停用,不再具有目標資源的存取權。

使用 REST API 停用

以下提供語法和範例步驟。

要求本文

下列要求本文會停用系統指派的受控識別,並使用 HTTP PATCH 方法移除任何使用者指派的受控識別。

{ 
 "identity": { 
   "type": "None" 
  } 
}

如果已定義多個使用者指派的身分識別,若要保留這些身分識別,而只移除系統指派的身分識別,必須使用逗號分隔清單來指定每個使用者指派的身分識別。 下方範例使用 HTTP PATCH 方法。

{ 
"identity" : {
    "type": "UserAssigned",
    "userAssignedIdentities": {
        "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroupName/providers/Microsoft.ManagedIdentity/userAssignedIdentities/firstIdentity": {},
        "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroupName/providers/Microsoft.ManagedIdentity/userAssignedIdentities/secondIdentity": {}
        }
    }
}

以下是該服務用來傳送 PATCH 要求的 REST API 要求 URI。

PATCH https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resource-group-name/providers/Microsoft.Automation/automationAccounts/automation-account-name?api-version=2020-01-13-preview

範例

執行下列步驟。

  1. 根據您想要執行的作業,將要求本文複製並貼到名為 body_remove_sa.json 的檔案中。 將檔案儲存在本機電腦或 Azure 儲存體帳戶中。

  2. 使用 Connect-AzAccount cmdlet 以互動方式登入 Azure 並遵循指示。

    # Sign in to your Azure subscription
    $sub = Get-AzSubscription -ErrorAction SilentlyContinue
    if(-not($sub))
    {
        Connect-AzAccount
    }
    
    # If you have multiple subscriptions, set the one to use
    # Select-AzSubscription -SubscriptionId "<SUBSCRIPTIONID>"
    
  3. 為變數提供適當的值,然後執行指令碼。

    $subscriptionID = "subscriptionID"
    $resourceGroup = "resourceGroupName"
    $automationAccount = "automationAccountName"
    $file = "path\body_remove_sa.json"
    
  4. 此範例會使用 PowerShell Cmdlet Invoke-RestMethod 將 PATCH 要求傳送至您的自動化帳戶。

    # build URI
    $URI = "https://management.azure.com/subscriptions/$subscriptionID/resourceGroups/$resourceGroup/providers/Microsoft.Automation/automationAccounts/$automationAccount`?api-version=2020-01-13-preview"
    
    # build body
    $body = Get-Content $file
    
    # obtain access token
    $azContext = Get-AzContext
    $azProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
    $profileClient = New-Object -TypeName Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient -ArgumentList ($azProfile)
    $token = $profileClient.AcquireAccessToken($azContext.Subscription.TenantId)
    $authHeader = @{
        'Content-Type'='application/json'
        'Authorization'='Bearer ' + $token.AccessToken
    }
    
    # Invoke the REST API
    Invoke-RestMethod -Uri $URI -Method PATCH -Headers $authHeader -Body $body
    
    # Confirm removal
    (Get-AzAutomationAccount `
        -ResourceGroupName $resourceGroup `
        -Name $automationAccount).Identity.Type
    

    根據您使用的語法,輸出會是:UserAssigned 或空白。

下一步