Skip to content

Commit 59193f0

Browse files
authored
[Microsoft Entra ID] az ad sp create-for-rbac: Add --create-password argument (#31215)
1 parent 07c9e1c commit 59193f0

File tree

5 files changed

+452
-2
lines changed

5 files changed

+452
-2
lines changed

src/azure-cli/azure/cli/command_modules/role/_help.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@
536536
text: az ad sp create-for-rbac -n MyApp
537537
- name: Create with a Contributor role assignments on specified scopes. To retrieve current subscription ID, run `az account show --query id --output tsv`.
538538
text: az ad sp create-for-rbac -n MyApp --role Contributor --scopes /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup2
539+
- name: Do not create password credential.
540+
text: az ad sp create-for-rbac --create-password false
539541
- name: Create using a self-signed certificate.
540542
text: az ad sp create-for-rbac --create-cert
541543
- name: Create using an existing certificate string.

src/azure-cli/azure/cli/command_modules/role/_params.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ def load_arguments(self, _):
186186
c.argument('display_name', options_list=['--display-name', '--name', '-n'],
187187
help='Display name of the service principal. If not present, default to azure-cli-%Y-%m-%d-%H-%M-%S '
188188
'where the suffix is the time of creation.')
189+
c.argument('create_password', arg_type=get_three_state_flag(), arg_group='Credential',
190+
help='Create a password credential (secret) on the the application. This is the default behavior. '
191+
'Set this argument to false to disable creating password credential.')
189192
c.argument('scopes', nargs='+',
190193
help="Space-separated list of scopes the service principal's role assignment applies to. e.g., "
191194
"subscriptions/0b1f6471-1bf0-4dda-aec3-111122223333/resourceGroups/myGroup, "

src/azure-cli/azure/cli/command_modules/role/custom.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,7 @@ def create_service_principal_for_rbac(
12191219
# pylint:disable=too-many-statements,too-many-locals, too-many-branches, unused-argument
12201220
cmd, display_name=None,
12211221
service_management_reference=None,
1222+
create_password=True,
12221223
years=None, create_cert=False, cert=None, scopes=None, role=None,
12231224
show_auth_in_json=None, skip_assignment=False, keyvault=None):
12241225
import time
@@ -1278,7 +1279,7 @@ def create_service_principal_for_rbac(
12781279

12791280
# Password credential is created *after* application creation.
12801281
# https://learn.microsoft.com/en-us/graph/api/resources/passwordcredential
1281-
if not use_cert:
1282+
if create_password and not use_cert:
12821283
result = _application_add_password(graph_client, aad_application, 'rbac', app_start_date, app_end_date)
12831284
password = result['secretText']
12841285

@@ -1333,7 +1334,9 @@ def create_service_principal_for_rbac(
13331334
ex.response.headers) # pylint: disable=no-member
13341335
raise
13351336

1336-
logger.warning(CREDENTIAL_WARNING)
1337+
# No need to show warning if no credential is created
1338+
if password or cert_file:
1339+
logger.warning(CREDENTIAL_WARNING)
13371340

13381341
if show_auth_in_json:
13391342
from azure.cli.core._profile import Profile

0 commit comments

Comments
 (0)