该种方式是推荐的进行Automation认证的方式,好处在于安全性高,过期时间由自己控制,不好的地方在于大家在Windows上要生成证书比较麻烦,而且必须上传到Azure management和Automation, Automation需要两个文件:.pfx证书用于用户自动化端连接Azure,.cer文件,Azure管理端证书文件,这两个文件必须互相匹配。 对于创建证书,个人比较推荐的办法,或者我喜欢用的方法,就是利用开源的openssl工具,几个命令快速搞定,我在我的本机安装的是Ubuntu on windows,非常方便,大家感兴趣可以 基于Linux的Openssl生成证书:
使用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文件,输入密码,然后确定,完成上传:
在后续章节中介绍如何使用凭证进行验证使用。
|