Skip to content

Commit c45ad91

Browse files
authored
Add an option to tctl to override server name for TLS host verification (#889)
* Add an option to tctl to override server name for TLS host verification * Enable host verification if server name is provided
1 parent 9e3ed33 commit c45ad91

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

tools/cli/app.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ func NewCliApp() *cli.App {
8888
Usage: "validates hostname of temporal cluster against server certificate",
8989
EnvVar: "TEMPORAL_CLI_TLS_ENABLE_HOST_VERIFICATION",
9090
},
91+
cli.StringFlag{
92+
Name: FlagTLSServerName,
93+
Value: "",
94+
Usage: "override for target server name",
95+
EnvVar: "TEMPORAL_CLI_TLS_SERVER_NAME",
96+
},
9197
}
9298
app.Commands = []cli.Command{
9399
{

tools/cli/factory.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,14 @@ func (b *clientFactory) createGRPCConnection(c *cli.Context) (*grpc.ClientConn,
134134
}
135135

136136
func (b *clientFactory) createTLSConfig(c *cli.Context) (*tls.Config, error) {
137-
hostPort := c.GlobalString(FlagAddress)
138-
if hostPort == "" {
139-
hostPort = localHostPort
140-
}
141-
// Ignoring error as we'll fail to dial anyway, and that will produce a meaningful error
142-
host, _, _ := net.SplitHostPort(hostPort)
143137

144138
certPath := c.GlobalString(FlagTLSCertPath)
145139
keyPath := c.GlobalString(FlagTLSKeyPath)
146140
caPath := c.GlobalString(FlagTLSCaPath)
147141
hostNameVerification := c.GlobalBool(FlagTLSEnableHostVerification)
142+
serverName := c.GlobalString(FlagTLSServerName)
148143

144+
var host string
149145
var cert *tls.Certificate
150146
var caPool *x509.CertPool
151147

@@ -167,6 +163,19 @@ func (b *clientFactory) createTLSConfig(c *cli.Context) (*tls.Config, error) {
167163
}
168164
// If we are given arguments to verify either server or client, configure TLS
169165
if caPool != nil || cert != nil {
166+
if serverName != "" {
167+
host = serverName
168+
// If server name is provided, we enable host verification
169+
// because that's the only reason for providing server name
170+
hostNameVerification = true
171+
} else {
172+
hostPort := c.GlobalString(FlagAddress)
173+
if hostPort == "" {
174+
hostPort = localHostPort
175+
}
176+
// Ignoring error as we'll fail to dial anyway, and that will produce a meaningful error
177+
host, _, _ = net.SplitHostPort(hostPort)
178+
}
170179
tlsConfig := auth.NewTLSConfigForServer(host, hostNameVerification)
171180
if caPool != nil {
172181
tlsConfig.RootCAs = caPool

tools/cli/flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ const (
217217
FlagTLSKeyPath = "tls_key_path"
218218
FlagTLSCaPath = "tls_ca_path"
219219
FlagTLSEnableHostVerification = "tls_enable_host_verification"
220+
FlagTLSServerName = "tls_server_name"
220221
FlagDLQType = "dlq_type"
221222
FlagDLQTypeWithAlias = FlagDLQType + ", dt"
222223
FlagMaxMessageCount = "max_message_count"

0 commit comments

Comments
 (0)