Skip to content

Commit f76cfd2

Browse files
authored
{Microsoft Entra ID} az ad sp create-for-rbac: Update examples and warnings (#30277)
1 parent 97f79c9 commit f76cfd2

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -528,18 +528,27 @@
528528
You may also use `az role assignment create` to create role assignments for this service principal later.
529529
See [steps to add a role assignment](https://aka.ms/azadsp-more) for more information.
530530
examples:
531-
- name: Create without role assignment.
532-
text: az ad sp create-for-rbac
533-
- name: Create using a custom display name.
534-
text: az ad sp create-for-rbac -n MyApp
535-
- name: Create with a Contributor role assignments on specified scopes. To retrieve current subscription ID, run `az account show --query id --output tsv`.
536-
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
537-
- name: Create using a self-signed certificate.
538-
text: az ad sp create-for-rbac --create-cert
539-
- name: Create using a self-signed certificate, and store it within KeyVault.
540-
text: az ad sp create-for-rbac --keyvault MyVault --cert CertName --create-cert
541-
- name: Create using existing certificate in KeyVault.
542-
text: az ad sp create-for-rbac --keyvault MyVault --cert CertName
531+
- name: Create without role assignment.
532+
text: az ad sp create-for-rbac
533+
- name: Create using a custom display name.
534+
text: az ad sp create-for-rbac -n MyApp
535+
- name: Create with a Contributor role assignments on specified scopes. To retrieve current subscription ID, run `az account show --query id --output tsv`.
536+
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
537+
- name: Create using a self-signed certificate.
538+
text: az ad sp create-for-rbac --create-cert
539+
- name: Create using an existing certificate string.
540+
text: az ad sp create-for-rbac --cert "MIICoT..."
541+
- name: Create using an existing certificate file.
542+
text: |-
543+
az ad sp create-for-rbac --cert "@~/cert.pem"
544+
`cert.pem` contains the following content
545+
-----BEGIN CERTIFICATE----- <<< this line is optional
546+
MIICoT...
547+
-----END CERTIFICATE----- <<< this line is optional
548+
- name: Create using a self-signed certificate, and store it within Azure Key Vault.
549+
text: az ad sp create-for-rbac --keyvault MyVault --cert CertName --create-cert
550+
- name: Create using existing certificate in Azure Key Vault.
551+
text: az ad sp create-for-rbac --keyvault MyVault --cert CertName
543552
"""
544553

545554
helps['ad sp credential'] = """

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def load_arguments(self, _):
205205
c.argument('cert', arg_group='keyCredential', validator=validate_cert,
206206
help='Certificate to use for credentials. When used with `--keyvault,`, indicates the name of the '
207207
'cert to use or create. Otherwise, supply a PEM or DER formatted public certificate string. '
208-
'Use `@{path}` to load from a file. Do not include private key info.')
208+
'Use `@{path}` to load from a file. Do not include the private key.')
209209
c.argument('create_cert', arg_group='keyCredential', action='store_true',
210210
help='Create a self-signed certificate to use for the credential. Only the current OS user has '
211211
'read/write permission to this certificate. Use with `--keyvault` to create the certificate in '

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,14 +1302,10 @@ def create_service_principal_for_rbac(
13021302
}
13031303
if cert_file:
13041304
logger.warning(
1305-
"Please copy %s to a safe place. When you run 'az login', provide the file path in the --password argument",
1305+
"Please copy %s to a safe place. When you run `az login`, provide the file path in the --certificate "
1306+
"argument",
13061307
cert_file)
13071308
result['fileWithCertAndPrivateKey'] = cert_file
1308-
1309-
login_hint = ('To log in with this service principal, run:\n'
1310-
f'az login --service-principal --username {app_id} --password {password or cert_file} '
1311-
f'--tenant {graph_client.tenant}')
1312-
logger.info(login_hint)
13131309
return result
13141310

13151311

0 commit comments

Comments
 (0)