bigywater.tech
Spring · 78

Actuator 端点:暴露、安全与开销

装了 Actuator 默认暴露什么?include=* 危险在哪?heapdump 和 shutdown 为什么默认打不开?env 里的密码会不会明文?单独的管理端口有什么坑?这篇在 Spring Boot 4.0.8 上逐个端点实测。

3 个链接
默认的 /actuator 只列出 health、health-path 和 self
32.2 MB
打开 heapdump 的 access 之后,无认证就能下载的堆转储大小
******
默认 /actuator/env 里 4 个属性的值全部脱敏,包括不敏感的 app.name

默认暴露

实测 · 本机执行输出
  GET /actuator → 200;links = ['health', 'health-path', 'self']
  GET /actuator/health → 200  {"groups":["liveness","readiness"],"status":"UP"}
  GET /actuator/info → 404  {"timestamp":"2026-10-20T02:51:39.612Z","status":404,"error":"Not Foun…
  GET /actuator/env → 404  {"timestamp":"2026-10-20T02:51:39.620Z","status":404,"error":"Not Foun…
  GET /actuator/metrics → 404  {"timestamp":"2026-10-20T02:51:39.625Z","status":404,"error":"Not Foun…
  GET /actuator/beans → 404  {"timestamp":"2026-10-20T02:51:39.629Z","status":404,"error":"Not Foun…
  GET /actuator/heapdump → 404  {"timestamp":"2026-10-20T02:51:39.635Z","status":404,"error":"Not Foun…

只暴露 health,且不带组件明细;其他端点 404。

暴露与访问权限

实测 · 本机执行输出
  GET /actuator → 200;共 19 个链接(含 self);端点:['beans', 'conditions', 'configprops', 'configprops-prefix', 'env', 'env-toMatch', 'health', 'health-path', 'info', 'loggers', 'loggers-name', 'mappings', 'metrics', 'metrics-requiredMetricName', 'sbom', 'sbom-id', 'scheduledtasks', 'threaddump']
  GET /actuator/env → 200,8 KB,17 ms
  GET /actuator/beans → 200,99 KB,10 ms
  GET /actuator/mappings → 200,19 KB,20 ms
  GET /actuator/threaddump → 200,60 KB,16 ms
  GET /actuator/configprops → 200,13 KB,57 ms
  GET /actuator/loggers → 200,31 KB,7 ms
  GET /actuator/conditions → 200,65 KB,6 ms
  GET /actuator/heapdump → 404,0 KB,8 ms
  POST /actuator/shutdown → 404  {"timestamp":"2026-10-20T02:51:41.679Z","status":404,"error":"Not Foun…
  -- 额外加 management.endpoint.heapdump.access=unrestricted:
  /actuator 里有 heapdump:True
  GET /actuator/heapdump → 200,Content-Type application/octet-stream,32.2 MB,261 ms;请求里没有带任何认证信息
  -- 暴露了但把访问权限关掉:management.endpoint.env.access=none、management.endpoint.shutdown.access=unrestricted
  /actuator 里有 env:False;有 shutdown:True
  GET /actuator/env → 404
  POST /actuator/shutdown → 200  {"message":"Shutting down, bye..."}
  shutdown 之后 3 秒,java 进程 已退出,退出码 0

include=* 之后 19 个端点没有认证;heapdump、shutdown 还要把 access 设成 unrestricted,打开后同样没有认证。

env 的脱敏

实测 · 本机执行输出
  默认(management.endpoint.env.show-values 不设):
    app.name → 200,值 '******',来源 systemProperties
    app.password → 200,值 '******',来源 systemProperties
    app.token → 200,值 '******',来源 systemProperties
    app.url → 200,值 '******',来源 systemProperties
  management.endpoint.env.show-values=ALWAYS:
    app.name → 200,值 'demo',来源 systemProperties
    app.password → 200,值 'p@ssw0rd',来源 systemProperties
    app.token → 200,值 'tok-123',来源 systemProperties
    app.url → 200,值 'http://example.com',来源 systemProperties
  management.endpoint.env.show-values=WHEN_AUTHORIZED(没有装 Spring Security):
    app.name → 200,值 '******',来源 systemProperties
    app.password → 200,值 '******',来源 systemProperties
    app.token → 200,值 '******',来源 systemProperties
    app.url → 200,值 '******',来源 systemProperties

默认所有值脱敏;show-values=ALWAYS 全部明文;WHEN_AUTHORIZED 没有 Security 时仍脱敏。

管理端口

实测 · 本机执行输出
  management.server.port=9608:业务端口 GET /actuator/health → 404;管理端口 GET /fast → 404;管理端口 GET /actuator/health:业务端口可连接之后又过了 261 ms 才连得上管理端口(此前连接被拒绝 11 次),第一次响应 → 503 {"groups":["liveness","readiness"],"status":"DOWN"},2 秒后 → 200 {"groups":["liveness","readiness"],"status":"UP"}
  management.endpoints.web.base-path=/ops:/actuator/health → 404;/ops/health → 200

管理端口比业务端口晚开,刚开时 health 返回 503 DOWN;base-path 可以改。

开销

实测 · 本机执行输出
  没有 actuator:启动到端口可连接 中位 817 ms(范围 815~917);启动后常驻内存中位 168 MB
  有 actuator(默认):启动到端口可连接 中位 1082 ms(范围 972~1203);启动后常驻内存中位 184 MB

装 actuator 启动多约 265 ms、内存多约 16 MB(量级参考);请求吞吐开销没有得到可信结果。

分步演示

Actuator 端点
本步的对象

    本文用到的工具与边界

    • 本机 macOS 27 arm64 / OpenJDK 21.0.12(Homebrew) / Spring Boot 4.0.8(Spring Framework 7.0.9、Tomcat 11.0.24) / Spring Cloud 2025.1.3;用 javac 编译、java 直接运行,依赖由 Maven 从 Maven Central 解析;数字每次运行会有小幅抖动。被测应用是 spring-boot-starter-webmvc 加 spring-boot-starter-actuator 的单个程序,一个 /fast 接口;敏感值用 -D 系统属性传入;HTTP 请求用 Python http.client;第五节每组 7 次取中位数,但测试时机器上有其他程序在运行(负载较高),所以只当量级看
    • 没有验证:装了 Spring Security 之后 WHEN_AUTHORIZED 与端点保护的行为;Prometheus、Micrometer 指标端点与 /actuator/metrics 里具体指标的内容(见第 80 篇);/actuator/health 的组件明细(show-details)与健康指示器(见第 79 篇);JMX 暴露;每个请求上 Micrometer 观测的吞吐开销(本篇几轮压测都被机器负载搅乱,没有得到可信结果);CORS、路径映射等 Web 层对端点的影响;heapdump 里是否真的包含配置里的密码(只测了大小和是否需要认证)
    京ICP备2026067502号-1京公网安备11010502063487号