|
| 1 | +--- |
| 2 | +title: Using Namespaced Broker Resources |
| 3 | +layout: docwithnav |
| 4 | +--- |
| 5 | + |
| 6 | +# Cluster-Scoped vs Namespace-Scoped Broker Resources |
| 7 | + |
| 8 | +Service Catalog enables service brokers to be registered in two manners: as a |
| 9 | +cluster-scoped resource or as a namespace-scoped resource. As a user of service |
| 10 | + catalog, you might use these approaches to accomplish different goals such as |
| 11 | + providing a common set of service broker resources to all users or utilizing |
| 12 | + role based access (RBAC) policies to control service provisioning. This |
| 13 | + document will explain some use cases for namespace-scoped resources and how to |
| 14 | + accomplish them using Service Catalog. |
| 15 | + |
| 16 | +## Possible Use Cases |
| 17 | + |
| 18 | +When using `ClusterServiceBroker` and associated `ClusterServiceClass` and |
| 19 | +`ClusterServicePlan` resources, service broker resources, such as classes and |
| 20 | +plans, are created as cluster-scoped resources. This means that you are limited |
| 21 | + in how you can apply RBAC and you can only have a single instance of that |
| 22 | + resource for a given identifier. As an example, if the service broker you are |
| 23 | + registering has fixed class and plan identifiers, you will be limited to one |
| 24 | + instance of the broker. With namespace-scoped brokers, however, the |
| 25 | + `ServiceBroker`, along with the `ServiceClass` and `ServicePlan` resources are |
| 26 | + scoped to a particular namespace. This allows for some more advanced use |
| 27 | + cases that were not possible with the cluster-scoped broker resources. |
| 28 | + |
| 29 | +### Registering Brokers Per Namespace |
| 30 | + |
| 31 | +A service broker that provisions services in a cloud provider usually needs |
| 32 | +credentials in order to complete the request on behalf of Service Catalog. |
| 33 | +Some organizations may provide different access credentials to different teams |
| 34 | +in order to separate billing usage or to isolate control of resources. In these |
| 35 | +cases, the cluster operator might want to register two copies of the broker |
| 36 | +using different credentials for each team. When using `ClusterServiceBroker` |
| 37 | +and the associated `ClusterServiceClass` and `ClusterServicePlan` resources, it |
| 38 | + was not possible to register two instances of a service broker unless each |
| 39 | + registration could provide unique identifiers for service c lasses and service |
| 40 | + plans. |
| 41 | + |
| 42 | +Using namespace-scoped brokers, however, enables the broker to be installed in |
| 43 | + each namespace without conflicting at the class and plan level. When creating |
| 44 | + a service instance, you specify either the external class or plan name, or |
| 45 | + provide the class or plan identifier. Service Catalog then resolves these in |
| 46 | + order to determine which broker it should issue the provision command to. |
| 47 | + When using namespace-scoped brokers and their associated resources, this |
| 48 | + resolution occurs within the namespace. That means that users in namespace |
| 49 | + `backend-team` and namespace `frontend-team` can have the their own broker |
| 50 | + registrations and provision requests will be issued to the correct broker. |
| 51 | + |
| 52 | +### Limiting Access to Plans |
| 53 | + |
| 54 | +There are often situations when not all services and plans should be available |
| 55 | +to all users. A cluster administrator may wish to only provide free plans to |
| 56 | +certain users or restrict the ability to provision very expensive services. |
| 57 | +Additionally, when developers are creating new services that are exposed by |
| 58 | +brokers, they want to be able to iterate on those services without exposing |
| 59 | +them to all users in a cluster. |
| 60 | + |
| 61 | +Service Catalog's cluster-scoped resources for brokers, services, and plans are |
| 62 | + not sufficient to implement access control to ensure that users have access |
| 63 | + only to the service and plans that they should. For these resources, |
| 64 | + application of RBAC is really centered around what is visible to them, but is |
| 65 | + not enforced when a provision request is issued. For example, a `ClusterRole` |
| 66 | + could be created to prohibit a given user or group from viewing |
| 67 | + `ClusterServiceClass` and `ClusterServicePlan` resources, but this role cannot |
| 68 | +be used to prevent a user from creating a `ServiceInstance` using that |
| 69 | +`ClusterServiceClass` and `ClusterServicePlan`. Namespace-scoped brokers, |
| 70 | +services and plans, however, can be effectively combined with Kubernetes RBAC |
| 71 | +and Service Catalog Catalog Restrictions in order to provide more granular |
| 72 | +control over service instance provisioning. |
| 73 | + |
| 74 | +## Enabling Namespace Scoped Broker Resources |
| 75 | + |
| 76 | +Currently, namespace-scoped broker resources are an alpha-feature of Service |
| 77 | +Catalog behind a feature flag. To start using these resources, you will need |
| 78 | +to pass an argument to the API Server when you install Service Catalog: |
| 79 | + `--feature-gates NamespacedServiceBroker=true`. |
| 80 | + |
| 81 | +If you are using Helm, you can use the `namespacedServiceBrokerEnabled` setting |
| 82 | + to control that flag: |
| 83 | + |
| 84 | +```console |
| 85 | +helm install svc-cat/catalog \ |
| 86 | + --name catalog \ |
| 87 | + --namespace catalog \ |
| 88 | + --set namespacedServiceBrokerEnabled=true |
| 89 | +``` |
| 90 | + |
| 91 | +## Using Namespace Scoped Broker Resources |
| 92 | + |
| 93 | +Once Service Catalog has been installed with this feature gate enabled, you |
| 94 | +should see three new resource types: `ServiceBroker`, `ServiceClass`, |
| 95 | +and `ServicePlan`. |
| 96 | + |
| 97 | +In order to register a `ServiceBroker` resource, you create a YAML definition |
| 98 | +that looks similar to a `ClusterServiceBroker`. This resource will use resource |
| 99 | + kind `ServiceBroker` and requires a namespace. An example might look like: |
| 100 | + |
| 101 | +```yaml |
| 102 | +apiVersion: servicecatalog.k8s.io/v1beta1 |
| 103 | +kind: ServiceBroker |
| 104 | +metadata: |
| 105 | + name: example-ns-broker |
| 106 | + namespace: ns-broker |
| 107 | +spec: |
| 108 | + authInfo: |
| 109 | + basic: |
| 110 | + secretRef: |
| 111 | + name: my-service-broker-auth |
| 112 | + namespace: broker |
| 113 | + url: http://my-service-broker.broker.svc.cluster.local |
| 114 | +``` |
| 115 | +
|
| 116 | +Once this resource is created, Service Catalog will query the Service Broker |
| 117 | +for the list of available Services and create corresponding `ServiceClass` |
| 118 | +and `ServicePlan` resources. These resources might look like this: |
| 119 | + |
| 120 | +```yaml |
| 121 | +apiVersion: servicecatalog.k8s.io/v1beta1 |
| 122 | +kind: ServiceClass |
| 123 | +metadata: |
| 124 | + creationTimestamp: 2018-07-12T13:30:01Z |
| 125 | + name: 25434f16-d762-41c7-bbdd-8045d7f74ca6 |
| 126 | + namespace: ns-broker |
| 127 | + resourceVersion: "13" |
| 128 | + selfLink: /apis/servicecatalog.k8s.io/v1beta1/namespaces/ns-broker/serviceclasses/25434f16-d762-41c7-bbdd-8045d7f74ca6 |
| 129 | + uid: adfa2d9a-85d7-11e8-a4f3-2ae408f4a9e4 |
| 130 | +spec: |
| 131 | + bindable: true |
| 132 | + bindingRetrievable: false |
| 133 | + description: MySQL |
| 134 | + externalID: 25434f16-d762-41c7-bbdd-8045d7f74ca6 |
| 135 | + externalName: mysql-5-7 |
| 136 | + planUpdatable: false |
| 137 | + serviceBrokerName: example-ns-broker |
| 138 | +``` |
| 139 | + |
| 140 | +```yaml |
| 141 | +apiVersion: servicecatalog.k8s.io/v1beta1 |
| 142 | +kind: ServicePlan |
| 143 | +metadata: |
| 144 | + creationTimestamp: 2018-07-12T13:30:02Z |
| 145 | + name: 4c6932e8-30ec-4af9-83d2-6e27286dbab3 |
| 146 | + namespace: ns-broker |
| 147 | + resourceVersion: "24" |
| 148 | + selfLink: /apis/servicecatalog.k8s.io/v1beta1/namespaces/ns-broker/serviceplans/4c6932e8-30ec-4af9-83d2-6e27286dbab3 |
| 149 | + uid: ae8e23ac-85d7-11e8-a4f3-2ae408f4a9e4 |
| 150 | +spec: |
| 151 | + description: basic plan |
| 152 | + externalID: 4c6932e8-30ec-4af9-83d2-6e27286dbab3 |
| 153 | +serviceBrokerName: example-ns-broker |
| 154 | + serviceClassRef: |
| 155 | + name: 25434f16-d762-41c7-bbdd-8045d7f74ca6e |
| 156 | +``` |
| 157 | + |
| 158 | +The `ServiceInstance` resource has also been updated to allow you to use these |
| 159 | +resources just as you would the existing `ClusterServiceBroker`, |
| 160 | +`ClusterServiceClass` and `ClusterServicePlan` resources, except you will use |
| 161 | +them in the context of a namespace. For example, a `ServiceInstance` YAML that |
| 162 | + references a `ClusterServiceClass` and a `ClusterServicePlan` resource might |
| 163 | + look like this: |
| 164 | + |
| 165 | +```yaml |
| 166 | +apiVersion: servicecatalog.k8s.io/v1beta1 |
| 167 | +kind: ServiceInstance |
| 168 | +metadata: |
| 169 | + name: example-mysql-instance |
| 170 | + namespace: default |
| 171 | +spec: |
| 172 | + clusterServiceClassExternalName: mysql-5-7 |
| 173 | + clusterServicePlanExternalName: basic |
| 174 | +``` |
| 175 | + |
| 176 | +If you instead want to use the `ServiceClass` and `ServicePlan` |
| 177 | + namespace-scoped resources, the yaml might look like this: |
| 178 | + |
| 179 | +```yaml |
| 180 | +apiVersion: servicecatalog.k8s.io/v1beta1 |
| 181 | +kind: ServiceInstance |
| 182 | +metadata: |
| 183 | + name: example-mysql-instance |
| 184 | + namespace: default |
| 185 | +spec: |
| 186 | + serviceClassExternalName: mysql-5-7 |
| 187 | + servicePlanExternalName: basic |
| 188 | +``` |
| 189 | + |
| 190 | +For comparison, using the cluster-scoped `ClusterServiceClass` or |
| 191 | +`ClusterServicePlan`, the yaml would look like: |
| 192 | + |
| 193 | +```yaml |
| 194 | +apiVersion: servicecatalog.k8s.io/v1beta1 |
| 195 | +kind: ServiceInstance |
| 196 | +metadata: |
| 197 | + name: example-mysql-instance |
| 198 | + namespace: default |
| 199 | +spec: |
| 200 | + clusterServiceClassExternalName: mysql-5-7 |
| 201 | + clusterServicePlanExternalName: basic |
| 202 | +``` |
| 203 | + |
| 204 | +Instances can reference cluster-scoped `ClusterServiceClass` or |
| 205 | +`ClusterServicePlan` resources or to the namespace scope `ServiceClass` and |
| 206 | +`ServicePlan` resources in the same namespace. They cannot reference |
| 207 | +`ServiceClass` and `ServicePlan` resources in another namespace. |
| 208 | + |
| 209 | +## Further Restricting Plan Access |
| 210 | + |
| 211 | +The use of namespace-scoped resources enables you to register brokers within a |
| 212 | + given namespace and leverage RBAC in order to control who can |
| 213 | +provision services in that namespace. By default, all service classes and plans |
| 214 | +from that broker will be available to users of the namespace. When registering |
| 215 | +a broker, catalog restrictions can be specified in order to restrict what plans |
| 216 | + are available within a given namespace. This allows you to specify that in |
| 217 | + the `developer` namespace, only plans named `basic` can be created. The YAML |
| 218 | + to accomplish this might look like: |
| 219 | + |
| 220 | +```yaml |
| 221 | +apiVersion: servicecatalog.k8s.io/v1beta1 |
| 222 | +kind: ServiceBroker |
| 223 | +metadata: |
| 224 | + name: example-ns-broker |
| 225 | + namespace: ns-broker |
| 226 | +spec: |
| 227 | + authInfo: |
| 228 | + basic: |
| 229 | + secretRef: |
| 230 | + name: my-service-broker-auth |
| 231 | + namespace: broker |
| 232 | + url: http://my-service-broker.broker.svc.cluster.local |
| 233 | + catalogRestrictions: |
| 234 | + servicePlan: |
| 235 | + - "spec.externalName==basic" |
| 236 | +``` |
| 237 | + |
| 238 | +When you combine the two capabilities, you can effectively restrict |
| 239 | +provisioning of service classes or plans to very specific namespaces. |
| 240 | +Production grade instances, for example, could be heavily restricted to a small |
| 241 | + subset of users. Other namespaces could be given access to other plans. |
0 commit comments