Nacos v2.2运行出错

文章描述了在初次运行Nacos时遇到的由于JWT密钥不足256位导致的异常,以及如何通过修改`application.properties`文件,设置`nacos.core.auth.*`相关参数来解决此问题。首先,将默认的secretkey设置为足够安全的值,然后添加serveridentitykey和value以满足认证需求,最终成功运行Nacos。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第一次下载Nacos,直接运行后出现异常错误:

Caused by: java.lang.IllegalArgumentException: The specified key byte array is 0 bits which is not secure enough for any JWT HMAC-SHA algorithm.  The JWT JWA Specification (RFC 7518, Section 3.2) states that keys used with HMAC-SHA algorithms MUST have a size >= 256 bits (the key size must be greater than or equal to the hash output size).  See https://tools.ietf.org/html/rfc7518#section-3.2 for more information.
        at com.alibaba.nacos.plugin.auth.impl.jwt.NacosJwtParser.<init>(NacosJwtParser.java:56)
        at com.alibaba.nacos.plugin.auth.impl.token.impl.JwtTokenManager.processProperties(JwtTokenManager.java:71)
        ... 115 common frames omitted
2023-03-23 11:20:14,716 WARN [ThreadPoolManager] Start destroying ThreadPool

查看某度、官方才知道,Nacos官方因前期爆出的权限漏洞,把安装包内的默认参数置空了,所以把application.properties文件修改如下:

nacos.core.auth.enabled=true 
nacos.core.auth.system.type=nacos #启用
nacos.core.auth.plugin.nacos.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789 #官方默认参数,自行修改

然后再尝试运行,出现如下异常信息:

Caused by: com.alibaba.nacos.api.exception.NacosException: Empty identity, Please set `nacos.core.auth.server.identity.key` and `nacos.core.auth.server.identity.value`, detail: https://nacos.io/zh-cn/docs/v2/guide/user/auth.html
        at com.alibaba.nacos.auth.config.AuthConfigs.validate(AuthConfigs.java:100)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        at java.base/java.lang.reflect.Method.invoke(Method.java:578)
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:389)
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:333)
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:157)

修改参数配置文件:

### The two properties is the white list for auth and used by identity the request from other server.
nacos.core.auth.server.identity.key=test
nacos.core.auth.server.identity.value=test

修改后,运行成功!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

biyeyuanma

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值