Skip to content

Conversation

@ReaNAiveD
Copy link
Member

@ReaNAiveD ReaNAiveD commented Nov 19, 2025

Related command

az ad app create
az ad sp create-for-rbac

Description

Add a in-tool warning about using non-unique display names to create a service principal.
image
image
image
image

For more details, see #30427

Testing Guide

History Notes

{Role} az ad app create: Add warning about using non-unique display names in az ad app create
{Role} az ad sp create-for-rbac: Add warning about using non-unique display names in az ad sp create-for-rbac


This checklist is used to make sure that common guidelines for a pull request are followed.

@ReaNAiveD ReaNAiveD self-assigned this Nov 19, 2025
Copilot AI review requested due to automatic review settings November 19, 2025 04:09
@ReaNAiveD ReaNAiveD requested a review from bebound as a code owner November 19, 2025 04:09
@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Nov 19, 2025

️✔️AzureCLI-FullTest
️✔️acr
️✔️latest
️✔️3.12
️✔️3.13
️✔️acs
️✔️latest
️✔️3.12
️✔️3.13
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.13
️✔️ams
️✔️latest
️✔️3.12
️✔️3.13
️✔️apim
️✔️latest
️✔️3.12
️✔️3.13
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.13
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️aro
️✔️latest
️✔️3.12
️✔️3.13
️✔️backup
️✔️latest
️✔️3.12
️✔️3.13
️✔️batch
️✔️latest
️✔️3.12
️✔️3.13
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.13
️✔️billing
️✔️latest
️✔️3.12
️✔️3.13
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️cdn
️✔️latest
️✔️3.12
️✔️3.13
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.13
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.13
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.13
️✔️config
️✔️latest
️✔️3.12
️✔️3.13
️✔️configure
️✔️latest
️✔️3.12
️✔️3.13
️✔️consumption
️✔️latest
️✔️3.12
️✔️3.13
️✔️container
️✔️latest
️✔️3.12
️✔️3.13
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.13
️✔️core
️✔️latest
️✔️3.12
️✔️3.13
️✔️cosmosdb
️✔️latest
️✔️3.12
️✔️3.13
️✔️databoxedge
️✔️latest
️✔️3.12
️✔️3.13
️✔️dls
️✔️latest
️✔️3.12
️✔️3.13
️✔️dms
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventhubs
️✔️latest
️✔️3.12
️✔️3.13
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.13
️✔️find
️✔️latest
️✔️3.12
️✔️3.13
️✔️hdinsight
️✔️latest
️✔️3.12
️✔️3.13
️✔️identity
️✔️latest
️✔️3.12
️✔️3.13
️✔️iot
️✔️latest
️✔️3.12
️✔️3.13
️✔️keyvault
️✔️latest
️✔️3.12
️✔️3.13
️✔️lab
️✔️latest
️✔️3.12
️✔️3.13
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️maps
️✔️latest
️✔️3.12
️✔️3.13
️✔️marketplaceordering
️✔️latest
️✔️3.12
️✔️3.13
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.13
️✔️mysql
️✔️latest
️✔️3.12
️✔️3.13
️✔️netappfiles
️✔️latest
️✔️3.12
️✔️3.13
️✔️network
️✔️latest
️✔️3.12
️✔️3.13
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.13
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.13
️✔️profile
️✔️latest
️✔️3.12
️✔️3.13
️✔️rdbms
️✔️latest
️✔️3.12
️✔️3.13
️✔️redis
️✔️latest
️✔️3.12
️✔️3.13
️✔️relay
️✔️latest
️✔️3.12
️✔️3.13
️✔️resource
️✔️latest
️✔️3.12
️✔️3.13
️✔️role
️✔️latest
️✔️3.12
️✔️3.13
️✔️search
️✔️latest
️✔️3.12
️✔️3.13
️✔️security
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicebus
️✔️latest
️✔️3.12
️✔️3.13
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.13
️✔️signalr
️✔️latest
️✔️3.12
️✔️3.13
️✔️sql
️✔️latest
️✔️3.12
️✔️3.13
️✔️sqlvm
️✔️latest
️✔️3.12
️✔️3.13
️✔️storage
️✔️latest
️✔️3.12
️✔️3.13
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.13
️✔️telemetry
️✔️latest
️✔️3.12
️✔️3.13
️✔️util
️✔️latest
️✔️3.12
️✔️3.13
️✔️vm
️✔️latest
️✔️3.12
️✔️3.13

@azure-client-tools-bot-prd
Copy link

Hi @ReaNAiveD,
Since the current milestone time is less than 7 days, this pr will be reviewed in the next milestone.

@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Nov 19, 2025

️✔️AzureCLI-BreakingChangeTest
️✔️Non Breaking Changes

@yonzhan
Copy link
Collaborator

yonzhan commented Nov 19, 2025

Thank you for your contribution! We will review the pull request and get back to you soon.

@github-actions
Copy link

