Skip to content

Commit e29868d

Browse files
author
Maddie Clayton
authored
Merge pull request #7727 from cormacpayne/enable-certs
Implement certificate-based SP authentication in Az
2 parents 537d599 + 0ee0aed commit e29868d

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

src/ResourceManager/Profile/Commands.Profile/Account/ConnectAzureRmAccount.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public override void ExecuteCmdlet()
278278
}
279279

280280
#if NETSTANDARD
281-
if (azureAccount.Type == AzureAccount.AccountType.ServicePrincipal)
281+
if (azureAccount.Type == AzureAccount.AccountType.ServicePrincipal && string.IsNullOrEmpty(CertificateThumbprint))
282282
{
283283
azureAccount.SetProperty(AzureAccount.Property.ServicePrincipalSecret, password.ConvertToString());
284284
if (GetContextModificationScope() == ContextModificationScope.CurrentUser)

src/ResourceManager/Profile/Commands.Profile/help/Connect-AzureRmAccount.md

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ After executing this cmdlet, you can disconnect from an Azure account using Disc
6464
## EXAMPLES
6565

6666
### Example 1: Use an interactive login to connect to an Azure account
67-
```
67+
```powershell
6868
PS C:\> Connect-AzureRmAccount
69+
6970
Account SubscriptionName TenantId Environment
7071
------- ---------------- -------- -----------
7172
[email protected] Subscription1 xxxx-xxxx-xxxx-xxxx AzureCloud
@@ -76,34 +77,36 @@ To run Azure Resource Manager cmdlets with this account, you must provide Micros
7677
If multi-factor authentication is enabled for your credentials, you must log in using the interactive option or use service principal authentication.
7778

7879
### Example 2: Connect to an Azure account using organizational ID credentials
79-
```
80+
```powershell
8081
PS C:\> $Credential = Get-Credential
8182
PS C:\> Connect-AzureRmAccount -Credential $Credential
83+
8284
Account SubscriptionName TenantId Environment
8385
------- ---------------- -------- -----------
8486
[email protected] Subscription1 xxxx-xxxx-xxxx-xxxx AzureCloud
8587
```
8688

87-
The first command gets the user credentials, and then stores them in the $Credential variable.
89+
The first command will prompt for user credentials (username and password), and then stores them in the $Credential variable.
8890
The second command connects to an Azure account using the credentials stored in $Credential.
8991
This account authenticates with Azure Resource Manager using organizational ID credentials.
9092
You cannot use multi-factor authentication or Microsoft account credentials to run Azure Resource Manager cmdlets with this account.
9193

9294
### Example 3: Connect to an Azure service principal account
93-
```
95+
```powershell
9496
PS C:\> $Credential = Get-Credential
97+
9598
PS C:\> Connect-AzureRmAccount -Credential $Credential -Tenant "xxxx-xxxx-xxxx-xxxx" -ServicePrincipal
9699
Account SubscriptionName TenantId Environment
97100
------- ---------------- -------- -----------
98101
xxxx-xxxx-xxxx-xxxx Subscription1 xxxx-xxxx-xxxx-xxxx AzureCloud
99102
```
100103

101-
The first command gets the user credentials, and then stores them in the $Credential variable.
104+
The first command gets the service principal credentials (application id and service principal secret), and then stores them in the $Credential variable.
102105
The second command connect to Azure using the service principal credentials stored in $Credential for the specified Tenant.
103106
The ServicePrincipal switch parameter indicates that the account authenticates as a service principal.
104107

105108
### Example 4: Use an interactive login to connect to an account for a specific tenant and subscription
106-
```
109+
```powershell
107110
PS C:\> Connect-AzureRmAccount -Tenant "xxxx-xxxx-xxxx-xxxx" -SubscriptionId "yyyy-yyyy-yyyy-yyyy"
108111
Account SubscriptionName TenantId Environment
109112
------- ---------------- -------- -----------
@@ -113,16 +116,40 @@ [email protected] Subscription1 xxxx-xxxx-xxxx-xxxx AzureCloud
113116
This command connects to an Azure account and configured AzureRM PowerShell to run cmdlets for the specified tenant and subscription by default.
114117

115118
### Example 5: Add an Account Using Managed Service Identity Login
116-
```
119+
```powershell
117120
PS C:\> Connect-AzureRmAccount -MSI
121+
118122
Account SubscriptionName TenantId Environment
119123
------- ---------------- -------- -----------
120124
MSI@50342 Subscription1 xxxx-xxxx-xxxx-xxxx AzureCloud
121125
```
122126

123-
This command connects using the managed service identity of the host environment (for example, if executed on a
127+
This command connects using the managed service identity of the host environment (for example, if executed on a
124128
VirtualMachine with an assigned Managed Service Identity, this will allow the code to login using that assigned identity)
125129

130+
### Example 6: Add an account using certificates
131+
```powershell
132+
# For more information on creating a self-signed certificate
133+
# and giving it proper permissions, please see the following:
134+
# https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-authenticate-service-principal-powershell
135+
PS C:\> $Thumbprint = "0SZTNJ34TCCMUJ5MJZGR8XQD3S0RVHJBA33Z8ZXV"
136+
PS C:\> $TenantId = "4cd76576-b611-43d0-8f2b-adcb139531bf"
137+
PS C:\> $ApplicationId = "3794a65a-e4e4-493d-ac1d-f04308d712dd"
138+
PS C:\> Connect-AzureRmAccount -CertificateThumbprint $Thumbprint -ApplicationId $ApplicationId -Tenant $TenantId -ServicePrincipal
139+
140+
Account SubscriptionName TenantId Environment
141+
------- ---------------- -------- -----------
142+
xxxx-xxxx-xxxx-xxxx Subscription1 xxxx-xxxx-xxxx-xxxx AzureCloud
143+
144+
Account : 3794a65a-e4e4-493d-ac1d-f04308d712dd
145+
SubscriptionName : MyTestSubscription
146+
SubscriptionId : 85f0f653-1f86-4d2c-a9f1-042efc00085c
147+
TenantId : 4cd76576-b611-43d0-8f2b-adcb139531bf
148+
Environment : AzureCloud
149+
```
150+
151+
This command connects to an Azure account using certificate-based service principal authentication. Theservice principal used for authentication should have been created with the given certificate.
152+
126153
## PARAMETERS
127154

128155
### -AccessToken

0 commit comments

Comments
 (0)