|
| 1 | +### Service binding files |
| 2 | + |
| 3 | +By default, service binding details are exposed to an app through the `VCAP_SERVICES` environment variable. Two mutually exclusive app features instead expose them as files on the container's file system. Only one of the two features may be enabled for an app at a time. |
| 4 | + |
| 5 | +- **file-based-vcap-services** writes the full contents of `VCAP_SERVICES` verbatim to a single file named `vcap_services`. |
| 6 | +- **service-binding-k8s** translates each service binding into its own directory of files, as described below. |
| 7 | + |
| 8 | +#### Translation of VCAP_SERVICES to service binding files |
| 9 | + |
| 10 | +When **service-binding-k8s** is enabled, the service binding details in `VCAP_SERVICES` are converted into a tree of files, following the [servicebinding.io](https://servicebinding.io/spec/core/1.1.0/#workload-projection) workload-projection specification. The binding's name becomes a directory name, and each of the binding's properties becomes a file within that directory whose contents are the property's value. |
| 11 | + |
| 12 | +The translation follows these rules: |
| 13 | + |
| 14 | +- Each binding name must be unique and valid; duplicate or invalid names cause an error. A name must match `[a-z0-9\-.]{1,253}` (per the Kubernetes/servicebinding.io spec). |
| 15 | +- The binding's name is used as the directory name; its properties become the file names. |
| 16 | +- The `credentials` attribute is a JSON object: each top-level key becomes a file whose content is that key's value. Nested objects and lists are serialized as JSON. |
| 17 | +- Reserved attributes may overwrite credential keys of the same name without error. The reserved attributes are: `binding_guid`, `binding_name`, `instance_guid`, `instance_name`, `name`, `label`, `tags`, `plan`, `syslog_drain_url`, `volume_mounts`, `type`, and `provider`. |
| 18 | +- All file names must match `[a-z0-9\-._]{1,253}`; an invalid name causes an error. The underscore follows a post-1.1.0 update to the servicebinding.io spec ([commit `b5d6755`](https://github.com/servicebinding/spec/commit/b5d67551d13c8801f6b8a084c70b7167e3fbbe7e)), which is not yet part of a published spec release. |
| 19 | +- List values (for example `tags` or `volume_mounts`) are stored as JSON arrays. |
| 20 | +- Empty lists and `null` values are omitted - no file is created. |
| 21 | +- Cloud Controller always writes a `type` file and a `provider` file, both set to the service label. |
| 22 | +- If the total byte size (file paths plus contents) exceeds **1,000,000 bytes**, an error is raised. |
| 23 | + |
| 24 | +##### Examples |
| 25 | + |
| 26 | +The following examples illustrate individual translation rules, showing only the properties relevant to each rule. |
| 27 | + |
| 28 | +Nested and list credentials are serialized as JSON. |
| 29 | + |
| 30 | +Input (`VCAP_SERVICES`): |
| 31 | + |
| 32 | +```json |
| 33 | +{ |
| 34 | + "foo": [ |
| 35 | + { |
| 36 | + "name": "foo", |
| 37 | + "credentials": { |
| 38 | + "simple": "value", |
| 39 | + "deeply": { |
| 40 | + "nested": "value" |
| 41 | + }, |
| 42 | + "list": ["v", "a", "l", "u", "e"] |
| 43 | + } |
| 44 | + } |
| 45 | + ] |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +Output (service binding files): |
| 50 | + |
| 51 | +``` |
| 52 | +foo/name: foo |
| 53 | +foo/simple: value |
| 54 | +foo/deeply: {"nested":"value"} |
| 55 | +foo/list: ["v","a","l","u","e"] |
| 56 | +``` |
| 57 | + |
| 58 | +A reserved attribute overwrites a credential key (the `name` credential is dropped in favor of the binding's `name`). |
| 59 | + |
| 60 | +Input (`VCAP_SERVICES`): |
| 61 | + |
| 62 | +```json |
| 63 | +{ |
| 64 | + "foo": [ |
| 65 | + { |
| 66 | + "name": "foo", |
| 67 | + "credentials": { |
| 68 | + "name": "user", |
| 69 | + "secret": "password" |
| 70 | + } |
| 71 | + } |
| 72 | + ] |
| 73 | +} |
| 74 | +``` |
| 75 | + |
| 76 | +Output (service binding files): |
| 77 | + |
| 78 | +``` |
| 79 | +foo/name: foo |
| 80 | +foo/secret: password |
| 81 | +``` |
| 82 | + |
| 83 | +`null` and empty values are omitted. |
| 84 | + |
| 85 | +Input (`VCAP_SERVICES`): |
| 86 | + |
| 87 | +```json |
| 88 | +{ |
| 89 | + "foo": [ |
| 90 | + { |
| 91 | + "name": "foo", |
| 92 | + "binding_guid": "45436ca8-0a7c-45e3-9439-ca1b44db7a2b", |
| 93 | + "syslog_drain_url": null, |
| 94 | + "volume_mounts": [] |
| 95 | + } |
| 96 | + ] |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +Output (service binding files): |
| 101 | + |
| 102 | +``` |
| 103 | +foo/name: foo |
| 104 | +foo/binding_guid: 45436ca8-0a7c-45e3-9439-ca1b44db7a2b |
| 105 | +``` |
0 commit comments