Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Commit a9d33a0

Browse files
jrcampcharless-splunk
authored andcommitted
add config options for tls ca and client auth (#137)
will require doc changes
1 parent 49acd13 commit a9d33a0

File tree

3 files changed

+69
-13
lines changed

3 files changed

+69
-13
lines changed

config/config.go

+18-5
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,15 @@ type userConfig struct {
5353
Skip string
5454
}
5555
Kubernetes *struct {
56-
IgnoreTLSVerify bool `yaml:"ignoreTLSVerify,omitempty"`
57-
Role string
58-
Cluster string
59-
CAdvisorURL string `yaml:"cadvisorURL,omitempty"`
56+
TLS struct {
57+
SkipVerify bool `yaml:"skipVerify"`
58+
ClientCert string `yaml:"clientCert"`
59+
ClientKey string `yaml:"clientKey"`
60+
CACert string `yaml:"caCert"`
61+
} `yaml:"tls"`
62+
Role string
63+
Cluster string
64+
CAdvisorURL string `yaml:"cadvisorURL,omitempty"`
6065
}
6166
Mesosphere *struct {
6267
Cluster string
@@ -125,7 +130,15 @@ func loadUserConfig(pair *store.KVPair) error {
125130
plugins["cadvisor"] = cadvisor
126131
}
127132
kubernetes := map[string]interface{}{}
128-
kubernetes["ignoretlsverify"] = kube.IgnoreTLSVerify
133+
134+
tls := kube.TLS
135+
tlsConfig := map[string]interface{}{
136+
"caCert": tls.CACert,
137+
"skipVerify": tls.SkipVerify,
138+
"clientCert": tls.ClientCert,
139+
"clientKey": tls.ClientKey,
140+
}
141+
kubernetes["tls"] = tlsConfig
129142
plugins["kubernetes"] = kubernetes
130143
}
131144
}

etc/kubernetes-defaults.yaml

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ pipeline: kubernetes
33
plugins:
44
kubernetes:
55
plugin: observers/kubernetes
6-
hostUrl: https://localhost:10250
7-
# Whether to ignore SSL certification validation errors.
8-
# ignoreTLSVerify: false
6+
# hostUrl: https://<hostname>:10250
7+
# tls:
8+
# # Whether to ignore SSL certification validation errors.
9+
# skipVerify: false
910

1011
integrations:
1112
overrides: /mnt/integrations

plugins/observers/kubernetes/kubernetes.go

+47-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"encoding/json"
1616

1717
"crypto/tls"
18+
"crypto/x509"
1819

1920
"github.com/signalfx/neo-agent/plugins"
2021
"github.com/signalfx/neo-agent/services"
@@ -94,20 +95,61 @@ func (k *Kubernetes) Configure(config *viper.Viper) error {
9495
}
9596

9697
func (k *Kubernetes) load() error {
97-
if hostname, err := os.Hostname(); err == nil {
98-
k.Config.SetDefault("hosturl", fmt.Sprintf("https://%s:%d", hostname, DefaultPort))
98+
hostname, err := os.Hostname()
99+
if err != nil {
100+
hostname = "localhost"
99101
}
102+
k.Config.SetDefault("hosturl", fmt.Sprintf("https://%s:%d", hostname, DefaultPort))
100103

101104
hostURL := k.Config.GetString("hosturl")
102105
if len(hostURL) == 0 {
103106
return errors.New("hostURL config value missing")
104107
}
105108
k.hostURL = hostURL
106109

110+
skipVerify := k.Config.GetBool("tls.skipverify")
111+
caCert := k.Config.GetString("tls.cacert")
112+
clientCert := k.Config.GetString("tls.clientcert")
113+
clientKey := k.Config.GetString("tls.clientkey")
114+
115+
certs, err := x509.SystemCertPool()
116+
if err != nil {
117+
return err
118+
}
119+
120+
if caCert != "" {
121+
bytes, err := ioutil.ReadFile(caCert)
122+
if err != nil {
123+
return fmt.Errorf("unable to read CA certificate: %s", err)
124+
}
125+
if !certs.AppendCertsFromPEM(bytes) {
126+
return fmt.Errorf("unable to add %s to certs", caCert)
127+
}
128+
log.Printf("configured TLS cert from %s", caCert)
129+
}
130+
131+
var clientCerts []tls.Certificate
132+
133+
if clientCert != "" && clientKey != "" {
134+
cert, err := tls.LoadX509KeyPair(clientCert, clientKey)
135+
if err != nil {
136+
return err
137+
}
138+
clientCerts = append(clientCerts, cert)
139+
log.Printf("configured TLS client cert %s with key %s", clientCert, clientKey)
140+
}
141+
142+
tlsConfig := &tls.Config{
143+
Certificates: clientCerts,
144+
InsecureSkipVerify: skipVerify,
145+
RootCAs: certs,
146+
}
147+
tlsConfig.BuildNameToCertificate()
148+
149+
log.Printf("configured InsecureSkipVerify=%t", skipVerify)
150+
107151
transport := &http.Transport{
108-
TLSClientConfig: &tls.Config{
109-
InsecureSkipVerify: k.Config.GetBool("ignoretlsverify"),
110-
},
152+
TLSClientConfig: tlsConfig,
111153
}
112154
k.client = http.Client{
113155
Timeout: 10 * time.Second,

0 commit comments

Comments
 (0)