Skip to content

Commit

Permalink
Add TLS client config option to disable it (linkerd#1856)
Browse files Browse the repository at this point in the history
TLS is enabled if the TLS param is set at all.  In the case of a per-client config, this means that if any matching config for a client enables TLS, it is impossible for a later client config to override this with a value that disables TLS.

We add an `enabled` property to the TLS client config which defaults to true, but can be set to false to disable client TLS.

Example config excerpt:

```
  client:
    kind: io.l5d.static
    configs:
    # enables TLS for all "inet" clients
    - prefix: "/$/inet/{service}"
      tls:
        commonName: "{service}"
    # override the above to disable TLS for localhost
    - prefix: /$/inet/localhost
      tls:
        enabled: false
```

Fixes linkerd#1845 

Signed-off-by: Alex Leong <[email protected]>
  • Loading branch information
adleong authored Mar 26, 2018
1 parent c1c1e29 commit 019608d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@ import java.io._
import scala.util.control.NoStackTrace

case class TlsClientConfig(
enabled: Option[Boolean],
disableValidation: Option[Boolean],
commonName: Option[String],
trustCerts: Option[Seq[String]] = None,
clientAuth: Option[ClientAuth] = None
) {
def params: Stack.Params = this match {
case TlsClientConfig(Some(true), _, _, clientAuth) =>
case TlsClientConfig(Some(false), _, _, _, _) =>
Stack.Params.empty + Transport.ClientSsl(None)
case TlsClientConfig(_, Some(true), _, _, clientAuth) =>
val tlsConfig = SslClientConfiguration(
trustCredentials = TrustCredentials.Insecure,
keyCredentials = keyCredentials(clientAuth)
)
Stack.Params.empty + Transport.ClientSsl(Some(tlsConfig)) +
SslClientEngineFactory.Param(Netty4ClientEngineFactory())

case TlsClientConfig(_, Some(cn), certs, clientAuth) =>
case TlsClientConfig(_, _, Some(cn), certs, clientAuth) =>
// map over the optional certs parameter - we want to pass
// `TrustCredentials.CertCollection` if we were given a list of certs,
// but `TrustCredentials.Unspecified` (rather than an empty cert
Expand Down Expand Up @@ -60,7 +63,7 @@ case class TlsClientConfig(
Stack.Params.empty + Transport.ClientSsl(Some(tlsConfig)) +
SslClientEngineFactory.Param(Netty4ClientEngineFactory())

case TlsClientConfig(Some(false) | None, None, _, _) =>
case TlsClientConfig(_, Some(false) | None, None, _, _) =>
val msg = "tls is configured with validation but `commonName` is not set"
throw new IllegalArgumentException(msg) with NoStackTrace
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ case class Retry(
case class ClientTlsConfig(commonName: String, caCert: Option[String]) {
def params: Stack.Params = {
TlsClientConfig(
enabled = Some(true),
disableValidation = Some(false),
commonName = Some(commonName),
trustCerts = caCert.map(Seq(_)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ trait ClientConfig {
}

case class TlsClientConfig(
enabled: Option[Boolean],
disableValidation: Option[Boolean],
commonName: Option[String],
trustCerts: Option[Seq[String]] = None,
Expand All @@ -47,6 +48,7 @@ case class TlsClientConfig(
)
def params(vars: Map[String, String]): Stack.Params =
FTlsClientConfig(
enabled,
disableValidation,
commonName.map(PathMatcher.substitute(vars, _)),
trustCerts,
Expand Down
1 change: 1 addition & 0 deletions linkerd/docs/client_tls.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ the server.
Key | Default Value | Description
--- | ------------- | -----------
enabled | true | Enable TLS on outgoing connections.
certPath | _required_ | File path to the TLS certificate file.
keyPath | _required_ | File path to the TLS key file.
requireClientAuth | false | If true, only accept requests with valid client certificates.
Expand Down
20 changes: 20 additions & 0 deletions linkerd/examples/disable-tls.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namers: []

routers:
- protocol: http
dtab: |
/svc/foo => /$/inet/www.google.com/443 ;
/svc/bar => /$/inet/localhost/7777
servers:
- port: 4140

client:
kind: io.l5d.static
configs:
- prefix: "/$/inet/{service}"
tls:
commonName: "{service}"
- prefix: /$/inet/localhost
tls:
enabled: false

0 comments on commit 019608d

Please sign in to comment.