Consul Server Discovery Service

HashiCorp Consul has multiple components, but as a whole, it is a tool for discovering and configuring services in your infrastructure. It provides key features:

  • Service Discovery: Clients of Consul can provide a service, such as api or mysql, and other clients can use Consul to discover providers of a given service. Using either DNS or HTTP, applications can easily find the services they depend upon.

  • Health Checking: Consul clients can provide any number of health checks, either associated with a given service (“is the webserver returning 200 OK”), or with the local node (“is memory utilization below 90%”). This information can be used by an operator to monitor cluster health, and it is used by the service discovery components to route traffic away from unhealthy hosts.

  • KV Store: Applications can make use of Consul’s hierarchical key/value store for any number of purposes, including dynamic configuration, feature flagging, coordination, leader election, and more. The simple HTTP API makes it easy to use.

  • Multi Datacenter: Consul supports multiple datacenters out of the box. This means users of Consul do not have to worry about building additional layers of abstraction to grow to multiple regions.

CAS provides a Consul-enabled service discovery server that is based on Spring Cloud Consul and bootstrapped via Spring Cloud.

Installation

  • To run the Consul discovery server, please see this guide for installation instructions. A simple Consul installation may be run as consul agent -dev -ui
  • Look for a suitable and relevant ready-made Docker image via docker search consul.

When deployed and assuming default settings, the Consul dashboard would be available at: http://localhost:8500/ui.

Note that a Consul Agent client must be available to all CAS server nodes. By default, the agent client is expected to be at localhost:8500. See the Agent documentation for specifics on how to start an Agent client.

CAS Discovery Service Clients

Each individual CAS server is given the ability to auto-register itself with the discovery server, provided configuration is made available to instruct the CAS server how to locate and connect to the discover server service.

Support is added by including the following dependency in the WAR overlay:

1
2
3
4
5
<dependency>
    <groupId>org.apereo.cas</groupId>
    <artifactId>cas-server-support-consul-client</artifactId>
    <version>${cas.version}</version>
</dependency>
1
implementation "org.apereo.cas:cas-server-support-consul-client:${project.'cas.version'}"
1
2
3
4
5
6
7
8
9
dependencyManagement {
    imports {
        mavenBom "org.apereo.cas:cas-server-support-bom:${project.'cas.version'}"
    }
}

dependencies {
    implementation "org.apereo.cas:cas-server-support-consul-client"
}
1
2
3
4
5
6
7
8
9
10
dependencies {
    /*
    The following platform references should be included automatically and are listed here for reference only.
            
    implementation enforcedPlatform("org.apereo.cas:cas-server-support-bom:${project.'cas.version'}")
    implementation platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
    */

    implementation "org.apereo.cas:cas-server-support-consul-client"
}

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

The configuration settings listed below are tagged as Required in the CAS configuration metadata. This flag indicates that the presence of the setting may be needed to activate or affect the behavior of the CAS feature and generally should be reviewed, possibly owned and adjusted. If the setting is assigned a default value, you do not need to strictly put the setting in your copy of the configuration, but should review it nonetheless to make sure it matches your deployment expectations.

The configuration settings listed below are tagged as Optional in the CAS configuration metadata. This flag indicates that the presence of the setting is not immediately necessary in the end-user CAS configuration, because a default value is assigned or the activation of the feature is not conditionally controlled by the setting value. In other words, you should only include this field in your configuration if you need to modify the default value or if you need to turn on the feature controlled by the setting.

