-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow front proxy in front of API #12803
Changes from all commits
e204190
98bf37e
8d20a24
76db97a
ee008eb
f40bb8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"crypto/tls" | ||
"errors" | ||
"fmt" | ||
"io/ioutil" | ||
"net" | ||
"net/http" | ||
"net/url" | ||
|
@@ -112,6 +113,7 @@ func BuildDefaultAPIServer(options configapi.MasterConfig) (*apiserveroptions.Se | |
server.GenericServerRunOptions.TLSCertFile = options.ServingInfo.ServerCert.CertFile | ||
server.GenericServerRunOptions.TLSPrivateKeyFile = options.ServingInfo.ServerCert.KeyFile | ||
server.GenericServerRunOptions.ClientCAFile = options.ServingInfo.ClientCA | ||
|
||
server.GenericServerRunOptions.MaxRequestsInFlight = options.ServingInfo.MaxRequestsInFlight | ||
server.GenericServerRunOptions.MinRequestTimeout = options.ServingInfo.RequestTimeoutSeconds | ||
for _, nc := range options.ServingInfo.NamedCertificates { | ||
|
@@ -305,6 +307,14 @@ func BuildKubernetesMasterConfig(options configapi.MasterConfig, requestContextM | |
for _, cert := range oAuthClientCertCAs { | ||
genericConfig.SecureServingInfo.ClientCA.AddCert(cert) | ||
} | ||
requestHeaderCACerts, err := configapi.GetRequestHeaderClientCertCAs(options) | ||
if err != nil { | ||
glog.Fatalf("Error setting up request header client certificates: %v", err) | ||
} | ||
for _, cert := range requestHeaderCACerts { | ||
genericConfig.SecureServingInfo.ClientCA.AddCert(cert) | ||
} | ||
|
||
url, err := url.Parse(options.MasterPublicURL) | ||
if err != nil { | ||
glog.Fatalf("Error parsing master public url %q: %v", options.MasterPublicURL, err) | ||
|
@@ -545,3 +555,27 @@ func getAPIResourceConfig(options configapi.MasterConfig) genericapiserver.APIRe | |
|
||
return resourceConfig | ||
} | ||
|
||
// TODO remove this func in 1.6 when we get rid of the hack above | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @deads2k you forgot to remove |
||
func concatenateFiles(prefix, separator string, files ...string) (string, error) { | ||
data := []byte{} | ||
for _, file := range files { | ||
fileBytes, err := ioutil.ReadFile(file) | ||
if err != nil { | ||
return "", err | ||
} | ||
data = append(data, fileBytes...) | ||
data = append(data, []byte(separator)...) | ||
} | ||
tmpFile, err := ioutil.TempFile("", prefix) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. permissions on this file are important, given what write access to it allows |
||
if err != nil { | ||
return "", err | ||
} | ||
if _, err := tmpFile.Write(data); err != nil { | ||
return "", err | ||
} | ||
if err := tmpFile.Close(); err != nil { | ||
return "", err | ||
} | ||
return tmpFile.Name(), nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ import ( | |
"k8s.io/kubernetes/plugin/pkg/admission/namespace/lifecycle" | ||
saadmit "k8s.io/kubernetes/plugin/pkg/admission/serviceaccount" | ||
storageclassdefaultadmission "k8s.io/kubernetes/plugin/pkg/admission/storageclass/default" | ||
"k8s.io/kubernetes/plugin/pkg/auth/authenticator/request/headerrequest" | ||
|
||
"github.com/openshift/origin/pkg/auth/authenticator" | ||
"github.com/openshift/origin/pkg/auth/authenticator/anonymous" | ||
|
@@ -664,16 +665,28 @@ func newAuthenticator(config configapi.MasterConfig, restOptionsGetter restoptio | |
authenticators = append(authenticators, certauth) | ||
} | ||
|
||
ret := &unionrequest.Authenticator{ | ||
FailOnError: true, | ||
Handlers: []authenticator.Request{ | ||
// if you change this, have a look at the impersonationFilter where we attach groups to the impersonated user | ||
group.NewGroupAdder(&unionrequest.Authenticator{FailOnError: true, Handlers: authenticators}, []string{bootstrappolicy.AuthenticatedGroup}), | ||
anonymous.NewAuthenticator(), | ||
}, | ||
topLevelAuthenticators := []authenticator.Request{} | ||
// if we have a front proxy providing authentication configuration, wire it up and it should come first | ||
if config.AuthConfig.RequestHeader != nil { | ||
requestHeaderAuthenticator, err := headerrequest.NewSecure( | ||
config.AuthConfig.RequestHeader.ClientCA, | ||
config.AuthConfig.RequestHeader.ClientCommonNames, | ||
config.AuthConfig.RequestHeader.UsernameHeaders, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only gets defaulted if you round trip the config right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We do, don't we? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think we do so in integration tests (which is why I had to specify it directly). |
||
config.AuthConfig.RequestHeader.GroupHeaders, | ||
config.AuthConfig.RequestHeader.ExtraHeaderPrefixes, | ||
) | ||
if err != nil { | ||
return nil, fmt.Errorf("Error building front proxy auth config: %v", err) | ||
} | ||
topLevelAuthenticators = append(topLevelAuthenticators, requestHeaderAuthenticator) | ||
} | ||
topLevelAuthenticators = append(topLevelAuthenticators, group.NewGroupAdder(&unionrequest.Authenticator{FailOnError: true, Handlers: authenticators}, []string{bootstrappolicy.AuthenticatedGroup})) | ||
topLevelAuthenticators = append(topLevelAuthenticators, anonymous.NewAuthenticator()) | ||
|
||
return ret, nil | ||
return &unionrequest.Authenticator{ | ||
FailOnError: true, | ||
Handlers: topLevelAuthenticators, | ||
}, nil | ||
} | ||
|
||
func newProjectAuthorizationCache(authorizer authorizer.Authorizer, kubeClient *kclientset.Clientset, informerFactory shared.InformerFactory) *projectauth.AuthorizationCache { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this supposed to be optional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's net new, so we can require it if we want. I'd rather start by requiring it and relax later if we want