OpenShift Ansible Broker Configuration

You are viewing documentation for a release that is no longer supported. The latest supported version of version 3 is [3.11]. For the most recent version 4, see [4]

You are viewing documentation for a release that is no longer supported. The latest supported version of version 3 is [3.11]. For the most recent version 4, see [4]

Overview

When the OpenShift Ansible broker (OAB) is deployed in a cluster, its behavior is largely dictated by the broker’s configuration file loaded on startup. The broker’s configuration is stored as a ConfigMap object in the broker’s namespace (ansible-service-broker by default).

Example OpenShift Ansible Broker Configuration File

  1. registry: (1)
  2. - type: dockerhub
  3. name: docker
  4. url: https://registry.hub.docker.com
  5. org: <dockerhub_org>
  6. fail_on_error: false
  7. - type: rhcc
  8. name: rhcc
  9. url: https://registry.access.redhat.com
  10. fail_on_error: true
  11. white_list:
  12. - "^foo.*-apb$"
  13. - ".*-apb$"
  14. black_list:
  15. - "bar.*-apb$"
  16. - "^my-apb$"
  17. - type: local_openshift
  18. name: lo
  19. namespaces:
  20. - openshift
  21. white_list:
  22. - ".*-apb$"
  23. dao: (2)
  24. etcd_host: localhost
  25. etcd_port: 2379
  26. log: (3)
  27. logfile: /var/log/ansible-service-broker/asb.log
  28. stdout: true
  29. level: debug
  30. color: true
  31. openshift: (4)
  32. host: ""
  33. ca_file: ""
  34. bearer_token_file: ""
  35. image_pull_policy: IfNotPresent
  36. sandbox_role: "edit"
  37. keep_namespace: false
  38. keep_namespace_on_error: true
  39. broker: (5)
  40. bootstrap_on_startup: true
  41. dev_broker: true
  42. launch_apb_on_bind: false
  43. recovery: true
  44. output_request: true
  45. ssl_cert_key: /path/to/key
  46. ssl_cert: /path/to/cert
  47. refresh_interval: "600s"
  48. auth:
  49. - type: basic
  50. enabled: true
  51. secrets: (6)
  52. - title: Database credentials
  53. secret: db_creds
  54. apb_name: dh-rhscl-postgresql-apb
1See Registry Configuration for details.
2See DAO Configuration for details.
3See Log Configuration for details.
4See OpenShift Configuration for details.
5See Broker Configuration for details.
6See Secrets Configuration for details.

Modifying the OpenShift Ansible Broker Configuration

To modify the OAB’s default broker configuration after it has been deployed:

  1. Edit the broker-config ConfigMap object in the OAB’s namespace as a user with cluster-admin privileges:

    1. $ oc edit configmap broker-config -n ansible-service-broker
  2. After saving any updates, redeploy the OAB’s deployment configuration for the changes to take effect:

    1. $ oc rollout latest dc/asb -n ansible-service-broker

Registry Configuration

The registry section allows you to define the registries that the broker should look at for APBs.

Table 1. registry Section Configuration Options
FieldDescriptionRequired

name

The name of the registry. Used by the broker to identify APBs from this registry.

Y

user

The user name for authenticating to the registry. Not used when auth_type is set to secret or file.

N

pass

The password for authenticating to the registry. Not used when auth_type is set to secret or file.

N

auth_type

How the broker should read the registry credentials if they are not defined in the broker configuration via user and pass. Can be secret (uses a secret in the broker namespace) or file (uses a mounted file).

N

auth_name

Name of the secret or file storing the registry credentials that should be read. Used when auth_type is set to secret.

N, only required when auth_type is set to secret or file.

org

The namespace or organization that the image is contained in.

N

type

The type of registry. Available adapters are mock, rhcc, openshift, dockerhub, and local_openshift.

Y

namespaces

The list of namespaces to configure the local_openshift registry type with. By default, a user should use openshift.

N

url

The URL that is used to retrieve image information. Used extensively for RHCC while the dockerhub type uses hard-coded URLs.

N

fail_on_error

Should this registry fail, the bootstrap request if it fails. Will stop the execution of other registries loading.

