Skip to content

Commit ad369ea

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

File tree

4 files changed

+361
-10
lines changed

4 files changed

+361
-10
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 {
@@ -542,3 +554,27 @@ func getAPIResourceConfig(options configapi.MasterConfig) genericapiserver.APIRe
542554

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

pkg/cmd/server/origin/master_config.go

+6-3
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,9 +684,12 @@ 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
}
689-
ret.Handlers = append([]authenticator.Request{requestHeaderAuthenticator}, ret.Handlers...)
689+
// First try to authenticate with the front proxy
690+
// If that fails then gracefully fallthrough to the original authentication chain
691+
// Thus failing to authenticate with the front proxy is equivalent to not having the proxy in the authentication chain
692+
ret = unionrequest.NewUnionAuthentication(requestHeaderAuthenticator, ret)
690693
}
691694

692695
return ret, nil

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)