Using Smartcards/CACs to Manage Windows Azure via Powershell
Even though Windows Azure VM's can be managed from either the Azure Portal or Microsoft Azure PowerShell, some tasks can only be performed using Microsoft Azure PowerShell. In order to Manage windows Azure using PowerShell you must first prepare your workstation by completing the following:
Installing Microsoft Azure PowerShell
Importing the Azure Subscription Publish Settings File
Adding Azure Account
These steps are pretty straight forward, however you organization might require CAC/Smartcard authentication to Corporate resources so the following steps can be performed to utilize an existing Smartcard to authenticate to Windows Azure PowerShell.
Installing Microsoft Azure PowerShell
The easiest method for installing Microsoft Azure PowerShell is using the Microsoft Web Platform Installer. This installing will also install requirements like Microsoft .NET Framework 4.5. It can be downloaded from the following Link:
https://go.microsoft.com/fwlink/p/?linkid=320376&clcid=0x409
When prompted execute the WindowsAzurePowerShell.3f.3f.3fnew.exe click Run.
At the Web Platform Installer 5.0 click Install.
At the next pop-up select I Accept.
At the next screen click Finish, then Exit.
Managing Management Certificates
Microsoft Azure is a Subscription based service. In order to Manage your subscription using a Smartcard, the Public Key of the Certificate must be uploaded using the Azure Portal. The first step in this process is extracting the Public Key from your Smartcard.
Extracting the Public Key
Navigate to Start | Run.
In the Open: section enter mmc then click OK.
At the MMC navigate to File | Add/Remove Snap-in.
In the Left-Column select Certificates then click Add.
At the Certificates snap-in pop-up windows select My user account then click Finish then OK.
Insert your Smartcard into the Smartcard Reader.
In the Left-Column expand Certificates – Current User | Personal and right-click Certificates and select Refresh. (At this point your Smartcard Certificates should be visible)
In the Right-Column right-click the Certificate being exported and select All Tasks | Export.
At the Welcome to the Certificate Export Wizard select Next.
At the Export Private Key screen click Next.
At the Export File make sure Base-64 encoded X.509 (.CER) is selected then click Next.
At the File to Export screen enter C:\Smartcard.cer under File name: then click Next then Finish.
Uploading the Certificate
Once we have successfully exported the Public Key of our Smartcard we need to upload it to the Azure Portal for usage with our Subscription. This can be accomplished by completing the following steps:
Navigate to the Azure Portal and Login
https://manage.windowsazure.com
At the Microsoft Azure screen enter your logon account then click Continue.
At the next screen select Microsoft account.
At the Sign in screen enter your password then click Sign in.
In the Left-Column scroll down and select SETTINGS.
Under the Middle-Column under Settings select MANAGEMENT CERTIFICATES then on the bottom toolbar click UPLOAD.
At the Upload a management certificate pop-up click FILE then navigate to C:\Smartcard.cer then click Open and click on the OK Checkbox.
(Note: Stay logged in to the Portal. This will prevent you from having to re-enter your credentials for the next step.)
Downloading the Azure Publish Settings File
The Azure Publish Settings File contains the following information about your Subscription:
ServiceManagementURL
ID
Name
All Management Certificates Uploaded in the Azure Portal
The Azure Publish Settings file can be downloaded by using the following steps:
Launch Microsoft Azure Powershell.
At the prompt, enter the following command:
Get-AzurePublishSettingsFile
At the File Download select the Save pull-down menu and then select Save as.
At the Save As pop-up enter a name for the file then click Save (Subscription.publishsettings)
Modifying the Azure Publishing File
By default the Azure Publishing File contains the Public Key for the default Management Certificate created with the Azure Subscription. The steps below can be used to modify the Azure Publishing File to utilize your Smart Card Certificate Public Key:
Navigate to the location that you saved your Public Key (C:\Smartcard.cer).
Right-click the c:\Smartcard.cer and select Open with, then select Notepad.
Select and Copy the Public Key of your certificatesection between the -----BEGIN CERTIFICATE----- and ----- END CERTIFICATE -----
Navigate to the location that you saved the AzurePublishSettingsFile.
Right-click the AzurePublishSettingsFile and select Open with then select Notepad.
Locate the ManageCertificate= section and paste your copied Public Key then Save the File.
Connecting to and Manage your Azure Publish Subscription
Now that we have successfully uploaded our Management Certificate and downloaded our Azure Publish Settings File, we can now successfully connect to our Azure Subscription using the following steps:
Launch Microsoft Azure Powershell.
At the prompt, enter the following command:
Import-AzurePublishSettingsFile –PublishSetingsFile MySubscription.publishsettings
Test your newly Imported Certificate by issuing the command below:
Get-AzureVM
If everything is configured correctly a list of all of your Azure VM’s will be returned. J
Enjoy
-Elliott