N

white_list

The list of regular expressions used to define which image names should be allowed through. Must have a white list to allow APBs to be added to the catalog. The most permissive regular expression that you can use is .*-apb$ if you would want to retrieve all APBs in a registry. See APB Filtering for more details.

N

black_list

The list of regular expressions used to define which images names should never be allowed through. See APB Filtering for more details.

N

images

The list of images to be used with an OpenShift Container Registry.

N

Production or Development

A production broker configuration is designed to be pointed at a trusted container distribution registry, such as the Red Hat Container Catalog (RHCC):

  1. registry:
  2. - name: rhcc
  3. type: rhcc
  4. url: https://registry.access.redhat.com
  5. tag: v3.10
  6. white_list:
  7. - ".*-apb$"
  8. - type: local_openshift
  9. name: localregistry
  10. namespaces:
  11. - openshift
  12. white_list: []

However, a development broker configuration is primarily used by developers working on the broker. To enable developer settings, set the registry name to dev and the dev_broker field in the broker section to true:

  1. registry:
  2. name: dev
  1. broker:
  2. dev_broker: true

Storing Registry Credentials

The broker configuration determines how the broker should read any registry credentials. They can be read from the user and pass values in the registry section, for example:

  1. registry:
  2. - name: isv
  3. type: openshift
  4. url: https://registry.connect.redhat.com
  5. user: <user>
  6. pass: <password>

If you want to ensure these credentials are not publicly accessible, the auth_type field in the registry section can be set to the secret or file type. The secret type configures a registry to use a secret from the broker’s namespace, while the file type configures a registry to use a secret that has been mounted as a volume.

To use the secret or file type:

  1. The associated secret should have the values username and password defined. When using a secret, you must ensure that the ansible-service-broker namespace exists, as this is where the secret will be read from.

    For example, create a reg-creds.yaml file:

    1. $ cat reg-creds.yaml
    2. ---
    3. username: <user_name>
    4. password: <password>
  2. Create a secret from this file in the ansible-service-broker namespace:

    1. $ oc create secret generic \
    2. registry-credentials-secret \
    3. --from-file reg-creds.yaml \
    4. -n ansible-service-broker
  3. Choose whether you want to use the secret or file type:

    • To use the secret type:

      1. In the broker configuration, set auth_type to secret and auth_name to the name of the secret:

        1. registry:
        2. - name: isv
        3. type: openshift
        4. url: https://registry.connect.redhat.com
        5. auth_type: secret
        6. auth_name: registry-credentials-secret
      2. Set the namespace where the secret is located:

        1. openshift:
        2. namespace: ansible-service-broker
    • To use the file type:

      1. Edit the asb deployment configuration to mount your file into /tmp/registry-credentials/reg-creds.yaml:

        1. $ oc edit dc/asb -n ansible-service-broker

        In the containers.volumeMounts section, add:

        1. volumeMounts:
        2. - mountPath: /tmp/registry-credentials
        3. name: reg-auth

        In the volumes section, add:

        1. volumes:
        2. - name: reg-auth
        3. secret:
        4. defaultMode: 420
        5. secretName: registry-credentials-secret
      2. In the broker configuration, set auth_type to file and auth_type to the location of the file:

        1. registry:
        2. - name: isv
        3. type: openshift
        4. url: https://registry.connect.redhat.com
        5. auth_type: file
        6. auth_name: /tmp/registry-credentials/reg-creds.yaml

Mock Registry

A mock registry is useful for reading local APB specs. Instead of going out to a registry to search for image specs, this uses a list of local specs. Set the name of the registry to mock to use the mock registry.

  1. registry:
  2. - name: mock
  3. type: mock

Dockerhub Registry

The dockerhub type allows you to load APBs from a specific organization in the DockerHub. For example, the ansibleplaybookbundle organization.

  1. registry:
  2. - name: dockerhub
  3. type: dockerhub
  4. org: ansibleplaybookbundle
  5. user: <user>
  6. pass: <password>
  7. white_list:
  8. - ".*-apb$"

APB Filtering

