Azure automation的認證方式:證書
該種方式是推薦的進行Automation認證的方式,好處在於安全性高,過期時間由自己控制,不好的地方在於大家在Windows上要生成證書比較麻煩,而且必須上傳到Azure management和Automation,
Automation需要兩個文件:.pfx證書用於用戶自動化端連接Azure,.cer文件,Azure管理端證書文件,這兩個文件必須互相匹配。
對於創建證書,個人比較推薦的辦法,或者我喜歡用的方法,就是利用開源的openssl工具,幾個命令快速搞定,我在我的本機安裝的是Ubuntu on windows,非常方便,大家感興趣可以參考:
http://cloudapps.blog.51cto.com/3136598/1761954
基於Linux的Openssl生成證書:
一般的Linux上都自帶了OpenSSL,如果沒有需要安裝一下,當然你用Windows的也可以,首先第一步,生成服務器端的X509文件和key,記住在此處生成的密碼:
$ openssl req -x509 -days 365 -newkey rsa:1024 -keyout server-key.pem -out server-cert.pem
然後通過pem文件,key,利用openssl生成Azure automation需要的pfx文件:
$ openssl pkcs12 -export -in server-cert.pem -inkey server-key.pem -out mycert.pfx
最後,通過pem文件生成Azure服務器管理端需要的x.509的cer文件:
$ openssl x509 -inform pem -in server-cert.pem -outform der -out mycert.cer
使用Windows的makecert生成證書
你也可以使用Windows的makecert工具生成Azure需要的cer和pfx文件。
首先下載Windows SDK for Windows 10或者windows 8:
https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk
https://developer.microsoft.com/en-us/windows/downloads/windows-8-sdk
安裝完成後在program Files下的Windows kits下可以看到makecert命令行,使用makecert生成cer文件:
makecert.exe -sky exchange -r -n "CN=AzureAutomation" -pe -a sha1 -len 2048 -ss My "AzureAutomation.cer"
生成cer文件以後,我們可以使用Powershell生成pfx文件,請用管理員權限打開Powershell:
#myautomation是pfx的密碼,在導入到Azure Automation時需要使用
$MyPwd = ConvertTo-SecureString -String "myautomation" -Force –AsPlainText
# "AzureAutomation"是certificate的名字,在第一步生成的
$AzureCert = Get-ChildItem -Path Cert:\CurrentUser\My | where {$_.Subject -match "AzureAutomation"}
#導出生成pfx文件
Export-PfxCertificate -FilePath C:\AzureAutomation.pfx -Password $MyPwd -Cert $AzureCert
使用證書
無論你是使用Linux還是Windows生成證書,必須確保你有一個X509的cer證書和一個帶密碼的pfx證書,前者用於上傳到management證書,pfx上傳給runbook的資產作爲授權憑證。
上傳cer文件到Azure的管理證書,登陸Azure的portal,選擇設置,管理證書,然後再下方選擇"上載",選擇你在上述步驟中生成的.cer並選擇確定:
打開自動化管理賬號,選擇資產,並在下方菜單中選擇添加設置:
在添加類型中選擇添加憑據,在憑據類型中選擇證書,
選擇在上述步驟中生成的pfx文件,輸入密碼,然後確定,完成上傳:
在後續章節中介紹如何使用憑證進行驗證使用。