1

我们有需要两个证书的ASP.NET应用程序MVC5:在AWS Elastic Beanstalk部署中将证书自动部署到Windows证书存储?

  1. 的X509椭圆曲线证书和它相应的私钥(* .PFX)
  2. 的X509椭圆曲线证书(* .CER)

在Windows Server 2012 R2的证书存储区(“本地计算机”帐户,“个人”存储)中可用。为了澄清,这些证书是由MVC5应用程序的代码使用的,并且没有任何与SSL/TLS/HTTPS有关。

问题:如何配置AWS Elastic Beanstalk,以便在部署MVC5应用程序后,证书存储区中已具有这些证书和私钥? AWS已配置通过Elastic Beanstalk自动配置的EC2 Windows服务器,以便ASP.NET应用程序在IIS_IUSR用户权限下运行在IIS中,所以我们还需要授予IIS_IUSR访问证书私钥的权限。我不清楚IIS_IUSR实际上是遵循最小特权的原则,还是我授予了错误的帐户权限 - 但它确实有效(见下文)。我们目前正在通过适用于Visual Studio 2013的AWS Toolkit进行部署,但如果能够解决主要问题,则可以使用其他部署技术。


目前,我们拥有一个丑陋的,手动的解决方法是

  • 远程连接到每个实例,每个实例执行下列操作
  • 上传证书文件(* CER和* PFX)
  • 手动运行批处理文件以将它们加载到证书存储区(由于它们是自签名证书,因此也必须将它们添加到根存储区)。该批处理文件看起来像
certutil -f -addstore Root OurCert-SS.cer // just a CER version of the PFX below 
certutil -f -addstore Root RemoteCert-SS.cer 
certutil -f -p test -importPFX MY OurCert-SS.pfx 
certutil -f -addstore MY RemoteCert-SS.cer 
  • 手动打开MMC =>证书(本地计算机)=>给IIS_IUSRSFull control权限证书的私钥(否则ASP.NET应用程序可以拿不到私钥)。在this post

详细显然,这极大地杀死了抽象的PaaS应该提供随时随地,因为规模的实例或得到回收,我们要做的上述:(...所以希望得到任何帮助。

回答

1

你得到这个解决?

你能不能做这样的事情在这里描述的是什么https://forums.aws.amazon.com/thread.jspa?messageID=591375,忽略了网络结合件,新增的权限为IIS_IUSR

我想我会以w更新我们最终做的帽子。

我们设置ebextension从s3加载证书,然后分配所需的权限。我意识到我们没有.cer文件来处理,所以这可能不适合你。

--- 
files: 
    "c:\\init_scripts\\install_cert.ps1": 
    content: | 
    $env = $args[0] 
    $pwd = $args[1] 
    $securePwd = ConvertTo-SecureString -String $pwd -Force -asplaintext 
    $certName="$($env).auth.cert.pfx" 
    $certFilePath = "C:\$($certName)" 
    Read-S3Object -BucketName ourcertsbucket -Key $certName -File $certFilePath 
    $cert = Import-PfxCertificate -FilePath $certFilePath cert:\localmachine\my -Password $securePwd 
    # Now that we have the cert we need to grant access to the IIS user for the cert 
    Try 
    { 
     $WorkingCert = Get-ChildItem CERT:\LocalMachine\My |where {$_.Subject -match $env} | sort $_.NotAfter -Descending | select -first 1 -erroraction STOP 
     $TPrint = $WorkingCert.Thumbprint 
     $rsaFile = $WorkingCert.PrivateKey.CspKeyContainerInfo.UniqueKeyContainerName 
    } 
    Catch 
    { 
     "  Error: unable to locate certificate for $($env)" 
     Exit 
    } 
    $keyPath = "C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys\" 
    $fullPath=$keyPath+$rsaFile 
    $acl=Get-Acl -Path $fullPath 
    $permission="IIS_IUSRS","Read","Allow" 
    $accessRule=new-object System.Security.AccessControl.FileSystemAccessRule $permission 
    $acl.AddAccessRule($accessRule) 
    Try 
    { 
    Set-Acl $fullPath $acl 
     "  Success: ACL set on certificate" 
    } 
    Catch 
    { 
     "  Error: unable to set ACL on certificate" 
     Exit 
    } 
container_commands: 
    01_install_cert: 
    command: powershell -ExecutionPolicy RemoteSigned -File .\\install_cert.ps1 %Environment% %CertPassword% 
    cwd: c:\\init_scripts 
    waitAfterCompletion: 0 

由于这一link的电源外壳权限脚本

相关问题