zoukankan      html  css  js  c++  java
  • 利用Azure Automation实现云端自动化运维(3)

    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生成证书:

    1. 一般的Linux上都自带了OpenSSL,如果没有需要安装一下,当然你用Windows的也可以,首先第一步,生成服务器端的X509文件和key,记住在此处生成的密码

       

      $ openssl req -x509 -days 365 -newkey rsa:1024 -keyout server-key.pem -out server-cert.pem

       

    1. 然后通过pem文件,key,利用openssl生成Azure automation需要的pfx文件:

       

      $ openssl pkcs12 -export -in server-cert.pem -inkey server-key.pem -out mycert.pfx

       

       

    2. 最后,通过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文件。

    1. 首先下载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

       

    2. 安装完成后在program Files下的Windows kits下可以看到makecert命令行,使用makecert生成cer文件:

       

      makecert.exe -sky exchange -r -n "CN=AzureAutomation" -pe -a sha1 -len 2048 -ss My "AzureAutomation.cer"

       

       

     

     

    1. 生成cer文件以后,我们可以使用Powershell生成pfx文件,请用管理员权限打开Powershell:

      #myautomation是pfx的密码,在导入到Azure Automation时需要使用

      $MyPwd = ConvertTo-SecureString -String "myautomation" -Force –AsPlainText

       

      # "AzureAutomation"是certificate的名字,在第一步生成的

      $AzureCert = Get-ChildItem -Path Cert:CurrentUserMy | where {$_.Subject -match "AzureAutomation"}

       

      #导出生成pfx文件

      Export-PfxCertificate -FilePath C:AzureAutomation.pfx -Password $MyPwd -Cert $AzureCert

       

    使用证书

     

    无论你是使用Linux还是Windows生成证书,必须确保你有一个X509的cer证书和一个带密码的pfx证书,前者用于上传到management证书,pfx上传给runbook的资产作为授权凭证。

    1. 上传cer文件到Azure的管理证书,登陆Azure的portal,选择设置,管理证书,然后再下方选择"上载",选择你在上述步骤中生成的.cer并选择确定:

    2. 打开自动化管理账号,选择资产,并在下方菜单中选择添加设置:

       

       

       

    3. 在添加类型中选择添加凭据,在凭据类型中选择证书,

    1. 选择在上述步骤中生成的pfx文件,输入密码,然后确定,完成上传:

    在后续章节中介绍如何使用凭证进行验证使用。

     

     

     

  • 相关阅读:
    Python之禅
    浅析css布局模型1
    原型与继承学习笔记4
    原型与继承学习笔记3
    原型与继承学习笔记1
    javascript-this,call,apply,bind简述3
    javascript-this,call,apply,bind简述2
    javascript-this,call,apply,bind简述1
    javascript数组浅谈3
    javascript数组浅谈2
  • 原文地址:https://www.cnblogs.com/cloudapps/p/5498482.html
Copyright © 2011-2022 走看看