APBs can be filtered out by their image name using a combination of the white_list or black_list parameters, set on a registry basis inside the broker’s configuration.

Both are optional lists of regular expressions that will be run over the total set of discovered APBs for a given registry to determine matches.

Table 2. APB Filter Behavior
PresentAllowedBlocked

Only whitelist

Matches a regex in list.

Any APB that does not match.

Only blacklist

All APBs that do not match.

APBs that match a regex in list.

Both present

Matches regex in whitelist but not in blacklist.

APBs that match a regex in blacklist.

None

No APBs from the registry.

All APBs from that registry.

For example:

Whitelist Only

  1. white_list:
  2. - "foo.*-apb$"
  3. - "^my-apb$"

Anything matching on foo.*-apb$ and only my-apb will be allowed through in this case. All other APBs will be rejected.

Blacklist Only

  1. black_list:
  2. - "bar.*-apb$"
  3. - "^foobar-apb$"

Anything matching on bar.*-apb$ and only foobar-apb will be blocked in this case. All other APBs will be allowed through.

Whitelist and Blacklist

  1. white_list:
  2. - "foo.*-apb$"
  3. - "^my-apb$"
  4. black_list:
  5. - "^foo-rootkit-apb$"

Here, foo-rootkit-apb is specifically blocked by the blacklist despite its match in the whitelist because the whitelist match is overridden.

Otherwise, only those matching on foo.*-apb$ and my-apb will be allowed through.

Example Broker Configuration registry Section:

  1. registry:
  2. - type: dockerhub
  3. name: dockerhub
  4. url: https://registry.hub.docker.com
  5. user: <user>
  6. pass: <password>
  7. org: <org>
  8. white_list:
  9. - "foo.*-apb$"
  10. - "^my-apb$"
  11. black_list:
  12. - "bar.*-apb$"
  13. - "^foobar-apb$"

Local OpenShift Container Registry

Using the local_openshift type will allow you to load APBs from the OpenShift Container Registry that is internal to the OKD cluster. You can configure the namespaces in which you want to look for published APBs.

  1. registry:
  2. - type: local_openshift
  3. name: lo
  4. namespaces:
  5. - openshift
  6. white_list:
  7. - ".*-apb$"

Red Hat Container Catalog Registry

Using the rhcc type will allow you to load APBs that are published to the Red Hat Container Catalog (RHCC) registry.

  1. registry:
  2. - name: rhcc
  3. type: rhcc
  4. url: https://registry.access.redhat.com
  5. white_list:
  6. - ".*-apb$"

Red Hat Connect Partner Registry

Third-party images in the Red Hat Container Catalog are served from the Red Hat Connect Partner Registry at https://registry.connect.redhat.com. The partner_rhcc type allows the broker to be bootstrapped from the Partner Registry to retrieve a list of APBs and load their specs. The Partner Registry requires authentication for pulling images with a valid Red Hat Customer Portal user name and password.

  1. registry:
  2. - name: partner_reg
  3. type: partner_rhcc
  4. url: https://registry.connect.redhat.com
  5. user: <registry_user>
  6. pass: <registry_password>
  7. white_list:
  8. - ".*-apb$"

Because the Partner Registry requires authentication, the following manual step is also required to configure the broker to use the Partner Registry URL:

  1. Run the following command on all nodes of a OKD cluster:

    1. # docker --config=/var/lib/origin/.docker \
    2. login -u <registry_user> -p <registry_password> \
    3. registry.connect.redhat.com

Multiple Registries

You can use more than one registry to separate APBs into logical organizations and be able to manage them from the same broker. The registries must have a unique, non-empty name. If there is no unique name, the service broker will fail to start with an error message alerting you to the problem.

  1. registry:
  2. - name: dockerhub
  3. type: dockerhub
  4. org: ansibleplaybookbundle
  5. user: <user>
  6. pass: <password>
  7. white_list:
  8. - ".*-apb$"
  9. - name: rhcc
  10. type: rhcc
  11. url: <rhcc_url>
  12. white_list:
  13. - ".*-apb$"

Broker Authentication