The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR.

Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a warning about the risks of using non-unique display names when creating service principals with az ad sp create-for-rbac, addressing issue #30427.

  • Adds a runtime warning message displayed when the command is executed
  • Updates the help documentation with an IMPORTANT notice about the same issue

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/azure-cli/azure/cli/command_modules/role/custom.py Adds logger.warning to alert users about display name non-uniqueness risks at runtime
src/azure-cli/azure/cli/command_modules/role/_help.py Adds IMPORTANT section to command documentation explaining display name risks and recommending object ID or app ID usage

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ReaNAiveD ReaNAiveD changed the title {Role} az ad sp create-for-rbac: Add warning about using non-unique display names {Role} Add warning about using non-unique display names when creating service principal Nov 19, 2025


def create_service_principal(cmd, identifier):
logger.warning("The `az ad sp create` command can modify an existing application or service principal "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider displaying the warning only when the command is overwriting an existing SP?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be preferable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider displaying the warning only when the command is overwriting an existing SP?

We already have a warning when overwriting an existing SP.
image
I have added the new warning before it.

Comment on lines 512 to 514
**IMPORTANT**: The `az ad sp create` command can modify an existing application or service principal if
another object shares the same **display name**. Display names aren't unique and can change, which
could result in credential loss or incorrect RBAC assignments. Use a **unique object ID or app ID** instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we consider a shorter message with a link to our conceptual docs where the user can learn about the issue and have some code to help finding the existing application / sp ?

type: command
short-summary: Create a service principal.
long-summary: >-
**IMPORTANT**: The `az ad sp create` command can modify an existing application or service principal if
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only az ad app create and az ad sp create-for-rbac can modify an existing application. az ad sp create will not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

type: command
short-summary: Create a service principal.
long-summary: >-
**IMPORTANT**: The `az ad sp create` command can modify an existing application or service principal if
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually don't use Markdown syntax besides `code`, as this will make the in-tool help hard to read.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to double quota, i.e. "az ad app create". Also removed the markdown symbol like *

show_auth_in_json=None, skip_assignment=False, keyvault=None):
import time

logger.warning("The `az ad sp create-for-rbac` command can modify an existing application or service principal "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. I don't really like the idea of showing this warning unconditionally.

Copy link
Member Author

@ReaNAiveD ReaNAiveD Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the warning to the create_appication method. The warning will only show when there is exact one existing app with the same display_name and before the existing warning Found an existing application instance: (id) %s. We will patch it.
image

Copy link
Member

@jiasli jiasli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the comments first.

@ReaNAiveD ReaNAiveD force-pushed the ad-sp-create-for-rbac-warning branch from 1f74b72 to 23fd0c0 Compare November 24, 2025 03:07
short-summary: Create an application.
long-summary: For more detailed documentation, see https://learn.microsoft.com/graph/api/resources/application
long-summary: >-
IMPORTANT: The "az ad app create" command can modify an existing application or service principal if
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually use WARNING: instead of IMPORTANT:. See #16081

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

long-summary: >-
IMPORTANT: The "az ad app create" command can modify an existing application or service principal if
another object shares the same display name. Display names aren't unique and can change, which
could result in credential loss or incorrect RBAC assignments. Use a unique object ID or app ID instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is only possible for the user to choose a unique display name. The user cannot choose to use a unique object ID or app ID. The object ID or app ID is generated by the MS Graph service.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the sentence Use a unique object ID or app ID instead.

IMPORTANT: The "az ad app create" command can modify an existing application or service principal if
another object shares the same display name. Display names aren't unique and can change, which
could result in credential loss or incorrect RBAC assignments. Use a unique object ID or app ID instead.
For more details, see https://go.microsoft.com/fwlink/?linkid=2342455.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This link doesn't give more details than this help message:

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It might help to reach out to Mike and Alex to see if they can add more context to the documentation.

For more details, see https://go.microsoft.com/fwlink/?linkid=2342455.
For more detailed documentation, see https://learn.microsoft.com/graph/api/resources/application
Copy link
Member

@jiasli jiasli Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to describe what documentation - the Microsoft Entra application, not this az ad app create command:

Suggested change
For more detailed documentation, see https://learn.microsoft.com/graph/api/resources/application
For more detailed documentation on Microsoft Entra application, see https://learn.microsoft.com/graph/api/resources/application

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

helps['ad sp create'] = """
type: command
short-summary: Create a service principal.
long-summary:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The long summary should not be empty.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Comment on lines 618 to 623
logger.warning("IMPORTANT: The \"az %s\" command can modify an existing application or service principal "
"if another object shares the same display name. "
"Display names aren't unique and can change, "
"which could result in credential loss or incorrect RBAC assignments. "
"Use a unique object ID or app ID instead. For more details, "
"see https://go.microsoft.com/fwlink/?linkid=2342455.", cmd.name)
Copy link
Member

@jiasli jiasli Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since len(existing_apps) == 1 already evaluates to True, that means there is already an application that shares the same display name, so using conditional sentence (can or if) is not unnecessary.

It's better to combine this warning message with L624 and say:

Please notice that display names aren't unique, which could result in credential loss or incorrect RBAC assignments. To create a new application, use a unique display name instead. For more details, see https://go.microsoft.com/fwlink/?linkid=2342455.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve updated the warning as suggested. But I also reserved the warning line indicating the existing application ID to ensure clarity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auto-Assign Auto assign by bot Graph az ad RBAC az role

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants