# Create a client certificate

<br />

> [!NOTE]
> **Note:** The legacy *AzureClient* method of
> authenticating to Azure requires you to manage secrets and upload them
> manually. We recommend that you use [workload identity federation](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/azure/how-to/create-azure-ad-application.md.txt#workload-identity-federation)
> instead.

<br />

GKE on Azure authenticates to Azure with an *AzureClient*
resource. When you create a client, Google generates a key pair. You upload the
public key to Azure Active Directory (Azure AD). The GKE Multi-Cloud API uses the
AzureClient to authenticate as the application's service principal.

You can use the same AzureClient to create multiple clusters in the same
Google Cloud project. If you already have an AzureClient, skip to
[Create an SSH key pair](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/azure/how-to/create-ssh-keypair.md.txt).

To create an AzureClient, run the following commands:

1. Set environment variables with your Azure tenant and application IDs:

   ```bash
   export SUBSCRIPTION_ID=$(az account show --query "id" --output tsv)
   export TENANT_ID=$(az account list \
     --query "[?id=='${SUBSCRIPTION_ID}'].{tenantId:tenantId}" --output tsv)
   export APPLICATION_ID=$(az ad app list --all \
     --query "[?displayName=='APPLICATION_NAME'].appId" --output tsv)
   ```

   Replace `APPLICATION_NAME` with the Azure AD
   application name that you used when completing the
   [prerequisites](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/azure/how-to/create-azure-ad-application.md.txt).
2. Create the client:

   ```bash
   gcloud container azure clients create CLIENT_NAME \
     --location=GOOGLE_CLOUD_LOCATION \
     --tenant-id="${TENANT_ID}" \
     --application-id="${APPLICATION_ID}"
   ```

   Replace the following:
   - `CLIENT_NAME`: the name of your AzureClient
   - `GOOGLE_CLOUD_LOCATION`: the [supported Google Cloud region](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/azure/reference/supported-regions.md.txt) that manages your cluster---for example, `us-west1`
3. Get the certificate from an AzureClient and save it to an environment
   variable:

   ```bash
    CERT=$(gcloud container azure clients get-public-cert --location=GOOGLE_CLOUD_LOCATION \
         CLIENT_NAME)
   ```

   Replace the following:
   - `GOOGLE_CLOUD_LOCATION`
   - `CLIENT_NAME`
4. Upload the certificate to your application on Azure AD:

   ```bash
    az ad app credential reset --id "${APPLICATION_ID}" --cert "${CERT}" --append
   ```
5. After the certificate uploads and before you create a cluster, wait at least
   one minute for the certificate to be ready to use. If the command fails, you
   can try again.

   > [!NOTE]
   > **Note:** If the preceding command fails with the
   > following message, save the certificate to a file and upload it to your
   > application's page on the Azure portal:
   >
   > ```
   >  Update to existing credential with KeyId 'XXXXXXX-XXXXX-XXX-XXXX-XXXXXXXXXXXX' is not allowed.
   > ```
   >
   >
   > To get a link to your application's page, replace
   > <var translate="no">APPLICATION_ID</var> in the following URL with your application's ID:
   >
   > ```
   > https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Credentials/appId/APPLICATION_ID
   > ```

## What's next

- [Create an SSH key pair](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/azure/how-to/create-ssh-keypair.md.txt)