Dogodek
17. mar., 21h - 21. mar., 10h
Pridružite se nizu srečanj in ustvarite prilagodljive rešitve za AI na podlagi primerov uporabe v resničnem svetu s kolegi razvijalci in strokovnjaki.
Prijavite se zdajTa brskalnik ni več podprt.
Izvedite nadgradnjo na Microsoft Edge, če želite izkoristiti vse prednosti najnovejših funkcij, varnostnih posodobitev in tehnične podpore.
APPLIES TO: All API Management tiers
API Management provides the capability to secure access to APIs (that is, client to API Management) using client certificates and mutual TLS authentication. You can validate certificates presented by the connecting client and check certificate properties against desired values using policy expressions.
For information about securing access to the backend service of an API using client certificates (that is, API Management to backend), see How to secure back-end services using client certificate authentication.
For a conceptual overview of API authorization, see Authentication and authorization to APIs in API Management.
For certificate validation, API Management can check against certificates managed in your API Management instance. If you choose to use API Management to manage client certificates, you have the following options:
Using key vault certificates is recommended because it helps improve API Management security:
If you have not created an API Management service instance yet, see Create an API Management service instance.
You need access to the certificate and the password for management in an Azure key vault or upload to the API Management service. The certificate must be in either CER or PFX format. Self-signed certificates are allowed.
If you use a self-signed certificate, also install trusted root and intermediate CA certificates in your API Management instance.
Opomba
CA certificates for certificate validation are not supported in the Consumption tier.
Opomba
Currently, this feature isn't available in workspaces.
If you don't already have a key vault, create one. For steps to create a key vault, see Quickstart: Create a key vault using the Azure portal.
To create or import a certificate to the key vault, see Quickstart: Set and retrieve a certificate from Azure Key Vault using the Azure portal.
Enable a system-assigned or user-assigned managed identity in the API Management instance.
To add a key vault access policy:
If Key Vault firewall is enabled on your key vault, the following are additional requirements:
You must use the API Management instance's system-assigned managed identity to access the key vault.
In Key Vault firewall, enable the Allow Trusted Microsoft Services to bypass this firewall option.
Ensure that your local client IP address is allowed to access the key vault temporarily while you select a certificate or secret to add to Azure API Management. For more information, see Configure Azure Key Vault networking settings.
After completing the configuration, you may block your client address in the key vault firewall.
If the API Management instance is deployed in a virtual network, also configure the following network settings:
For details, see Network configuration when setting up Azure API Management in a VNet.
See Prerequisites for key vault integration.
Pomembno
When adding a key vault certificate to your API Management instance, you must have permissions to list secrets from the key vault.
Svarilo
When using a key vault certificate in API Management, be careful not to delete the certificate, key vault, or managed identity used to access the key vault.
To add a key vault certificate to API Management:
In the Azure portal, navigate to your API Management instance.
Under Security, select Certificates.
Select Certificates > + Add.
In Id, enter a name of your choice.
In Certificate, select Key vault.
Enter the identifier of a key vault certificate, or choose Select to select a certificate from a key vault.
Pomembno
If you enter a key vault certificate identifier yourself, ensure that it doesn't have version information. Otherwise, the certificate won't rotate automatically in API Management after an update in the key vault.
In Client identity, select a system-assigned or an existing user-assigned managed identity. Learn how to add or modify managed identities in your API Management service.
Opomba
The identity needs permissions to get and list certificate from the key vault. If you haven't already configured access to the key vault, API Management prompts you so it can automatically configure the identity with the necessary permissions.
Select Add.
Select Save.
To upload a client certificate to API Management:
In the Azure portal, navigate to your API Management instance.
Under Security, select Certificates.
Select Certificates > + Add.
In Id, enter a name of your choice.
In Certificate, select Custom.
Browse to select the certificate .pfx file, and enter its password.
Select Add.
Select Save.
Opomba
If you only wish to use the certificate to authenticate the client with API Management, you can upload a CER file.
To receive and verify client certificates over HTTP/2 in the Developer, Basic, Standard, or Premium tiers, you must enable the Negotiate client certificate setting on the Custom domain blade as shown below.
To receive and verify client certificates in the Consumption, Basic v2, Standard v2, or Premium v2 tier, you must enable the Request client certificate setting on the Custom domains blade as shown below.
Use the validate-client-certificate policy to validate one or more attributes of a client certificate used to access APIs hosted in your API Management instance.
Configure the policy to validate one or more attributes including certificate issuer, subject, thumbprint, whether the certificate is validated against online revocation list, and others.
You can also create policy expressions with the context
variable to check client certificates. Examples in the following sections show expressions using the context.Request.Certificate
property and other context
properties.
Opomba
Mutual certificate authentication might not function correctly when the API Management gateway endpoint is exposed through the Application Gateway. This is because Application Gateway functions as a Layer 7 load balancer, establishing a distinct SSL connection with the backend API Management service. Consequently, the certificate attached by the client in the initial HTTP request will not be forwarded to APIM. However, as a workaround, you can transmit the certificate using the server variables option. For detailed instructions, refer to Mutual Authentication Server Variables.
Pomembno
context.Request.Certificate
property only requests the certificate when the API Management instance's hostnameConfiguration
sets the negotiateClientCertificate
property to True. By default, negotiateClientCertificate
is set to False.context.Request.Certificate
property. If this occurs, enable TLS renegotiation settings in the client.Below policies can be configured to check the issuer and subject of a client certificate:
<choose>
<when condition="@(context.Request.Certificate == null || !context.Request.Certificate.Verify() || context.Request.Certificate.Issuer != "trusted-issuer" || context.Request.Certificate.SubjectName.Name != "expected-subject-name")" >
<return-response>
<set-status code="403" reason="Invalid client certificate" />
</return-response>
</when>
</choose>
Opomba
To disable checking certificate revocation list, use context.Request.Certificate.VerifyNoRevocation()
instead of context.Request.Certificate.Verify()
.
If client certificate is self-signed, root (or intermediate) CA certificate(s) must be uploaded to API Management for context.Request.Certificate.Verify()
and context.Request.Certificate.VerifyNoRevocation()
to work.
Below policies can be configured to check the thumbprint of a client certificate:
<choose>
<when condition="@(context.Request.Certificate == null || !context.Request.Certificate.Verify() || context.Request.Certificate.Thumbprint != "DESIRED-THUMBPRINT-IN-UPPER-CASE")" >
<return-response>
<set-status code="403" reason="Invalid client certificate" />
</return-response>
</when>
</choose>
Opomba
To disable checking certificate revocation list, use context.Request.Certificate.VerifyNoRevocation()
instead of context.Request.Certificate.Verify()
.
If client certificate is self-signed, root (or intermediate) CA certificate(s) must be uploaded to API Management for context.Request.Certificate.Verify()
and context.Request.Certificate.VerifyNoRevocation()
to work.
The following example shows how to check the thumbprint of a client certificate against certificates uploaded to API Management:
<choose>
<when condition="@(context.Request.Certificate == null || !context.Request.Certificate.Verify() || !context.Deployment.Certificates.Any(c => c.Value.Thumbprint == context.Request.Certificate.Thumbprint))" >
<return-response>
<set-status code="403" reason="Invalid client certificate" />
</return-response>
</when>
</choose>
Opomba
To disable checking certificate revocation list, use context.Request.Certificate.VerifyNoRevocation()
instead of context.Request.Certificate.Verify()
.
If client certificate is self-signed, root (or intermediate) CA certificate(s) must be uploaded to API Management for context.Request.Certificate.Verify()
and context.Request.Certificate.VerifyNoRevocation()
to work.
Nasvet
Client certificate deadlock issue described in this article can manifest itself in several ways, e.g. requests freeze, requests result in 403 Forbidden
status code after timing out, context.Request.Certificate
is null
. This problem usually affects POST
and PUT
requests with content length of approximately 60KB or larger.
To prevent this issue from occurring turn on "Negotiate client certificate" setting for desired hostnames on the "Custom domains" blade as shown in the first image of this document. This feature is not available in the Consumption tier.
Dogodek
17. mar., 21h - 21. mar., 10h
Pridružite se nizu srečanj in ustvarite prilagodljive rešitve za AI na podlagi primerov uporabe v resničnem svetu s kolegi razvijalci in strokovnjaki.
Prijavite se zdajUsposabljanje
Modul
Control authentication for your APIs with Azure API Management - Training
Discover how to protect your APIs from unauthorized use with API keys and client certificate authentication.
Potrdilo
Microsoft Certified: Identity and Access Administrator Associate - Certifications
Demonstrate the features of Microsoft Entra ID to modernize identity solutions, implement hybrid solutions, and implement identity governance.
Dokumentacija
Secure API Management backend using client certificate authentication - Azure API Management
Learn how to manage client certificates and secure backend services using client certificate authentication in Azure API Management.
Azure API Management policy reference - validate-client-certificate
Reference for the validate-client-certificate policy available for use in Azure API Management. Provides policy usage, settings, and examples.
Add a custom CA certificate - Azure API Management
Learn how to add a custom CA certificate in Azure API Management. You can also see instructions to delete a certificate.