外观
快速入门
2026-04-01
本文介绍
nebula-auth服务的部署配置和关键配置项说明。
目录
一、数据库初始化
nebula-auth 使用 Flyway 管理数据库版本,服务启动时自动执行迁移脚本:
| 脚本 | 说明 |
|---|---|
V1.0.0__init_auth_tables.sql | 初始化认证基础表(登录日志等) |
V1.1.0__auth_account.sql | 认证账号表 |
V1.2.0__drop_auth_oauth2_client.sql | 调整 OAuth2 客户端表(移除旧结构) |
V1.3.0__fix_auth_oauth2_client.sql | 修复 OAuth2 客户端表结构 |
脚本位置:nebula-auth-server/src/main/resources/db/migration/
二、关键配置项
以 nebula.auth 为前缀,主要分三个配置组:
nebula:
auth:
# 验证码配置
captcha:
enabled: true # 是否启用验证码(默认 true)
type: math # 验证码类型:math(数学题)/ image(图形)
length: 4 # 图形验证码长度(type=image 时)
expire-seconds: 120 # 验证码过期时间(秒)
math:
max-operand: 10 # 数学题最大操作数
operators: "+,-,*" # 支持的运算符
# 登录安全配置
login:
rsa-enabled: true # 是否启用 RSA 密码加密传输(默认 true)
max-fail-count: 5 # 最大登录失败次数(超过则锁定账号)
lock-minutes: 30 # 账号锁定时长(分钟)
ip-rate-limit: true # 是否启用 IP 维度登录频率限制
# OAuth2 配置
oauth2:
issuer: http://localhost:8080 # Token 签发者(生产环境改为实际域名)
rsa:
private-key-path: # RSA 私钥文件路径(留空则启动时随机生成)
public-key-path: # RSA 公钥文件路径三、JWT 密钥配置
nebula-auth 使用 RSA 非对称密钥签发 JWT Token。
开发环境(推荐)
不配置密钥路径,服务启动时自动生成临时 RSA 密钥对(重启后失效):
nebula:
auth:
oauth2:
rsa:
private-key-path: # 留空
public-key-path: # 留空生产/UAT 环境
使用固定密钥文件,确保服务重启后已颁发的 Token 仍然有效:
1. 生成密钥对:
# 生成 RSA 私钥(2048 bit)
openssl genrsa -out nebula-auth-private.pem 2048
# 从私钥提取公钥
openssl rsa -in nebula-auth-private.pem -pubout -out nebula-auth-public.pem2. 配置文件路径:
nebula:
auth:
oauth2:
issuer: https://auth.yourdomain.com
rsa:
private-key-path: /etc/nebula/keys/nebula-auth-private.pem
public-key-path: /etc/nebula/keys/nebula-auth-public.pem安全提示: 私钥文件权限应设置为
600,只允许服务账户读取,不要将私钥提交到代码仓库。
四、验证码配置
验证码支持两种类型,推荐使用数学题验证码(更简洁,用户体验好):
nebula:
auth:
captcha:
enabled: true
type: math # 推荐:数学题验证码(如 3 + 5 = ?)
expire-seconds: 120 # 2 分钟内必须完成登录
math:
max-operand: 10 # 题目中数字不超过 10
operators: "+,-" # 只用加减,不用乘法(更适合用户)若
enabled: false,登录时无需提交验证码字段(captchaId和captchaCode传空即可)。
五、登录安全配置
nebula:
auth:
login:
rsa-enabled: true # 密码传输时客户端用公钥加密,服务端用私钥解密
max-fail-count: 5 # 连续失败 5 次锁定账号
lock-minutes: 30 # 锁定 30 分钟后自动解锁(或管理员手动解锁)
ip-rate-limit: true # 同一 IP 的登录请求速率限制(防暴力破解)六、接口基本信息
| 项 | 值 |
|---|---|
| 服务名 | nebula-auth |
| 默认端口 | 8080 |
| Swagger 文档 | http://localhost:8080/doc.html |
| 认证接口前缀 | /auth |
| RPC 接口前缀 | /rpc/nebula/auth |
