Skip to content

Commit 13fa934

Browse files
committed
docs: mTLS documentation with example sample
Signed-off-by: [email protected] <[email protected]>
1 parent 1b55f32 commit 13fa934

File tree

1 file changed

+122
-5
lines changed

1 file changed

+122
-5
lines changed

docs/03-concepts/14-mutual-tls.md

Lines changed: 122 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,131 @@ The mTLS handshake process involves the following steps:
7575

7676
---
7777

78+
## Implementing mTLS in Cadence
79+
80+
### Server Configuration
81+
82+
To enable mTLS in Cadence server, you need to configure TLS settings and start the server with the appropriate environment configuration.
83+
84+
#### Starting the Server with TLS
85+
86+
Use the `--zone` flag to specify the TLS configuration when starting the Cadence server:
87+
88+
```bash
89+
./cadence-server --env development --zone tls start
90+
```
91+
92+
**Command breakdown:**
93+
- `--env development`: Specifies the environment configuration to use (corresponds to `config/development.yaml`)
94+
- `--zone tls`: Specifies the zone configuration to use (corresponds to the `tls` zone in `development_tls.yaml`)
95+
- `start`: Starts all Cadence services
96+
97+
The `--zone tls` flag tells the server to load additional configuration from the zone-specific file. In this case, it will look for `config/development_tls.yaml` which contains the TLS-specific settings.
98+
99+
#### TLS Configuration File
100+
101+
The server uses a YAML configuration file to define TLS settings. Here's an example from [`development_tls.yaml`](https://github.com/cadence-workflow/cadence/blob/master/config/development_tls.yaml):
102+
103+
```bash
104+
services:
105+
frontend:
106+
rpc:
107+
tls:
108+
enabled: true
109+
certFile: config/credentials/keytest.crt
110+
keyFile: config/credentials/keytest
111+
caFiles:
112+
- config/credentials/client.crt
113+
requireClientAuth: true
114+
115+
matching:
116+
rpc:
117+
tls:
118+
enabled: true
119+
certFile: config/credentials/keytest.crt
120+
keyFile: config/credentials/keytest
121+
122+
history:
123+
rpc:
124+
tls:
125+
enabled: true
126+
certFile: config/credentials/keytest.crt
127+
keyFile: config/credentials/keytest
128+
129+
clusterGroupMetadata:
130+
clusterGroup:
131+
cluster0:
132+
tls:
133+
enabled: true
134+
135+
```
136+
---
137+
138+
### Client Implementation
139+
140+
To connect a Cadence client with mTLS, you need to configure TLS credentials and pass them to the Cadence client. Here's the essential code from the [helloworld_tls sample](https://github.com/cadence-workflow/cadence-samples/blob/master/new_samples/client_samples/helloworld_tls/hello_world_tls.go):
141+
142+
#### Setting up TLS Client Connection
143+
144+
```go
145+
import (
146+
"crypto/tls"
147+
"crypto/x509"
148+
"os"
149+
150+
"go.uber.org/cadence/client"
151+
"google.golang.org/grpc"
152+
"google.golang.org/grpc/credentials"
153+
)
154+
155+
func createCadenceClient() (client.Client, error) {
156+
// Load client certificate and key
157+
clientCert, err := tls.LoadX509KeyPair("credentials/client.crt", "credentials/client.key")
158+
if err != nil {
159+
return nil, err
160+
}
161+
162+
// Load CA certificate to verify server
163+
caCert, err := os.ReadFile("credentials/keytest.crt")
164+
if err != nil {
165+
return nil, err
166+
}
167+
168+
caCertPool := x509.NewCertPool()
169+
caCertPool.AppendCertsFromPEM(caCert)
170+
171+
// Configure TLS
172+
tlsConfig := &tls.Config{
173+
Certificates: []tls.Certificate{clientCert},
174+
RootCAs: caCertPool,
175+
ServerName: "cadence-frontend", // Must match server certificate CN
176+
}
177+
178+
// Create Cadence client with TLS
179+
return client.NewClient(client.Options{
180+
HostPort: "127.0.0.1:7833", // gRPC port
181+
Domain: "samples-domain",
182+
Transport: &client.TransportConfiguration{
183+
GRPCDialOptions: []grpc.DialOption{
184+
grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig)),
185+
},
186+
},
187+
})
188+
}
189+
```
190+
191+
---
192+
78193
## Complete Working Example
79194

80-
For a complete working example with detailed code and configuration, refer to the [helloworld_tls sample](https://github.com/cadence-workflow/cadence-samples/tree/master/new_samples/client_samples/helloworld_tls) in the Cadence samples repository. This sample demonstrates how to:
195+
The [helloworld_tls sample](https://github.com/cadence-workflow/cadence-samples/tree/master/new_samples/client_samples/helloworld_tls) provides a complete, tested implementation of mTLS with Cadence, including:
196+
197+
- Certificate generation scripts
198+
- Complete client implementation with mTLS
199+
- Instructions for running with a TLS-enabled server
200+
- Step-by-step setup guide
81201

82-
- Generate test certificates using OpenSSL
83-
- Configure both server and client for mTLS
84-
- Implement a simple workflow with mTLS authentication
85-
- Test the mTLS connection
202+
For additional server configuration examples, refer to the [Cadence server repository](https://github.com/cadence-workflow/cadence)
86203

87204
---
88205

0 commit comments

Comments
 (0)