Skip to content

starter-security: 默认 permit-paths 未覆盖 /actuator/health/** —— K8s readiness/liveness 探针被 401 #26

Description

@JIAQIA

源起:hashmatrix-security#4(服务入口级达标)实现期发现。本仓已落临时 workaround(在 application.yml 覆写 hashmatrix.security.permit-paths 增列 /actuator/health/**),现回升根因到 starter-security 统一治理,避免各 service 仓各自发明。

问题

hashmatrix-starter-security(实测 0.2.0)默认放行路径为精确路径

permitPaths = ["/actuator/health", "/actuator/info", "/actuator/prometheus"]

SecurityFilterChainConfiguration 机制为 requestMatchers(permitPaths.toArray()).permitAll() + anyRequest().authenticated()。Spring Security 的 requestMatchers("/actuator/health") 只精确匹配 /actuator/health不覆盖其子路径。

影响

K8s 存活/就绪探针访问的是 /actuator/health/liveness/actuator/health/readiness(Spring Boot health group 子端点)。在默认 permit-paths 下,这两个子路径落入 anyRequest().authenticated()匿名探针被 401

凡是「actuator 与业务共享同一安全过滤链」的服务(单端口部署、或管理子上下文复用主链路)都会中招——这是平台级而非单仓问题。

复现

  • 任一启用 hashmatrix.security 的服务,未配自定义 permit-paths;
  • 匿名 GET /actuator/health → 200;GET /actuator/health/readiness401

建议修法(择一,主仓拍板)

  1. 默认 permit-paths 增列 /actuator/health/**(最小改动;/** 在 AntPath/PathPattern 下亦覆盖 /actuator/health 本身)。
  2. 或改用 EndpointRequest.to(HealthEndpoint.class) 之类的端点匹配器放行 health 及其分组,避免字符串路径漂移。

无论哪种,都需注意 show-details 策略:放行 health 子端点叠加 show-details: always 会把组件级明细(db/flowable 等)暴露给未认证调用方,建议默认 when_authorized 或在文档中提示部署期收敛。

临时 workaround(各仓现状)

hashmatrix:
  security:
    permit-paths:        # 覆盖默认值需重列默认项(列表整体替换语义)
      - /actuator/health
      - /actuator/health/**
      - /actuator/info
      - /actuator/prometheus

根因修复合入后,各仓可移除此覆写。

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions