spring-cloud / spring-cloud-zookeeper

Spring Cloud Zookeeper
http://cloud.spring.io/spring-cloud-zookeeper/
Apache License 2.0
556 stars 413 forks source link

KeeperErrorCode = NoAuth for /services #321

Closed WhiteStart closed 1 year ago

WhiteStart commented 1 year ago

Describe the bug in docker,I used this

It seems to be

Caused by: org.apache.zookeeper.KeeperException$NoAuthException: KeeperErrorCode = NoAuth for /services
    at org.apache.zookeeper.KeeperException.create(KeeperException.java:120) ~[zookeeper-3.8.1.jar:3.8.1]
    at org.apache.zookeeper.KeeperException.create(KeeperException.java:54) ~[zookeeper-3.8.1.jar:3.8.1]
    at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:1347) ~[zookeeper-3.8.1.jar:3.8.1]
    at org.apache.curator.utils.ZKPaths.mkdirs(ZKPaths.java:351) ~[curator-client-5.2.0.jar:na]
    at org.apache.curator.framework.imps.CreateBuilderImpl$18.call(CreateBuilderImpl.java:1222) ~[curator-framework-5.2.0.jar:5.2.0]
    at org.apache.curator.framework.imps.CreateBuilderImpl$18.call(CreateBuilderImpl.java:1193) ~[curator-framework-5.2.0.jar:5.2.0]
    at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:93) ~[curator-client-5.2.0.jar:na]
    at org.apache.curator.framework.imps.CreateBuilderImpl.pathInForeground(CreateBuilderImpl.java:1190) ~[curator-framework-5.2.0.jar:5.2.0]
    at org.apache.curator.framework.imps.CreateBuilderImpl.protectedPathInForeground(CreateBuilderImpl.java:605) ~[curator-framework-5.2.0.jar:5.2.0]
    at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:595) ~[curator-framework-5.2.0.jar:5.2.0]
    at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:48) ~[curator-framework-5.2.0.jar:5.2.0]
    at org.apache.curator.x.discovery.details.ServiceDiscoveryImpl.internalRegisterService(ServiceDiscoveryImpl.java:237) ~[curator-x-discovery-5.1.0.jar:na]
    at org.apache.curator.x.discovery.details.ServiceDiscoveryImpl.registerService(ServiceDiscoveryImpl.java:192) ~[curator-x-discovery-5.1.0.jar:na]
    at org.springframework.cloud.zookeeper.serviceregistry.ZookeeperServiceRegistry.register(ZookeeperServiceRegistry.java:71) ~[spring-cloud-zookeeper-discovery-3.1.1.jar:3.1.1]
    ... 28 common frames omitted

it did not work

@Configuration
public class ZookeeperConfigurer implements CuratorFrameworkCustomizer {

    @Override
    public void customize(CuratorFrameworkFactory.Builder builder) {
//        if (StrUtil.isNotBlank(username) && StrUtil.isNotBlank(password)) {
            builder.authorization("digest", "user:password".getBytes());
//        }
    }
}
<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.zookeeper</groupId>
                    <artifactId>zookeeper</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
            <version>3.8.1</version>
        </dependency>

<dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>2021.0.1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>2021.0.1.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.curator</groupId>
                <artifactId>curator-recipes</artifactId>
                <version>5.2.0</version>
            </dependency>
            <dependency>
                <groupId>org.apache.curator</groupId>
                <artifactId>curator-framework</artifactId>
                <version>5.2.0</version>
            </dependency>
            <dependency>
                <groupId>org.apache.curator</groupId>
                <artifactId>curator-client</artifactId>
                <version>5.2.0</version>
            </dependency>
spencergibb commented 1 year ago

Can you explain why you think this is a bug in spring cloud gateway?

WhiteStart commented 1 year ago

I raised issue for the first time,maybe it is a mistake,I this has something to do with springcloud's Zookeeper,but i can not work it out

spencergibb commented 1 year ago

I'm afraid I don't know much about zookeeper authentication and nothing about how the docker image sets that authentication up.

WhiteStart commented 1 year ago

I thought the problem was that spring-cloud-starter-zookeeper-discovery has its own way to connect to the zookeeper.Without auth,I can start the application.But when I enable auth, something went wrong.I read the document but it did not work.Thanks for your reply. https://cloud.spring.io/spring-cloud-zookeeper/reference/html/#access-control-lists-acls @BoostrapConfiguration public class CustomCuratorFrameworkConfig {

@Bean public CuratorFramework curatorFramework() { CuratorFramework curator = new CuratorFramework(); curator.addAuthInfo("digest", "user:password".getBytes()); return curator; }

}

The creation of this bean must occur during the boostrapping phase. You can register configuration classes to run during this phase by annotating them with @BootstrapConfiguration and including them in a comma-separated list that you set as the value of the org.springframework.cloud.bootstrap.BootstrapConfiguration property in the resources/META-INF/spring.factories file, as shown in the following example:

resources/META-INF/spring.factories org.springframework.cloud.bootstrap.BootstrapConfiguration=\ my.project.CustomCuratorFrameworkConfig,\ my.project.DefaultCuratorFrameworkConfig