Skip to content

Commit 6945dd5

Browse files
authored
Merge pull request #194697 from leebeasley-v/create-openshift-service-principal
To create article about creating OpenShift service principal
2 parents df815b3 + d1fa0bd commit 6945dd5

File tree

4 files changed

+168
-2
lines changed

4 files changed

+168
-2
lines changed
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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
57.8 KB
Loading

articles/openshift/toc.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@
4646
href: howto-create-a-storageclass.md
4747
- name: Use the built-in container registry
4848
href: built-in-container-registry.md
49-
- name: Use Azure Container registry
49+
- name: Use Azure Container registry
5050
href: howto-use-acr-with-aro.md
5151
- name: Security and authentication
5252
items:
5353
- name: Secure OpenShift with Azure Front Door
5454
href: howto-secure-openshift-with-front-door.md
55+
- name: Create and use a service principal
56+
href: howto-create-service-principal.md
5557
- name: Configure Azure Active Directory authentication (Portal)
5658
href: configure-azure-ad-ui.md
5759
- name: Update pull secret for an ARO cluster

articles/zone-pivot-groups.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1793,6 +1793,15 @@ groups:
17931793
title: Azure Resource Manager
17941794
- id: aro-bicep
17951795
title: Bicep
1796+
# Owner: rahulmehta
1797+
- id: azure-red-hat-openshift-service-principal
1798+
title: Azure CLI and Azure portal
1799+
prompt: Choose an option
1800+
pivots:
1801+
- id: aro-azurecli
1802+
title: Azure CLI
1803+
- id: aro-azureportal
1804+
title: Azure portal
17961805
# Owner: cshoe
17971806
- id: devops-or-github
17981807
title: Code host
@@ -1810,4 +1819,4 @@ groups:
18101819
- id: framework-dotnet
18111820
title: .Net
18121821
- id: framework-spring
1813-
title: Spring
1822+
title: Spring Framework

0 commit comments

Comments
 (0)