Skip to content
This repository was archived by the owner on May 6, 2022. It is now read-only.

Commit eb1f1e7

Browse files
DirectXMan12arschles
authored andcommitted
Actually Use Authentication and Authorization (#615)
* Add flag to disable auth for testing purposes Some of the tests run the service catalog API server without a corresponding Kubernetes API server. In this case, no delegating authentication or authorization is possible. The `--disable-auth` flag causes the API server setup to skip setting up authentication and authorization in these cases. * Update Helm Charts for Auth and Aggregation This commit updates the helm charts, inserting the requisite options for running the service catalog behind the master's integrated API server aggregator. The new options are: - `useAggregator`: causes the API server to be registered with the k8s API server and points the controller manager at the there instead of at the service catalog API server. - `apiserver.tls.requestHeaderCA`: the CA used to authenticate requests from the k8s API server proxy, so that we can trust the authentication information that it passes us (because it handles authentication itself, and then passes us the extracted information). - `apiserver.tls.ca`: the CA used to sign the serving certificates for the API server. This is needed by the API registration information, so that the k8s API server proxy can verify that it's talking to the correct server. In order to use aggregation, you must also pass `apiserver.tls.{cert,key}`, instead of letting them be autogenerated as self-signed certificates. * Fix up Kubeconfig handling This commit uncomments and fixes up the Kubeconfig handling, making it possible to actually pass in Kubeconfigs to use to connect to the k8s API server and the service catalog API server. Furthermore, we explicitly try and use in-cluster config for service catalog API server connections, avoiding a generic error message about it "possibly" not working in favor of our own warning, which advises viewers to make sure that the service catalog APIs are registered with the aggregator. * Actually die if APIs aren't available Previously, we'd start (and otherwise appear healthy), but not actually do anything if the service catalog APIs weren't available. Now, the controller manager fails if the APIs aren't available, so that we eventually get restarted. * Renable authentication and authorization This re-enables actually applying the effects of the authentication and authorization options. The API server will now attempt to delegate authentication and authorization options to a main Kube API server. These should work fine now that we're using the 1.6 generic API server code. * Ensure walkthrough requestheader certs This PR makes sure that when running the walkthrough test, the extensions-apiserver-authentication configmap, which is autogenerated by the main Kubernetes API server, contains requestheader certs. If it doesn't, it augments the configmap with requestheader certs matching the client certs from the cluster, since GKE does set these (this might not necessarily be what you normally want, but works fine for testing). * Force jenkins to use k8s 1.6.1 This commit tells Jenkins to use a 1.6.1 cluster. This ensures that we always know what cluster version we're running tests against, and also opts us in to using a 1.6 cluster (which is not the default at the time of authorship of this PR).
1 parent b2afca0 commit eb1f1e7

File tree

16 files changed

+106
-36
lines changed

16 files changed

+106
-36
lines changed

Jenkinsfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ node {
108108
--registry gcr.io/${test_project}/catalog/ \
109109
--version ${version} \
110110
--cleanup \
111+
--fix-auth \
111112
--create-artifacts
112113
"""
113114

@@ -116,6 +117,7 @@ node {
116117
--version ${version} \
117118
--with-tpr \
118119
--cleanup \
120+
--fix-auth \
119121
--create-artifacts
120122
"""
121123
} catch (Exception e) {

charts/catalog/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ chart and their default values.
4444
| `apiserver.insecure` | Whether to expose an insecure endpoint; keep this enabled because there are some outstanding problems with the TLS-secured endpoint | `true` |
4545
| `apiserver.tls.cert` | Base64-encoded x509 certificate | A self-signed certificate |
4646
| `apiserver.tls.key` | Base64-encoded private key | The private key for the certificate above |
47+
| `apiserver.tls.ca` | Base64-encoded CA certificate used to sign the above certificate | |
48+
| `apiserver.tls.requestHeaderCA` | Base64-encoded CA used to validate request-header authentication, when receiving delegated authentication from an aggregator | *none (will disable requestheader authentication)* |
4749
| `apiserver.service.type` | Type of service; valid values are `LoadBalancer` and `NodePort` | `NodePort` |
4850
| `apiserver.service.nodePort.securePort` | If service type is `NodePort`, specifies a port in allowable range (e.g. 30000 - 32767 on minikube); The TLS-enabled endpoint will be exposed here | `30443` |
4951
| `apiserver.service.nodePort.insecurePort` | If service type is `NodePort`, specifies a port in allowable range (e.g. 30000 - 32767 on minikube); The insecure endpoint, if enabled, will be exposed here | `30080` |
@@ -57,6 +59,7 @@ chart and their default values.
5759
| `controllerManager.verbosity` | Log level; valid values are in the range 0 - 10 | `10` |
5860
| `controllerManager.resyncInterval` | How often the controller should resync informers; duration format (`20m`, `1h`, etc) | `5m` |
5961
| `controllerManager.brokerRelistInterval` | How often the controller should relist the catalogs of ready brokers; duration format (`20m`, `1h`, etc) | `24h` |
62+
| `useAggregator` | whether or not to set up the controller-manager to go through the main Kubernetes API server's API aggregator (requires setting `apiserver.tls.ca` to work) | `false` |
6063

6164
Specify each parameter using the `--set key=value[,key=value]` argument to
6265
`helm install`.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{- if .Values.useAggregator }}
2+
apiVersion: apiregistration.k8s.io/v1alpha1
3+
kind: APIService
4+
metadata:
5+
name: v1alpha1.servicecatalog.k8s.io
6+
spec:
7+
group: servicecatalog.k8s.io
8+
version: v1alpha1
9+
service:
10+
namespace: {{ .Release.Namespace }}
11+
name: {{ template "fullname" . }}-apiserver
12+
caBundle: {{ .Values.apiserver.tls.ca }}
13+
priority: 100
14+
{{ end }}

charts/catalog/templates/apiserver-cert-secret.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ type: Opaque
1111
data:
1212
tls.crt: {{ .Values.apiserver.tls.cert }}
1313
tls.key: {{ .Values.apiserver.tls.key }}
14+
{{- if .Values.apiserver.tls.requestHeaderCA }}
15+
requestheader-ca.crt: {{ .Values.apiserver.tls.requestHeaderCA }}
16+
{{- end }}

charts/catalog/templates/apiserver-deployment.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ spec:
5151
{{- end }}
5252
- -v
5353
- "{{ .Values.apiserver.verbosity }}"
54+
{{- if .Values.apiserver.tls.requestHeaderCA }}
55+
- --requestheader-client-ca-file=/var/run/kubernetes-service-catalog/requestheader-ca.crt
56+
{{- end }}
5457
ports:
5558
{{- if .Values.apiserver.insecure }}
5659
- containerPort: 8080
@@ -133,6 +136,10 @@ spec:
133136
path: apiserver.crt
134137
- key: tls.key
135138
path: apiserver.key
139+
{{- if .Values.apiserver.tls.requestHeaderCA }}
140+
- key: requestheader-ca.crt
141+
path: requestheader-ca.crt
142+
{{- end }}
136143
{{- if eq .Values.apiserver.storage.type "etcd" }}
137144
- name: etcd-data-dir
138145
emptyDir: {}

charts/catalog/templates/controller-manager-deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ spec:
3434
args:
3535
- --port
3636
- "8080"
37+
{{- if not .Values.useAggregator }}
3738
- --service-catalog-api-server-url
3839
{{- if .Values.apiserver.insecure }}
3940
- http://{{ template "fullname" . }}-apiserver
4041
{{- else }}
4142
- https://{{ template "fullname" . }}-apiserver
4243
{{- end }}
44+
{{- end }}
4345
- -v
4446
- "{{ .Values.controllerManager.verbosity }}"
4547
- --resync-interval

charts/catalog/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,4 @@ controllerManager:
5656
resyncInterval: 5m
5757
# Broker relist interval; format is a duration (`20m`, `1h`, etc)
5858
brokerRelistInterval: 24h
59+
useAggregator: false

cmd/apiserver/app/server/options.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ type ServiceCatalogServerOptions struct {
4141
EtcdOptions *EtcdOptions
4242
// TPROptions are options for serving with TPR as the backing store
4343
TPROptions *TPROptions
44-
StopCh <-chan struct{}
44+
// DisableAuth disables delegating authentication and authorization for testing scenarios
45+
DisableAuth bool
46+
StopCh <-chan struct{}
4547
}
4648

4749
func (s *ServiceCatalogServerOptions) addFlags(flags *pflag.FlagSet) {
@@ -52,6 +54,13 @@ func (s *ServiceCatalogServerOptions) addFlags(flags *pflag.FlagSet) {
5254
"The type of backing storage this API server should use",
5355
)
5456

57+
flags.BoolVar(
58+
&s.DisableAuth,
59+
"disable-auth",
60+
false,
61+
"Disable authentication and authorization for testing purposes",
62+
)
63+
5564
s.GenericServerRunOptions.AddUniversalFlags(flags)
5665
s.SecureServingOptions.AddFlags(flags)
5766
s.AuthenticationOptions.AddFlags(flags)

cmd/apiserver/app/server/util.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package server
1818

1919
import (
20+
"github.com/golang/glog"
21+
2022
genericapiserver "k8s.io/apiserver/pkg/server"
2123
)
2224

@@ -43,22 +45,18 @@ func setupBasicServer(s *ServiceCatalogServerOptions) (*genericapiserver.Config,
4345
return nil, err
4446
}
4547

46-
// glog.V(4).Info("Setting up authn (disabled)")
47-
// need to figure out what's throwing the `missing clientCA file` err
48-
/*
49-
if _, err := genericConfig.ApplyDelegatingAuthenticationOptions(serverOptions.AuthenticationOptions); err != nil {
50-
glog.Infoln(err)
51-
return err
48+
if !s.DisableAuth {
49+
if err := s.AuthenticationOptions.ApplyTo(genericConfig); err != nil {
50+
return nil, err
5251
}
53-
*/
5452

55-
// glog.V(4).Infoln("Setting up authz (disabled)")
56-
// having this enabled causes the server to crash for any call
57-
/*
58-
if _, err := genericConfig.ApplyDelegatingAuthorizationOptions(serverOptions.AuthorizationOptions); err != nil {
59-
glog.Infoln(err)
60-
return err
53+
if err := s.AuthorizationOptions.ApplyTo(genericConfig); err != nil {
54+
return nil, err
6155
}
62-
*/
56+
} else {
57+
// always warn when auth is disabled, since this should only be used for testing
58+
glog.Infof("Authentication and authorization disabled for testing purposes")
59+
}
60+
6361
return genericConfig, nil
6462
}

