
In a recent post, I described how to configure CertKit to automatically deploy renewed TLS certificates to Microsoft Entra Application Proxy applications using an Entra app registration with client secret authentication. That method works anywhere, but it relies on a client secret that must be stored securely and rotated before it expires. When the CertKit agent runs on an Azure virtual machine or an Azure Arc-enabled server, CertKit can authenticate with a managed identity instead, eliminating the client secret entirely. This configuration uses the same least-privilege permissions as the client secret method. The following sections describe how to configure it using both PowerShell and the Azure portal.
Why Use a Managed Identity
A managed identity is an identity in Microsoft Entra ID that Azure manages on behalf of an Azure resource. It offers several advantages over a client secret, including the following.
- No secret to manage. There’s no client secret to store, protect, or rotate, and no expiration date that can unexpectedly break certificate deployments.
- Bound to a specific resource. The identity can only be used from the Azure resource it’s attached to. It can’t be copied out of a configuration file or password vault and used elsewhere.
- Aligned with Microsoft guidance. Microsoft recommends managed identities over client secrets for workloads that support them.
There are tradeoffs, however. A managed identity is available only to Azure resources, so the CertKit agent must run on an Azure virtual machine or a server onboarded to Azure Arc. In addition, anyone who compromises that server can request tokens as the managed identity. Least privilege limits the impact, just as it does with a client secret. Managed identity authentication is an alternative to client secret authentication, not a replacement. For organizations without an Azure or Azure Arc presence, the client secret method remains a good choice.
Requirements
Using a managed identity with CertKit requires the following.
- An Azure virtual machine or Azure Arc-enabled server. The CertKit agent must run on a server with a managed identity. Azure virtual machines support managed identities natively and don’t require Azure Arc. On-premises servers, or servers hosted in other clouds, must be onboarded to Azure Arc. The server doesn’t need to be domain-joined.
- An Azure subscription in the same tenant. The Azure subscription must be associated with the same Microsoft Entra tenant where Application Proxy is configured.
- Outbound internet access. The CertKit agent requires outbound HTTPS access to CertKit and Microsoft Graph. No inbound access or public IP address is required.
- The Microsoft Graph PowerShell module on the agent host. The CertKit agent uses the Microsoft.Graph.Authentication module to sign in with the managed identity. Since the agent runs as Local System, the module must be installed for all users.
- Microsoft Entra ID P1. This is already required for Application Proxy and custom roles. Assigning the role through Privileged Identity Management (PIM) requires Microsoft Entra ID P2 or Microsoft Entra ID Governance.
I recommend using a user-assigned managed identity. It’s a standalone Azure resource dedicated to CertKit, and it persists if the virtual machine is rebuilt or replaced. Azure Arc-enabled servers support only a system-assigned managed identity, which is shared with the Azure Arc agent and other services on the server.
Required Permissions for CertKit
The managed identity requires the same least-privilege permissions as the client secret method, including the following.
- Application.Read.All. A read-only Microsoft Graph application permission CertKit uses to find App Proxy applications in the tenant.
- A custom Entra role. A custom role, named App Proxy Certificate Manager in this example, with only three permissions: read Application Proxy settings, update the Application Proxy SSL certificate, and read connector groups.
This configuration follows security best practices and enforces least privilege. The managed identity can’t add credentials to applications, change API permissions, or grant consent. For more details on these permissions and why built-in roles such as Application Administrator should be avoided, see the client secret post. If you’ve already created the custom role for client secret authentication, you can reuse it.
Create the Managed Identity
A user-assigned managed identity is an Azure resource, so it’s created in the Azure portal rather than the Entra admin center. Create it and attach it to the virtual machine running the CertKit agent using the following steps.
Create the User-Assigned Managed Identity
To begin, create the managed identity.
- In the Azure portal, search for Managed Identities and click Create.
- Select the subscription, resource group, and region, and enter a name, such as certkit-app-proxy.
- Click Review + create, then Create.
- On the managed identity’s Overview page, record the Client ID. CertKit and the configuration script both use this value.
Attach the Managed Identity to the Virtual Machine
Next, attach the managed identity to the virtual machine running the CertKit agent.
- Open the virtual machine and navigate to Security > Identity.
- Select the User assigned tab and click Add.
- Select the managed identity and click Add.
Alternatively, attach the managed identity using the Azure CLI in Azure Cloud Shell. Replace the resource group, virtual machine name, and managed identity resource ID with your own. The resource ID is shown on the managed identity’s Properties page.
az vm identity assign --resource-group <resourceGroup> --name <vmName> --identities <managedIdentityResourceId>
Install the Microsoft Graph PowerShell Module on the Agent Host
With managed identity authentication, the CertKit agent signs in to Microsoft Graph locally on the server using the Microsoft.Graph.Authentication PowerShell module. The agent runs as Local System, so the module must be installed for all users. On the server running the CertKit agent, open an elevated Windows PowerShell command window and run the following command.
Install-Module -Name Microsoft.Graph.Authentication -Scope AllUsers -Repository PSGallery -Force
Be sure to use Windows PowerShell, not PowerShell 7. The two use separate module locations, and the CertKit agent uses Windows PowerShell. If the module is missing, CertKit deployments fail with an error indicating that Microsoft.Graph.Authentication is not installed.
Configuration Using PowerShell
You can grant the managed identity its permissions in a single run using my New-CertKitAppProxyIdentity.ps1 PowerShell script on GitHub. Specify the managed identity’s client ID with the -ManagedIdentityId parameter, and the script creates the custom role if it doesn’t already exist, grants Application.Read.All, and assigns the role. Add -UsePim to assign the role through PIM, and -TenantId if your account has access to more than one tenant. The script confirms the identity is a managed identity before making any changes. Alternatively, follow the manual steps below, which show exactly what the script does. Either way, you’ll need the Microsoft.Graph.Authentication module on your workstation. Install it using the following command.
Install-Module -Name Microsoft.Graph.Authentication -Scope CurrentUser
Then run the script, replacing <clientId> with the managed identity’s client ID.
New-CertKitAppProxyIdentity.ps1 -ManagedIdentityId <clientId> -UsePim
When the script finishes, it displays the managed identity’s name and client ID. Skip ahead to Configure CertKit to complete the configuration. To configure the managed identity manually instead, follow the steps below.
Connect to Microsoft Graph
First, connect to Microsoft Graph with an account that can create custom roles, grant application permissions, and assign directory roles, such as Privileged Role Administrator or Global Administrator. If your account has access to more than one tenant, add -TenantId with the tenant ID or domain name to sign in to the correct tenant.
Connect-MgGraph -Scopes 'Application.Read.All', 'AppRoleAssignment.ReadWrite.All', 'RoleManagement.ReadWrite.Directory' -NoWelcome
Find the Managed Identity
Next, find the managed identity’s service principal using its client ID. Confirm that servicePrincipalType is ManagedIdentity before continuing.
$Mi = (Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/servicePrincipals?`$filter=appId eq '<clientId>'&`$select=id,appId,displayName,servicePrincipalType").value[0]$Mi
Create the Custom Role
If you haven’t already created the custom role for client secret authentication, create it now. Otherwise, retrieve the existing role.
$RoleBody = @{ displayName = 'App Proxy Certificate Manager' description = 'Can read Application Proxy settings and update the Application Proxy SSL certificate. Used by CertKit.' isEnabled = $true rolePermissions = @(@{ allowedResourceActions = @( 'microsoft.directory/applications/applicationProxy/read' 'microsoft.directory/applications/applicationProxySslCertificate/update' 'microsoft.directory/connectorGroups/allProperties/read' ) })}$Role = Invoke-MgGraphRequest -Method POST -Uri 'https://graph.microsoft.com/v1.0/roleManagement/directory/roleDefinitions' -Body $RoleBody
To retrieve an existing role instead, use the following command.
$Role = (Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/roleManagement/directory/roleDefinitions?`$filter=displayName eq 'App Proxy Certificate Manager'").value[0]
Grant the Application.Read.All Permission
Next, grant the managed identity the read-only Microsoft Graph application permission Application.Read.All. Assigning the permission this way also grants admin consent.
$GraphSp = (Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/servicePrincipals?`$filter=appId eq '00000003-0000-0000-c000-000000000000'&`$select=id,appRoles").value[0]$AppRoleId = ($GraphSp.appRoles | Where-Object { $_.value -eq 'Application.Read.All' -and $_.allowedMemberTypes -contains 'Application' }).id$Grant = @{ principalId = $Mi.id resourceId = $GraphSp.id appRoleId = $AppRoleId}Invoke-MgGraphRequest -Method POST -Uri "https://graph.microsoft.com/v1.0/servicePrincipals/$($Mi.id)/appRoleAssignments" -Body $Grant
Assign the Custom Role
Finally, assign the custom role to the managed identity, scoped to the entire tenant.
$Body = @{ '@odata.type' = '#microsoft.graph.unifiedRoleAssignment' roleDefinitionId = $Role.id principalId = $Mi.id directoryScopeId = '/'}Invoke-MgGraphRequest -Method POST -Uri 'https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignments' -Body $Body
If your tenant is licensed for Microsoft Entra ID P2 or Microsoft Entra ID Governance, assign the role through Privileged Identity Management (PIM) instead. Role assignments made outside PIM aren’t tracked by PIM and trigger a high-severity alert. Managed identities support only active assignments in PIM, so the following command creates a permanent active assignment. If the custom role was just created, PIM can take several minutes to recognize it. If the command fails with a RoleNotFound error, wait a few minutes and try again.
$Body = @{ action = 'adminAssign' justification = 'CertKit certificate deployment to Entra Application Proxy' roleDefinitionId = $Role.id directoryScopeId = '/' principalId = $Mi.id scheduleInfo = @{ startDateTime = (Get-Date).ToUniversalTime().ToString('o') expiration = @{ type = 'noExpiration' } }}Invoke-MgGraphRequest -Method POST -Uri 'https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignmentScheduleRequests' -Body $Body
Configuration Using the Entra Admin Center
The Microsoft Entra admin center can’t grant Microsoft Graph application permissions to a managed identity, so the Application.Read.All permission must be granted using PowerShell, as shown above. The custom role can be created and assigned in the Entra admin center, however. Create the custom role as described in the client secret post if it doesn’t already exist, then assign it using the following steps.
- Navigate to Entra ID > Roles & admins, then search for and select App Proxy Certificate Manager.
- Click Add assignments, then Select member(s).
- Search for the managed identity by name, select it, and click Select.
- If Privileged Identity Management (PIM) is enabled, click Next, set the assignment type to Active and Permanently assigned, enter a justification, and click Assign. Without PIM, click Add.
Configure CertKit
With the managed identity configured, create a new deployment in CertKit using the Microsoft Entra Application Proxy (Managed Identity Auth) template for the agent running on the virtual machine. Select the certificate to deploy, then enter the user-assigned managed identity’s client ID in the Managed identity field. To use a system-assigned managed identity instead, such as on an Azure Arc-enabled server, leave the field set to system. No tenant ID or client secret is required. Then list the App Proxy applications to update by name, separated by commas, or enter an asterisk (*) as an app list wildcard to update all of them. If you update all applications, be sure to use a wildcard or multi-SAN certificate that covers the external URL of every App Proxy application you want CertKit to manage.
Deploy and Validate
After saving the CertKit deployment, wait a few minutes for the role assignment and API permission to take effect, then run the deployment. A successful run shows CertKit signing in as the user-assigned managed identity, then lists each App Proxy application, whether its external URL is covered by the certificate, and the thumbprint Entra reports after the update.
Update command output:Microsoft Entra Application Proxy Deployment | Apps: *[Step 1] Reading certificate... Certificate: | Thumbprint: <redacted> | Expires: 2026-11-30 Covers: *.example.net, example.net[Step 2] Signing in to Microsoft Graph... Signed in as the user-assigned managed identity <redacted> (tenant <redacted>) Graph permissions: Application.Read.All Warning: The identity has no Microsoft Graph permission to update apps. Unless an Entra role allows it, uploads will be refused. Grant the application permission Application.ReadWrite.OwnedBy (admin consented) and add the identity as an owner of each App Proxy app.[Step 3] Finding App Proxy apps... Found 8 App Proxy app(s) App1 (https://app1.example.net/): covered by this certificate Private Access App 1: skipped, a Global Secure Access (Private Access) app, which has no TLS certificate Private Access App 2: skipped, a Global Secure Access (Private Access) app, which has no TLS certificate App2 (https://app2.example.net/): covered by this certificate App3 (https://app3.example.net/): covered by this certificate App4 (https://app4.example.net/): covered by this certificate App5 (https://app5.example.net/): covered by this certificate App6 (https://app6.example.net/): covered by this certificate[Step 4] Uploading certificate... App1 (https://app1.example.net/): updated (Entra reports thumbprint <redacted>, expires 2026-11-30) App2 (https://app2.example.net/): updated (Entra reports thumbprint <redacted>, expires 2026-11-30) App3 (https://app3.example.net/): updated (Entra reports thumbprint <redacted>, expires 2026-11-30) App4 (https://app4.example.net/): updated (Entra reports thumbprint <redacted>, expires 2026-11-30) App5 (https://app5.example.net/): updated (Entra reports thumbprint <redacted>, expires 2026-11-30) App6 (https://app6.example.net/): updated (Entra reports thumbprint <redacted>, expires 2026-11-30)DONE | Updated 6 app(s), 0 already had the certificate. Entra takes a minute or two to start serving it.
CertKit displays a warning that the identity has no Graph permission to update apps, but you can safely ignore it, because the custom role grants that access. App Proxy can take several minutes to begin serving the new certificate. To confirm the certificate the endpoint is serving, use my Get-TlsCertificate PowerShell script, as described in the client secret post.
Get-TlsCertificate -Hostname app1.example.net
Removing the Configuration
To remove CertKit’s permissions from the managed identity, use my Remove-CertKitAppProxyIdentity.ps1 PowerShell script with the -ManagedIdentityId parameter. The script removes the role assignment and the Application.Read.All permission. It doesn’t delete the managed identity, which is an Azure resource, and it keeps the custom role if another identity still uses it. This makes it safe to move from client secret authentication to a managed identity, or back, without breaking the other deployment.
.\Remove-CertKitAppProxyIdentity.ps1 -ManagedIdentityId <clientId>
Summary
When the CertKit agent runs on an Azure virtual machine or an Azure Arc-enabled server, a managed identity eliminates the client secret, removing the need to store, protect, and rotate it. The managed identity uses the same custom Entra role and read-only Application.Read.All permission as the client secret method, so this configuration follows security best practices and enforces least privilege. For organizations without an Azure or Azure Arc presence, client secret authentication remains a secure and effective alternative.
Getting Started with CertKit
Need help automating TLS certificate deployment for Entra Application Proxy, Always On VPN, DirectAccess, IIS, SQL, and more? I can help you design and implement a secure, least-privilege certificate automation strategy with CertKit across your internal and public-facing workloads. Fill out the form below, and I’ll provide you with more information.
Additional Information
- Automating Entra App Proxy Certificates with CertKit (Client Secret)
- What Are Managed Identities for Azure Resources?
- Manage User-Assigned Managed Identities
- Authenticate Against Azure Resources with Azure Arc-Enabled Servers
- Enterprise Application Permissions for Custom Roles in Microsoft Entra ID
- Assign Microsoft Entra Roles in Privileged Identity Management
- CertKit PowerShell Scripts on GitHub











