powershell - 无法通过 Powershell 或 Visual Studio 连接到安全的 Azure Service Fabric 群集

标签 powershell azure visual-studio-2015 certificate azure-service-fabric

我创建了一个 Service Fabric 应用程序,当前由两个 Reliable Services 和一个 Reliable Actor 组成。为了进行开发,我在 Azure 中创建了 SQL Server 和数据库,并将连接字符串硬编码到我在本地 SF 集群上运行的应用程序中。这工作得很好,我能够在本地运行我的应用程序,同时操作云中的数据库。

我现在想将我的服务发布到云,并远程运行它(以便我可以设置和测试公开的 Web API),这就是问题开始的地方。

以下 Azure 文档:

  1. Create a Service Fabric cluster in Azure using Azure Resource Manager
  2. Connect to a secure cluster
  3. Configure secure connections to a Service Fabric cluster from Visual Studio
  4. Service Fabric cluster security scenarios
  5. Publish an application to a remote cluster by using Visual Studio
  6. Add or remove certificates for a Service Fabric cluster in Azure

我已采取以下步骤:

  1. 使用 Powershell(带有 ServiceFabricRPHelpers cmdlet)创建 KeyVault 资源组,并在其中创建一个 KeyVault

  2. 使用了 New-SelfSignedCertificate,并将 -DnsName 设置为 api.mydomain.co.uk,我已经购买了该证书并为指向 mycluster.northeurope.cloudapp 的 api 创建了 CNAME 记录。 azure.com:19000(当然,在此过程阶段它不存在),然后使用 Export-PfxCertificate 创建 .pfx 文件。然后将 .pfx 导入到 cert:\CurrentUser\TrustedPeoplecert:\CurrentUser\My

  3. 调用 Invoke-AddCertToKeyVault 将新生成的证书添加到我的 KeyVault

  4. 使用 SetupApplications.ps1 脚本配置 AAD。

  5. 将所有生成的字符串等放入 azuredeploy.jsonazuredeploy.parameters.json 中,解决了错误(其中一些似乎与文档相矛盾...... ),并成功部署集群。现在可以在我的 Azure 门户上看到它。

  6. 从经典门户分配用户角色(管理员给我自己)。

  7. 使用 Invoke-AddCertToKeyVault(这次创建并)向集群添加第二个“管理客户端”证书(而不是第一个集群证书)。

因此,完成所有这些后,我相信我应该完成所需的一切,以便能够连接到集群以通过 VS2015 进行发布,并从 api.mydomain.co.uk:19080。唉,这并没有发生...

我的集群仍然可以通过 SQL Server Explorer 使用 SQL 身份验证从 VS 中连接到资源组中的数据库,但是任何尝试使用基于 AAD 或 X509 的身份验证结果与服务器本身进行通信等待尝试连接,然后失败。几个例子:

Cloud Explorer Cloud Explorer message: Cloud Explorer could not connect to cluster - An error occurred while sending the request. Unable to connect to the remote server Failed to contact server, please try again later or get help

尝试连接到管理控制台时说它已被阻止,这对我来说意味着它在那里,但所有文档在告诉我如何访问它之前就结束了。 Web management interface blocked

尝试使用Connect-ServiceFabricCluster进行连接也失败,并且搜索错误消息没有给我任何指示要做什么。

connect-servicefabriccluster error

在花了两天时间吸收所有这些内容并试图让它发挥作用之后,我完全不知道该尝试和改变什么。谁能发现我所做的事情存在问题,或者建议我可以尝试什么? 如果您需要我提供更多详细信息,请直接询问!

最佳答案

我在尝试部署安全集群时也经历了一场噩梦,使用的大部分文档与您也尝试使用的文档相同。经过几天的努力,我终于让它工作起来了。

这是我自己的助手和模板:SecureCluster

需要注意的关键事项是:

  • 确保您的客户端和集群证书均位于 key 保管库中,并在 VM 规模集的 OSProfile 下的 ARM 模板中引用(我注意到在您的示例中,您在修改ARM 模板):

    
    "osProfile": {
            "adminUsername": "[parameters('adminUsername')]",
            "adminPassword": "[parameters('adminPassword')]",
            "computernamePrefix": "[parameters('vmNodeType0Name')]",
            "secrets": [
                            {
                                "sourceVault": {
                                    "id": "[parameters('sourceVault')]"
                                },
                                "vaultCertificates": [
                                    {
                                        "certificateStore": "My",
                                        "certificateUrl": "[parameters('clusterCertificateUrl')]"
                                    },
                                    {
                                        "certificateStore": "My",
                                        "certificateUrl": "[parameters('adminCertificateUrl')]"
                                    }
                                ]
                            }
                        ]
          },
    

这将确保您的所有证书都安装到集群内的每个节点上。

下一步是确保规模集中的 Service Fabric 扩展也具有您的证书:

"extensions": [
              {
                "name": "[concat(parameters('vmNodeType0Name'),'_ServiceFabricNode')]",
                "properties": {
                  "type": "ServiceFabricNode",
                  "autoUpgradeMinorVersion": false,
                  "protectedSettings": {
                    "StorageAccountKey1":
                      "[listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('supportLogStorageAccountName')),'2015-05-01-preview').key1]",
                    "StorageAccountKey2":
                      "[listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('supportLogStorageAccountName')),'2015-05-01-preview').key2]"
                  },
                  "publisher": "Microsoft.Azure.ServiceFabric",
                  "settings": {
                    "clusterEndpoint": "[reference(parameters('clusterName')).clusterEndpoint]",
                    "nodeTypeRef": "[parameters('vmNodeType0Name')]",
                    "dataPath": "D:\\\\SvcFab",
                    "durabilityLevel": "Bronze",
                    "certificate": {
                        "thumbprint": "[parameters('clusterCertificateThumbPrint')]",
                        "x509StoreName": "My"
                    }
                  },
                  "typeHandlerVersion": "1.0"
                }
              },

最后,在 ARM 模板内的 Service Fabric 资源部分下,确保指定用于节点到节点安全性的证书以及用于客户端到节点安全性的证书。

certificate": {
            "thumbprint": "[parameters('clusterCertificateThumbPrint')]",
            "x509StoreName": "My"
        },
        "clientCertificateCommonNames": [],
        "clientCertificateThumbprints": [{
                    "CertificateThumbprint": "[parameters('adminCertificateThumbPrint')]",
                    "IsAdmin": true
                }],

然后您应该能够按照您尝试的方式安全地连接到集群。虽然我发现的一件事是,发布配置文件中的 URL 不应该以“http”为前缀,并且当尝试浏览到资源管理器时,您需要将 URL 设为 https://[n]:19080/Explorer/index.html

希望本文对您有所帮助。

关于powershell - 无法通过 Powershell 或 Visual Studio 连接到安全的 Azure Service Fabric 群集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39212616/

相关文章:

Azure:交换 VIP(虚拟 IP)期间用户 session 会发生什么情况?

azure - 更改应用服务环境的子网地址

javascript - 如何在 visual studio "TypeScript HTML App"模板中导入 TypeScript 类?

deployment - 使用 Team Foundation Build 2015 部署到多个环境

powershell - 如何解压缩多个文件?

powershell - 我可以在 Write-Host 或 Write-Debug 中使用 -Format 运算符吗?

c# - 使用 Azure.Storage.Blobs 枚举大型 Azure BLOB 容器

powershell - 为什么 PowerShell 脚本在提示输入时会暂停?

sharepoint - 在 C# 中运行 powershell 命令

visual-studio-2015 - Visual Studio 2015 调试 session 结束后,IIS Express 继续运行