Bind certificate to a micro service in pod (mTLS)

106 Views Asked by At

I am trying to implement the mTLS in cluster across micro service for secured communication. I know that there are service meshes are available for this purpose. But we would like to stay away from service mesh and implement the mTLS in cluster.

So, after going through several posts, then I am able to create the tls secret and mount the volume as part of the service deployment. This certificate i can retrieve from X509Store:

using var certificateStore = new X509Store(StoreName.Root, StoreLocation.LocalMachine, OpenFlags.ReadOnly);
if (certificateStore.Certificates.Any())
{
 var certs = certificateStore.Certificates.Find(X509FindType.FindByIssuerName, issuerName, true);
 if (certs.Any())
  {
   return certs.First();
  }
 }
return null;

But, now, when i am trying to assign this certificate as part of the

kestrelServerOptions.ConfigureHttpsDefaults(listenOptions =>
{
 Log.Information($"Configuring the https defaults.");
 if (serverCertificate == null)
 {
  return;
 }

 // self signed certificate
 Log.Information($"Before : Private key: {serverCertificate?.HasPrivateKey}");
 Log.Information($"After : Server certificate: {listenOptions.ServerCertificate?.Issuer}");

 listenOptions.ServerCertificate = serverCertificate; // throws exception saying that the serer certificate should have the private key.
....

my secret volume has both .crt(pem) and .key files stored as part of the tls secret. But service is not able to attach this private .key to it.

I am really lost here... and not able to proceed further.

I really appreciate if someone help me to work with this certificate and mTLS.

Thanks in advance.

0

There are 0 best solutions below