Condividi tramite


Cosa sono le identità gestite per le risorse di Azure?

Uno dei problemi comuni a cui devono far fronte gli sviluppatori riguarda la gestione di segreti, credenziali, certificati e chiavi per proteggere la comunicazione tra i servizi. Manual handling of secrets and certificates are a known source of security issues and outages. Grazie alle identità gestite, gli sviluppatori non devono più gestire queste credenziali. Le applicazioni possono usare le identità gestite per ottenere i token di Microsoft Entra senza dover gestire le credenziali.

What are managed identities?

A livello generale, esistono due tipi di identità: le identità umane e le identità di macchine/non umane. Machine / non-human identities consist of device and workload identities. In Microsoft Entra le identità dei carichi di lavoro sono applicazioni, entità servizio e identità gestite. For more information on workload identities, see workload identities.

A managed identity is an identity that can be assigned to an Azure compute resource (Virtual Machine (VM), Virtual Machine Scale Set (VMSS), Service Fabric Cluster, Azure Kubernetes cluster) or any App hosting platform supported by Azure. Once a managed identity is assigned on the compute resource, it can be authorized, directly or indirectly, to access downstream dependency resources, such as a storage account, SQL database, CosmosDB, and so on. Managed identity replaces secrets such as access keys or passwords. In addition, managed identities can replace certificates or other forms of authentication for service-to-service dependencies.

Il video seguente illustra come è possibile usare le identità gestite:

Ecco alcuni vantaggi derivanti dall'uso delle identità gestite:

  • Non è necessario gestire le credenziali. Credentials aren’t even accessible to you.
  • È possibile usare le identità gestite per eseguire l'autenticazione per qualsiasi risorsa che supporti l'autenticazione di Microsoft Entra, incluse le proprie applicazioni.
  • Le identità gestite possono essere utilizzate senza costi aggiuntivi.

Tipi di identità gestita

Sono disponibili due tipi di identità gestite:

  • Assegnato dal sistema. Alcune risorse di Azure, ad esempio le macchine virtuali, consentono di abilitare un'identità gestita direttamente nella risorsa. Quando si abilita un'identità gestita assegnata dal sistema:

    • A service principal of a special type is created in Microsoft Entra ID for the identity. The service principal is tied to the lifecycle of that Azure resource. When the Azure resource is deleted, Azure automatically deletes the service principal for you.
    • Per impostazione predefinita, solo questa specifica risorsa di Azure può usare questa identità per richiedere token ad Microsoft Entra ID.
    • L'utente autorizza l'identità gestita ad avere accesso a uno o più servizi.
    • The name of the system-assigned service principal is always the same as the name of the Azure resource it's created for. For a deployment slot, the name of its system-assigned identity is <app-name>/slots/<slot-name>.
  • Assegnata dall'utente. È anche possibile creare un'identità gestita come risorsa di Azure autonoma. È possibile creare un'identità gestita assegnata dall'utente e assegnarla a una o più risorse di Azure. Quando si abilita un'identità gestita assegnata dall'utente:

    • A service principal of a special type is created in Microsoft Entra ID for the identity. L'entità principale del servizio viene gestita separatamente dalle risorse che lo utilizzano.
    • Le identità assegnate dall'utente possono essere usate da più risorse.
    • L'utente autorizza l'identità gestita ad avere accesso a uno o più servizi.

    User-assigned identities, which are provisioned independently from compute and can be assigned to multiple compute resources, are the recommended managed identity type for Microsoft services.

Le risorse che supportano le identità gestite assegnate dal sistema consentono di:

  • Abilitare o disabilitare le identità gestite a livello di risorsa.
  • Usare il controllo degli accessi in base al ruolo (RBAC) per concedere le autorizzazioni.
  • Visualizzare le operazioni di creazione, lettura, aggiornamento ed eliminazione (CRUD) nei Log Attività di Azure.
  • Visualizzare l'attività di accesso nei log di accesso di Microsoft Entra ID.

Se invece si sceglie un'identità gestita assegnata all'utente:

Le operazioni sulle identità gestite possono essere eseguite usando un modello di Azure Resource Manager, il portale di Azure, l'interfaccia della riga di comando di Azure, PowerShell e le API REST.

Differences between system-assigned and user-assigned managed identities

