alibaba / spring-cloud-alibaba

Spring Cloud Alibaba provides a one-stop solution for application development for the distributed solutions of Alibaba middleware.
https://sca.aliyun.com
Apache License 2.0
27.95k stars 8.34k forks source link

Nacos2.1.0开启auth.enabled后报错code=403,msg=unknown user! #2624

Closed LWHark closed 2 years ago

LWHark commented 2 years ago

springcloud 2.1.6 spring-boot 2.1.6 spring-cloud-starter-alibaba-nacos-discovery 2.1.0 spring-cloud-starter-alibaba-nacos-config 2.1.0 nacos-client 2.1.0 auth.enabled=false时,正常,nacos配置文件信息能读取; auto.enabled=true时,报错,错误信息如下:

LWHark commented 2 years ago

2022-06-28 15:28:50.058 INFO 6104 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$bdc98718] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

. _ _ /\ / '_ () \ \ \ \ ( ( )\ | ' | '| | ' \/ ` | \ \ \ \ \/ _)| |)| | | | | || (| | ) ) ) ) ' |__| .|| ||| |\, | / / / / =========|_|==============|__/=//// :: Spring Boot :: (v2.1.6.RELEASE)

2022-06-28 15:28:50.718 INFO 6104 --- [ main] c.a.n.p.a.s.c.ClientAuthPluginManager : [ClientAuthPluginManager] Load ClientAuthService com.alibaba.nacos.client.auth.impl.NacosClientAuthServiceImpl success. 2022-06-28 15:28:50.718 INFO 6104 --- [ main] c.a.n.p.a.s.c.ClientAuthPluginManager : [ClientAuthPluginManager] Load ClientAuthService com.alibaba.nacos.client.auth.ram.RamClientAuthServiceImpl success. 2022-06-28 15:28:52.884 ERROR 6104 --- [ main] c.a.c.n.c.NacosPropertySourceBuilder : get data from Nacos error,dataId:api-client.yaml,

com.alibaba.nacos.api.exception.NacosException: http error, code=403,msg=unknown user!,dataId=api-client.yaml,group=DEFAULT_GROUP,tenant=08e48ec6-712b-45e8-b708-e558854b37b4 at com.alibaba.nacos.client.config.impl.ClientWorker$ConfigRpcTransportClient.queryConfig(ClientWorker.java:979) ~[nacos-client-2.1.0.jar:na] at com.alibaba.nacos.client.config.impl.ClientWorker.getServerConfig(ClientWorker.java:396) ~[nacos-client-2.1.0.jar:na] at com.alibaba.nacos.client.config.NacosConfigService.getConfigInner(NacosConfigService.java:166) ~[nacos-client-2.1.0.jar:na] at com.alibaba.nacos.client.config.NacosConfigService.getConfig(NacosConfigService.java:94) ~[nacos-client-2.1.0.jar:na] at com.alibaba.cloud.nacos.client.NacosPropertySourceBuilder.loadNacosData(NacosPropertySourceBuilder.java:85) [spring-cloud-alibaba-nacos-config-2.1.0.RELEASE.jar:2.1.0.RELEASE] at com.alibaba.cloud.nacos.client.NacosPropertySourceBuilder.build(NacosPropertySourceBuilder.java:75) [spring-cloud-alibaba-nacos-config-2.1.0.RELEASE.jar:2.1.0.RELEASE] at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadNacosDataIfPresent(NacosPropertySourceLocator.java:179) [spring-cloud-alibaba-nacos-config-2.1.0.RELEASE.jar:2.1.0.RELEASE] at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadApplicationConfiguration(NacosPropertySourceLocator.java:155) [spring-cloud-alibaba-nacos-config-2.1.0.RELEASE.jar:2.1.0.RELEASE] at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.locate(NacosPropertySourceLocator.java:88) [spring-cloud-alibaba-nacos-config-2.1.0.RELEASE.jar:2.1.0.RELEASE] at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:97) [spring-cloud-context-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:621) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:365) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:310) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] at com.nacos.NacosDynamicConfigurationApplication.main(NacosDynamicConfigurationApplication.java:10) [classes/:na]

2022-06-28 15:28:52.893 ERROR 6104 --- [ main] c.a.c.n.c.NacosPropertySourceBuilder : get data from Nacos error,dataId:api-client-dev.yaml,

com.alibaba.nacos.api.exception.NacosException: http error, code=403,msg=unknown user!,dataId=api-client-dev.yaml,group=DEFAULT_GROUP,tenant=08e48ec6-712b-45e8-b708-e558854b37b4 at com.alibaba.nacos.client.config.impl.ClientWorker$ConfigRpcTransportClient.queryConfig(ClientWorker.java:979) ~[nacos-client-2.1.0.jar:na] at com.alibaba.nacos.client.config.impl.ClientWorker.getServerConfig(ClientWorker.java:396) ~[nacos-client-2.1.0.jar:na] at com.alibaba.nacos.client.config.NacosConfigService.getConfigInner(NacosConfigService.java:166) ~[nacos-client-2.1.0.jar:na] at com.alibaba.nacos.client.config.NacosConfigService.getConfig(NacosConfigService.java:94) ~[nacos-client-2.1.0.jar:na] at com.alibaba.cloud.nacos.client.NacosPropertySourceBuilder.loadNacosData(NacosPropertySourceBuilder.java:85) [spring-cloud-alibaba-nacos-config-2.1.0.RELEASE.jar:2.1.0.RELEASE] at com.alibaba.cloud.nacos.client.NacosPropertySourceBuilder.build(NacosPropertySourceBuilder.java:75) [spring-cloud-alibaba-nacos-config-2.1.0.RELEASE.jar:2.1.0.RELEASE] at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadNacosDataIfPresent(NacosPropertySourceLocator.java:179) [spring-cloud-alibaba-nacos-config-2.1.0.RELEASE.jar:2.1.0.RELEASE] at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadApplicationConfiguration(NacosPropertySourceLocator.java:159) [spring-cloud-alibaba-nacos-config-2.1.0.RELEASE.jar:2.1.0.RELEASE] at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.locate(NacosPropertySourceLocator.java:88) [spring-cloud-alibaba-nacos-config-2.1.0.RELEASE.jar:2.1.0.RELEASE] at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:97) [spring-cloud-context-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:621) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:365) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:310) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] at com.nacos.NacosDynamicConfigurationApplication.main(NacosDynamicConfigurationApplication.java:10) [classes/:na]

2022-06-28 15:28:52.893 INFO 6104 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='NACOS', propertySources=[NacosPropertySource {name='api-client-dev.yaml'}, NacosPropertySource {name='api-client.yaml'}]} 2022-06-28 15:28:52.896 INFO 6104 --- [ main] c.n.NacosDynamicConfigurationApplication : The following profiles are active: dev 2022-06-28 15:28:53.284 INFO 6104 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=28e95515-080a-36b4-a4e5-4184daa880d7 2022-06-28 15:28:53.297 INFO 6104 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$bdc98718] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2022-06-28 15:28:53.437 INFO 6104 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8087 (http) 2022-06-28 15:28:53.454 INFO 6104 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2022-06-28 15:28:53.454 INFO 6104 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.21] 2022-06-28 15:28:53.551 INFO 6104 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2022-06-28 15:28:53.551 INFO 6104 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 649 ms 2022-06-28 15:28:53.624 WARN 6104 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources. 2022-06-28 15:28:53.624 INFO 6104 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath. 2022-06-28 15:28:53.627 WARN 6104 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources. 2022-06-28 15:28:53.627 INFO 6104 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath. 2022-06-28 15:28:53.741 INFO 6104 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor' 2022-06-28 15:28:54.403 INFO 6104 --- [ main] c.a.n.p.a.s.c.ClientAuthPluginManager : [ClientAuthPluginManager] Load ClientAuthService com.alibaba.nacos.client.auth.impl.NacosClientAuthServiceImpl success. 2022-06-28 15:28:54.403 INFO 6104 --- [ main] c.a.n.p.a.s.c.ClientAuthPluginManager : [ClientAuthPluginManager] Load ClientAuthService com.alibaba.nacos.client.auth.ram.RamClientAuthServiceImpl success. 2022-06-28 15:28:54.573 INFO 6104 --- [ main] o.s.s.c.ThreadPoolTaskScheduler : Initializing ExecutorService 2022-06-28 15:28:55.279 INFO 6104 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8087 (http) with context path '' 2022-06-28 15:28:55.298 ERROR 6104 --- [ main] c.a.c.n.registry.NacosServiceRegistry : nacos registry, api-client register failed...NacosRegistration{nacosDiscoveryProperties=NacosDiscoveryProperties{serverAddr='10.43.81.29:8848', endpoint='', namespace='08e48ec6-712b-45e8-b708-e558854b37b4', watchDelay=30000, logName='', service='api-client', weight=1.0, clusterName='DEFAULT', namingLoadCacheAtStart='false', metadata={preserved.register.source=SPRING_CLOUD}, registerEnabled=true, ip='10.43.81.29', networkInterface='', port=8087, secure=false, accessKey='', secretKey=''}},

com.alibaba.nacos.api.exception.NacosException: Request nacos server failed: at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.requestToServer(NamingGrpcClientProxy.java:288) ~[nacos-client-2.1.0.jar:na] at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.doRegisterService(NamingGrpcClientProxy.java:128) ~[nacos-client-2.1.0.jar:na] at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.registerService(NamingGrpcClientProxy.java:114) ~[nacos-client-2.1.0.jar:na] at com.alibaba.nacos.client.naming.remote.NamingClientProxyDelegate.registerService(NamingClientProxyDelegate.java:94) ~[nacos-client-2.1.0.jar:na] at com.alibaba.nacos.client.naming.NacosNamingService.registerInstance(NacosNamingService.java:145) ~[nacos-client-2.1.0.jar:na] at com.alibaba.nacos.client.naming.NacosNamingService.registerInstance(NacosNamingService.java:139) ~[nacos-client-2.1.0.jar:na] at com.alibaba.cloud.nacos.registry.NacosServiceRegistry.register(NacosServiceRegistry.java:61) ~[spring-cloud-alibaba-nacos-discovery-2.1.0.RELEASE.jar:2.1.0.RELEASE] at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.register(AbstractAutoServiceRegistration.java:239) [spring-cloud-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE] at com.alibaba.cloud.nacos.registry.NacosAutoServiceRegistration.register(NacosAutoServiceRegistration.java:74) [spring-cloud-alibaba-nacos-discovery-2.1.0.RELEASE.jar:2.1.0.RELEASE] at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.start(AbstractAutoServiceRegistration.java:138) [spring-cloud-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.bind(AbstractAutoServiceRegistration.java:101) [spring-cloud-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.onApplicationEvent(AbstractAutoServiceRegistration.java:88) [spring-cloud-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.onApplicationEvent(AbstractAutoServiceRegistration.java:47) [spring-cloud-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) [spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) [spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) [spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE] at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:402) [spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE] at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:359) [spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:164) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:552) [spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] at com.nacos.NacosDynamicConfigurationApplication.main(NacosDynamicConfigurationApplication.java:10) [classes/:na] Caused by: com.alibaba.nacos.api.exception.NacosException: unknown user! at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.requestToServer(NamingGrpcClientProxy.java:280) ~[nacos-client-2.1.0.jar:na] ... 26 common frames omitted

2022-06-28 15:28:55.299 INFO 6104 --- [ main] c.n.NacosDynamicConfigurationApplication : Started NacosDynamicConfigurationApplication in 6.547 seconds (JVM running for 7.682)

LWHark commented 2 years ago

bootstrap.yml信息: spring: cloud: nacos: username: test password: test discovery: server-addr: 10.43.81.29:8848 group: DEFAULT_GROUP namespace: 08e48ec6-712b-45e8-b708-e558854b37b4 config: server-addr: ${spring.cloud.nacos.discovery.server-addr} file-extension: yaml group: ${spring.cloud.nacos.discovery.group} context-path: /nacos namespace: ${spring.cloud.nacos.discovery.namespace}

LWHark commented 2 years ago

application.yml信息: spring: application: name: api-client profiles: active: dev server: port: 8087

yuhuangbin commented 2 years ago

你使用的版本比较老,不一定支持了spring.cloud.nacos.username/password这个配置项,你换成spring.cloud.nacos.discovery.username/password试一下?

LWHark commented 2 years ago

你使用的版本比较老,不一定支持了spring.cloud.nacos.username/password这个配置项,你换成spring.cloud.nacos.discovery.username/password试一下?

改成这样的,还是一样的错误: spring: cloud: nacos: discovery: server-addr: localhost:8848 group: DEFAULT_GROUP namespace: 08e48ec6-712b-45e8-b708-e558854b37b4 username: test password: test config: server-addr: ${spring.cloud.nacos.discovery.server-addr} file-extension: yaml group: ${spring.cloud.nacos.discovery.group} context-path: /nacos namespace: ${spring.cloud.nacos.discovery.namespace} username: ${spring.cloud.nacos.discovery.username} password: ${spring.cloud.nacos.discovery.password}

yuhuangbin commented 2 years ago

你使用的 Spring Cloud Alibaba 2.1.0.RELEASE版本,不支持Nacos 鉴权,这个版本比较老,建议参考 版本说明 使用

ghairui commented 1 year ago

我加了鉴权以后,nacos服务那没问题,客户端刚启动没问题,用一会就突然连不上了,而且是部分dataId连不上,怪

MRHXXX1 commented 1 year ago

@yuhuangbin 我这边使用的nacos版本为1.3.0;spring-boot版本为2.0.3.RELEASE;在启动服务的时候,出现unknown User! 还望解答