Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for a TLS-enabled Docker daemon #910

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions plugins/inputs/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ for the stat structure can be found
# To use TCP, set endpoint = "tcp://[ip]:[port]"
# To use environment variables (ie, docker-machine), set endpoint = "ENV"
endpoint = "unix:///var/run/docker.sock"
# To collect metrics from a TLS-enabled daemon
# tls_enabled = true
# tls_ca = "~/certificates_path/ca.pem"
# tls_cert = "~/certificates_path/cert.pem"
# tls_key = "~/certificates_path/key.pem"
# Only collect metrics for these containers, collect all if empty
container_names = []
```
Expand Down
34 changes: 33 additions & 1 deletion plugins/inputs/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package system

import (
"encoding/json"
"errors"
"fmt"
"log"
"regexp"
Expand All @@ -20,6 +21,15 @@ type Docker struct {
Endpoint string
ContainerNames []string

// Enables TLS
TLSEnabled bool `toml:"tls_enabled"`
// Path to CA file
TLSCA string `toml:"tls_ca"`
// Path to cert file
TLSCert string `toml:"tls_cert"`
// Path to cert key file
TLSKey string `toml:"tls_key"`

client DockerClient
}

Expand Down Expand Up @@ -48,6 +58,11 @@ var sampleConfig = `
## To use TCP, set endpoint = "tcp://[ip]:[port]"
## To use environment variables (ie, docker-machine), set endpoint = "ENV"
endpoint = "unix:///var/run/docker.sock"
## To collect metrics from a TLS-enabled daemon
# tls_enabled = true
# tls_ca = "~/certificates_path/ca.pem"
# tls_cert = "~/certificates_path/cert.pem"
# tls_key = "~/certificates_path/key.pem"
## Only collect metrics for these containers, collect all if empty
container_names = []
`
Expand All @@ -73,7 +88,24 @@ func (d *Docker) Gather(acc telegraf.Accumulator) error {
return err
}
} else {
c, err = docker.NewClient(d.Endpoint)
if !d.TLSEnabled {
c, err = docker.NewClient(d.Endpoint)
} else {
if d.TLSCert == "" {
return errors.New("tls_cert must be configured when tls_enable is set to true")
}

if d.TLSKey == "" {
return errors.New("tls_key must be configured when tls_enable is set to true")
}

if d.TLSCA == "" {
return errors.New("tls_ca must be configured when tls_enable is set to true")
}

c, err = docker.NewTLSClient(d.Endpoint, d.TLSCert, d.TLSKey, d.TLSCA)
}

if err != nil {
return err
}
Expand Down