Skip to content

Commit 8f818e4

Browse files
committed
Add argument to Dashboard API to allow for a custom CA bundle
1 parent abba0ef commit 8f818e4

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

modules/api/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func main() {
4444
client.WithKubeconfig(args.KubeconfigPath()),
4545
client.WithMasterUrl(args.ApiServerHost()),
4646
client.WithInsecureTLSSkipVerify(args.ApiServerSkipTLSVerify()),
47+
client.WithCaBundle(args.ApiServerCaBundle()),
4748
)
4849

4950
if !args.IsProxyEnabled() {

modules/api/pkg/args/args.go

+5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ var (
6666
argBindAddress = pflag.IP("bind-address", net.IPv4(0, 0, 0, 0), "IP address on which to serve the --port, set to 0.0.0.0 for all interfaces")
6767

6868
argDefaultCertDir = pflag.String("default-cert-dir", "/certs", "directory path containing files from --tls-cert-file and --tls-key-file, used also when auto-generating certificates flag is set")
69+
argApiServerCaBundle = pflag.String("apiserver-ca-bundle", "", "file containing the x509 certificates used for HTTPS connection to the API Server")
6970
argCertFile = pflag.String("tls-cert-file", "", "file containing the default x509 certificate for HTTPS")
7071
argKeyFile = pflag.String("tls-key-file", "", "file containing the default x509 private key matching --tls-cert-file")
7172
argApiServerHost = pflag.String("apiserver-host", "", "address of the Kubernetes API server to connect to in the format of protocol://address:port, leave it empty if the binary runs inside cluster for local discovery attempt")
@@ -112,6 +113,10 @@ func DefaultCertDir() string {
112113
return *argDefaultCertDir
113114
}
114115

116+
func ApiServerCaBundle() string {
117+
return *argApiServerCaBundle
118+
}
119+
115120
func CertFile() string {
116121
return *argCertFile
117122
}

modules/common/client/init.go

+12
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type configBuilder struct {
4141
kubeconfigPath string
4242
masterUrl string
4343
insecure bool
44+
caBundlePath string
4445
}
4546

4647
func (in *configBuilder) buildBaseConfig() (config *rest.Config, err error) {
@@ -58,6 +59,11 @@ func (in *configBuilder) buildBaseConfig() (config *rest.Config, err error) {
5859
klog.InfoS("Using apiserver-host location", "masterUrl", in.masterUrl)
5960
}
6061

62+
if len(in.caBundlePath) > 0 {
63+
klog.InfoS("Using custom CA Bundle", "caBundle", in.caBundlePath)
64+
config.TLSClientConfig.CertificateAuthority = in.caBundlePath
65+
}
66+
6167
config, err = clientcmd.BuildConfigFromFlags(in.masterUrl, in.kubeconfigPath)
6268
if err != nil {
6369
return nil, err
@@ -123,6 +129,12 @@ func WithInsecureTLSSkipVerify(insecure bool) Option {
123129
}
124130
}
125131

132+
func WithCaBundle(caBundlePath string) Option {
133+
return func(c *configBuilder) {
134+
c.caBundlePath = caBundlePath
135+
}
136+
}
137+
126138
func configFromRequest(request *http.Request) (*rest.Config, error) {
127139
authInfo, err := buildAuthInfo(request)
128140
if err != nil {

0 commit comments

Comments
 (0)