Skip to content

Commit 7c22cc5

Browse files
authored
Merge pull request #4771 from MicrosoftDocs/main
2 parents 1b2fff9 + 3f0b8d5 commit 7c22cc5

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

docs-ref-conceptual/authenticate-azure-cli-service-principal.md

+15-7
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ ms.date: 09/02/2024
55
ms.topic: concept-article
66
ms.service: azure-cli
77
ms.custom: devx-track-azurecli
8-
#customer intent: As an app developer, I need to security automate authentication to Azure using a service principal.
8+
#customer intent: As an app developer, I need to security automate authentication to Azure using a service principal.
99
---
1010

11-
# Sign into Azure with a service principal using the Azure CLI
11+
# Sign into Azure with a service principal using the Azure CLI
1212

1313
Service principals are accounts not tied to any particular user, which can have permissions on them assigned through
1414
predefined roles. Authenticating with a service principal is the best way to write secure scripts or programs,
@@ -18,32 +18,40 @@ about service principals, see [Work with Azure service principals using the Azur
1818
To sign in with a service principal, you need:
1919

2020
* The URL or name associated with the service principal
21-
* The service principal password, or the X509 certificate used to create the service principal in PEM format
22-
* The tenant associated with the service principal, as either an `.onmicrosoft.com` domain or Azure object ID
21+
* The service principal client secret, or the X509 certificate used to create the service principal in PEM format
22+
* The tenant associated with the service principal, as either an `.onmicrosoft.com` domain or Microsoft Entra tenant ID
2323

2424
Note two important facts when working with service principals and the Azure CLI:
2525

2626
* A **CERTIFICATE** must be appended to the **PRIVATE KEY** within a PEM file. For an example of a PEM file format, see [Certificate-based authentication](./azure-cli-sp-tutorial-3.md).
2727

2828
* If your service principal uses a certificate that is stored in Key Vault, that certificate's private key must be available without signing in to Azure. To retrieve the certificate for `az login`, see [Retrieve certificate from Key Vault](./azure-cli-sp-tutorial-3.md#work-with-azure-key-vault).
2929

30+
Log in with client secret:
31+
32+
```azurecli-interactive
33+
az login --service-principal --username APP_ID --password CLIENT_SECRET --tenant TENANT_ID
34+
```
35+
36+
Log in with certificate:
37+
3038
```azurecli-interactive
31-
az login --service-principal -u <app-id> -p <password-or-cert> --tenant <tenant>
39+
az login --service-principal --username APP_ID --certificate /path/to/cert.pem --tenant TENANT_ID
3240
```
3341

3442
> [!IMPORTANT]
3543
> If you want to avoid displaying your password on console and are using `az login` interactively,
3644
> use the `read -s` command under `bash`.
3745
>
3846
> ```bash
39-
> read -sp "Azure password: " AZ_PASS && echo && az login --service-principal -u <app-id> -p $AZ_PASS --tenant <tenant>
47+
> read -sp "Azure password: " AZ_PASS && echo && az login --service-principal --username <app-id> --password $AZ_PASS --tenant <tenant>
4048
> ```
4149
>
4250
> Under PowerShell, use the `Get-Credential` cmdlet.
4351
>
4452
> ```powershell
4553
> $AzCred = Get-Credential -UserName <app-id>
46-
> az login --service-principal -u $AzCred.UserName -p $AzCred.GetNetworkCredential().Password --tenant <tenant>
54+
> az login --service-principal --username $AzCred.UserName --password $AzCred.GetNetworkCredential().Password --tenant <tenant>
4755
> ```
4856
4957
## See also

docs-ref-conceptual/azure-cli-sp-tutorial-3.md

+2-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ keywords: azure service principal, create service principal azure, create servic
1010

1111
# Use an Azure service principal with certificate-based authentication
1212

13-
When creating a service principal, you choose the type of sign-in authentication it uses. There are two types of authentication available for Azure service principals: **password-based authentication** and **certificate-based authentication**.
13+
When creating a service principal, you choose the type of sign-in authentication it uses. There are two types of authentication available for Azure service principals: **password-based authentication** and **certificate-based authentication**.
1414

1515
We recommend using certificate-based authentication due to the security restrictions of password-based authentication. Certificate-based authentication enables you to adopt a phishing resistant authentication by using [conditional access policies](/azure/active-directory/conditional-access/overview), which better protects Azure resources. To learn more about why certificate-based authentication is more secure, see [Microsoft Entra certificate-based authentication](/azure/active-directory/authentication/concept-certificate-based-authentication).
1616

@@ -102,8 +102,6 @@ az keyvault secret download --file /path/to/cert.pfx \
102102
--name CertName \
103103
--encoding base64
104104
openssl pkcs12 -in cert.pfx -passin pass: -passout pass: -out cert.pem -nodes
105-
106-
az login --service-principal -u "<myAppClientID>" -p cert.pem --tenant "<myTenantID>"
107105
```
108106

109107
## Convert an existing PKCS12 file
@@ -142,10 +140,7 @@ The output includes credentials that you must protect. Be sure that you do not i
142140
To sign in with a certificate, the certificate must be available locally as a PEM or DER file in ASCII format. PKCS#12 files (.p12/.pfx) don't work. When you use a PEM file, the **PRIVATE KEY** and **CERTIFICATE** must be appended together within the file. You don't need to prefix the path with an `@` like you do with other az commands.
143141

144142
```azurecli-interactive
145-
az login --service-principal \
146-
--username myServicePrincipalID \
147-
--tenant myOwnerOrganizationId \
148-
--password /path/to/cert
143+
az login --service-principal --username APP_ID --certificate /path/to/cert.pem --tenant TENANT_ID
149144
```
150145

151146
## Next Steps

docs-ref-conceptual/upcoming-breaking-changes.md

+6
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ The [db-up](https://github.com/Azure/azure-cli-extensions/tree/main/src/db-up) e
6363

6464
- This command group has been deprecated and will be removed in next breaking change release(2.67.0). Use 'az network public-ip ddos-protection' instead.
6565

66+
## profile
67+
68+
### `az login`
69+
70+
- The `--password` parameter will not accept service principal certificate. Use the `--certificate` parameter instead.
71+
6672
## sql
6773

6874
[Link to sql mi link subgroup](/cli/azure/sql/mi/link)

0 commit comments

Comments
 (0)