|
| 1 | +--- |
| 2 | +title: Creating and using a service principal with an Azure Red Hat OpenShift cluster |
| 3 | +description: In this how-to article, learn how to create a service principal with an Azure Red Hat OpenShift cluster using Azure CLI or the Azure portal. |
| 4 | +author: rahulm23 |
| 5 | +ms.service: azure-redhat-openshift |
| 6 | +ms.topic: how-to |
| 7 | +ms.author: rahulmehta |
| 8 | +ms.date: 03/21/2022 |
| 9 | +topic: how-to |
| 10 | +keywords: azure, openshift, aro, red hat, azure CLI, azure portal |
| 11 | +#Customer intent: I need to create and use an Azure service principal to restrict permissions to my Azure Red Hat OpenShift cluster. |
| 12 | +zone_pivot_groups: azure-red-hat-openshift-service-principal |
| 13 | +--- |
| 14 | + |
| 15 | +# Create and use a service principal with an Azure Red Hat OpenShift cluster |
| 16 | + |
| 17 | +To interact with Azure APIs, an Azure Red Hat OpenShift cluster requires an Azure Active Directory (AD) service principal. This service principal is used to dynamically create, manage, or access other Azure resources, such as an Azure load balancer or an Azure Container Registry (ACR). For more information, see [Application and service principal objects in Azure Active Directory](../active-directory/develop/app-objects-and-service-principals.md). |
| 18 | + |
| 19 | +This article explains how to create and use a service principal for your Azure Red Hat OpenShift clusters using the Azure command-line interface (Azure CLI) or the Azure portal. |
| 20 | + |
| 21 | +## Before you begin |
| 22 | + |
| 23 | +The user creating an Azure AD service principal must have permissions to register an application with your Azure AD tenant and to assign the application to a role in your subscription. You need **User Access Administrator** and **Contributor** permissions at the resource-group level to create service principals. |
| 24 | + |
| 25 | +Use the following Azure CLI command to add these permissions. |
| 26 | + |
| 27 | +```azurecli-interactive |
| 28 | +az role assignment create \ |
| 29 | + --role 'User Access Administrator' \ |
| 30 | + --assignee-object-id $SP_OBJECT_ID \ |
| 31 | + --resource-group $RESOURCEGROUP \ |
| 32 | + --assignee-principal-type 'ServicePrincipal' |
| 33 | +
|
| 34 | +az role assignment create \ |
| 35 | + --role 'Contributor' \ |
| 36 | + --assignee-object-id $SP_OBJECT_ID \ |
| 37 | + --resource-group $RESOURCEGROUP \ |
| 38 | + --assignee-principal-type 'ServicePrincipal' |
| 39 | +``` |
| 40 | + |
| 41 | +If you don't have the required permissions, you can ask your Azure AD or subscription administrator to assign them. Alternatively, your Azure AD or subscription administrator can create a service principal in advance for you to use with the Azure Red Hat OpenShift cluster. |
| 42 | + |
| 43 | +If you're using a service principal from a different Azure AD tenant, there are more considerations regarding the permissions available when you deploy the cluster. For example, you may not have the appropriate permissions to read and write directory information. |
| 44 | + |
| 45 | +For more information on user roles and permissions, see [What are the default user permissions in Azure Active Directory?](../active-directory/fundamentals/users-default-permissions.md). |
| 46 | + |
| 47 | +> [!NOTE] |
| 48 | +> Service principals expire in one year unless configured for longer periods. For information on extending your service principal expiration period, see [Rotate service principal credentials for your Azure Red Hat OpenShift (ARO) Cluster](howto-service-principal-credential-rotation.md). |
| 49 | +
|
| 50 | +::: zone pivot="aro-azurecli" |
| 51 | + |
| 52 | +## Create a service principal with Azure CLI |
| 53 | + |
| 54 | +The following sections explain how to use the Azure CLI to create a service principal for your Azure Red Hat OpenShift cluster. |
| 55 | + |
| 56 | +## Prerequisite |
| 57 | + |
| 58 | +If you’re using the Azure CLI, you’ll need Azure CLI version 2.0.59 or later installed and configured. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI](/cli/azure/install-azure-cli). |
| 59 | + |
| 60 | + |
| 61 | +## Create a service principal - Azure CLI |
| 62 | + |
| 63 | + To create a service principal with the Azure CLI, run the `az ad sp create-for-rbac` command. |
| 64 | + |
| 65 | +> [!NOTE] |
| 66 | +> When using a service principal to create a new cluster, you may need to assign a Contributor role here. |
| 67 | +
|
| 68 | +```azure-cli |
| 69 | +az ad sp create-for-rbac --name myAROClusterServicePrincipal |
| 70 | +``` |
| 71 | + |
| 72 | +The output is similar to the following example. |
| 73 | + |
| 74 | +``` |
| 75 | +{ |
| 76 | +
|
| 77 | + "appId": "", |
| 78 | +
|
| 79 | + "displayName": "myAROClusterServicePrincipal", |
| 80 | +
|
| 81 | + "name": "http://myAROClusterServicePrincipal", |
| 82 | +
|
| 83 | + "password": "", |
| 84 | +
|
| 85 | + "tenant": "" |
| 86 | +
|
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +Retain your `appId` and `password`. These values are used when you create an Azure Red Hat OpenShift cluster below. |
| 91 | + |
| 92 | +## Grant permissions to the service principal - Azure CLI |
| 93 | + |
| 94 | +Grant permissions to an existing service principal with Azure CLI, as shown in the following command. |
| 95 | + |
| 96 | +```azurecli-interactive |
| 97 | +az role assignment create \ |
| 98 | + --role 'Contributor' \ |
| 99 | + --assignee-object-id $SP_OBJECT_ID \ |
| 100 | + --resource-group $RESOURCEGROUP \ |
| 101 | + --assignee-principal-type 'ServicePrincipal' |
| 102 | +``` |
| 103 | + |
| 104 | +## Use the service principal to create a cluster - Azure CLI |
| 105 | + |
| 106 | +To use an existing service principal when you create an Azure Red Hat OpenShift cluster using the `az aro create` command, use the `--client-id` and `--client-secret` parameters to specify the appId and password from the output of the `az ad sp create-for-rbac` command: |
| 107 | + |
| 108 | +```azure-cli |
| 109 | +az aro create \ |
| 110 | +
|
| 111 | + --resource-group myResourceGroup \ |
| 112 | +
|
| 113 | + --name myAROCluster \ |
| 114 | +
|
| 115 | + --client-id <appID> \ |
| 116 | +
|
| 117 | + --client-secret <password> |
| 118 | +``` |
| 119 | + |
| 120 | +> [!IMPORTANT] |
| 121 | +> If you're using an existing service principal with a customized secret, ensure the secret doesn't exceed 190 bytes. |
| 122 | +
|
| 123 | +::: zone-end |
| 124 | + |
| 125 | +::: zone pivot="aro-azureportal" |
| 126 | + |
| 127 | +## Create a service principal with the Azure portal |
| 128 | + |
| 129 | +The following sections explain how to use the Azure portal to create a service principal for your Azure Red Hat OpenShift cluster. |
| 130 | + |
| 131 | +## Create a service principal - Azure portal |
| 132 | + |
| 133 | +To create a service principal using the Azure portal, see [Create an Azure AD app and service principal in the portal](../active-directory/develop/howto-create-service-principal-portal.md). |
| 134 | + |
| 135 | +## Grant permissions to the service principal - Azure portal |
| 136 | + |
| 137 | +To grant permissions to an existing service principal with the Azure portal, see [Create an Azure AD app and service principal in the portal](../active-directory/develop/howto-create-service-principal-portal.md#configure-access-policies-on-resources). |
| 138 | + |
| 139 | +## Use the service principal - Azure portal |
| 140 | + |
| 141 | +When deploying an Azure Red Hat OpenShift cluster using the Azure portal, configure the service principal on the **Authentication** page of the **Azure Red Hat OpenShift** dialog. |
| 142 | + |
| 143 | +:::image type="content" source="./media/openshift-service-principal-portal.png" alt-text="Screenshot that shows how to use the Azure Red Hat service principal with Azure portal to create a cluster." lightbox="./media/openshift-service-principal-portal.png"::: |
| 144 | + |
| 145 | +Specify the following values, and then select **Review + Create**. |
| 146 | + |
| 147 | +In the **Service principal information** section: |
| 148 | + |
| 149 | +- **Service principal client ID** is your appId. |
| 150 | +- **Service principal client secret** is the service principal's decrypted Secret value. |
| 151 | + |
| 152 | +In the **Cluster pull secret** section: |
| 153 | + |
| 154 | +- **Pull secret** is your cluster's pull secret's decrypted value. |
| 155 | +::: zone-end |
0 commit comments