Skip to content

Commit 359c312

Browse files
enjdeads2k
authored andcommitted
Add integration test for front proxy
Signed-off-by: Monis Khan <[email protected]>
1 parent 1e87781 commit 359c312

File tree

4 files changed

+357
-9
lines changed

4 files changed

+357
-9
lines changed

pkg/cmd/server/kubernetes/master_config.go

+36
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"crypto/tls"
55
"errors"
66
"fmt"
7+
"io/ioutil"
78
"net"
89
"net/http"
910
"net/url"
@@ -112,6 +113,17 @@ func BuildDefaultAPIServer(options configapi.MasterConfig) (*apiserveroptions.Se
112113
server.GenericServerRunOptions.TLSCertFile = options.ServingInfo.ServerCert.CertFile
113114
server.GenericServerRunOptions.TLSPrivateKeyFile = options.ServingInfo.ServerCert.KeyFile
114115
server.GenericServerRunOptions.ClientCAFile = options.ServingInfo.ClientCA
116+
117+
// TODO this is a terrible hack that should be removed in 1.6
118+
if options.AuthConfig.RequestHeader != nil {
119+
clientCAFile, err := concatenateFiles("cafrontproxybundle", "\n", options.ServingInfo.ClientCA, options.AuthConfig.RequestHeader.ClientCA)
120+
if err != nil {
121+
return nil, nil, fmt.Errorf("unable to create ca bundle temp file: %v", err)
122+
}
123+
glog.V(2).Infof("temp clientCA bundle file is %s", clientCAFile)
124+
server.GenericServerRunOptions.ClientCAFile = clientCAFile
125+
}
126+
115127
server.GenericServerRunOptions.MaxRequestsInFlight = options.ServingInfo.MaxRequestsInFlight
116128
server.GenericServerRunOptions.MinRequestTimeout = options.ServingInfo.RequestTimeoutSeconds
117129
for _, nc := range options.ServingInfo.NamedCertificates {
@@ -545,3 +557,27 @@ func getAPIResourceConfig(options configapi.MasterConfig) genericapiserver.APIRe
545557

546558
return resourceConfig
547559
}
560+
561+
// TODO remove this func in 1.6 when we get rid of the hack above
562+
func concatenateFiles(prefix, separator string, files ...string) (string, error) {
563+
data := []byte{}
564+
for _, file := range files {
565+
fileBytes, err := ioutil.ReadFile(file)
566+
if err != nil {
567+
return "", err
568+
}
569+
data = append(data, fileBytes...)
570+
data = append(data, []byte(separator)...)
571+
}
572+
tmpFile, err := ioutil.TempFile("", prefix)
573+
if err != nil {
574+
return "", err
575+
}
576+
if _, err := tmpFile.Write(data); err != nil {
577+
return "", err
578+
}
579+
if err := tmpFile.Close(); err != nil {
580+
return "", err
581+
}
582+
return tmpFile.Name(), nil
583+
}

pkg/cmd/server/origin/master_config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ func newAuthenticator(config configapi.MasterConfig, restOptionsGetter restoptio
665665
authenticators = append(authenticators, certauth)
666666
}
667667

668-
ret := &unionrequest.Authenticator{
668+
var ret authenticator.Request = &unionrequest.Authenticator{
669669
FailOnError: true,
670670
Handlers: []authenticator.Request{
671671
// if you change this, have a look at the impersonationFilter where we attach groups to the impersonated user
@@ -684,7 +684,7 @@ func newAuthenticator(config configapi.MasterConfig, restOptionsGetter restoptio
684684
config.AuthConfig.RequestHeader.ExtraHeaderPrefixes,
685685
)
686686
if err != nil {
687-
return nil, err
687+
return nil, fmt.Errorf("Error building front proxy auth config: %v", err)
688688
}
689689
// First try to authenticate with the front proxy
690690
// If that fails then gracefully fallthrough to the original authentication chain

test/integration/auth_proxy_test.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
configapi "github.com/openshift/origin/pkg/cmd/server/api"
1414
"github.com/openshift/origin/pkg/cmd/server/origin"
1515
oauthapi "github.com/openshift/origin/pkg/oauth/api"
16-
clientregistry "github.com/openshift/origin/pkg/oauth/registry/oauthclient"
1716
testutil "github.com/openshift/origin/test/util"
1817
testserver "github.com/openshift/origin/test/util/server"
1918
)
@@ -90,6 +89,9 @@ func TestAuthProxyOnAuthorize(t *testing.T) {
9089

9190
// make our authorize request again, but this time our transport has properly set the auth info for the front proxy
9291
req, err := http.NewRequest("GET", rawAuthorizeRequest, nil)
92+
if err != nil {
93+
t.Fatalf("Unexpected error: %v", err)
94+
}
9395
_, err = httpClient.Do(req)
9496
if err != nil {
9597
t.Errorf("Unexpected error: %v", err)
@@ -108,12 +110,6 @@ func TestAuthProxyOnAuthorize(t *testing.T) {
108110
}
109111
}
110112

111-
func createClient(t *testing.T, clientRegistry clientregistry.Registry, client *oauthapi.OAuthClient) {
112-
if _, err := clientRegistry.CreateClient(kapi.NewContext(), client); err != nil {
113-
t.Errorf("Error creating client: %v due to %v\n", client, err)
114-
}
115-
}
116-
117113
type checkRedirect func(req *http.Request, via []*http.Request) error
118114

119115
func getRedirectMethod(t *testing.T, redirectRecord *[]url.URL) checkRedirect {

0 commit comments

Comments
 (0)