diff --git a/README.md b/README.md index 0af77059..2802e788 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,18 @@ Memorising docker commands is hard. Memorising aliases is slightly less hard. Ke - Docker >= **1.13** (API >= **1.25**) - Docker-Compose >= **1.23.2** (optional) +## TLS Configuration + +Lazydocker supports secure connections to Docker daemon using TLS. To enable TLS, you can configure it in your config.yml: + +```yaml +tls: + enable: true + caCertPath: "/path/to/ca.pem" + certPath: "/path/to/cert.pem" + keyPath: "/path/to/key.pem" +``` + ## Installation ### Homebrew diff --git a/pkg/commands/docker.go b/pkg/commands/docker.go index 28c12c23..d99143ca 100644 --- a/pkg/commands/docker.go +++ b/pkg/commands/docker.go @@ -97,7 +97,22 @@ func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Translat dockerHost = dockerHostFromEnv } - cli, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion(APIVersion), client.WithHost(dockerHost)) + opts := []client.Opt{ + client.FromEnv, + client.WithVersion(APIVersion), + client.WithHost(dockerHost), + } + + if config.UserConfig.TLS.Enable { + tlsOpts := client.WithTLSClientConfig( + config.UserConfig.TLS.CACertPath, + config.UserConfig.TLS.CertPath, + config.UserConfig.TLS.KeyPath, + ) + opts = append(opts, tlsOpts) + } + + cli, err := client.NewClientWithOpts(opts...) if err != nil { ogLog.Fatal(err) } diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 9c0ad474..b0754116 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -32,6 +32,9 @@ type UserConfig struct { // hit esc or q when no confirmation panels are open ConfirmOnQuit bool `yaml:"confirmOnQuit,omitempty"` + // TLS configuration for connecting to Docker daemon + TLS TLSConfig `yaml:"tls,omitempty"` + // Logs determines how we render/filter a container's logs Logs LogsConfig `yaml:"logs,omitempty"` @@ -346,6 +349,14 @@ type LogsConfig struct { Tail string `yaml:"tail,omitempty"` } +// TLSConfig holds TLS configuration for connecting to Docker daemon +type TLSConfig struct { + Enable bool `yaml:"enable,omitempty"` + CACertPath string `yaml:"caCertPath,omitempty"` + CertPath string `yaml:"certPath,omitempty"` + KeyPath string `yaml:"keyPath,omitempty"` +} + // GetDefaultConfig returns the application default configuration NOTE (to // contributors, not users): do not default a boolean to true, because false is // the boolean zero value and this will be ignored when parsing the user's @@ -474,6 +485,12 @@ func GetDefaultConfig() UserConfig { Replacements: Replacements{ ImageNamePrefixes: map[string]string{}, }, + TLS: TLSConfig{ + Enable: false, + CACertPath: "", + CertPath: "", + KeyPath: "", + }, } }