Skip to content

Commit 47a725a

Browse files
authored
Merge pull request #1198 from cloudfoundry/create-rfc-binding-recreation
[RFC] Service Credential Binding Rotation for Apps
2 parents 32ced3f + 53f7468 commit 47a725a

File tree

1 file changed

+131
-0
lines changed

1 file changed

+131
-0
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# Meta
2+
[meta]: #meta
3+
- Name: Service Credential Binding Rotation for Applications
4+
- Start Date: 2025-06-10
5+
- Authors: @beyhan, @stephanme
6+
- Status: Draft <!-- Acceptable values: Draft, Approved, On Hold, Superseded -->
7+
- RFC Pull Request: (fill in with PR link after you submit it)
8+
9+
## Summary
10+
11+
Cloud Controller does not support creating a second binding between an application and a service instance, which prevents seamless rotation of credential bindings. As a result, the only current method to rotate service credential bindings is through blue-green deployments, a process that many developers are hesitant to use solely for credential rotation. That is why, this RFC proposes to add support for multiple service credential bindings per service instance and application. To simplify the rotation process the RFC suggests a new CF API endpoint and CF CLI extensions.
12+
13+
## Problem
14+
15+
Cloud Controller does not support creation of a second binding for a service instance and application which would enable seamless binding credential rotation. Attempting to create a second binding using the CF CLI results in the following error:
16+
17+
```
18+
cf bind-service myApp myService --binding-name second-binding
19+
Binding service instance myService to app myApp in org myOrg / space mySpace as ...
20+
App myApp is already bound to service instance myService.
21+
OK
22+
```
23+
This limitation is not due to the CF CLI but rather a restriction in the CC API, which prevents multiple bindings for the same application. Attempting to create the binding directly via the CF API results in a similar error:
24+
25+
```
26+
cf curl -X POST "/v3/service_credential_bindings" -d '{
27+
"name": "test-second-binding",
28+
"relationships": {
29+
"app": {
30+
"data": {
31+
"guid": "<myApp-guid>"
32+
}
33+
},
34+
"service_instance": {
35+
"data": {
36+
"guid": "<mySerivce-guid>"
37+
}
38+
}
39+
},
40+
"type": "app"
41+
}'
42+
43+
{"errors":[{"detail":"The app is already bound to the service instance","title":"CF-UnprocessableEntity","code":10008}]}
44+
```
45+
As a result, the only way to rotate service credential bindings currently is by performing blue-green deployments. However, many CF application developers are reluctant to push a new version of their application solely for the purpose of credential rotation.
46+
47+
## Proposal
48+
49+
The CC should allow multiple service credential bindings per service instance and application. Only the newest one should be visible in the application VCAP_SERVICES env var (or file-based service binding information) so that existing applications don’t need to change.
50+
51+
### CF Cloud Controller
52+
53+
#### POST /v3/service_credential_bindings
54+
55+
Shall allow the creation of multiple service credential bindings for the same app and service instance under the following conditions:
56+
- service credential bindings are of type `app`
57+
- bindings of type `key` don't have a reference to an application
58+
- multiple service keys for a service instance are already supported
59+
- service credential binding name is not changed
60+
- multiple bindings to the same service instance are intended for credential rotation
61+
- VCAP_SERVICES structure doesn't allow multiple bindings to the same service instance so different binding names don't make sense
62+
63+
The number of multiple service credential bindings for the same app and service instance should be limited. The limit prevents a DoS threat and eventually reminds users to clean up old, likely outdated bindings.
64+
65+
#### GET /v3/service_credential_bindings
66+
67+
The API `GET /v3/service_credential_bindings` will return all service credential bindings of an application including multiple bindings to the same service instance.
68+
69+
### Mapping of service credential bindings into application containers
70+
71+
When creating the service credential binding information like VCAP_SERVICES or file-based one the CC must select the newest one per service instance only that is in state `succeeded`. This must be based on the `created_at` and `last_operation.state` fields from the credential binding.
72+
73+
An application restart or restage as today will be required to activate the new binding.
74+
75+
### CF CLI
76+
77+
Users can create multiple service credential bindings by invoking the `bind-service` command with a `--strategy multiple` option. The default strategy `single` ensures backward compatibility of the `cf bind-service` command.
78+
79+
Example:
80+
```
81+
cf bind-service myApp myService # create initial binding
82+
cf bind-service myApp myService # succeeds with message "App myApp is already bound to service instance myService." No secondary binding is added.
83+
cf bind-service myApp myService --strategy single # same as previous command, 'single' is the default strategy
84+
85+
cf bind-service myApp myService --strategy multiple # adds a secondary binding to the same service instance
86+
cf bind-service myApp myService --strategy multiple # adds a third binding to the same service instance
87+
```
88+
89+
The exact parameter naming can be finalized at implementation time. A `strategy` parameter allows future extension, e.g. for OSBAPI 2.17 support mention in section "Possible Future Work".
90+
91+
`cf unbind-service myApp myService` shall delete all existing service credential bindings for `myApp` to `myService`.
92+
An additional parameter `cf unbind-service --guid <guid>` should support the deletion of a single service credential binding.
93+
94+
`cf service myService` should list all bindings to apps including their `guid` and `created_at` timestamp. This information is helpful to understand which binding will be mapped into the application container.
95+
96+
The cleanup of old service credential bindings should be supported by a new CF CLI command:
97+
```
98+
cf cleanup-outdated-service-bindings myApp [--service-instance myService] [--keep-last 1]
99+
```
100+
The CLI will use the CF API `GET /v3/service_credential_bindings?app_guids=:guid` to list the service instance bindings for an application and should delete all old bindings based on the creation date leaving the newest service bindings. With the `keep-last` parameter, users can keep the x newest bindings per app and service instance. If no service instance name is provided, the CLI should delete the old bindings of all services currently bound to the application.
101+
It is in the responsibility of the user to invoke `cf cleanup-outdated-service-bindings myApp` only after a successfully restage/restart of the app, i.e. when old service credential bindings are not used anymore by any app container.
102+
103+
A full service binding rotation flow with the CF CLI could look like:
104+
```
105+
cf bind-service myApp myService -c {<parameters>} --strategy multiple
106+
cf bind-service myApp myService2 -c {<parameters>} --strategy multiple
107+
cf restage myApp --strategy rolling
108+
cf cleanup-outdated-service-bindings myApp
109+
```
110+
111+
## Possible Future Work
112+
113+
### CC adoption of OSBAPI 2.17
114+
115+
The CC could use the service binding rotation functionality introduced with the OSBAPI 2.17 and introduce a dedicated API endpoint for rotation, e.g. `POST /v3/service_credential_bindings/:guid/actions/duplicate` (good naming to be found).
116+
117+
### Integrate Service Binding Recreation into Rolling Deployment
118+
119+
Here an example how this could look with the CF CLI:
120+
```
121+
cf restage myApp –strategy rolling-with-binding-rotation
122+
```
123+
The result should be that all bindings of the application are recreated after a successful restage.
124+
125+
### Binding Recreation with no App Restart
126+
127+
With the adoption of file-based service bindings in Diego it is technically possible to update a service instance binding for a running application container at runtime without requiring an application restart. Things to consider:
128+
- This will require an extension of the CC and Diego API (https://github.com/cloudfoundry/bbs/blob/main/docs/053-actions.md )
129+
- CF application will need support for service binding credential updates during runtime
130+
- Some service bindings requiring restage can’t be supported
131+
- CC will need a trigger to update the service binding information for the corresponding LRP(s)

0 commit comments

Comments
 (0)