forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoauth_apiserver_adapter.go
71 lines (61 loc) · 2.94 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
package origin
import (
"net"
"strconv"
apiserveroptions "k8s.io/apiserver/pkg/server/options"
utilflag "k8s.io/apiserver/pkg/util/flag"
routeclient "github.com/openshift/client-go/route/clientset/versioned/typed/route/v1"
"github.com/openshift/library-go/pkg/crypto"
"github.com/openshift/origin/pkg/oauthserver/oauthserver"
)
// 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, listener net.Listener) (*oauthserver.OAuthServerConfig, error) {
options := masterConfig.Options
servingConfig := options.ServingInfo
oauthConfig := masterConfig.Options.OAuthConfig
oauthServerConfig, err := oauthserver.NewOAuthServerConfig(*oauthConfig, &masterConfig.PrivilegedLoopbackClientConfig)
if err != nil {
return nil, err
}
oauthServerConfig.GenericConfig.CorsAllowedOriginList = options.CORSAllowedOrigins
// TODO pull this out into a function
host, 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.Listener = listener
secureServingOptions.BindAddress = net.ParseIP(host)
secureServingOptions.BindNetwork = servingConfig.BindNetwork
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.Config.SecureServing); err != nil {
return nil, err
}
oauthServerConfig.GenericConfig.SecureServing.MinTLSVersion = crypto.TLSVersionOrDie(servingConfig.MinTLSVersion)
oauthServerConfig.GenericConfig.SecureServing.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.ExtraOAuthConfig.RouteClient = routeClient
oauthServerConfig.ExtraOAuthConfig.KubeClient = masterConfig.PrivilegedLoopbackKubernetesClientsetExternal
// Build the list of valid redirect_uri prefixes for a login using the openshift-web-console client to redirect to
oauthServerConfig.ExtraOAuthConfig.AssetPublicAddresses = []string{oauthConfig.AssetPublicURL}
return oauthServerConfig, nil
}