spring-cloud / spring-cloud-consul

Spring Cloud Consul
http://cloud.spring.io/spring-cloud-consul/
Apache License 2.0
805 stars 543 forks source link

Spring Boot Consul Client sends http requests despite https configuration set #794

Closed bemar76 closed 1 year ago

bemar76 commented 1 year ago

Describe the bug Im want to use a shared config with consul and its working well in http-mode but https won't work. With postman and browser the UI and the API endpoints in consul are reachable and working well. The spring.cloud.consul.discovery.schema attribte is set to "https" but the Spring Boot Client still requests with http

bootstrap.yml

spring:
  cloud:
    consul:
      port: '8501'
      discovery:
        serviceName: ${spring.application.name}
        instance-id: ${spring.application.name}:${vcap.application.instance_id:${spring.application.instance_id:${spring.cloud.consul.host}}}
        healthCheckInterval: 30s
        healthCheckUrl: http://localhost:9000/actuator/health
        scheme: https
      config:
        data-key: data
        prefix: config
        defaultContext: application
        format: yaml
        enabled: true
        failFast: false
      host: server.dc1.consul
  application:
    name: workflow-engine

consul.config

{
    "bind_addr": "127.0.0.1",
    "addresses": {
        "http": "127.0.0.1"
    },
    "ui_config": {
        "enabled": true
    },
    "bootstrap": true,
    "server": true,
    "datacenter": "dc1",
    "data_dir": "C:\\Development\\consul\\data",
    "log_level": "INFO",
    "enable_syslog": false,
    "enable_debug": true,
    "node_name": "mymaschine-bemar-net",
    "verify_incoming": false,
    "verify_outgoing": true,
    "verify_server_hostname": true,
    "ca_file": "consul-agent-ca.pem",
    "cert_file": "dc1-server-consul-0.pem",
    "key_file": "dc1-server-consul-0-key.pem",
    "auto_encrypt": {
        "allow_tls": true
    },
    "ports": {
        "http": -1,
        "https": 8501
    }
}

The certificates were created by the consul-commands https://www.consul.io/commands/tls/cert

Consul info at startup

Starting Consul agent...
           Version: '1.13.1'
        Build Date: '2022-08-11 19:07:00 +0000 UTC'
           Node ID: '28b2f786-e292-81f0-62af-3c4215723b38'
         Node name: 'mymaschine-bemar-net'
        Datacenter: 'dc1' (Segment: '<all>')
            Server: true (Bootstrap: true)
       Client Addr: [127.0.0.1] (HTTP: -1, HTTPS: 8501, gRPC: -1, DNS: 8600)
      Cluster Addr: 127.0.0.1 (LAN: 8301, WAN: 8302)
           Encrypt: Gossip: false, TLS-Outgoing: true, TLS-Incoming: false, Auto-Encrypt-TLS: true

Operating system and Environment details

Windows 10 using consul.exe

Log Fragments

2022-09-12 11:45:38,332 TRACE [main] com.ecwid.consul.transport.AbstractHttpTransport: GET http://server.dc1.consul:8501/v1/kv/config/workflow-engine/?recurse&token= 
2022-09-12 11:45:38,424 WARN  [main] org.springframework.cloud.consul.config.ConsulPropertySourceLocator: Unable to load consul config from config/workflow-engine/
com.ecwid.consul.v1.OperationException: OperationException(statusCode=400, statusMessage='Bad Request', statusContent='Client sent an HTTP request to an HTTPS server.
')
        at com.ecwid.consul.v1.kv.KeyValueConsulClient.getKVValues(KeyValueConsulClient.java:156)
        at com.ecwid.consul.v1.ConsulClient.getKVValues(ConsulClient.java:644)
        at org.springframework.cloud.consul.config.ConsulPropertySource.init(ConsulPropertySource.java:70)
        at org.springframework.cloud.consul.config.ConsulPropertySources.create(ConsulPropertySources.java:155)
        at org.springframework.cloud.consul.config.ConsulPropertySources.createPropertySource(ConsulPropertySources.java:134)
        at org.springframework.cloud.consul.config.ConsulPropertySourceLocator.locate(ConsulPropertySourceLocator.java:88)
        at org.springframework.cloud.bootstrap.config.PropertySourceLocator.locateCollection(PropertySourceLocator.java:51)
        at org.springframework.cloud.consul.config.ConsulPropertySourceLocator.locateCollection(ConsulPropertySourceLocator.java:71)
        at org.springframework.cloud.consul.config.ConsulPropertySourceLocator$$FastClassBySpringCGLIB$$b35ebf8.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
        at org.springframework.retry.interceptor.RetryOperationsInterceptor$1.doWithRetry(RetryOperationsInterceptor.java:97)
        at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:329)
        at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:209)
        at org.springframework.retry.interceptor.RetryOperationsInterceptor.invoke(RetryOperationsInterceptor.java:133)
        at org.springframework.retry.annotation.AnnotationAwareRetryOperationsInterceptor.invoke(AnnotationAwareRetryOperationsInterceptor.java:160)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708)
        at org.springframework.cloud.consul.config.ConsulPropertySourceLocator$$EnhancerBySpringCGLIB$$6890359e.locateCollection(<generated>)
        at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:95)
        at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:607)
        at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:373)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
        at ch.bemar.iam.workflow.WorkflowApplication.main(WorkflowApplication.java:12)

dependencies

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-consul-all</artifactId>
        </dependency>

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

<properties>
        <java.version>17</java.version>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <spring-cloud.version>2021.0.4</spring-cloud.version>
    </properties>
spencergibb commented 1 year ago

spring.cloud.consul.discovery.scheme refers to the scheme of the registering service, not the consul client. You want spring.cloud.consul.scheme