Skip to content

Commit

Permalink
Enable extended apiserver support (#122)
Browse files Browse the repository at this point in the history
* Enable extended apiserver support

Signed-off-by: Tamal Saha <tamal@appscode.com>

* Add aggregator config to ocm config

Signed-off-by: Tamal Saha <tamal@appscode.com>

---------

Signed-off-by: Tamal Saha <tamal@appscode.com>
  • Loading branch information
tamalsaha authored Oct 23, 2023
1 parent 03f5145 commit 82ba943
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 9 deletions.
4 changes: 2 additions & 2 deletions charts/multicluster-controlplane/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ spec:
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 15
volumeMounts:
volumeMounts:
- name: controlplane-config
mountPath: /controlplane_config
- name: ocm-data
mountPath: /.ocm
volumes:
volumes:
- name: controlplane-config
secret:
secretName: controlplane-config
Expand Down
17 changes: 17 additions & 0 deletions charts/multicluster-controlplane/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
{{ $caKey = $ca.Key }}
{{- end }}

{{- $proxyCA := genCA "proxy-ca" 3650 }}
{{- $proxyClient := genSignedCert "front-proxy-client" nil nil 3650 $proxyCA }}

apiVersion: v1
kind: Secret
metadata:
Expand Down Expand Up @@ -42,11 +45,25 @@ stringData:
certFile: "/controlplane_config/etcd_cert.crt"
keyFile: "/controlplane_config/etcd_cert.key"
{{- end }}
aggregator:
proxyClientCertFile: /controlplane_config/proxy-client.crt
proxyClientKeyFile: /controlplane_config/proxy-client.key
requestheaderClientCAFile: /controlplane_config/requestheader-client-ca.crt
requestheaderUsernameHeaders: ["X-Remote-User"]
requestheaderGroupHeaders: ["X-Remote-Group"]
requestheaderExtraHeadersPrefix: ["X-Remote-Extra-"]
requestheaderAllowedNames: ["front-proxy-client"]
{{- if $caCrt }}
apiserver_ca.crt: {{ $caCrt | quote }}
apiserver_ca.key: {{ $caKey | quote }}
{{- end }}

requestheader-client-ca.crt: {{ $proxyCA.Cert | quote }}
requestheader-client-ca.key: {{ $proxyCA.Key | quote }}
proxy-client.crt: {{ $proxyClient.Cert | quote }}
proxy-client.key: {{ $proxyClient.Key | quote }}

{{- if (eq .Values.etcd.mode "external") }}
etcd_ca.crt: {{ (required "etcd.ca should be set together with etcd.mode" .Values.etcd.ca) | quote }}
etcd_cert.crt: {{ (required "etcd.cert should be set together with etcd.mode" .Values.etcd.cert) | quote }}
Expand Down
6 changes: 4 additions & 2 deletions pkg/servers/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ func createAggregatorConfig(
SharedInformerFactory: externalInformers,
},
ExtraConfig: aggregatorapiserver.ExtraConfig{
ServiceResolver: serviceResolver,
ProxyTransport: proxyTransport,
ProxyClientCertFile: genericOptions.ProxyClientCertFile,
ProxyClientKeyFile: genericOptions.ProxyClientKeyFile,
ServiceResolver: serviceResolver,
ProxyTransport: proxyTransport,
},
}

Expand Down
17 changes: 14 additions & 3 deletions pkg/servers/configs/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ const (
)

type ControlplaneRunConfig struct {
DataDirectory string `yaml:"dataDirectory"`
Apiserver ApiserverConfig `yaml:"apiserver"`
Etcd EtcdConfig `yaml:"etcd"`
DataDirectory string `yaml:"dataDirectory"`
Apiserver ApiserverConfig `yaml:"apiserver"`
Etcd EtcdConfig `yaml:"etcd"`
Aggregator AggregatorConfig `yaml:"aggregator"`
}

