Add a custom domain

In addition to the default domain that is included in an instance of Azure Web PubSub, you can add a custom domain. A custom domain is a domain name that you own and manage. You can use a custom domain to access your Web PubSub resources. For example, you can use contoso.example.com instead of contoso.webpubsub.azure.com to access your resources.

Prerequisites

  • An Azure account with an active subscription. If you don't have an Azure account, you can create an account for free.
  • An Azure Web PubSub resource at a minimum Premium tier.
  • An Azure Key Vault resource.
  • A custom certificate matching custom domain that is stored in Azure Key Vault.

Add a custom certificate

Before you can add a custom domain, add a matching custom certificate. A custom certificate is a resource of your instance of Web PubSub. It references a certificate in your key vault. For security and compliance, Web PubSub doesn't permanently store your certificate. Instead, it fetches the certificate from your key vault and keeps it in memory.

Access the key vault by using a managed identity

Azure Web PubSub uses a managed identity to access your key vault. To authorize access, it must be granted permissions.

Create a managed identity

  1. In the Azure portal, go to your Web PubSub resource.

  2. On the left menu, select Identity.

  3. Select the type of identity to use: System assigned or User assigned. To use a user-assigned identity, you create one first.

    To use a system-assigned identity:

    1. Select On.

    2. Select Yes to confirm.

    3. Select Save.

    Screenshot that shows adding a system-assigned managed identity.

    To add a user-assigned identity:

    1. Select Add user assigned managed identity.

    2. Select an existing identity.

    3. Select Add.

    Screenshot that shows adding a user-assigned managed identity.

  4. Select Save.

Give key vault access to the managed identity

Depending on how you configure your Azure Key Vault permissions model, you might need to grant permissions at different locations in the Azure portal.

If you use a key vault built-in access policy as a key vault permissions model:

Screenshot of a built-in access policy selected as the key vault permissions model.

  1. In the Azure portal, go to your key vault.

  2. On the left menu, select Access configuration.

  3. Select Vault access policy.

  4. Select Go to access policies.

  5. Select Create.

  6. On the Create an access policy pane, select the Permissions tab.

  7. For Secret permissions, select Get.

  8. For Certificate permissions, select Get.

  9. Select Next.

    Screenshot of permissions selection in a key vault.

  10. Search for the Web PubSub resource name.

  11. Select Next.

    Screenshot of principal selection in a key vault.

  12. Select the Application tab, and then select Next.

  13. Select Create.

Create a custom certificate

  1. In the Azure portal, go to your Web PubSub resource.

  2. On the left menu, select Custom domain.

  3. On the Custom certificate pane, select Add.

    Screenshot that shows managing a custom certificate.

  4. Enter a name for the custom certificate.

  5. Choose Select from your Key Vault to choose a key vault certificate. After you select a key vault, values for Key Vault Base URI and Key Vault Secret Name are automatically added. You also have to option to edit these fields manually.

  6. (Optional) To pin the certificate to a specific version, enter a value for Key Vault Secret Version.

  7. Select Add.

    Screenshot that shows adding a custom certificate.

Web PubSub fetches the certificate and validates its contents. When certificate validation succeeds, Provisioning State for the certificate is Succeeded.

Screenshot that shows an added custom certificate.

Create a custom domain CNAME

To validate the ownership of your custom domain, create a CNAME record for the custom domain and point it to the default domain of your Web PubSub resource.

For example, if your default domain is contoso.webpubsub.azure.com and your custom domain is contoso.example.com, create a CNAME record on example.com like in this example:

contoso.example.com. 0 IN CNAME contoso.webpubsub.azure.com

If you use Azure DNS Zone, to learn how to add a CNAME record, see Manage DNS records.

Screenshot that shows adding a CNAME record in Azure DNS Zone.

If you use other DNS providers, follow guidance in the provider's documentation to create a CNAME record.

Add a custom domain to Web PubSub

A custom domain is another sub resource of your Web PubSub instance. It contains all configurations that are required for a custom domain.

  1. In the Azure portal, go to your Web PubSub resource.

  2. On the left menu, select Custom domain.

  3. On the Custom domain pane, select Add.

    Screenshot that shows custom domain management.

  4. Enter a name for the custom domain. Use the sub resource name.

  5. Enter the domain name. Use the full domain name of your custom domain, for example, contoso.com.

  6. Select a custom certificate that applies to this custom domain.

  7. Select Add.

    Screenshot that shows adding a custom domain.

Verify your custom domain

You can now access your Web PubSub endpoint by using the custom domain.

To verify the domain, you can access the Health API. The following examples use cURL.

PS C:\> curl.exe -v https://contoso.example.com/api/health
...
> GET /api/health HTTP/1.1
> Host: contoso.example.com

< HTTP/1.1 200 OK
...
PS C:\>

The Health API should return a 200 status code without any certificate errors.

Configure a private network key vault

If you configure a private endpoint to your key vault, Web PubSub can't access the key vault by using a public network. You must set up a shared private endpoint to give Web PubSub access to your key vault via a private network.

After you create a shared private endpoint, you can create a custom certificate as usual. You don't have to change the domain in the key vault URI. For example, if your key vault base URI is https://contoso.vault.azure.net, continue to use this URI to configure a custom certificate.

You don't have to explicitly allow Web PubSub IP addresses in your key vault firewall settings. For more information, see Key vault private link diagnostics.

Rotate the certificate

If you don't specify a secret version when you create a custom certificate, Web PubSub periodically checks for the latest version in the key vault. When a new version is detected, it's automatically applied. The delay is typically less than an hour.

Alternatively, you can pin a custom certificate to a specific secret version in your key vault. When you need to apply a new certificate, you can edit the secret version, and then update the custom certificate proactively.