无法向安全的 Service Fabric 集群验证 FabricClient
Unable to authenticate FabricClient to a secured Service Fabric Cluster
我有一个安全的服务结构集群。同一证书用作服务器证书和客户端身份验证。我无法在允许我连接到此集群的控制台应用程序中创建 FabricClient
。我正在使用 "Connect to a secure cluster using a client certificate":
下 here 记录的代码片段
static void Main(string[] args)
{
string thumb = "1234567890123456789012345678901234567890";
string CommonName = "somefabric.cloudapp.azure.com";
string connection = "somefabric.cloudapp.azure.com:19000";
try
{
X509Credentials xc = GetCredentials(thumb, thumb, CommonName);
FabricClient fc = new FabricClient(xc, connection);
Console.WriteLine("Cluster is connected");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.ReadKey();
}
static X509Credentials GetCredentials(string clientCertThumb, string serverCertThumb, string name)
{
X509Credentials xc = new X509Credentials();
// Client certificate
xc.StoreLocation = StoreLocation.CurrentUser;
xc.StoreName = "MY";
xc.FindType = X509FindType.FindByThumbprint;
xc.FindValue = clientCertThumb;
// Server certificate
xc.RemoteCertThumbprints.Add(serverCertThumb);
xc.RemoteCommonNames.Add(name);
xc.ProtectionLevel = ProtectionLevel.EncryptAndSign;
return xc;
}
此代码导致
The X509 thumbprint specified is invalid.
证书似乎确实通过其他方式授予我访问权限。我能够成功查看 Fabric Explorer 和
以下 PowerShell 命令也成功连接到集群
Connect-ServiceFabricCluster
-ConnectionEndpoint somefabric.cloudapp.azure.com:19000
-X509Credential
-FindType FindByThumbprint
-FindValue 1234567890123456789012345678901234567890
-StoreLocation CurrentUser
-StoreName MY
-ServerCertThumbprint 1234567890123456789012345678901234567890
我做错了什么?
我想样本中提供的指纹和通用名称只是虚拟数据,因此您不必 post 这里的真实值?但是,问题可能就在于此,如果你 运行 this 具有实际值,你仍然会得到相同的异常吗?
例如
string thumb = "1234567890123456789012345678901234567890";
string CommonName = "somefabric.cloudapp.azure.com";
string connection = "somefabric.cloudapp.azure.com:19000";
try
{
X509Credentials xc = GetCredentials(thumb, thumb, CommonName);
FabricClient fc = new FabricClient(xc, connection);
Console.WriteLine("Cluster is connected");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
这将引发异常 The X509 thumbprint specified is invalid.
。但是,如果您将其更改为与 Microsoft 示例中的相同:
string clientCertThumb = "71DE04467C9ED0544D021098BCD44C71E183414E";
string serverCertThumb = "A8136758F4AB8962AF2BF3F27921BE1DF67F4326";
string CommonName = "www.clustername.westus.azure.com";
string connection = "somefabric.westus.cloudapp.azure.com:19000";
try
{
X509Credentials xc = GetCredentials(clientCertThumb, serverCertThumb, CommonName);
FabricClient fc = new FabricClient(xc, connection);
Console.WriteLine("Cluster is connected");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
您现在将得到一个异常 An error occurred during this operation. Please check the trace logs for more details.
。您收到此错误是因为群集 somefabric.westus.cloudapp.azure.com
不存在并且您无法使用 FabricClient 连接到该地址,但证书指纹被识别为指纹。
将其替换为实际的指纹、公用名和与集群的连接即可。
详细解释:
Service Fabric 底层代码中的某处实际验证了您的证书指纹。在这种情况下,证书的指纹是证书的 SHA-1 散列(通常是 der 格式的整个证书内容),不太可能以 1234567890123456789012345678901234567890
作为实际散列结束。 Here is a nice blog entry 详细解释证书指纹的结构。
此外,您不应为客户端安全使用与集群安全相同的证书:
https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-cluster-security (见文末注释).
All management operations on a Service Fabric cluster require server certificates. Client certificates cannot be used for management.
检查证书
集群的证书应该是您第一次创建集群时提供的证书。您应该能够在保存它的 Key Vault 中找到它。您还可以通过在 Azure 门户中查找群集资源来检查它的缩略图。单击集群资源下的安全性。
表示 Primary certificate 的字段显示了您在连接到集群时可能期望从集群获得的缩略图。
当您连接到 Service Fabric Explorer(通常在端口 19080)时,如果您检查为 HTTPS 连接提供的证书,也可以查看它。如果您单击证书的详细信息,您应该会在证书的属性中看到指纹。
在您被允许访问之前,浏览器会要求您提供客户端证书,此时您可以提供应该位于您的计算机上的证书。
之后,您应该能够通过在浏览器中查看页面的安全性来查看证书详细信息。
如果您打开管理用户证书,您可以在Windows中找到您的本地证书,在这里您应该能够找到您不想使用的证书在 Personal/Certificates 下。在详细信息下找到的缩略图应该与您在代码中显示的缩略图类似。查看集群安全性时,它还应该出现在 Azure 门户的客户端证书列表中。如果不存在,则需要添加它。在 Azure 更新完群集的安全性后,您应该能够连接到该证书。
我确实遇到了这个问题,但原因完全不同。
我对此很困惑;
- https 资源管理器工作(在 IExporer 中)
- Powershell Connect-ServiceFabricCluster 也有效。
- Visual Studio发布失败
我发现我的指纹值附加了 4 个不可见字符,这可能是剪切和粘贴操作的产物。怎么,为什么?不知道
我在编辑 Deploy-FabricApplication 以添加此行后才发现。
$publishProfile.ClusterConnectionParameters|Format-List
就在
之前
[void](Connect-ServiceFabricCluster @ClusterConnectionParameters)
然后我看到不可见的字符显示为????在指纹末尾。
使用二进制编辑器打开 Cloud.xml 文件后,我可以看到并删除它们。
然后我就可以发布我的申请了。
我有一个安全的服务结构集群。同一证书用作服务器证书和客户端身份验证。我无法在允许我连接到此集群的控制台应用程序中创建 FabricClient
。我正在使用 "Connect to a secure cluster using a client certificate":
static void Main(string[] args)
{
string thumb = "1234567890123456789012345678901234567890";
string CommonName = "somefabric.cloudapp.azure.com";
string connection = "somefabric.cloudapp.azure.com:19000";
try
{
X509Credentials xc = GetCredentials(thumb, thumb, CommonName);
FabricClient fc = new FabricClient(xc, connection);
Console.WriteLine("Cluster is connected");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.ReadKey();
}
static X509Credentials GetCredentials(string clientCertThumb, string serverCertThumb, string name)
{
X509Credentials xc = new X509Credentials();
// Client certificate
xc.StoreLocation = StoreLocation.CurrentUser;
xc.StoreName = "MY";
xc.FindType = X509FindType.FindByThumbprint;
xc.FindValue = clientCertThumb;
// Server certificate
xc.RemoteCertThumbprints.Add(serverCertThumb);
xc.RemoteCommonNames.Add(name);
xc.ProtectionLevel = ProtectionLevel.EncryptAndSign;
return xc;
}
此代码导致
The X509 thumbprint specified is invalid.
证书似乎确实通过其他方式授予我访问权限。我能够成功查看 Fabric Explorer 和 以下 PowerShell 命令也成功连接到集群
Connect-ServiceFabricCluster
-ConnectionEndpoint somefabric.cloudapp.azure.com:19000
-X509Credential
-FindType FindByThumbprint
-FindValue 1234567890123456789012345678901234567890
-StoreLocation CurrentUser
-StoreName MY
-ServerCertThumbprint 1234567890123456789012345678901234567890
我做错了什么?
我想样本中提供的指纹和通用名称只是虚拟数据,因此您不必 post 这里的真实值?但是,问题可能就在于此,如果你 运行 this 具有实际值,你仍然会得到相同的异常吗?
例如
string thumb = "1234567890123456789012345678901234567890";
string CommonName = "somefabric.cloudapp.azure.com";
string connection = "somefabric.cloudapp.azure.com:19000";
try
{
X509Credentials xc = GetCredentials(thumb, thumb, CommonName);
FabricClient fc = new FabricClient(xc, connection);
Console.WriteLine("Cluster is connected");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
这将引发异常 The X509 thumbprint specified is invalid.
。但是,如果您将其更改为与 Microsoft 示例中的相同:
string clientCertThumb = "71DE04467C9ED0544D021098BCD44C71E183414E";
string serverCertThumb = "A8136758F4AB8962AF2BF3F27921BE1DF67F4326";
string CommonName = "www.clustername.westus.azure.com";
string connection = "somefabric.westus.cloudapp.azure.com:19000";
try
{
X509Credentials xc = GetCredentials(clientCertThumb, serverCertThumb, CommonName);
FabricClient fc = new FabricClient(xc, connection);
Console.WriteLine("Cluster is connected");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
您现在将得到一个异常 An error occurred during this operation. Please check the trace logs for more details.
。您收到此错误是因为群集 somefabric.westus.cloudapp.azure.com
不存在并且您无法使用 FabricClient 连接到该地址,但证书指纹被识别为指纹。
将其替换为实际的指纹、公用名和与集群的连接即可。
详细解释:
Service Fabric 底层代码中的某处实际验证了您的证书指纹。在这种情况下,证书的指纹是证书的 SHA-1 散列(通常是 der 格式的整个证书内容),不太可能以 1234567890123456789012345678901234567890
作为实际散列结束。 Here is a nice blog entry 详细解释证书指纹的结构。
此外,您不应为客户端安全使用与集群安全相同的证书: https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-cluster-security (见文末注释).
All management operations on a Service Fabric cluster require server certificates. Client certificates cannot be used for management.
检查证书
集群的证书应该是您第一次创建集群时提供的证书。您应该能够在保存它的 Key Vault 中找到它。您还可以通过在 Azure 门户中查找群集资源来检查它的缩略图。单击集群资源下的安全性。 表示 Primary certificate 的字段显示了您在连接到集群时可能期望从集群获得的缩略图。
当您连接到 Service Fabric Explorer(通常在端口 19080)时,如果您检查为 HTTPS 连接提供的证书,也可以查看它。如果您单击证书的详细信息,您应该会在证书的属性中看到指纹。
在您被允许访问之前,浏览器会要求您提供客户端证书,此时您可以提供应该位于您的计算机上的证书。
之后,您应该能够通过在浏览器中查看页面的安全性来查看证书详细信息。
如果您打开管理用户证书,您可以在Windows中找到您的本地证书,在这里您应该能够找到您不想使用的证书在 Personal/Certificates 下。在详细信息下找到的缩略图应该与您在代码中显示的缩略图类似。查看集群安全性时,它还应该出现在 Azure 门户的客户端证书列表中。如果不存在,则需要添加它。在 Azure 更新完群集的安全性后,您应该能够连接到该证书。
我确实遇到了这个问题,但原因完全不同。
我对此很困惑;
- https 资源管理器工作(在 IExporer 中)
- Powershell Connect-ServiceFabricCluster 也有效。
- Visual Studio发布失败
我发现我的指纹值附加了 4 个不可见字符,这可能是剪切和粘贴操作的产物。怎么,为什么?不知道
我在编辑 Deploy-FabricApplication 以添加此行后才发现。
$publishProfile.ClusterConnectionParameters|Format-List
就在
之前[void](Connect-ServiceFabricCluster @ClusterConnectionParameters)
然后我看到不可见的字符显示为????在指纹末尾。
使用二进制编辑器打开 Cloud.xml 文件后,我可以看到并删除它们。
然后我就可以发布我的申请了。