Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用创建的用户注册到nacos时出现403 #3961

Closed
zbsBrave opened this issue Oct 9, 2020 · 11 comments
Closed

使用创建的用户注册到nacos时出现403 #3961

zbsBrave opened this issue Oct 9, 2020 · 11 comments

Comments

@zbsBrave
Copy link

zbsBrave commented Oct 9, 2020

1,设置nacos.core.auth.enabled=true
2,使用nacos新创建一个用户gataway,密码gataway
3,使用这个账号和密码注册到nacos失败,Caused by: com.alibaba.nacos.api.exception.NacosException: failed to req API:/nacos/v1/ns/instance after all servers([ctos.cn:8848]) tried: ErrCode:403,
4,使用username=nacos时注册到nacos是正常的

bootstrap.yml是这样的:
spring:
cloud:
nacos:
server-addr: ctos.cn:8848
username: gateway
password: gateway
config:
namespace: 6f257580-f5cc-4f5a-aeb3-1194dfe793f4
file-extension: yml

@horizonzy
Copy link
Collaborator

服务端开启了权限的情况下。注册服务需要保证登陆的用户要写写操作的权限,给你的这个gateway用户分配一下写操作的权限

@zbsBrave
Copy link
Author

服务端开启了权限的情况下。注册服务需要保证登陆的用户要写写操作的权限,给你的这个网关用户分配一下写操作的权限

我给这个用户分配过public和gateway的读写权限,还是不行:
ROLE_GATEWAY | public | 读写 (rw) |
ROLE_GATEWAY | gateway (6f257580-f5cc-4f5a-aeb3-1194dfe793f4) | 读写 (rw)

@horizonzy
Copy link
Collaborator

用户和角色挂钩没得

@KomachiSion
Copy link
Collaborator

角色又读写权限,然后需要把这个用户设定为这个角色。

@zbsBrave
Copy link
Author

zbsBrave commented Oct 12, 2020

角色又读写权限,然后需要把这个用户设定为这个角色。
这是用户管理:gateway | ************************************************************ | 修改
这是角色管理:ROLE_GATEWAY | gateway
这是权限管理:
ROLE_GATEWAY | public | 读写 (rw) |
ROLE_GATEWAY | gateway (6f257580-f5cc-4f5a-aeb3-1194dfe793f4) | 读写 (rw)

感觉这个应该不是权限配置的问题,因为在最开始能够读取到nacos远程配置的数据,这个‘hi,这是test 11111’就是配置在nacos的。