cmd/controller-manager/app/controller_manager.go

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,20 @@ func Run(controllerManagerOptions *options.ControllerManagerServer) error {
9090
// Build the K8s kubeconfig / client / clientBuilder
9191
glog.V(4).Info("Building k8s kubeconfig")
9292

93-
k8sKubeconfig, err := rest.InClusterConfig()
93+
var err error
94+
var k8sKubeconfig *rest.Config
95+
if controllerManagerOptions.K8sAPIServerURL == "" && controllerManagerOptions.K8sKubeconfigPath == "" {
96+
k8sKubeconfig, err = rest.InClusterConfig()
97+
} else {
98+
k8sKubeconfig, err = clientcmd.BuildConfigFromFlags(
99+
controllerManagerOptions.K8sAPIServerURL,
100+
controllerManagerOptions.K8sKubeconfigPath)
101+
}
94102
if err != nil {
95-
glog.Fatalf("Failed to get kube client config (%s)", err)
103+
return fmt.Errorf("failed to get Kubernetes client config: %v", err)
96104
}
97105
k8sKubeconfig.GroupVersion = &schema.GroupVersion{}
98106

99-
// k8sKubeconfig, err := clientcmd.BuildConfigFromFlags(
100-
// controllerManagerOptions.K8sAPIServerURL,
101-
// controllerManagerOptions.K8sKubeconfigPath)
102-
// if err != nil {
103-
// // TODO: disambiguate API errors
104-
// return err
105-
// }
106107
k8sKubeconfig.ContentConfig.ContentType = controllerManagerOptions.ContentType
107108
// Override kubeconfig qps/burst settings from flags
108109
k8sKubeconfig.QPS = controllerManagerOptions.KubeAPIQPS
@@ -111,21 +112,30 @@ func Run(controllerManagerOptions *options.ControllerManagerServer) error {
111112
rest.AddUserAgent(k8sKubeconfig, controllerManagerAgentName),
112113
)
113114
if err != nil {
114-
glog.Fatalf("Invalid k8s API configuration: %v", err)
115+
return fmt.Errorf("invalid Kubernetes API configuration: %v", err)
115116
}
116117

117118
glog.V(4).Infof("Building service-catalog kubeconfig for url: %v\n", controllerManagerOptions.ServiceCatalogAPIServerURL)
119+
120+
var serviceCatalogKubeconfig *rest.Config
118121
// Build the service-catalog kubeconfig / clientBuilder
119-
serviceCatalogKubeconfig, err := clientcmd.BuildConfigFromFlags(
120-
controllerManagerOptions.ServiceCatalogAPIServerURL,
121-
// controllerManagerOptions.ServiceCatalogKubeconfigPath,
122-
"", // TODO: tolerate missing kubeconfig
123-
)
122+
if controllerManagerOptions.ServiceCatalogAPIServerURL == "" && controllerManagerOptions.ServiceCatalogKubeconfigPath == "" {
123+
// explicitly fall back to InClusterConfig, assuming we're talking to an API server which does aggregation
124+
// (BuildConfigFromFlags does this, but gives a more generic warning message than we do here)
125+
glog.V(4).Infof("Using inClusterConfig to talk to service catalog API server -- make sure your API server is registered with the aggregator")
126+
serviceCatalogKubeconfig, err = rest.InClusterConfig()
127+
} else {
128+
serviceCatalogKubeconfig, err = clientcmd.BuildConfigFromFlags(
129+
controllerManagerOptions.ServiceCatalogAPIServerURL,
130+
controllerManagerOptions.ServiceCatalogKubeconfigPath)
131+
}
124132
if err != nil {
125133
// TODO: disambiguate API errors
126-
return err
134+
return fmt.Errorf("failed to get Service Catalog client configuration: %v", err)
127135
}
128136

137+
// due to using both k8s.io/kubernetes and k8s.io/client-go, we need to convert this object over
138+
129139
glog.V(4).Info("Starting http server and mux")
130140
// Start http server and handlers
131141
go func() {
@@ -306,7 +316,7 @@ func StartControllers(s *options.ControllerManagerServer,
306316
glog.V(1).Info("Starting shared informers")
307317
informerFactory.Start(stop)
308318
} else {
309-
glog.V(1).Infof("Skipping starting service-catalog controller because servicecatalog/v1alpha1 is not available")
319+
return fmt.Errorf("unable to start service-catalog controller: servicecatalog/v1alpha1 is not available")
310320
}
311321

312322
select {}

0 commit comments

Comments
 (0)