Automating Entra App Proxy Certificates with CertKit (Certificate Authentication)

Microsoft Entra ID icon

In previous posts, I described how to configure CertKit to automatically deploy renewed TLS certificates to Microsoft Entra Application Proxy applications using client secret authentication and managed identity authentication. Client secret authentication works anywhere, but the secret is a bearer credential that can be copied, pasted, logged, or leaked. A managed identity eliminates the secret, but it requires the CertKit agent to run on an Azure virtual machine or an Azure Arc-enabled server. CertKit now supports certificate authentication, which offers the best of both. The private key is created on the CertKit agent server, protected by the Trusted Platform Module (TPM), and can’t be exported, and it works on any Windows server without an Azure dependency. Version 2.0 of my New-CertKitAppProxyIdentity.ps1 PowerShell script configures it end to end in a single run, using the same least-privilege permissions as the other methods. The following sections describe how to configure it using both PowerShell and the Entra admin center.

Why Use Certificate Authentication

With certificate authentication, CertKit signs in to Microsoft Graph by signing a client assertion with the certificate’s private key, and Entra validates it against the public key uploaded to the app registration. This approach offers several advantages, including the following.

  • No shared secret. Only the public key leaves the server. CertKit stores the certificate thumbprint, which is useless without the private key.
  • Bound to the server. The private key is created in the TPM and marked non-exportable, so it can’t be copied out of the server and used elsewhere.
  • Works anywhere. No Azure subscription, Azure virtual machine, or Azure Arc agent is required. The CertKit agent can run on any Windows server, on-premises or in any cloud.
  • Aligned with Microsoft guidance. Microsoft recommends certificate credentials over client secrets for app registrations, and notes that self-signed certificates are still preferred over secrets.

The following table compares the three authentication methods CertKit supports for Entra App Proxy.

Client SecretManaged IdentityCertificate
Where the agent runsAnywhereAzure virtual machine or Azure Arc-enabled serverAny Windows server
CredentialShared secret entered in CertKitTokens issued by AzurePrivate key stored in the TPM
Can be copied and reused elsewhereYesNoNo
Azure dependencyNoneAzure subscription, plus Azure Arc outside AzureNone
RotationAt least every 12 monthsNot requiredEvery 30 to 365 days

A managed identity is a good choice when the CertKit agent already runs on an Azure virtual machine. For servers outside Azure, though, it carries a management burden. The server must be onboarded to Azure Arc, the Azure Arc agent must be kept up to date, the server needs outbound access to Azure endpoints, and an Azure subscription is required in the same tenant. Azure Arc-enabled servers also support only a system-assigned managed identity, which is shared with the Azure Arc agent and other services on the server. The Azure Arc core control plane is free, but add-on management services such as Azure Update Manager, Azure Policy guest configuration, and Microsoft Defender for Cloud are billed per server once enabled, and they’re easy to accumulate once servers are managed in Azure. Certificate authentication avoids all of this. There are tradeoffs, however. The certificate expires and must be rotated, and anyone with administrative access to the server can use the key to sign in as CertKit, even though they can’t export it. Least privilege limits the impact, just as it does with the other methods.

Requirements

Using certificate authentication with CertKit requires the following.

  • Access to the CertKit agent server. The certificate’s private key is non-exportable, so it must be created on the server running the CertKit agent, in an elevated PowerShell session. There’s no option to import an existing certificate.
  • A TPM (recommended). A physical TPM or a virtual TPM (vTPM) protects the private key in hardware. Most virtualization platforms provide a vTPM, including Hyper-V Generation 2 virtual machines, Azure virtual machines with Trusted Launch, and VMware vSphere, though it may need to be enabled. If no TPM is available, the key is stored in software instead. More on that below.
  • The Microsoft Graph PowerShell module on the agent host. The CertKit agent uses the Microsoft.Graph.Authentication module to sign in with the certificate. Since the agent runs as Local System, the module must be installed for all users. The configuration script uses the same module.
  • An administrative account. An account that can create custom roles, grant application permissions, and assign directory roles, such as Privileged Role Administrator or Global Administrator.
  • 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.

Required Permissions for CertKit

Certificate authentication uses an Entra app registration with 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.

