容器化部署nacos 1.4.6报错caused: The specified key byte array is 0 bits which is not secure enough for any JWT

发布时间 2023-08-18 13:44:40作者: 挎木剑的游侠儿

nacos2.0+ 与nacos 1.x区别

nacos在2.0+版本开始使用grpc与客户端通信,并且通过非8848端口通信
主要是有两个端口

端口 与主端口的偏移量 描述
9848 1000 客户端gRPC请求服务端端口,用于客户端向服务端发起连接和请求
9849 1001 服务端gRPC请求服务端端口,用于服务间同步等

然而,我们的需求是在k8s中部署nacos,并且使用nodeport方式映射端口。
这样就会导致9848端口映射出去的端口,并不是8848端口映射出去的端口+1000。

降低版本至nacos1.4.6

所以降低nacos版本至dockerhub中存在的1.x的最高版本1.4.6
但是部署时又发现问题,使用默认debry数据库启动时,使用账号nacos/nacos登录报错,同时报错十分莫名其妙

caused: 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).Consider using the io.jsonwebtoken.security.Keys #secretKeyFor(SignatureAlgorithm)method to create a key guaranteed to be secure enough for your preferred HMAC-SHA algorithm.See https: //tools.ietf.org/html/rfc7518#section-3.2 for more information.;

查了半天换了好几个镜像也没整明白,最后发现有一个文章中提到了nacos.core.auth.default.token.secret.key。 这个参数必须配置为base64编码而且不能小于32位,咱也不知道咋回事总之先试试,就随便整个值配上了,结果还真好啦
真是奇葩啊,为啥要搞个莫名其妙的参数,和启动访问又没有关系,服啦

docker部署demo命令

docker run -d --name=nacos -p 8848:8848 -e MODE=standalone -e NACOS_AUTH_TOKEN= SecretKey012345678901234567890123456789012345678901234567890123456789 nacos/nacos-server:v1.4.6-slim