Skip to content

feat(auth api): Allow to pass a path with the Root/Intermediate CA used for the apiserver #10012

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions docs/common/arguments.md
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ Dashboard containers accept multiple arguments that can be used to customize the
| bind-address | 0.0.0.0 | The IP address on which to serve the `--port` (set to 0.0.0.0 for all interfaces). |
| token-exchange-endpoint | - | Endpoint used when `--cluster-context-enabled=true` to exchange auth token for the unique context identifier. |
| default-cert-dir | /certs | Directory path containing `--tls-cert-file` and `--tls-key-file` files. Used also when auto-generating certificates flag is set. Relative to the container, not the host. |
| apiserver-ca-bundle | - | File containing the x509 certificates used for HTTPS connection to the API Server. Relative to the container, not the host. |
| tls-cert-file | - | File containing the default x509 Certificate for HTTPS. |
| tls-key-file | - | File containing the default x509 private key matching --tls-cert-file. |
| apiserver-host | - | The address of the Kubernetes Apiserver to connect to in the format of protocol://address:port, e.g., http://localhost:8080. If not specified, the assumption is that the binary runs inside a Kubernetes cluster and local discovery is attempted. |
@@ -41,6 +42,7 @@ Dashboard containers accept multiple arguments that can be used to customize the
| Argument name | Default value | Description |
|---------------------------|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| apiserver-skip-tls-verify | false | Enable if connection with remote Kubernetes API should skip TLS verify. |
| apiserver-ca-bundle | - | File containing the x509 certificates used for HTTPS connection to the API Server. Relative to the container, not the host. |
| port | 8000 | The secure port to listen to for incoming HTTPS requests. |
| address | 0.0.0.0 | The IP address on which to serve the `--port` (set to 0.0.0.0 for all interfaces). |
| kubeconfig | - | Path to `kubeconfig` file. |
1 change: 1 addition & 0 deletions modules/api/main.go
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@ func main() {
client.WithKubeconfig(args.KubeconfigPath()),
client.WithMasterUrl(args.ApiServerHost()),
client.WithInsecureTLSSkipVerify(args.ApiServerSkipTLSVerify()),
client.WithCaBundle(args.ApiServerCaBundle()),
)

if !args.IsProxyEnabled() {
5 changes: 5 additions & 0 deletions modules/api/pkg/args/args.go
Original file line number Diff line number Diff line change
@@ -66,6 +66,7 @@ var (
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")

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")
argApiServerCaBundle = pflag.String("apiserver-ca-bundle", "", "file containing the x509 certificates used for HTTPS connection to the API Server")
argCertFile = pflag.String("tls-cert-file", "", "file containing the default x509 certificate for HTTPS")
argKeyFile = pflag.String("tls-key-file", "", "file containing the default x509 private key matching --tls-cert-file")
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 {
return *argDefaultCertDir
}

func ApiServerCaBundle() string {
return *argApiServerCaBundle
}

func CertFile() string {
return *argCertFile
}
1 change: 1 addition & 0 deletions modules/auth/main.go
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ func main() {
client.WithKubeconfig(args.KubeconfigPath()),
client.WithMasterUrl(args.ApiServerHost()),
client.WithInsecureTLSSkipVerify(args.ApiServerSkipTLSVerify()),
client.WithCaBundle(args.ApiServerCaBundle()),
)

klog.V(1).InfoS("Listening and serving insecurely on", "address", args.Address())
5 changes: 5 additions & 0 deletions modules/auth/pkg/args/args.go
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ var (
argKubeconfig = pflag.String("kubeconfig", "", "path to kubeconfig file")
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")
argApiServerSkipTLSVerify = pflag.Bool("apiserver-skip-tls-verify", false, "enable if connection with remote Kubernetes API server should skip TLS verify")
argApiServerCaBundle = pflag.String("apiserver-ca-bundle", "", "file containing the x509 certificates used for HTTPS connection to the API Server")
)

func init() {
@@ -59,6 +60,10 @@ func ApiServerSkipTLSVerify() bool {
return *argApiServerSkipTLSVerify
}

func ApiServerCaBundle() string {
return *argApiServerCaBundle
}

func Address() string {
return fmt.Sprintf("%s:%d", *argAddress, *argPort)
}
13 changes: 13 additions & 0 deletions modules/common/client/init.go
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@ type configBuilder struct {
kubeconfigPath string
masterUrl string
insecure bool
caBundlePath string
}

func (in *configBuilder) buildBaseConfig() (config *rest.Config, err error) {
@@ -59,6 +60,12 @@ func (in *configBuilder) buildBaseConfig() (config *rest.Config, err error) {
}

config, err = clientcmd.BuildConfigFromFlags(in.masterUrl, in.kubeconfigPath)

if len(in.caBundlePath) > 0 {
klog.InfoS("Using custom CA Bundle", "caBundle", in.caBundlePath)
config.TLSClientConfig.CAFile = in.caBundlePath
}

if err != nil {
return nil, err
}
@@ -123,6 +130,12 @@ func WithInsecureTLSSkipVerify(insecure bool) Option {
}
}

func WithCaBundle(caBundlePath string) Option {
return func(c *configBuilder) {
c.caBundlePath = caBundlePath
}
}

func configFromRequest(request *http.Request) (*rest.Config, error) {
authInfo, err := buildAuthInfo(request)
if err != nil {