The broker supports authentication, meaning when connecting to the broker, the caller must supply the Basic Auth or Bearer Auth credentials for each request. Using curl, it is as simple as supplying:

  1. -u <user_name>:<password>

or

  1. -h "Authorization: bearer <token>

to the command. The service catalog must be configured with a secret containing the user name and password combinations or the bearer token.

Basic Auth

To enable Basic Auth usage, set the following in the broker configuration:

  1. broker:
  2. ...
  3. auth:
  4. - type: basic (1)
  5. enabled: true (2)
1The type field specifies the type of authentication to use.
2The enabled field allows you to disable a particular authentication type. This keeps you from having to delete the entire section of auth just to disable it.

Deployment Template and Secrets

Typically the broker is configured using a ConfigMap in a deployment template. You supply the authentication configuration the same way as in the file configuration.

The following is an example of the deployment template:

  1. auth:
  2. - type: basic
  3. enabled: ${ENABLE_BASIC_AUTH}

Another part to Basic Auth is the user name and password used to authenticate against the broker. While the Basic Auth implementation can be backed by different back-end services, the currently supported one is backed by a secret. The secret must be injected into the pod via a volume mount at the /var/run/asb_auth location. This is from where the broker will read the user name and password.

In the deployment template, a secret must be specified. For example:

  1. - apiVersion: v1
  2. kind: Secret
  3. metadata:
  4. name: asb-auth-secret
  5. namespace: ansible-service-broker
  6. data:
  7. username: ${BROKER_USER}
  8. password: ${BROKER_PASS}

The secret must contain a user name and password. The values must be base64 encoded. The easiest way to generate the values for those entries is to use the echo and base64 commands:

  1. $ echo -n admin | base64 (1)
  2. YWRtaW4=
1The -n option is very important.

This secret must now be injected to the pod via a volume mount. This is configured in the deployment template as well:

  1. spec:
  2. serviceAccount: asb
  3. containers:
  4. - image: ${BROKER_IMAGE}
  5. name: asb
  6. imagePullPolicy: IfNotPresent
  7. volumeMounts:
  8. ...
  9. - name: asb-auth-volume
  10. mountPath: /var/run/asb-auth

Then, in the volumes section, mount the secret:

  1. volumes:
  2. ...
  3. - name: asb-auth-volume
  4. secret:
  5. secretName: asb-auth-secret

The above will have created a volume mount located at /var/run/asb-auth. This volume will have two files: a user name and password written by the asb-auth-secret secret.

Configuring Service Catalog and Broker Communication

Now that the broker is configured to use Basic Auth, you must tell the service catalog how to communicate with the broker. This is accomplished by the authInfo section of the broker resource.

The following is an example of creating a broker resource in the service catalog. The spec tells the service catalog what URL the broker is listening at. The authInfo tells it what secret to read to get the authentication information.

  1. apiVersion: servicecatalog.k8s.io/v1alpha1
  2. kind: Broker
  3. metadata:
  4. name: ansible-service-broker
  5. spec:
  6. url: https://asb-1338-ansible-service-broker.172.17.0.1.nip.io
  7. authInfo:
  8. basicAuthSecret:
  9. namespace: ansible-service-broker
  10. name: asb-auth-secret

Starting with v0.0.17 of the service catalog, the broker resource configuration changes:

  1. apiVersion: servicecatalog.k8s.io/v1alpha1
  2. kind: ServiceBroker
  3. metadata:
  4. name: ansible-service-broker
  5. spec:
  6. url: https://asb-1338-ansible-service-broker.172.17.0.1.nip.io
  7. authInfo:
  8. basic:
  9. secretRef:
  10. namespace: ansible-service-broker
  11. name: asb-auth-secret

Bearer Auth

By default, if no authentication is specified the broker will use bearer token authentication (Bearer Auth). Bearer Auth uses delegated authentication from the Kubernetes apiserver library.

Bearer Auth is only available starting in OKD 3.7.

The configuration grants access, through Kubernetes RBAC roles and role bindings, to the URL prefix. The broker has added a configuration option cluster_url to specify the url_prefix. This value defaults to ansible-service-broker.

