起因:每隔一段时间阿里云就会报AccessKey泄露了,但是并没有在代码中写AccessKey,后来发现在nacos中多了个新用户,是之前没有添加过的
排查:
1.检查是否开启了鉴权
查看配置文件application.properties
# 是否开启授权
nacos.core.auth.enabled=true
开启授权为true,无需修改,排除
2.检查是否使用默认的token.secret.key
# 默认访问密钥
nacos.core.auth.default.token.secret.key={需要修改}
也已经修改了(默认值为:SecretKey012345678901234567890123456789012345678901234567890123456789),且使用了默认值构造JWT来调用接口/nacos/v1/auth/users?pageNo=1&pageSize=9,调用失败,证明也不是这个默认值的问题,排除
3.检查是否因为请求头添加了参数User-Agent: Nacos-Server

报权限错误,排除
4.真正原因,默认的serverIdentity和security
就没有修改或者配置这两个值,导致可以使用这两个值来进行新增用户的调用
# 这两个值就是个serverIdentity和security,如果没有配置,其默认值也是serverIdentity和security
nacos.core.auth.server.identity.key=serverIdentity
nacos.core.auth.server.identity.value=security
尝试调用:
获取用户:调用成功

新增用户:成功

解决方法:设置这两个配置的值,不使用默认值
nacos.core.auth.server.identity.key={新的值}
nacos.core.auth.server.identity.value={新的值}
设置了新的值之后:新增用户失败了

至此,解决了