# HELP: How to create a client with TLS

**URL:** <https://community.temporal.io/t/help-how-to-create-a-client-with-tls/4287>\
**Category:** Community Support\
**Tags:** go-sdk\
**Created:** [March 27, 2022, 9:05pm UTC](https://community.temporal.io/t/help-how-to-create-a-client-with-tls/4287 "2022-03-27T21:05:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dlo](https://avatars.discourse-cdn.com/v4/letter/d/f08c70/32.png) [@Dlo](https://community.temporal.io/u/Dlo)\
**Post date:** [March 27, 2022, 9:05pm UTC](https://community.temporal.io/t/help-how-to-create-a-client-with-tls/4287/1 "2022-03-27T21:05:37Z")

</div>

I am using this example to start a temporal server: [https://github.com/temporalio/samples-server/tree/main/tls/tls-simple](https://github.com/temporalio/samples-server/tree/main/tls/tls-simple)  
I am not sure how the client will use the client’s certs to connect with temporal server.  
when I start a worker, I am getting this error:  
` get system info failed: last connection error: connection closed before server preface received - *serviceerror.Unavailable`

is these any documentation or example about how to configure a client with TLS?

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [March 28, 2022, 2:32am UTC](https://community.temporal.io/t/help-how-to-create-a-client-with-tls/4287/2 "2022-03-28T02:32:44Z")

</div>

Hi @Dlo

> get system info failed: last connection error: connection closed before server preface received - \*serviceerror.Unavailable

Yes, you will get this if you do not configure TLS in client.Options.

Following code worked for me:

```auto
    var cert *tls.Certificate
	myCert, err := tls.LoadX509KeyPair("./myproject/mypem.pem", "./myproject/mykey.key")
	if err != nil {
		log.Fatal("Failed to load client certificate", tag.Error(err))
	}
	cert = &myCert
	
	c, err := client.NewClient(client.Options{
        // set HostPort if you are not using default 127.0.0.1:7233
		HostPort: "MyHost:MyPort",
        // set Namespace if you are not using default "default" namespace name
		Namespace: "MyNamespace",
		ConnectionOptions: client.ConnectionOptions{
			TLS: &tls.Config{
				Certificates: []tls.Certificate{*cert},
			},
		},
	})
    if err != nil {
		log.Fatalln("Unable to create client", err)
	}

```

Note you will have to do do this for client you use in your code that starts workflow execs, as well the one you use to create your worker(s). Hope this helps.

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [March 28, 2022, 2:45am UTC](https://community.temporal.io/t/help-how-to-create-a-client-with-tls/4287/3 "2022-03-28T02:45:31Z")

</div>

> is these any documentation or example about how to configure a client with TLS?

Opened [issue](https://github.com/temporalio/samples-go/issues/189) to add a sample for this in the [go samples](https://github.com/temporalio/samples-go).

---

<div class="post-metadata">

**Author:** ![Dlo](https://avatars.discourse-cdn.com/v4/letter/d/f08c70/32.png) [@Dlo](https://community.temporal.io/u/Dlo)\
**Post date:** [March 28, 2022, 8:39am UTC](https://community.temporal.io/t/help-how-to-create-a-client-with-tls/4287/4 "2022-03-28T08:39:21Z")

</div>

Hi @tihomir  
thank you so much for the example code.

---

<div class="post-metadata">

**Author:** ![sumesh\_kanayi](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/sumesh_kanayi/32/1876_2.png) [@sumesh\_kanayi](https://community.temporal.io/u/sumesh_kanayi)\
**Post date:** [May 16, 2022, 11:03am UTC](https://community.temporal.io/t/help-how-to-create-a-client-with-tls/4287/5 "2022-05-16T11:03:59Z")

</div>

Hi @tihomir I am following the same approach but getting this error

```auto
2022/05/16 10:58:15 Unable to create client get system info failed: last connection error: connection error: desc = "transport: authentication handshake failed: x509: certificate has expired or is not yet valid: current time 2022-05-16T10:58:15Z is after 2022-05-16T08:53:54Z" - *serviceerror.Unavailable

```

certificate time stamps are as below

```auto
notBefore=May 16 08:52:44 2022 GMT
notAfter=May 17 08:53:14 2022 GMT

**current date in my machine is**
Mon 16 May 2022 11:02:22 AM UTC

```

same time tctl cli works fine

```auto
tctl n list
Name: abc                                                                                                                                                                                                     
Id: 2e386412-efd7-4634-b82a-7c6d1a362450                                                                                                                                                                           

```

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [May 16, 2022, 1:06pm UTC](https://community.temporal.io/t/help-how-to-create-a-client-with-tls/4287/6 "2022-05-16T13:06:55Z")

</div>

@sumesh_kanayi  
how/where are you deploying? check the system time on the container(s) the server is running on, maybe there is a diff.

---

<div class="post-metadata">

**Author:** ![sumesh\_kanayi](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/sumesh_kanayi/32/1876_2.png) [@sumesh\_kanayi](https://community.temporal.io/u/sumesh_kanayi)\
**Post date:** [May 16, 2022, 1:13pm UTC](https://community.temporal.io/t/help-how-to-create-a-client-with-tls/4287/7 "2022-05-16T13:13:51Z")

</div>

sure.I am checking in details . I am running temporal server in a clustered mode. All services (front end,history,matching etc) are running on different virtual machines with MTLS enabled. Using hashicorp vault PKI for certificate issuer. Primary investigation doesn’t show any time differences. I am trying to run the `go code above` on the same front end server. `tctl cli `was also tested successfully on the same machine. Funny part is that, the error message says `current date is after notBefore time stamp` which i thought is OK 🙂

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [May 16, 2022, 2:23pm UTC](https://community.temporal.io/t/help-how-to-create-a-client-with-tls/4287/8 "2022-05-16T14:23:04Z")

</div>

Do you have a load balancer setup? Could be some issue with not updated certs there? Think this issue has to do with cert management and maybe not Temporal itself. Let me know if you find something out.

---

<div class="post-metadata">

**Author:** ![sumesh\_kanayi](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/sumesh_kanayi/32/1876_2.png) [@sumesh\_kanayi](https://community.temporal.io/u/sumesh_kanayi)\
**Post date:** [May 20, 2022, 5:01am UTC](https://community.temporal.io/t/help-how-to-create-a-client-with-tls/4287/9 "2022-05-20T05:01:34Z")

</div>

You were right @tihomir . It was a problem with certificates in Worker service node. Worked fine after fixing it