以下是日志:
hi,这是test 11111
2020-10-12 11:07:34.924 WARN 11132 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2020-10-12 11:07:34.924 INFO 11132 --- [ 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.
2020-10-12 11:07:34.926 WARN 11132 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2020-10-12 11:07:34.926 INFO 11132 --- [ 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.
2020-10-12 11:07:36.236 INFO 11132 --- [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2020-10-12 11:07:37.561 INFO 11132 --- [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2020-10-12 11:07:37.936 INFO 11132 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [After]
2020-10-12 11:07:37.936 INFO 11132 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Before]
2020-10-12 11:07:37.936 INFO 11132 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Between]
2020-10-12 11:07:37.936 INFO 11132 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Cookie]
2020-10-12 11:07:37.936 INFO 11132 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Header]
2020-10-12 11:07:37.936 INFO 11132 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Host]
2020-10-12 11:07:37.936 INFO 11132 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Method]
2020-10-12 11:07:37.936 INFO 11132 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Path]
2020-10-12 11:07:37.936 INFO 11132 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Query]
2020-10-12 11:07:37.936 INFO 11132 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [ReadBodyPredicateFactory]
2020-10-12 11:07:37.936 INFO 11132 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [RemoteAddr]
2020-10-12 11:07:37.936 INFO 11132 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Weight]
2020-10-12 11:07:37.936 INFO 11132 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [CloudFoundryRouteService]
2020-10-12 11:07:39.290 INFO 11132 --- [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2020-10-12 11:07:40.557 INFO 11132 --- [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2020-10-12 11:07:40.621 ERROR 11132 --- [ main] com.alibaba.nacos.client.naming : [NA] failed to request
Caused by: com.alibaba.nacos.api.exception.NacosException: failed to req API:/nacos/v1/ns/instance after all servers([ctos.cn:8848]) tried: ErrCode:403, ErrMsg:

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Mon Oct 12 11:07:41 CST 2020
There was an unexpected error (type=Forbidden, status=403).
authorization failed!

at com.alibaba.nacos.client.naming.net.NamingProxy.reqApi(NamingProxy.java:552) ~[nacos-client-1.3.2.jar:na]
at com.alibaba.nacos.client.naming.net.NamingProxy.reqApi(NamingProxy.java:491) ~[nacos-client-1.3.2.jar:na]
at com.alibaba.nacos.client.naming.net.NamingProxy.reqApi(NamingProxy.java:486) ~[nacos-client-1.3.2.jar:na]
at com.alibaba.nacos.client.naming.net.NamingProxy.registerService(NamingProxy.java:239) ~[nacos-client-1.3.2.jar:na]
at com.alibaba.nacos.client.naming.NacosNamingService.registerInstance(NacosNamingService.java:200) ~[nacos-client-1.3.2.jar:na]
at com.alibaba.cloud.nacos.registry.NacosServiceRegistry.register(NacosServiceRegistry.java:70) ~[spring-cloud-starter-alibaba-nacos-discovery-2.2.2.RELEASE.jar:2.2.2.RELEASE]
... 20 common frames omitted

@KomachiSion
Copy link
Collaborator

看报错是配置中心使用了gateway用户,但是注册中心没有使用gateway用户,403错误都是服务发现模块抛出来的,给服务发现模块也配置一下用户名密码试试

spring:
  cloud:
    nacos:
      naming:
        username: gateway
        password: gateway

@zbsBrave
Copy link
Author

看报错是配置中心使用了gateway用户,但是注册中心没有使用gateway用户,403错误都是服务发现模块抛出来的,给服务发现模块也配置一下用户名密码试试

spring:
  cloud:
    nacos:
      naming:
        username: gateway
        password: gateway

我这里没有naming配置,只有discovery,配置了discovery的用户名和密码后也报同样错误。
spring:
cloud:
nacos:
server-addr: ctos.cn:8848
username: gateway
password: gateway
config:
namespace: 6f257580-f5cc-4f5a-aeb3-1194dfe793f4
file-extension: yml
discovery:
username: gateway
password: gateway
而且同样配置我用默认的nacos账号是可以正常使用的,应该不是这个配置的原因。
在nacos的配置文件application.properties发现这样一句话,是不是说目前只支持nacos这个账号

The auth system to use, currently only 'nacos' is supported:

nacos.core.auth.system.type=nacos

@horizonzy
Copy link
Collaborator

看报错是配置中心使用了gateway用户,但是注册中心没有使用gateway用户,403错误都是服务发现模块抛出来的,给服务发现模块也配置一下用户名密码试试

spring:
  cloud:
    nacos:
      naming:
        username: gateway
        password: gateway

我这里没有naming配置,只有discovery,配置了discovery的用户名和密码后也报同样错误。
spring:
cloud:
nacos:
server-addr: ctos.cn:8848
username: gateway
password: gateway
config:
namespace: 6f257580-f5cc-4f5a-aeb3-1194dfe793f4
file-extension: yml
discovery:
username: gateway
password: gateway
而且同样配置我用默认的nacos账号是可以正常使用的,应该不是这个配置的原因。
在nacos的配置文件application.properties发现这样一句话,是不是说目前只支持nacos这个账号

The auth system to use, currently only 'nacos' is supported:

nacos.core.auth.system.type=nacos

这个是认证的类型。

@KomachiSion
Copy link
Collaborator

@zbsBrave 看一下nacos的access_log,看下是哪个接口报的403, 如果你没有使用discovery,应该不启动discovery才对,从报错来看就是启动了discovery,但是discovery没有权限。

@KomachiSion
Copy link
Collaborator

@zbsBrave 你应用注册的服务是用gateway用户注册到public?那可能会有问题 #3524

@zbsBrave
Copy link
Author

@zbsBrave 你应用注册的服务是用gateway用户注册到public?那可能会有问题 #3524

谢谢大佬,就是这个问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants