Skip to content

Commit 6c62773

Browse files
authored
Merge pull request #551 from sap-contributions/add-file-based-service-binding-docs
Add file-based service binding information to dev docs
2 parents ec9b851 + ec9823a commit 6c62773

7 files changed

+174
-26
lines changed

deploy-apps/environment-variable.html.md.erb

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Environment variables are the means <%= vars.app_runtime_abbr %> uses to communi
1515
For information about setting your own app-specific environment variables, see the [Environment variable](./manifest.html#env-block) in _Deploying with app manifests_.
1616

1717
<p class="note important">
18-
Do not use user-provided environment variables for security-sensitive information such as credentials. They might unintentionally show up in cf CLI output and Cloud Controller logs. Use <a href="../services/user-provided.html">user-provided service instances</a> instead. The system-provided environment variable <a href="#VCAP_SERVICES">VCAP_SERVICES</a> is properly redacted for user roles such as Space Supporter and in Cloud Controller log files.</p>
18+
Do not use user-provided environment variables for security-sensitive information such as credentials. They might unintentionally show up in cf CLI output and Cloud Controller logs. Use <a href="../services/user-provided.html">user-provided service instances</a> instead. Credentials which are provided to the app via service bindings are redacted for user roles such as Space Supporter and in Cloud Controller log files.</p>
1919

2020
<p class="note important">
2121
The maximum size of an environment variable is 130&nbsp;KB. This limit applies also to <%= vars.app_runtime_abbr %> system environment variables such as <code>VCAP_SERVICES</code> and <code>VCAP_APPLICATION</code>.</p>
@@ -25,10 +25,15 @@ The maximum size of an environment variable is 130&nbsp;KB. This limit applies a
2525

2626
Using the Cloud Foundry Command Line Interface (cf CLI), you can run the `cf env` command to view the <%= vars.app_runtime_abbr %> environment variables for your app. The `cf env` command displays the following environment variables:
2727

28-
* The `VCAP_APPLICATION` and `VCAP_SERVICES` variables provided in the container environment
29-
28+
* The `VCAP_APPLICATION` variable, which contains app metadata
3029
* The user-provided variables set using the `cf set-env` command
3130

31+
There are 3 possible ways of providing service binding data to apps, see [Credential Delivery Methods](../services/application-binding.html#credential-delivery-methods). Depending on the chosen method there will be one of the following environment variables:
32+
33+
* [VCAP_SERVICES](#VCAP-SERVICES)
34+
* [SERVICE_BINDING_ROOT](#SERVICE-BINDING-ROOT) (experimental)
35+
* [VCAP_SERVICES_FILE_PATH](#VCAP-SERVICES-FILE-PATH) (experimental)
36+
3237
For more information about the `cf env` command, see [env](http://cli.cloudfoundry.org/en-US/cf/env.html) in the cf CLI documentation. For more information about the `cf set-env` command, see [set-env](http://cli.cloudfoundry.org/en-US/cf/set-env.html) in the cf CLI documentation.
3338

3439
The following example demonstrates the environment variables `cf env` displays:
@@ -100,12 +105,14 @@ The following table lists the system variables available to your application con
100105
| `PATH` | x | x | x |
101106
| `PORT` | x | | |
102107
| `PWD` | x | x | x |
108+
| `SERVICE_BINDING_ROOT` | x | x | x |
103109
| `TMPDIR` | x | | x |
104110
| `USER` | x | x | x |
105111
| `VCAP_APP_HOST` | x | | |
106112
| `VCAP_APP_PORT` | x | | |
107113
| `VCAP_APPLICATION` | x | x | x |
108114
| `VCAP_SERVICES` | x | x | x |
115+
| `VCAP_SERVICES_FILE_PATH` | x | x | x |
109116

110117
### <a id='CF-INSTANCE-ADDR'></a> CF_INSTANCE_ADDR
111118

@@ -222,6 +229,12 @@ The present working directory where the buildpack that processed the app ran.
222229

223230
For example: `PWD=/home/vcap/app`
224231

232+
### <a id='SERVICE-BINDING-ROOT'></a> SERVICE_BINDING_ROOT (experimental)
233+
234+
The root directory location, which contains the service binding information. This needs to be enabled by an app feature flag. See [Service Binding K8s](../services/application-binding.html#service-binding-k8s) for information on how to enable and how service binding data is stored in this directory.
235+
236+
For example: `SERVICE_BINDING_ROOT=/etc/cf-service-bindings`
237+
225238
### <a id='TMPDIR'></a> TMPDIR
226239

227240
The directory location where temporary and staging files are stored.
@@ -270,6 +283,8 @@ This environment variable contains the associated attributes for a deployed app.
270283

271284
For bindable services, <%= vars.app_runtime_abbr %> adds connection details to the `VCAP_SERVICES` environment variable when you restart your app, after binding a service instance to your app. For more information about bindable services, see [Services overview](../services/index.html).
272285

286+
This is the default [Credential Delivery Method](../services/application-binding.html#credential-delivery-methods).
287+
273288
<%= vars.app_runtime_abbr %> returns the results as a JSON document that contains an object for each service for which one or more instances are bound to the app. The service object contains a child object for each instance of the service that is bound to the app.
274289

275290
The following table defines the attributes that describe a bound service. The key for each service in the JSON document is the same as the value of the "label" attribute.
@@ -341,6 +356,11 @@ VCAP_SERVICES=
341356
}
342357
~~~
343358

359+
### <a id='VCAP-SERVICES-FILE-PATH'></a> VCAP_SERVICES_FILE_PATH (experimental)
360+
361+
The path to the file containing the service binding information in JSON format. This needs to be enabled by an app feature flag. See [File-based VCAP services](../services/application-binding.html#file-based-vcap-services) for more information.
362+
363+
For example: `VCAP_SERVICES_FILE_PATH=/etc/cf-service-bindings/vcap_services`
344364

345365
## <a id='evgroups'></a> Environment variable groups
346366

deploy-apps/large-app-deploy.html.md.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ To deploy large apps to <%= vars.app_runtime_abbr %>, ensure that:
2626

2727
* The size of each environment variable for your app does not exceed 130&nbsp;KB. This includes <%= vars.app_runtime_abbr %> system environment variables such as `VCAP_SERVICES` and `VCAP_APPLICATION`. For more information, see [<%= vars.app_runtime_abbr %> environment variables](environment-variable.html).
2828

29+
* If VCAP_SERVICES does get too large either because of too many service bindings or too much data provided by the services, check out the other two [Credential Delivery Methods](../services/application-binding.html#credential-delivery-methods) which have a limit of 1 MB.
30+
2931
* You push only the files that are necessary for your app. To meet this requirement, push only the directory for your app, and remove unneeded files or use the `.cfignore` file to specify excluded files. For more information about specifying excluded files, see [Ignore unnecessary files when pushing](prepare-to-deploy.html#exclude) in _Considerations for Designing and Running an App in the Cloud_.
3032

3133
* You configure Cloud Foundry Command Line Interface (cf CLI) staging, startup, and timeout settings to override settings in the manifest, as necessary:

deploy-apps/manifest-attributes.html.md.erb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ For example:
695695
<div class="note important">
696696
<ul>
697697
<li>You must name variables with alphanumeric characters and underscores. Non-conforming variable names might cause unpredictable behavior.</li>
698-
<li>Do not use user-provided environment variables for security sensitive information such as credentials, because they might unintentionally show up in cf CLI output and Cloud Controller logs. Use <a href="../services/user-provided.html">user-provided service instances</a> instead. The system-provided environment variable <a href="./environment-variable.html#VCAP-SERVICES">VCAP_SERVICES</a> is properly redacted for user roles such as Space Supporter and in Cloud Controller log files.</li>
698+
<li>Do not use user-provided environment variables for security sensitive information such as credentials, because they might unintentionally show up in cf CLI output and Cloud Controller logs. Use <a href="../services/user-provided.html">user-provided service instances</a> instead. Credentials which are provided to the app via service bindings are redacted for user roles such as Space Supporter and in Cloud Controller log files.</li>
699699
</ul>
700700
</div>
701701

@@ -776,8 +776,7 @@ For example:
776776
- instance_XYZ
777777
```
778778

779-
You can bind an app to a service instance by setting the `VCAP_SERVICES` environment variable. For more information, see [Bind a
780-
service](../services/application-binding.html#bind) in _Delivering Service Credentials to an App_.
779+
For more information, see [Bind a service](../services/application-binding.html#bind) in _Delivering Service Credentials to an App_.
781780

782781

783782
## <a id='deprecated'></a> Deprecated app manifest features

services/_using-vol-services.html.md.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ To access the volume service from your app, you must know which file path to use
133133

134134
You can view the file path in the details of the service binding, which are available from the `VCAP_SERVICES` environment variable. See [VCAP_SERVICES](../deploy-apps/environment-variable.html#view-env).
135135

136+
Check [Credential Delivery Methods](./application-binding.html#credential-delivery-methods) on how to retrieve the volume mount information if you chose to use file-based service bindings.
137+
136138
To access the volume service from your app:
137139

138140
1. View environment variables for your app. Run:

services/application-binding.html.md.erb

Lines changed: 139 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ You can bind your apps to service instances for the purpose of generating creden
99

1010
## <a id='bind'></a>Bind a service instance
1111

12-
Binding a service instance to your app triggers credentials to be provisioned for the service instance and delivered to the app runtime in the [VCAP_SERVICES](../deploy-apps/environment-variable.html) environment variable. For details about consuming these credentials with your app, see [Using bound service instances](#use).
12+
Binding a service instance to your app triggers credentials to be provisioned for the service instance and delivered to the app runtime. CloudFoundry offers 3 different methods to deliver those credentials to the app.
13+
14+
For details about the different delivery methods and consumption of these credentials with your app, see [Credential Delivery Methods](#credential-delivery-methods).
1315

1416
Not all services support binding, as some services deliver value to users directly without integration with an app. In many cases, binding credentials are unique to an app, and another app bound to the same service instance receives different credentials, but this depends on the service.
1517

@@ -25,6 +27,140 @@ $ cf restart my-app
2527
<p class="note important">
2628
You must restart or in some cases re-push your app for changes to be applied to the <a href="../deploy-apps/environment-variable.html">VCAP_SERVICES</a> environment variable and for the app to recognize these changes.</p>
2729

30+
### <a id='credential-delivery-methods'></a> Credential Delivery Methods
31+
32+
After your service instance is created and bound to your app, the credentials together with some metadata are available in the app container and can be consumed by your app.
33+
There are the following three delivery methods, which are mutually exclusive. The developer can choose which one to use and needs to adjust the consumption in the app accordingly.
34+
For details about consuming credentials specific to your development framework, see the Service Binding section in the documentation for your framework's [buildpack](../../buildpacks/index.html).
35+
36+
#### <a id='vcap-services'></a> Default VCAP_SERVICES environment variable
37+
38+
By default credentials and additional metadata for all bound service instances are stored in the <a href="../deploy-apps/environment-variable.html">VCAP_SERVICES</a> environment variable.
39+
40+
There are two methods developers can use to have their apps consume binding credentials.
41+
42+
* **Parse the JSON yourself:** See the documentation for [VCAP_SERVICES](../deploy-apps/environment-variable.html#VCAP-SERVICES). Helper libraries are available for some frameworks.
43+
* **Auto-configuration:** Some buildpacks create a service connection for you by creating additional environment variables, updating config files, or passing system parameters to the JVM.
44+
45+
For checking the binding data manually app developers can use `cf env`. See [View Env](../deploy-apps/environment-variable.html#view-env).
46+
47+
<p class="note important">
48+
The maximum size of content of the VCAP_SERVICES environment variable is 130 KB. If you want to bind more services to the app or the services you want to bind provide lots of data, you can use one of the other methods.</p>
49+
50+
#### <a id='file-based-vcap-services'></a> File-based VCAP services (experimental)
51+
52+
This delivery method is used when the app feature [file-based-vcap-services](https://v3-apidocs.cloudfoundry.org/index.html#app-features) is enabled.
53+
The environment variable [VCAP_SERVICES_FILE_PATH](../deploy-apps/environment-variable.html#VCAP-SERVICES-FILE-PATH) will be made available in the app container and contains the path to a file containing the same content as the VCAP_SERVICES environment variable above.
54+
55+
The binding data can be viewed like this:
56+
57+
```
58+
cf ssh <app_name> -c 'cat $VCAP_SERVICES_FILE_PATH'
59+
```
60+
61+
<p class="note important">
62+
The vcap_services file content cannot exceed 1 MB, otherwise an <code>IncompatibleBindings</code> error is raised.</p>
63+
64+
#### <a id='service-binding-k8s'></a> Service Binding K8s (experimental)
65+
66+
This delivery method is used when the app feature [service-binding-k8s](https://v3-apidocs.cloudfoundry.org/index.html#app-features) is enabled.
67+
The environment variable [SERVICE_BINDING_ROOT](../deploy-apps/environment-variable.html#SERVICE-BINDING-ROOT) will be made available in the app container and contains the path to the root folder of a file structure containing binding information.
68+
This method is fully compatible with the specification on [servicebinding.io](https://servicebinding.io/), which is used by Kubernetes as well.
69+
70+
The binding data can be viewed like this:
71+
72+
```
73+
cf ssh <app_name> -c 'find $SERVICE_BINDING_ROOT -type f -exec bash -c "echo {}: \$(cat {})" \;'
74+
```
75+
76+
<p class="note important">
77+
The bytesize of all files and their content combined cannot exceed 1 MB, otherwise an <code>IncompatibleBindings</code> error is raised.</p>
78+
79+
Here are some examples outlining the transformation of VCAP_SERVICES to the file structure:
80+
81+
Nested structures inside their value will be serialized as JSON objects. The same applies if the value is a list.
82+
83+
```
84+
VCAP_SERVICES= {
85+
"foo": [
86+
{
87+
"name": "foo",
88+
"credentials": {
89+
"simple": "value",
90+
"deeply": {
91+
"nested": "value"
92+
},
93+
"list": ["v", "a", "l", "u", "e"]
94+
}
95+
}
96+
]
97+
}
98+
99+
Service Binding Files:
100+
foo/name: foo
101+
foo/simple: value
102+
foo/deeply: {"nested":"value"}
103+
foo/list: ["v","a","l","u","e"]
104+
```
105+
106+
Existing credential keys can be overwritten by other attributes, that are [VCAP_SERVICES](../deploy-apps/environment-variable.html#VCAP-SERVICES) attributes plus type and provider. The full list of reserved file names is: binding-guid, binding-name, instance-guid, instance-name, name, label, tags, plan, syslog-drain-url, volume-mounts, type, and provider. Overwriting an existing key does not result in an error.
107+
108+
```
109+
VCAP_SERVICES= {
110+
"foo": [
111+
{
112+
"name": "foo",
113+
"credentials": {
114+
"name": "user",
115+
"secret": "password"
116+
}
117+
}
118+
]
119+
}
120+
121+
Service Binding Files:
122+
foo/name: foo
123+
foo/secret: password
124+
```
125+
126+
Empty lists or null values are omitted, i.e. no file will be created.
127+
128+
```
129+
VCAP_SERVICES= {
130+
"foo": [
131+
{
132+
"name": "foo",
133+
"binding_guid": "45436ca8-0a7c-45e3-9439-ca1b44db7a2b",
134+
"syslog_drain_url": null,
135+
"volume_mounts": []
136+
}
137+
]
138+
}
139+
140+
Service Binding Files:
141+
foo/name: foo
142+
foo/binding-guid: 45436ca8-0a7c-45e3-9439-ca1b44db7a2b
143+
```
144+
145+
Binding names and keys resulting in filenames must match [a-z0-9\-.]{1,253}. Invalid binding names and keys will result in IncompatibleBindings error. VCAP_SERVICES attributes are transformed to comply to this schema, i.e. underscores are replaced by hyphens, so that e.g. VCAP_SERVICES attribute binding_guid becomes file name binding-guid.
146+
147+
```
148+
VCAP_SERVICES= {
149+
"foo": [
150+
{
151+
"name": "foo",
152+
"binding_guid": "45436ca8-0a7c-45e3-9439-ca1b44db7a2b",
153+
"instance_guid": "83745ca8-0a7c-45e3-9439-ca1b44db7a2b"
154+
}
155+
]
156+
}
157+
158+
Service Binding Files:
159+
foo/name: foo
160+
foo/binding-guid: 45436ca8-0a7c-45e3-9439-ca1b44db7a2b
161+
foo/instance-guid: 83745ca8-0a7c-45e3-9439-ca1b44db7a2b
162+
```
163+
28164
### <a id='arbitrary-params-binding'></a> Arbitrary parameters
29165

30166
Some services support additional configuration parameters with the bind request. These parameters are passed in a valid JSON object containing service-specific configuration parameters, provided either in-line or in a file. For a list of supported configuration parameters, see documentation for the particular service offering.
@@ -90,7 +226,7 @@ OK
90226

91227
The provided name is available in the `name` and `binding_name` properties in the [VCAP_SERVICES](../deploy-apps/environment-variable.html) environment variable:
92228

93-
~~~
229+
```
94230
"VCAP_SERVICES": {
95231
"service-name": [
96232
{
@@ -100,16 +236,7 @@ The provided name is available in the `name` and `binding_name` properties in th
100236
}
101237
]
102238
}
103-
~~~
104-
105-
### <a id='use'></a>Using bound service instances
106-
107-
After your service instance is created and bound to your app, you must configure the app to dynamically fetch the credentials for your service instance. The [VCAP_SERVICES](../deploy-apps/environment-variable.html#VCAP-SERVICES) environment variable contains credentials and additional metadata for all bound service instances. There are two methods developers can use to have their apps consume binding credentials.
108-
109-
* **Parse the JSON yourself:** See the documentation for [VCAP_SERVICES](../deploy-apps/environment-variable.html#VCAP-SERVICES). Helper libraries are available for some frameworks.
110-
* **Auto-configuration:** Some buildpacks create a service connection for you by creating additional environment variables, updating config files, or passing system parameters to the JVM.
111-
112-
For details about consuming credentials specific to your development framework, see the Service Binding section in the documentation for your framework's [buildpack](../../buildpacks/index.html).
239+
```
113240

114241
## <a id='update-credentials'></a>Update service credentials
115242

0 commit comments

Comments
 (0)