With these permissions, CertKit 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 another authentication method, you can reuse it.

Configuration Using PowerShell

You can perform the entire configuration in a single run using my New-CertKitAppProxyIdentity.ps1 PowerShell script on GitHub. Beginning with version 2.0, certificate authentication is the default. The script is also available in the PowerShell Gallery. On the CertKit agent server, open an elevated Windows PowerShell window and install the Microsoft.Graph.Authentication module for all users, along with the script, using the following commands. Be sure to use Windows PowerShell, not PowerShell 7, when installing the module. The two use separate module locations, and the CertKit agent uses Windows PowerShell.

Install-Module -Name Microsoft.Graph.Authentication -Scope AllUsers -Repository PSGallery -Force
Install-Script -Name New-CertKitAppProxyIdentity -Scope CurrentUser

Then run the script. Add -UsePim to assign the role through PIM, and -TenantId if your account has access to more than one tenant.

New-CertKitAppProxyIdentity.ps1 -UsePim

What the Script Does

A single run of the script performs the following steps.

  1. Creates a self-signed certificate in the local computer’s personal certificate store, before anything changes in Entra.
  2. Creates or reuses the custom role, the app registration, and its service principal.
  3. Grants Application.Read.All and assigns the role, either directly or through PIM.
  4. Uploads the public certificate to the app registration, named CertKit Agent – <computer name>.
  5. Removes expired certificates and client secrets from the app registration, and expired CertKit certificates from the local store.
  6. With -RemoveExistingCertificates, removes this server’s older certificates from Entra and the local store.
  7. Displays the tenant ID, client ID, and certificate thumbprint to enter in CertKit.

Creating the certificate first means a TPM failure leaves the tenant untouched, with no partially configured app registration or role. If the certificate never reaches Entra, because of an error or a declined confirmation prompt, the script deletes it from the local store so nothing is left behind. When the script finishes, it displays output similar to the following.

TenantName : Contoso
TenantId : 00000000-0000-0000-0000-000000000000
ClientId : 11111111-1111-1111-1111-111111111111
CertificateThumbprint : 0123456789ABCDEF0123456789ABCDEF01234567
CertificateSubject : CN=CertKit App Proxy Agent
CertificateEku : 1.3.6.1.5.5.7.3.2
CertificateExpires : 12/1/2027 2:00:15 PM
KeyStorageProvider : Microsoft Platform Crypto Provider
CustomRole : App Proxy Certificate Manager
RoleAssigned : Through PIM
OldCertificatesRemoved : 0
ExpiredCertificatesRemoved : 0
LocalCertificatesRemoved : 0
ExpiredSecretsRemoved : 0

CertKit needs three values from this output: TenantId, ClientId, and CertificateThumbprint. Skip ahead to Configure CertKit to complete the configuration. To learn more about the certificate and its options, or to configure certificate authentication manually, continue reading.

Certificate Details

The script creates a self-signed certificate with the following settings.

SettingValue
SubjectCN=CertKit App Proxy Agent, no subject alternative names
KeyRSA 2048, non-exportable
SignatureSHA256
Key usageDigital Signature
Enhanced key usageClient Authentication (1.3.6.1.5.5.7.3.2), or a custom OID
Validity365 days by default; 30, 90, or 180 days with -CertificateValidityDays
StoreCert:\LocalMachine\My

The key length is fixed at RSA 2048 because many TPMs don’t support larger RSA keys. The maximum lifetime is one year, which keeps rotation a practiced routine. With a TPM-protected key, the risk of key theft is low, so very short lifetimes add little. A 30-day lifetime is practical only if you automate rotation.

TPM Key Storage

The script first asks the Microsoft Platform Crypto Provider to create the private key in the TPM. If that fails, such as on a virtual machine without a vTPM or a server with the TPM disabled, the script displays a warning with the reason and stores the key using the Microsoft Software Key Storage Provider instead. A non-exportable software key resists normal export tools, but not a determined local administrator. If your security policy requires hardware-protected credentials, add -RequireTpm, which turns the fallback into an error before any changes are made to the tenant. The KeyStorageProvider value in the script output reports the provider actually holding the key.

New-CertKitAppProxyIdentity.ps1 -RequireTpm -UsePim

