Nacos 2.2.0.1 鉴权配置

  1. 启动错误
  2. 配置
  3. 版本差异
  4. 参考

启动错误

Nacos Server 2.2.0.1 使用默认 application.properties 启动失败,异常末端为:

java.lang.IllegalArgumentException:
the length of secret key must great than or equal 32 bytes;
And the secret key must be encoded by base64.

Caused by: io.jsonwebtoken.security.WeakKeyException:
The specified key byte array is 0 bits which is not secure enough
for any JWT HMAC-SHA algorithm.

该版本的默认配置:

nacos.core.auth.enabled=false
nacos.core.auth.server.identity.key=serverIdentity
nacos.core.auth.server.identity.value=security
nacos.core.auth.plugin.nacos.token.secret.key=

2.2.0.1 移除了 token.secret.key 的默认值,空值会触发 JWT key 长度检查。

配置

生成 32 字节随机值并进行 Base64 编码:

openssl rand -base64 32

conf/application.properties

nacos.core.auth.system.type=nacos
nacos.core.auth.enabled=true
nacos.core.auth.caching.enabled=true
nacos.core.auth.enable.userAgentAuthWhite=false

nacos.core.auth.server.identity.key=<custom-identity-key>
nacos.core.auth.server.identity.value=<custom-identity-value>

nacos.core.auth.plugin.nacos.token.expire.seconds=18000
nacos.core.auth.plugin.nacos.token.secret.key=<base64-secret>

重新启动:

sh startup.sh -m standalone

配置后 2.2.0.1 正常启动,控制台登录可以生成 accessToken

版本差异

原记录同时检查了 2.1.1。该版本自带默认 JWT secret,直接启动不会触发空密钥异常;nacos.core.auth.enabled=false 时,配置和服务接口没有鉴权。

2.2.0.1 的变更只移除了默认 JWT secret,并没有自动开启鉴权。关闭鉴权仍然会形成未授权访问面。

当前 Nacos 文档中的相关配置仍包括:

nacos.core.auth.enabled=true
nacos.core.auth.admin.enabled=true
nacos.core.auth.console.enabled=true
nacos.core.auth.server.identity.key=<custom-identity-key>
nacos.core.auth.server.identity.value=<custom-identity-value>
nacos.core.auth.plugin.nacos.token.secret.key=<base64-secret>

自 Nacos 2.4.0 起,首次启用默认鉴权时不再提供 nacos/nacos 默认管理员密码,管理员密码由控制台或初始化 API 创建。

原笔记中的公网扫描 PoC 和第三方主机结果未保留。

参考

Nacos 2.x 鉴权文档

Nacos 最新鉴权文档

Nacos issue #10047


转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。

文章标题:Nacos 2.2.0.1 鉴权配置

字数:495

本文作者:

发布时间:2023-03-09, 19:53:00

最后更新:2026-08-26, 14:57:00

原始链接:https://cnlnn.pages.dev/posts/nacos-2201-auth-config/

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。