Upstream Azure AD Service Auth Policy
Secure your origin server with Azure Active Directory authentication by
automatically adding an Authorization
header to upstream requests. This policy
enables your Zuplo gateway to authenticate with Azure AD-protected services
using client credentials flow.
With this policy, you'll benefit from:
- Enhanced Backend Security: Restrict access to your origin servers to only your Zuplo gateway
- Simplified Authentication: Delegate authentication and authorization to your gateway without backend code changes
- Automatic Token Management: Handle token acquisition, caching, and renewal automatically
- Azure Integration: Seamlessly connect with Azure App Services, Functions, and other Azure AD-protected resources
- Credential Security: Store sensitive Azure AD credentials securely in your Zuplo environment
For instructions on configuring Azure AD authentication, see Configure your App Service or Azure Functions app to use Azure AD login.
Configuration
The configuration shows how to configure the policy in the 'policies.json' document.
Code(json)
Policy Configuration
name
<string>
- The name of your policy instance. This is used as a reference in your routes.policyType
<string>
- The identifier of the policy. This is used by the Zuplo UI. Value should beupstream-azure-ad-service-auth-inbound
.handler.export
<string>
- The name of the exported type. Value should beUpstreamAzureAdServiceAuthInboundPolicy
.handler.module
<string>
- The module containing the policy. Value should be$import(@zuplo/runtime)
.handler.options
<object>
- The options for this policy. See Policy Options below.
Policy Options
The options for this policy are specified below. All properties are optional unless specifically marked as required.
activeDirectoryTenantId
(required)<string>
- Azure Active Directory Tenant ID.activeDirectoryClientId
(required)<string>
- The Application (client) ID of the Azure AD App Registration.activeDirectoryClientSecret
(required)<string>
- The client secret of the Azure AD App Registration.tokenRetries
<number>
- The number of times to retry fetching the token in the event of a failure.. Defaults to3
.expirationOffsetSeconds
<number>
- The number of seconds less than the token expiration to cache the token. Defaults to300
.
Using the Policy
This policy authenticates your Zuplo gateway to Azure AD-protected backend
services by automatically adding an OAuth 2.0 Bearer token to the
Authorization
header of upstream requests. It uses the Azure AD client
credentials flow to obtain access tokens.
How It Works
The policy performs the following operations:
- Requests an access token from Azure AD using the configured client credentials
- Caches the token for subsequent requests until it nears expiration
- Adds the token to the
Authorization
header as a Bearer token - Automatically handles token renewal when needed
Policy Configuration
Configure the policy with your Azure AD application credentials:
Code(json)
Usage Example
Securing Azure Function App Access
Apply the policy to routes that need to access your Azure Function App:
Code(json)
Azure AD Configuration
To use this policy, you need to:
- Create an Azure AD app registration for your Zuplo gateway
- Generate a client secret for the app registration
- Configure your backend service (e.g., Azure Functions, App Service) to use Azure AD authentication
- Grant the necessary permissions for your app registration to access your backend service
Security Considerations
- Store the client secret as an environment variable using
$env(VARIABLE_NAME)
syntax - Ensure your Azure AD app has the minimum required permissions to access your backend services
- Consider using managed identities for Azure resources when possible
- Regularly rotate your client secrets according to your security policies
Read more about how policies work