Note: If the TPM is cleared or the server’s motherboard is replaced, the private key is lost. Run the script again to issue a new certificate.

Custom EKU

By default, the certificate includes the Client Authentication enhanced key usage (EKU), which works for all deployments. If your organization has a registered IANA Private Enterprise Number (PEN), you can use -CustomEku to replace Client Authentication with an object identifier (OID) under your PEN. Entra doesn’t check the EKU when CertKit signs in. It only verifies the signature against the uploaded public key. A custom EKU documents the certificate’s purpose and prevents it from being used for general client authentication elsewhere. The script validates the OID format, but it can’t confirm the PEN belongs to you. Windows displays a private EKU as Unknown Key Usage, which is expected. The following example uses 32473, a PEN reserved for documentation. Replace it with your own.

New-CertKitAppProxyIdentity.ps1 -CustomEku 1.3.6.1.4.1.32473.1.1 -UsePim

Configuration Using the Entra Admin Center

The same configuration can be performed manually. The certificate must still be created with PowerShell on the CertKit agent server, but the rest can be done in the Microsoft Entra admin center.

Create the Certificate

To begin, open an elevated PowerShell window on the CertKit agent server and create the certificate using the following commands. The private key is created in the TPM using the Microsoft Platform Crypto Provider and marked non-exportable. To use a custom EKU, replace 1.3.6.1.5.5.7.3.2 with your PEN-based OID.

$CertParams = @{
Type = 'Custom'
Subject = 'CN=CertKit App Proxy Agent'
CertStoreLocation = 'Cert:\LocalMachine\My'
Provider = 'Microsoft Platform Crypto Provider'
KeyAlgorithm = 'RSA'
KeyLength = 2048
HashAlgorithm = 'SHA256'
KeyExportPolicy = 'NonExportable'
KeyUsage = 'DigitalSignature'
TextExtension = @('2.5.29.37={text}1.3.6.1.5.5.7.3.2')
NotAfter = (Get-Date).AddMonths(12)
}
$Cert = New-SelfSignedCertificate @CertParams
$Cert.Thumbprint

Record the thumbprint, which CertKit needs later. If the server doesn’t have a TPM, the command fails. Remove the Provider line to store the key using the software key storage provider instead.

Export the Public Key

Next, export the certificate’s public key to a file. The private key isn’t included, and because it’s non-exportable, it can’t be.

Export-Certificate -Cert $Cert -FilePath "$env:TEMP\CertKitAppProxyAgent.cer"

Create the App Registration and Custom Role

Now create the app registration, grant the Application.Read.All permission, and create and assign the custom role as described in the client secret post. Skip the step to create a client secret. If you’ve already configured an app registration for client secret authentication, you can reuse it.

Upload the Certificate

Finally, upload the public certificate to the app registration.

  1. Navigate to Entra ID > App registrations and select CertKit App Proxy Deployment.
  2. Navigate to Certificates & secrets > Certificates and click Upload certificate.
  3. Select the exported .cer file, enter a description, such as CertKit Agent – <computer name>, and click Add.
  4. Confirm the thumbprint displayed matches the one recorded earlier.
The Certificates tab of the CertKit app registration in the Entra admin center, showing the uploaded CertKit Agent certificate with its thumbprint, description, start date, and expiration date.

Configure CertKit

With the app registration and certificate in place, create a new deployment in CertKit using the Microsoft Entra Application Proxy (Certificate Auth) template for the agent running on the server where the certificate was created. Select the certificate to deploy, then enter the Entra tenant ID, App registration (client) ID, and App registration certificate thumbprint. The thumbprint is displayed in the script output, or you can find it on the certificate’s Details tab in the Certificates (Local Computer) management console (certlm.msc) under Personal > Certificates. 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 (subject alternative name) certificate that covers the external URL of every App Proxy application you want CertKit to manage.