type ApiserverConfig struct {
Expand All @@ -43,6 +44,16 @@ type EtcdConfig struct {
Prefix string `yaml:"prefix"`
}

type AggregatorConfig struct {
ProxyClientCertFile string `yaml:"proxyClientCertFile"`
ProxyClientKeyFile string `yaml:"proxyClientKeyFile"`
RequestHeaderClientCAFile string `yaml:"requestheaderClientCAFile"`
RequestHeaderUsernameHeaders []string `yaml:"requestheaderUsernameHeaders"`
RequestHeaderGroupHeaders []string `yaml:"requestheaderGroupHeaders"`
RequestHeaderExtraHeaderPrefixes []string `yaml:"requestheaderExtraHeadersPrefix"`
RequestHeaderAllowedNames []string `yaml:"requestheaderAllowedNames"`
}

func LoadConfig(configDir string) (*ControlplaneRunConfig, error) {
configFile := path.Join(configDir, "ocmconfig.yaml")
configFileData, err := os.ReadFile(configFile)
Expand Down
3 changes: 3 additions & 0 deletions pkg/servers/kubeapiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ func createKubeAPIServerConfig(options options.ServerRunOptions) (
APIServerServiceIP: options.APIServerServiceIP,
APIServerServicePort: 443,

ServiceIPRange: options.PrimaryServiceClusterIPRange,
SecondaryServiceIPRange: options.SecondaryServiceClusterIPRange,

EndpointReconcilerType: reconcilers.Type(options.EndpointReconcilerType),
MasterCount: 1,

Expand Down
18 changes: 16 additions & 2 deletions pkg/servers/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import (
"errors"
"fmt"
"net"
registrationhub "open-cluster-management.io/ocm/pkg/registration/hub"
"os"
"strconv"
"strings"
"time"

"github.com/spf13/pflag"
registrationhub "open-cluster-management.io/ocm/pkg/registration/hub"

// add the kubernetes feature gates
_ "k8s.io/kubernetes/pkg/features"
Expand Down Expand Up @@ -117,6 +117,9 @@ type ServerRunOptions struct {

// EnableDelegatingAuthentication delegate the authentication with controlplane hosing cluster
EnableDelegatingAuthentication bool

ProxyClientCertFile string
ProxyClientKeyFile string
}

type ExtraOptions struct {
Expand Down Expand Up @@ -231,7 +234,8 @@ func NewServerRunOptions() *ServerRunOptions {

KubeControllerManagerOptions: kubeControllerManagerOptions,

ServiceClusterIPRanges: "10.0.0.0/24",
ServiceClusterIPRanges: "10.0.0.0/8",
EnableAggregatorRouting: false,

ControlplaneConfigDir: "/controlplane_config",

Expand Down Expand Up @@ -479,6 +483,16 @@ func (o *ServerRunOptions) InitServerRunOptions(cfg *configs.ControlplaneRunConf
o.Etcd.StorageConfig.Prefix = cfg.Etcd.Prefix
}

o.ProxyClientCertFile = cfg.Aggregator.ProxyClientCertFile
o.ProxyClientKeyFile = cfg.Aggregator.ProxyClientKeyFile
if o.Authentication.RequestHeader != nil {
o.Authentication.RequestHeader.ClientCAFile = cfg.Aggregator.RequestHeaderClientCAFile
o.Authentication.RequestHeader.UsernameHeaders = cfg.Aggregator.RequestHeaderUsernameHeaders
o.Authentication.RequestHeader.GroupHeaders = cfg.Aggregator.RequestHeaderGroupHeaders
o.Authentication.RequestHeader.ExtraHeaderPrefixes = cfg.Aggregator.RequestHeaderExtraHeaderPrefixes
o.Authentication.RequestHeader.AllowedNames = cfg.Aggregator.RequestHeaderAllowedNames
}

o.SecureServing.BindPort = bindPort
o.Authentication.ClientCert.ClientCA = certificate.ClientCACertFile(certsDir)
o.ExtraOptions.ClientKeyFile = certificate.ClientCAKeyFile(certsDir)
Expand Down

0 comments on commit 82ba943

Please sign in to comment.