Skip to content

Support loading file-based service bindings #47858

@beyhan

Description

@beyhan

This issue proposes to add support for file-based service bindings in Spring Boot, as specified in Cloud Foundry RFC-0030 and supported since CF version v48.5.0.

Currently, service binding information is provided to applications through the VCAP_SERVICES environment variable, which has:

  • Size Limit: The Linux kernel imposes a size limit of 130KB on environment variables, which can be reached when an application is bound to a large number of services.
  • Dynamic Updates: Service binding updates require an application to be restaged, which prevents the adoption of features like on-the-fly credential rotation.

That is why, the RFC-0030 introduces a file-based approach to address these limitations. There are two alternatives support in CF to provide the file-based service bindings:

  1. Store the VCAP_SERVICES content in a file. The file's location is specified by the VCAP_SERVICES_FILE_PATH environment variable, and the content format remains the same as the VCAP_SERVICES environment variable.
  2. The second option is an implementation of the K8s service binding specification. The environment variable SERVICE_BINDING_ROOT defines the location for the service bindings. The name of the file and the format follow the K8s specification

I think as first step support for option 1) can be added and if there is need for the 2) option could be done in a separate issue. To support the 1) option, the CloudFoundryVcapEnvironmentPostProcessor should be enhanced to detect the presence of the VCAP_SERVICES_FILE_PATH environment variable if VCAP_SERVICES isn't set. The CF platform sets either VCAP_SERVICES or VCAP_SERVICES_FILE_PATH but not both environment variables in the same time. I don't have experience with the spring-boot code base but it looks to me like the method

private Properties getPropertiesFromServices(Environment environment, JsonParser parser) {
Properties properties = new Properties();
try {
String property = environment.getProperty("VCAP_SERVICES", "{}");
Map<String, Object> map = parser.parseMap(property);
extractPropertiesFromServices(properties, map);
}
catch (Exception ex) {
this.logger.error("Could not parse VCAP_SERVICES", ex);
}
return properties;
}
needs to be adapted to consider VCAP_SERVICES_FILE_PATH env var when VCAP_SERVICES is not present.

It would be from benefit to support this new file-based service bindings approach because in CF ecosystem we see more and more users starting to use this feature because of the mentioned size limit for environment variables.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions