/
oauth_apiserver_adapter.go
73 lines (63 loc) · 3.01 KB
/
oauth_apiserver_adapter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package origin
import (
"net"
"strconv"
apiserveroptions "k8s.io/apiserver/pkg/server/options"
utilflag "k8s.io/apiserver/pkg/util/flag"
configapi "github.com/openshift/origin/pkg/cmd/server/api"
"github.com/openshift/origin/pkg/cmd/server/crypto"
oauthapiserver "github.com/openshift/origin/pkg/oauth/apiserver"
routeclient "github.com/openshift/origin/pkg/route/generated/internalclientset"
)
// TODO this is taking a very large config for a small piece of it. The information must be broken up at some point so that
// we can run this in a pod. This is an indication of leaky abstraction because it spent too much time in openshift start
func NewOAuthServerConfigFromMasterConfig(masterConfig *MasterConfig) (*oauthapiserver.OAuthServerConfig, error) {
options := masterConfig.Options
servingConfig := options.ServingInfo
oauthConfig := masterConfig.Options.OAuthConfig
oauthServerConfig, err := oauthapiserver.NewOAuthServerConfig(*oauthConfig, &masterConfig.PrivilegedLoopbackClientConfig)
if err != nil {
return nil, err
}
oauthServerConfig.GenericConfig.CorsAllowedOriginList = options.CORSAllowedOrigins
// TODO pull this out into a function
_, portString, err := net.SplitHostPort(servingConfig.BindAddress)
if err != nil {
return nil, err
}
port, err := strconv.Atoi(portString)
if err != nil {
return nil, err
}
secureServingOptions := apiserveroptions.SecureServingOptions{}
secureServingOptions.BindPort = port
secureServingOptions.ServerCert.CertKey.CertFile = servingConfig.ServerCert.CertFile
secureServingOptions.ServerCert.CertKey.KeyFile = servingConfig.ServerCert.KeyFile
for _, nc := range servingConfig.NamedCertificates {
sniCert := utilflag.NamedCertKey{
CertFile: nc.CertFile,
KeyFile: nc.KeyFile,
Names: nc.Names,
}
secureServingOptions.SNICertKeys = append(secureServingOptions.SNICertKeys, sniCert)
}
if err := secureServingOptions.ApplyTo(oauthServerConfig.GenericConfig); err != nil {
return nil, err
}
oauthServerConfig.GenericConfig.SecureServingInfo.BindAddress = servingConfig.BindAddress
oauthServerConfig.GenericConfig.SecureServingInfo.BindNetwork = servingConfig.BindNetwork
oauthServerConfig.GenericConfig.SecureServingInfo.MinTLSVersion = crypto.TLSVersionOrDie(servingConfig.MinTLSVersion)
oauthServerConfig.GenericConfig.SecureServingInfo.CipherSuites = crypto.CipherSuitesOrDie(servingConfig.CipherSuites)
routeClient, err := routeclient.NewForConfig(&masterConfig.PrivilegedLoopbackClientConfig)
if err != nil {
return nil, err
}
// TODO pass a privileged client config through during construction. It is NOT a loopback client.
oauthServerConfig.RouteClient = routeClient
oauthServerConfig.KubeClient = masterConfig.PrivilegedLoopbackKubernetesClientsetInternal
// Build the list of valid redirect_uri prefixes for a login using the openshift-web-console client to redirect to
if !options.DisabledFeatures.Has(configapi.FeatureWebConsole) {
oauthServerConfig.AssetPublicAddresses = []string{oauthConfig.AssetPublicURL}
}
return oauthServerConfig, nil
}