security(P0①): 安全链改 fail-safe 默认 + prod 配置 + JWT 弱密钥守卫

宽松 permitAll 链由 @Profile("!prod") 改为显式 opt-in @Profile(dev|local|ci|parity);严格认证链覆盖默认(含裸 java -jar)与 prod。新增 SecurityProfiles 作旁路名单唯一真相、JwtSecretSafetyCheck(严格 profile 下拒开发默认密钥启动)、application-prod.yml(密钥/DB 无默认强制环境变量)。修 2026-06-24 架构评审 P0:未设 profile 即全放行的 fail-open 默认。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-25 11:41:21 +08:00
parent a132e67a20
commit 24160db684
6 changed files with 248 additions and 18 deletions

View File

@@ -0,0 +1,54 @@
# ============================================================================
# 生产 profile(P0 修复,2026-06-24 架构评审:补齐缺失的 prod 配置)。
#
# 启用方式:-Dspring.profiles.active=prod(或 SPRING_PROFILES_ACTIVE=prod)。
# 设计原则 fail-safe:所有敏感项<strong>无内置默认</strong>,必须经环境变量显式提供,
# 缺失即启动失败——杜绝继承 application.yml 的开发默认值(共享测试库 / 弱 JWT 密钥)裸奔进生产。
#
# 安全链:prod 不在 SecurityProfiles 旁路名单内 → 自动走严格链(其余 /api/** 强制认证),
# 且 JwtSecretSafetyCheck 在此 profile 下拒绝开发默认 JWT 密钥。
# ============================================================================
spring:
datasource:
# 生产库连接必须经环境变量提供,无默认值(缺失 → 占位符解析失败 → 启动拒绝)。
url: ${EIP4_DB_URL}
username: ${EIP4_DB_USERNAME}
password: ${EIP4_DB_PASSWORD}
hikari:
maximum-pool-size: ${EIP4_DB_POOL_MAX:20}
read-only: false
connection-init-sql: "SET statement_timeout = '${EIP4_DB_STATEMENT_TIMEOUT:120s}'"
server:
port: ${SERVER_PORT:8084}
eip4:
auth:
jwt:
# 生产 JWT 密钥必须经环境变量提供,无默认值(故意去掉 application.yml 的 dev 默认回退)。
# 缺失 → 占位符解析失败启动拒绝;若误填为开发默认值 → JwtSecretSafetyCheck 拒绝启动。
secret: ${EIP4_AUTH_JWT_SECRET}
expire-seconds: ${EIP4_AUTH_JWT_EXPIRE_SECONDS:28800}
issuer: eip4-platform
file:
# 生产附件根必须为绝对路径,经环境变量提供。
root: ${EIP4_FILE_ROOT}
# 可观测性:生产仅暴露健康探针,详情仅对已认证者可见(匿名只见 UP/DOWN)。
management:
endpoints:
web:
exposure:
include: health
endpoint:
health:
probes:
enabled: true
show-details: when-authorized
show-components: when-authorized
logging:
level:
com.dsasp: INFO
org.springframework.jdbc.core: INFO