Example Cluster Role

  1. - apiVersion: authorization.k8s.io/v1
  2. kind: ClusterRole
  3. metadata:
  4. name: access-asb-role
  5. rules:
  6. - nonResourceURLs: ["/ansible-service-broker", "/ansible-service-broker/*"]
  7. verbs: ["get", "post", "put", "patch", "delete"]

Deployment Template and Secrets

The following is an example of creating a secret that the service catalog can use. This example assumes that the role, access-asb-role, has been created already. From the deployment template:

  1. - apiVersion: v1
  2. kind: ServiceAccount
  3. metadata:
  4. name: ansibleservicebroker-client
  5. namespace: ansible-service-broker
  6. - apiVersion: authorization.openshift.io/v1
  7. kind: ClusterRoleBinding
  8. metadata:
  9. name: ansibleservicebroker-client
  10. subjects:
  11. - kind: ServiceAccount
  12. name: ansibleservicebroker-client
  13. namespace: ansible-service-broker
  14. roleRef:
  15. kind: ClusterRole
  16. name: access-asb-role
  17. - apiVersion: v1
  18. kind: Secret
  19. metadata:
  20. name: ansibleservicebroker-client
  21. annotations:
  22. kubernetes.io/service-account.name: ansibleservicebroker-client
  23. type: kubernetes.io/service-account-token

The above example creates a service account, granting access to access-asb-role and creating a secret for that service accounts token.

Configuring Service Catalog and Broker Communication

Now that the broker is configured to use Bearer Auth tokens, you must tell the service catalog how to communicate with the broker. This is accomplished by the authInfo section of the broker resource.

The following is an example of creating a broker resource in the service catalog. The spec tells the service catalog what URL the broker is listening at. The authInfo tells it what secret to read to get the authentication information.

  1. apiVersion: servicecatalog.k8s.io/v1alpha1
  2. kind: ServiceBroker
  3. metadata:
  4. name: ansible-service-broker
  5. spec:
  6. url: https://asb.ansible-service-broker.svc:1338${BROKER_URL_PREFIX}/
  7. authInfo:
  8. bearer:
  9. secretRef:
  10. kind: Secret
  11. namespace: ansible-service-broker
  12. name: ansibleservicebroker-client

DAO Configuration

FieldDescriptionRequired

etcd_host

The URL of the etcd host.

Y

etcd_port

The port to use when communicating with etcd_host.

Y

Log Configuration

FieldDescriptionRequired

logfile

Where to write the broker’s logs.

Y

stdout

Write logs to stdout.

Y

level

Level of the log output.

Y

color

Color the logs.

Y

OpenShift Configuration

FieldDescriptionRequired

host

OKD host.

N

ca_file

Location of the certificate authority file.

N

bearer_token_file

Location of bearer token to be used.

N

image_pull_policy

When to pull the image.

Y

namespace

The namespace that the broker has been deployed to. Important for things like passing parameter values via secret.

Y

sandbox_role

Role to give to an APB sandbox environment.

Y

keep_namespace

Always keep namespace after an APB execution.

N

keep_namespace_on_error

Keep namespace after an APB execution has an error.

N

Broker Configuration

The broker section tells the broker what functionality should be enabled and disabled. It will also tell the broker where to find files on disk that will enable the full functionality.

FieldDescriptionDefault ValueRequired

dev_broker

Allow development routes to be accessible.

false

N

launch_apb_on_bind

Allow bind to be a no-op.

false

N

bootstrap_on_startup

Allow the broker attempt to bootstrap itself on start up. Will retrieve the APBs from configured registries.

false

N

recovery

Allow the broker to attempt to recover itself by dealing with pending jobs noted in etcd.

false

N

output_request

Allow the broker to output the requests to the log file as they come in for easier debugging.

false

N

ssl_cert_key

Tells the broker where to find the TLS key file. If not set, the API server will attempt to create one.

“”

N

ssl_cert

Tells the broker where to find the TLS .crt file. If not set, the API server will attempt to create one.

“”

N

refresh_interval

The interval to query registries for new image specs.

“600s”

N

auto_escalate

Allows the broker to escalate the permissions of a user while running the APB.

