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

feat: add support for custom TLS certificate #212

Merged
merged 1 commit into from
Dec 21, 2018
Merged
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
11 changes: 11 additions & 0 deletions cli/ingress-controller/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ The controller will set the endpoint records on the ingress using this address.`
kongURL = flags.String("kong-url", "http://localhost:8001",
"The address of the Kong Admin URL to connect to in the format of protocol://address:port")

kongTLSSkipVerify = flag.Bool("admin-tls-skip-verify", false,
"Disable verification of TLS certificate of Kong's Admin endpoint.")
kongTLSServerName = flag.String("admin-tls-server-name", "",
"SNI name to use to verify the certificate presented by Kong in TLS.")
kongCACert = flag.String("admin-ca-cert-file", "",
"Path to PEM-encoded CA certificate file to verify the Kong's Admin SSL certificate.")

kongHeaders headers
)

Expand Down Expand Up @@ -156,6 +163,10 @@ The controller will set the endpoint records on the ingress using this address.`
Kong: controller.Kong{
URL: *kongURL,
Headers: kongHeaders,

TLSServerName: *kongTLSServerName,
TLSSkipVerify: *kongTLSSkipVerify,
CACert: *kongCACert,
},
APIServerHost: *apiserverHost,
KubeConfigFile: *kubeConfigFile,
Expand Down
30 changes: 29 additions & 1 deletion cli/ingress-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ limitations under the License.
package main

import (
"crypto/tls"
"crypto/x509"
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
"net/http"
"net/http/pprof"
Expand Down Expand Up @@ -114,10 +117,35 @@ func main() {
conf.KubeClient = kubeClient
conf.KubeConf = kubeCfg

defaultTransport := http.DefaultTransport.(*http.Transport)

var tlsConfig tls.Config

if conf.Kong.TLSSkipVerify {
tlsConfig.InsecureSkipVerify = true
}

if conf.Kong.TLSServerName != "" {
tlsConfig.ServerName = conf.Kong.TLSServerName
}

if conf.Kong.CACert != "" {
certPool := x509.NewCertPool()
cert, err := ioutil.ReadFile(conf.Kong.CACert)
if err != nil {
glog.Fatalf("failed to read CACert: %s", conf.Kong.CACert)
}
ok := certPool.AppendCertsFromPEM([]byte(cert))
if !ok {
glog.Fatalf("failed to load CACert: %s", conf.Kong.CACert)
}
tlsConfig.RootCAs = certPool
}
defaultTransport.TLSClientConfig = &tlsConfig
c := http.DefaultClient
c.Transport = &HeaderRoundTripper{
headers: conf.Kong.Headers,
rt: http.DefaultTransport,
rt: defaultTransport,
}

kongClient, err := kong.NewClient(kong.String(conf.Kong.URL), c)
Expand Down
8 changes: 7 additions & 1 deletion internal/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@ const (
)

type Kong struct {
URL string
URL string
// Headers are injected into every request to Kong's Admin API
// to help with authorization/authentication.
Headers []string
Client *kong.Client

TLSSkipVerify bool
TLSServerName string
CACert string
}

// Configuration contains all the settings required by an Ingress controller
Expand Down