The configuration settings listed below are tagged as Third Party in the CAS configuration metadata. This flag indicates that the configuration setting is not controlled, owned or managed by the CAS ecosystem, and affects functionality that is offered by a third-party library, such as Spring Boot or Spring Cloud to CAS. For additional info, you might have to visit the third-party source to find more details.

  • spring.cloud.config.discovery.enabled=false
  • Flag to indicate that config server discovery is enabled (config server URL will be looked up via discovery).

    org.springframework.cloud.config.client.ConfigClientProperties$Discovery.

    How can I configure this property?

  • spring.cloud.config.discovery.service-id=configserver
  • Service id to locate config server.

    org.springframework.cloud.config.client.ConfigClientProperties$Discovery.

    How can I configure this property?

  • spring.cloud.consul.config.acl-token=
  • org.springframework.cloud.consul.config.ConsulConfigProperties.

    How can I configure this property?

  • spring.cloud.consul.config.data-key=data
  • If format is Format.PROPERTIES or Format.YAML then the following field is used as key to look up consul for configuration.

    org.springframework.cloud.consul.config.ConsulConfigProperties.

    How can I configure this property?

  • spring.cloud.consul.config.default-context=application
  • org.springframework.cloud.consul.config.ConsulConfigProperties.

    How can I configure this property?

  • spring.cloud.consul.config.enabled=true
  • org.springframework.cloud.consul.config.ConsulConfigProperties.

    How can I configure this property?

  • spring.cloud.consul.config.fail-fast=true
  • Throw exceptions during config lookup if true, otherwise, log warnings.

    org.springframework.cloud.consul.config.ConsulConfigProperties.

    How can I configure this property?

  • spring.cloud.consul.config.format=
  • org.springframework.cloud.consul.config.ConsulConfigProperties.

    How can I configure this property?

  • spring.cloud.consul.config.name=
  • Alternative to spring.application.name to use in looking up values in consul KV.

    org.springframework.cloud.consul.config.ConsulConfigProperties.

    How can I configure this property?

  • spring.cloud.consul.config.prefix=
  • org.springframework.cloud.consul.config.ConsulConfigProperties.

    How can I configure this property?

    Deprecation status is WARNINGwith a replacement setting: spring.cloud.consul.config.prefixes.

  • spring.cloud.consul.config.prefixes=
  • org.springframework.cloud.consul.config.ConsulConfigProperties.

    How can I configure this property?

  • spring.cloud.consul.config.profile-separator=,
  • org.springframework.cloud.consul.config.ConsulConfigProperties.

    How can I configure this property?

  • spring.cloud.consul.config.watch.delay=1000
  • The value of the fixed delay for the watch in millis. Defaults to 1000.

    org.springframework.cloud.consul.config.ConsulConfigProperties$Watch.

    How can I configure this property?

  • spring.cloud.consul.config.watch.enabled=true
  • If the watch is enabled. Defaults to true.

    org.springframework.cloud.consul.config.ConsulConfigProperties$Watch.

    How can I configure this property?

  • spring.cloud.consul.config.watch.wait-time=55
  • 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.

    org.springframework.cloud.consul.config.ConsulConfigProperties$Watch.

    How can I configure this property?

  • spring.cloud.consul.discovery.acl-token=
  • org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.catalog-services-watch-delay=1000
  • The delay between calls to watch consul catalog in millis, default is 1000.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.catalog-services-watch-timeout=2
  • The number of seconds to block while watching consul catalog, default is 2.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.consistency-mode=
  • Consistency mode for health service request.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.datacenters=
  • Map of serviceId's -> datacenter to query for in server list. This allows looking up services in another datacenters.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.default-query-tag=
  • Tag to query for in service list if one is not listed in serverListQueryTags. Multiple tags can be specified with a comma separated value.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.default-zone-metadata-name=zone
  • Service instance zone comes from metadata. This allows changing the metadata tag name.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.deregister=true
  • Disable automatic de-registration of service in consul.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.enable-tag-override=
  • Enable tag override for the registered service.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.enabled=true
  • Is service discovery enabled?

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.fail-fast=true
  • Throw exceptions during service registration if true, otherwise, log warnings (defaults to true).

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.health-check-critical-timeout=
  • Timeout to deregister services critical for longer than timeout (e.g. 30m). Requires consul version 7.x or higher.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.health-check-headers=
  • Headers to be applied to the Health Check calls.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.health-check-interval=10s
  • How often to perform the health check (e.g. 10s), defaults to 10s.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.health-check-path=/actuator/health
  • Alternate server path to invoke for health checking.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.health-check-timeout=
  • Timeout for health check (e.g. 10s).

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.health-check-tls-skip-verify=
  • Skips certificate verification during service checks if true, otherwise runs certificate verification.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.health-check-url=
  • Custom health check url to override default.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.heartbeat.actuator-health-group=
  • The actuator health group to use (null for the root group) when determining system health via Actuator.

    org.springframework.cloud.consul.discovery.HeartbeatProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.heartbeat.enabled=false
  • org.springframework.cloud.consul.discovery.HeartbeatProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.heartbeat.interval-ratio=
  • org.springframework.cloud.consul.discovery.HeartbeatProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.heartbeat.reregister-service-on-failure=false
  • org.springframework.cloud.consul.discovery.HeartbeatProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.heartbeat.ttl=30s
  • org.springframework.cloud.consul.discovery.HeartbeatProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.heartbeat.use-actuator-health=true
  • Whether or not to take the current system health (as reported via the Actuator Health endpoint) into account when reporting the application status to the Consul TTL check. Actuator Health endpoint also has to be available to the application.

    org.springframework.cloud.consul.discovery.HeartbeatProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.hostname=
  • Hostname to use when accessing server.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.include-hostname-in-instance-id=false
  • Whether hostname is included into the default instance id when registering service.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.instance-group=
  • Service instance group.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.instance-id=
  • Unique service instance id.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.instance-zone=
  • Service instance zone.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.ip-address=
  • IP address to use when accessing service (must also set preferIpAddress to use).

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.lifecycle.enabled=true
  • org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties$Lifecycle.

    How can I configure this property?

  • spring.cloud.consul.discovery.management-enable-tag-override=
  • Enable tag override for the registered management service.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.management-metadata=
  • Metadata to use when registering management service.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.management-port=
  • Port to register the management service under (defaults to management port).

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.management-suffix=management
  • Suffix to use when registering management service.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.management-tags=
  • Tags to use when registering management service.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.metadata=
  • Metadata to use when registering service.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.order=0
  • Order of the discovery client used by `CompositeDiscoveryClient` for sorting available clients.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.port=
  • Port to register the service under (defaults to listening port).

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.prefer-agent-address=false
  • Source of how we will determine the address to use.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.prefer-ip-address=false
  • Use ip address rather than hostname during registration.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.query-passing=false
  • Add the 'passing` parameter to /v1/health/service/serviceName. This pushes health check passing to the server.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.register=true
  • Register as a service in consul.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.register-health-check=true
  • Register health check in consul. Useful during development of a service.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.scheme=http
  • Whether to register an http or https service.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.server-list-query-tags=
  • Map of serviceId's -> tag to query for in server list. This allows filtering services by one more tags. Multiple tags can be specified with a comma separated value.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.service-name=
  • Service name.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.discovery.tags=
  • Tags to use when registering service.

    org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties.

    How can I configure this property?

  • spring.cloud.consul.enabled=true
  • Is spring cloud consul enabled.

    org.springframework.cloud.consul.ConsulProperties.

    How can I configure this property?

  • spring.cloud.consul.host=localhost
  • Consul agent hostname. Defaults to 'localhost'.

    org.springframework.cloud.consul.ConsulProperties.

    How can I configure this property?

  • spring.cloud.consul.path=
  • Custom path if consul is under non-root.

    org.springframework.cloud.consul.ConsulProperties.

    How can I configure this property?

  • spring.cloud.consul.port=8500
  • Consul agent port. Defaults to '8500'.

    org.springframework.cloud.consul.ConsulProperties.

    How can I configure this property?

  • spring.cloud.consul.retry.enabled=true
  • If consul retry is enabled.

    org.springframework.cloud.consul.RetryProperties.

    How can I configure this property?

  • spring.cloud.consul.retry.initial-interval=1000
  • Initial retry interval in milliseconds.

    org.springframework.cloud.consul.RetryProperties.

    How can I configure this property?

  • spring.cloud.consul.retry.max-attempts=6
  • Maximum number of attempts.

    org.springframework.cloud.consul.RetryProperties.

    How can I configure this property?

  • spring.cloud.consul.retry.max-interval=2000
  • Maximum interval for backoff.

    org.springframework.cloud.consul.RetryProperties.

    How can I configure this property?

  • spring.cloud.consul.retry.multiplier=1.1
  • Multiplier for next interval.

    org.springframework.cloud.consul.RetryProperties.

    How can I configure this property?

  • spring.cloud.consul.ribbon.enabled=true
  • Enables Consul and Ribbon integration.

    How can I configure this property?

  • spring.cloud.consul.scheme=
  • Consul agent scheme (HTTP/HTTPS). If there is no scheme in address - client will use HTTP.

    org.springframework.cloud.consul.ConsulProperties.

    How can I configure this property?

  • spring.cloud.consul.service-registry.auto-registration.enabled=true
  • Enables Consul Service Registry Auto-registration.

    How can I configure this property?

  • spring.cloud.consul.service-registry.enabled=true
  • Enables Consul Service Registry functionality.

    How can I configure this property?

  • spring.cloud.consul.tls.certificate-password=
  • Password to open the certificate.

    org.springframework.cloud.consul.ConsulProperties$TLSConfig.

    How can I configure this property?

  • spring.cloud.consul.tls.certificate-path=
  • File path to the certificate.

    org.springframework.cloud.consul.ConsulProperties$TLSConfig.

    How can I configure this property?

  • spring.cloud.consul.tls.key-store-instance-type=
  • Type of key framework to use.

    org.springframework.cloud.consul.ConsulProperties$TLSConfig.

    How can I configure this property?

  • spring.cloud.consul.tls.key-store-password=
  • Password to an external keystore.

    org.springframework.cloud.consul.ConsulProperties$TLSConfig.

    How can I configure this property?

  • spring.cloud.consul.tls.key-store-path=
  • Path to an external keystore.

    org.springframework.cloud.consul.ConsulProperties$TLSConfig.

    How can I configure this property?

    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, specially 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.

    Troubleshooting

    To enable additional logging, configure the log4j configuration file to add the following levels:

    1
    2
    3
    4
    
    <Logger name="org.springframework.cloud.consul" level="debug" additivity="false">
      <AppenderRef ref="casConsole"/>
      <AppenderRef ref="casFile"/>
    </Logger>