false

N

cluster_url

Sets the prefix for the URL that the broker is expecting.

ansible-service-broker

N

Async bind and unbind is an experimental feature and is not supported or enabled by default. With the absence of async bind, setting launch_apb_on_bind to true can cause the bind action to timeout and will span a retry. The broker will handle this with “409 Conflicts” because it is the same bind request with different parameters.

Secrets Configuration

The secrets section creates associations between secrets in the broker’s namespace and APBs the broker runs. The broker uses these rules to mount secrets into running APBs, allowing the user to use secrets to pass parameters without exposing them to the catalog or users.

The section is a list where each entry has the following structure:

FieldDescriptionRequired

title

The title of the rule. This is just for display and output purposes.

Y

apb_name

The name of the APB to associate with the specified secret. This is the fully qualified name (<registry_name>-<image_name>).

Y

secret

The name of the secret to pull parameters from.

Y

You can download and use the create_broker_secret.py file to create and format this configuration section.

  1. secrets:
  2. - title: Database credentials
  3. secret: db_creds
  4. apb_name: dh-rhscl-postgresql-apb

Running Behind a Proxy

When running the OAB inside of a proxied OKD cluster, it is important to understand its core concepts and consider them within the context of a proxy used for external network access.

As an overview, the broker itself runs as a pod within the cluster. It has a requirement for external network access depending on how its registries have been configured.

Registry Adapter Whitelists

The broker’s configured registry adapters must be able to communicate with their external registries in order to bootstrap successfully and load remote APB manifests. These requests can be made via the proxy, however, the proxy must ensure that the required remote hosts are accessible.

Example required whitelisted hosts:

Registry Adapter TypeWhitelisted Hosts

rhcc

registry.access.redhat.com, access.redhat.com

dockerhub

docker.io

Configuring the Broker Behind a Proxy Using Ansible

If during initial installation you configure your OKD cluster to run behind a proxy (see Configuring Global Proxy Options), when the OAB is deployed it will:

  • inherit those cluster-wide proxy settings automatically and

  • generate the required NO_PROXY list, including the cidr fields and serviceNetworkCIDR,

and no further configuration is needed.

Configuring the Broker Behind a Proxy Manually

If your cluster’s global proxy options were not configured during initial installation or prior to the broker being deployed, or if you have modified the global proxy settings, you must manually configure the broker for external access via proxy:

  1. Before attempting to run the OAB behind a proxy, review Working with HTTP Proxies and ensure your cluster is configured accordingly to run behind a proxy.

    In particular, the cluster must be configured to not proxy internal cluster requests. This is typically configured with a NO_PROXY setting of:

    1. .cluster.local,.svc,<serviceNetworkCIDR_value>,<master_IP>,<master_domain>,.default

    in addition to any other desired NO_PROXY settings. See Configuring NO_PROXY for more details.

    Brokers deploying unversioned, or v1 APBs must also add 172.30.0.1 to their NO_PROXY list. APBs prior to v2 extracted their credentials from running APB pods via an exec HTTP request, rather than a secret exchange. Unless you are running a broker with experimental proxy support in a cluster prior to OKD 3.9, you probably do not have to worry about this.

  2. Edit the broker’s DeploymentConfig as a user with cluster-admin privileges:

    1. $ oc edit dc/asb -n ansible-service-broker
  3. Set the following environment variables:

    • HTTP_PROXY

    • HTTPS_PROXY

    • NO_PROXY

  4. After saving any updates, redeploy the OAB’s deployment configuration for the changes to take effect:

    1. $ oc rollout latest dc/asb -n ansible-service-broker

Setting Proxy Environment Variables in Pods

It is common that APB pods themselves may require external access via proxy as well. If the broker recognizes it has a proxy configuration, it will transparently apply these environment variables to the APB pods that it spawns. As long as the modules used within the APB respect proxy configuration via environment variable, the APB will also use these settings to perform its work.

Finally, it is possible the services spawned by the APB may also require external network access via proxy. The APB must be authored to set these environment variables explicitly if recognizes them in its own execution environment, or the cluster operator must manually modify the required services to inject them into their environments.