Spring Cloud Configuration Server - Spring Cloud HashiCorp Consul

Spring Cloud Configuration Server is able to use Consul to locate properties and settings.

Consul provides a Key/Value Store for storing configuration and other metadata. Configuration is loaded into the CAS environment during the special “bootstrap” phase at runtime. Configuration is stored in the /config folder by default. Multiple PropertySource instances are created based on the application’s name and the active profiles that mimics the Spring Cloud Config order of resolving properties. For example, an application with the name cas and with the dev profile will have the following property sources created:

1
2
3
4
config/cas,dev/
config/cas/
config/application,dev/
config/application/

The most specific property source is at the top, with the least specific at the bottom. Properties in the config/application folder are applicable to all applications using consul for configuration. Properties in the config/cas folder are only available to the instances of the service named cas.

Configuration is currently read on startup of the application. Sending an HTTP POST to /refresh will cause the configuration to be reloaded. Watching the key value store (which Consul supports) is not currently possible, but will be a future addition to this project.

The Consul Config Watch takes advantage of the ability of consul to watch a key prefix. The Config Watch makes a blocking Consul HTTP API call to determine if any relevant configuration data has changed for the current application. If there is new configuration data a Refresh Event is published. This is equivalent to calling the /refresh Spring Boot actuator endpoint.

The following settings and properties are available from the CAS configuration catalog:

spring.cloud.consul.config.acl-token
no default
Third party
Type
String
Default
none
Defined by
ConsulConfigProperties
spring.cloud.consul.config.data-keyIf format is Format.PROPERTIES or Format.YAML then the following field is used as key to look up consul for configuration.
data
Third party

If format is Format.PROPERTIES or Format.YAML then the following field is used as key to look up consul for configuration.

Type
String
Default
data
Defined by
ConsulConfigProperties
spring.cloud.consul.config.default-context
application
Third party
Type
String
Default
application
Defined by
ConsulConfigProperties
spring.cloud.consul.config.enabled
true
Third party
Type
Boolean
Default
true
Defined by
ConsulConfigProperties
spring.cloud.consul.config.fail-fastThrow exceptions during config lookup if true, otherwise, log warnings.
true
Third party

Throw exceptions during config lookup if true, otherwise, log warnings.

Type
Boolean
Default
true
Defined by
ConsulConfigProperties
spring.cloud.consul.config.format
key-value
Third party
Type
ConsulConfigProperties.Format
Default
key-value
Defined by
ConsulConfigProperties
spring.cloud.consul.config.nameAlternative to spring.application.name to use in looking up values in consul KV.
no default
Third party

Alternative to spring.application.name to use in looking up values in consul KV.

Type
String
Default
none
Defined by
ConsulConfigProperties
spring.cloud.consul.config.prefix
no default
Third partyDeprecated
Type
String
Default
none
Defined by
ConsulConfigProperties
Deprecation
WARNING, replaced by spring.cloud.consul.config.prefixes
spring.cloud.consul.config.prefixes
no default
Third party
Type
List<String>
Default
none
Defined by
ConsulConfigProperties
spring.cloud.consul.config.profile-separator
,
Third party
Type
String
Default
,
Defined by
ConsulConfigProperties
spring.cloud.consul.config.watch.delayThe value of the fixed delay for the watch in millis.
1000
Third party

The value of the fixed delay for the watch in millis. Defaults to 1000.

Type
Integer
Default
1000
Defined by
ConsulConfigProperties$Watch
spring.cloud.consul.config.watch.enabledIf the watch is enabled.
true
Third party

If the watch is enabled. Defaults to true.

Type
Boolean
Default
true
Defined by
ConsulConfigProperties$Watch
spring.cloud.consul.config.watch.wait-timeThe number of seconds to wait (or block) for watch query, defaults to 55.
55
Third party

The number of seconds to wait (or block) for watch query, defaults to 55. Needs to be less than default ConsulClient (defaults to 60). To increase ConsulClient timeout create a ConsulClient bean with a custom ConsulRawClient with a custom HttpClient.

Type
Integer
Default
55
Defined by
ConsulConfigProperties$Watch

Required settings may be needed to activate or affect the feature; review them even when they have a default. Optional settings only need to be set to change a default or to turn on the behavior they control. Third party settings belong to libraries such as Spring Boot that CAS builds on; their own documentation may have more detail.

Notes on configuration

Configuration Metadata

The collection of configuration properties listed in this section are automatically generated from the CAS source and components that contain the actual field definitions, types, descriptions, modules, etc. This metadata may not always be 100% accurate, or could be lacking details and sufficient explanations.

Be Selective

This section is meant as a guide only. Do NOT copy/paste the entire collection of settings into your CAS configuration; rather pick only the properties that you need. Do NOT enable settings unless you are certain of their purpose and do NOT copy settings into your configuration only to keep them as reference. All these ideas lead to upgrade headaches, maintenance nightmares and premature aging.

YAGNI

Note that for nearly ALL use cases, declaring and configuring properties listed here is sufficient. You should NOT have to explicitly massage a CAS XML/Java/etc configuration file to design an authentication handler, create attribute release policies, etc. CAS at runtime will auto-configure all required changes for you. If you are unsure about the meaning of a given CAS setting, do NOT turn it on without hesitation. Review the codebase or better yet, ask questions to clarify the intended behavior.

Naming Convention

Property names can be specified in very relaxed terms. For instance cas.someProperty, cas.some-property, cas.some_property are all valid names. While all forms are accepted by CAS, there are certain components (in CAS and other frameworks used) whose activation at runtime is conditional on a property value, where this property is required to have been specified in CAS configuration using kebab case. This is both true for properties that are owned by CAS as well as those that might be presented to the system via an external library or framework such as Spring Boot, etc.

:information_source: Note

When possible, properties should be stored in lower-case kebab format, such as cas.property-name=value. The only possible exception to this rule is when naming actuator endpoints; The name of the actuator endpoints (i.e. ssoSessions) MUST remain in camelCase mode.

Settings and properties that are controlled by the CAS platform directly always begin with the prefix cas. All other settings are controlled and provided to CAS via other underlying frameworks and may have their own schemas and syntax. BE CAREFUL with the distinction. Unrecognized properties are rejected by CAS and/or frameworks upon which CAS depends. This means if you somehow misspell a property definition or fail to adhere to the dot-notation syntax and such, your setting is entirely refused by CAS and likely the feature it controls will never be activated in the way you intend.

Validation

Configuration properties are automatically validated on CAS startup to report issues with configuration binding, especially if defined CAS settings cannot be recognized or validated by the configuration schema. Additional validation processes are also handled via Configuration Metadata and property migrations applied automatically on startup by Spring Boot and family.

Indexed Settings

CAS settings able to accept multiple values are typically documented with an index, such as cas.some.setting[0]=value. The index [0] is meant to be incremented by the adopter to allow for distinct multiple configuration blocks.

:information_source: Usage

The configuration modules provided here may also be used verbatim inside a CAS server overlay and do not exclusively belong to a Spring Cloud Configuration server. While this module is primarily useful when inside the Spring Cloud Configuration server, it nonetheless may also be used inside a CAS server overlay directly to fetch settings from a source.

Actuator Endpoints

The following endpoints are provided by Spring Cloud:

consul
Third-party endpoint1 operationNot exposed by default
1

Turn the endpoint on and expose it over the web. One entry covers every operation. By default only info, health and status are exposed.

1
2
management.endpoint.consul.access=UNRESTRICTED
management.endpoints.web.exposure.include=consul

Endpoints may be mapped to other paths. For example, to serve health at healthcheck:

1
management.endpoints.web.path-mapping.health=healthcheck