A CertKit deployment using the Microsoft Entra Application Proxy (Certificate Auth) template, with the tenant ID, client ID, and app registration certificate thumbprint entered and the app list wildcard set to update all App Proxy applications.

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 app registration using the authentication certificate’s thumbprint, 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: CN=*.example.net | Thumbprint: <redacted> | Expires: 2027-03-02
Covers: *.example.net, example.net
[Step 2] Signing in to Microsoft Graph...
Signed in as the app registration <redacted> using certificate <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 7 App Proxy app(s)
App1 (https://app1.example.net/): covered by this certificate
Private Access App: 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 2027-03-02)
App2 (https://app2.example.net/): updated (Entra reports thumbprint <redacted>, expires 2027-03-02)
App3 (https://app3.example.net/): updated (Entra reports thumbprint <redacted>, expires 2027-03-02)
App4 (https://app4.example.net/): updated (Entra reports thumbprint <redacted>, expires 2027-03-02)
App5 (https://app5.example.net/): updated (Entra reports thumbprint <redacted>, expires 2027-03-02)
App6 (https://app6.example.net/): updated (Entra reports thumbprint <redacted>, expires 2027-03-02)
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

Certificate Rotation and Multiple Agent Servers

The authentication certificate must be rotated before it expires, or CertKit deployments will fail. Each time the script runs, it creates a new certificate, and you can rotate in one of two ways.

  • Two-step rotation. Run the script without additional switches, update CertKit with the new thumbprint, confirm a deployment succeeds, then delete the old certificate in the Entra admin center. There’s no downtime.
  • One-step rotation. Run the script with -RemoveExistingCertificates, which removes this server’s older certificates from Entra and deletes them locally, along with their private keys. CertKit deployments fail until it’s updated with the new thumbprint.

Expired certificates and client secrets are removed from the app registration automatically, and expired CertKit certificates are deleted from the local store, so cleanup happens with each run. Certificates are named after the server that created them in Entra, which lets multiple CertKit agent servers share a single app registration. Running the script on one server rotates only that server’s certificates and never touches another server’s. Certificates are identified by NetBIOS computer name, so be sure each agent server has a unique name. Also, if your tenant has an app management policy that limits credential lifetimes, it may reject a certificate with a longer validity period.

Migrating from Client Secret Authentication

Version 2.0 of the script includes two changes that may affect existing scripts or runbooks. First, certificate authentication is now the default, so running the script with no parameters creates a certificate and requires an elevated session on the CertKit agent server. Add -UseClientSecret to keep using client secrets. Second, client secrets are now limited to 12 months, down from 24, so -SecretExpirationMonths values greater than 12 are rejected. To move an existing deployment from a client secret to a certificate, use the following steps.

  1. On the CertKit agent server, run the script in an elevated session with the same -DisplayName and -RoleName used originally. The existing app registration and role are reused, a certificate is added, and the script warns that client secrets remain.
  2. Update the CertKit deployment to use certificate authentication with the new thumbprint, and confirm a deployment succeeds.
  3. Delete the old client secrets in the Entra admin center under Certificates & secrets > Client secrets.

Removing the Configuration

To remove the configuration, use my Remove-CertKitAppProxyIdentity.ps1 PowerShell script. The script removes the role assignments, deletes the app registration along with its certificates and secrets in Entra, and keeps the custom role if another identity still uses it. Beginning with version 1.3, the -RemoveLocalCertificates switch also deletes the app registration’s certificates and private keys from the CertKit agent server. Run it in an elevated session on the agent server.

.\Remove-CertKitAppProxyIdentity.ps1 -RemoveLocalCertificates

The script matches local certificates by thumbprint, so certificates belonging to any other CertKit app registration on the same server are left alone. Local certificates are deleted only after the app registration is deleted, so a declined prompt or a failure never breaks a working configuration. Use -WhatIf to preview the changes. If multiple agent servers share the app registration, the first server’s run deletes it, so the remaining servers can’t match thumbprints afterward. The script’s README on GitHub includes a command to clean them up manually.

Summary

Certificate authentication gives CertKit a credential that can’t leave the server it was created on. It provides stronger protection than a client secret without the Azure subscription, Azure Arc onboarding, and ongoing management a managed identity requires for servers outside Azure. It uses the same custom Entra role and read-only Application.Read.All permission as the other methods, so the configuration follows security best practices and enforces least privilege. With version 2.0 of New-CertKitAppProxyIdentity.ps1, the certificate, app registration, permissions, and role assignment are configured in a single run.

Additional Information

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.

← Back

Thank you for your response. ✨

Leave a comment

Leave a Reply