hashicorp / consul

Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure.
https://www.consul.io
Other
28.39k stars 4.43k forks source link

Not able to read consul KV store after enabling ACL #9876

Open raonelakurti opened 3 years ago

raonelakurti commented 3 years ago

I have a spring boot application to read propeties from KV store in consul. Some how I'm not able to read consul KV config values after enabling ACL

Bootstrap.yaml:

spring:
  profiles:
    active: "prod-zone1"
  application:
    name: myApp

spring:
  profiles: prod-zone1
  cloud:
    consul:
      host: http://consul-server.consul-poc.svc.cluster.local
      port: 8500
      config:
        enabled: true
      discovery:
        acl-token: ///Added acl master token
        instanceZone: zone1
        instance-id: "${spring.application.name}:${random.value}"
        prefer-ip-address: true

Java Config Class:

package pl.piomin.services.account.controller;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
@Configuration
@RefreshScope
public class ConsulConfiguration {
    @Value("${cassandra.host}")
    private String cassandraHost;
    @PostConstruct
    public void postConstruct() {
        // to validate if properties are loaded
        System.out.println("** cassandra.host: " + cassandraHost);

}
}

In Consul I've added kv store-> config/myApp/data/cassandra/host: 12.3.2.10

FYI, This code is working fine before ACL setup. Please help me understand what am I missing.

jkirschner-hashicorp commented 3 years ago

Hi @raonelakurti ,

Are you sure spring.cloud.consul.discovery.acl-token is the right property for your version of spring-cloud-consul? This SO thread and the current source suggest spring.cloud.consul.token may also be an option.

And have you ensured that your token has the necessary privileges to read/write your keys?

raonelakurti commented 2 years ago

@jkirschner-hashicorp Sorry for the delayed response. Even after adding the property that you suggested still the same issue