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的電源外殼權限腳本

相關問題