Proprietà Identità gestita assegnata dal sistema Identità gestita assegnata dall'utente
Creazione Creato come parte di una risorsa di Azure (ad esempio Macchine virtuali di Azure o Servizio app di Azure). Creata come risorsa di Azure autonoma.
Ciclo di vita Ciclo di vita condiviso con la risorsa di Azure con cui viene creata l'identità gestita.
Quando viene eliminata la risorsa principale, viene eliminata anche l'identità gestita.
Ciclo di vita indipendente.
Deve essere eliminata in modo esplicito.
Condivisione tra risorse di Azure Can’t be shared.
Può essere associata solo a una singola risorsa di Azure.
Può essere condivisa.
La stessa identità gestita assegnata dall'utente può essere associata a più risorse di Azure.
Casi d'uso comuni Carichi di lavoro contenuti in una singola risorsa di Azure.
I carichi di lavoro necessitano di identità indipendenti.
Ad esempio, un'applicazione eseguita in una singola macchina virtuale.
Carichi di lavoro che possono essere eseguiti su più risorse e condividere una singola identità.
Workloads needing preauthorization to a secure resource, as part of a provisioning flow.
Carichi di lavoro in cui le risorse vengono riciclate frequentemente, ma le autorizzazioni devono rimanere coerenti.
Ad esempio, un carico di lavoro in cui più macchine virtuali devono accedere alla stessa risorsa.

Come usare le identità gestite per le risorse di Azure

È possibile usare le identità gestite seguendo questa procedura:

  1. Creare un'identità gestita in Azure. È possibile scegliere tra l'identità gestita assegnata dal sistema o l'identità gestita assegnata dall'utente.
    1. Quando si usa un'identità gestita assegnata all'utente, si assegna l'identità gestita alla risorsa di "origine" di Azure, ad esempio una macchina virtuale, un'app per la logica di Azure o un'app Web di Azure.
  2. Autorizzare l'identità gestita ad avere accesso al servizio di destinazione.
  3. Usare l'identità gestita per accedere a una risorsa. In questo passaggio è possibile usare Azure SDK con la libreria Azure.Identity. Alcune risorse di "origine" offrono connettori che sanno come usare le identità gestite per le connessioni. In tal caso, si usa l'identità come funzionalità della risorsa di "origine".

Quali servizi di Azure supportano la funzionalità?

È possibile usare le identità gestite per le risorse di Azure per eseguire l'autenticazione ai servizi che supportano l'autenticazione di Microsoft Entra. Per un elenco dei servizi Azure supportati, vedere Servizi che supportano le identità gestite per le risorse di Azure.

Work with managed identities

Managed identities can be used directly or as a Federated Identity Credential for Microsoft Entra ID applications.

The steps involved in using managed identities are as follows:

  1. Creare un'identità gestita in Azure. È possibile scegliere tra l'identità gestita assegnata dal sistema o l'identità gestita assegnata dall'utente. When using a user-assigned managed identity, you assign the managed identity to the source Azure Resource, such as a Virtual Machine, Azure Logic App or an Azure Web App.
  2. Authorize the managed identity to have access to the target service.
  3. Usare l'identità gestita per accedere a una risorsa. In this step, you can use any of the client libraries. Some source resources offer connectors that know how to use Managed identities for the connections. In that case, you use the identity as a feature of that source resource.

Use managed identity directly

Service code running on your Azure compute resource uses either the Microsoft Authentication Library (MSAL) or Azure.Identity SDK to retrieve a managed identity token from Entra ID backed by the managed identity. This token acquisition doesn't require any secrets and is automatically authenticated based on the environment where the code runs. As long as the managed identity is authorized, the service code can access downstream dependencies that support Entra ID authentication.

For example, you can use an Azure Virtual Machine (VM) as Azure Compute. You can then create a user-assigned managed identity and assign it to the VM. The workload running on the VM interfaces with both Azure.Identity (or MSAL) and Azure Storage client SDKs to access a storage account. The user-assigned managed identity is authorized to access the storage account.

Use managed identity as a Federated Identity Credential (FIC) on an Entra ID app

Workload Identity Federation enables using a managed identity as a credential, just like certificate or password, on Entra ID Applications. Whenever an Entra ID app is required, this is the recommended way to be credential-free. There's a limit of 20 FICs when using managed identities as FIC on an Entra ID App.

A workload acting in the capacity of Entra ID application can be hosted on any Azure compute which has a managed identity. The workload uses the managed identity to acquire a token to be exchanged for an Entra ID Application token, via workload identity federation. This feature is also referred to as managed identity as FIC (Federated Identity Credentials). For more information, see configure an application to trust a managed identity.

Passaggi successivi