对应 docs/operation-audit-halo-compliance.md 评审的两项不符合与第 5 节修复建议: 1. API 客户端生成(清单第 2 条):build.gradle 配置 haloPlugin.openApi 管线; 查询/导出/测试端点补 tag、参数声明与类型化 response(生成契约输入); bootstrap OpenAPI 规范 JSON(与 Springdoc 声明一一对手工对齐)驱动 devtools generateApiClient 产出 TS 客户端(ui/src/api/generated,openapi-generator 7.7.0); UI 经 ui/src/api 封装层复用宿主 axiosInstance,替换手写类型与裸 fetch; @halo-dev/api-client 由死依赖转为 axiosInstance 实际来源。 2. 出站安全与凭据(清单第 4 条):新增 OutboundUrlGuard——URI 解析 + scheme 白名单 + 禁止用户名/密码形态 + 全量 DNS 解析并拒绝环回/私网/链路本地/组播/未指定/ 云元数据(169.254.169.254、100.100.100.200、fd00:ec2::254)/CGNAT/ULA/Teredo/ 6to4/文档与保留段;PinnedAddressResolverGroup 钉定校验地址建连(DNS rebinding 防护,TLS SNI/Host 仍取原主机名);重定向显式关闭、三层超时 10 秒。 Webhook 地址凭据迁移 Halo Secret(settings.yaml 改 secret 输入存引用,服务端经 ReactiveExtensionClient 解析键 webhookUrl,fail closed);日志只记主机名, 不再记录可能内嵌 access_token 的完整地址。 测试:后端 244 用例(新增守卫地址段枚举/Secret 解析 fail closed/建连钉定证明等 25 例)+ UI vitest 54 用例 + vue-tsc + ./gradlew build 全部通过。
106 lines
3.6 KiB
Groovy
106 lines
3.6 KiB
Groovy
plugins {
|
||
id 'java'
|
||
id 'io.freefair.lombok' version '9.2.0'
|
||
id "run.halo.plugin.devtools" version "0.8.0"
|
||
}
|
||
|
||
group = 'run.halo.operationaudit'
|
||
|
||
repositories {
|
||
mavenCentral()
|
||
}
|
||
|
||
dependencies {
|
||
implementation platform('run.halo.tools.platform:plugin:2.26.0')
|
||
compileOnly 'run.halo.app:api'
|
||
|
||
testImplementation 'run.halo.app:api'
|
||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||
testImplementation 'io.projectreactor:reactor-test'
|
||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
||
}
|
||
|
||
java {
|
||
toolchain {
|
||
languageVersion = JavaLanguageVersion.of(21)
|
||
}
|
||
}
|
||
|
||
tasks.withType(JavaCompile).configureEach {
|
||
options.encoding = 'UTF-8'
|
||
options.release = 21
|
||
}
|
||
|
||
test {
|
||
useJUnitPlatform()
|
||
testLogging {
|
||
events 'passed', 'skipped', 'failed'
|
||
}
|
||
}
|
||
|
||
// 将 ui 子项目构建产物打包进插件 jar 的 console/ 目录(Console 前端入口由 ui-plugin.json 清单声明)
|
||
tasks.register('processUiResources', Copy) {
|
||
from project(':ui').layout.buildDirectory.dir('dist')
|
||
into layout.buildDirectory.dir('resources/main/console')
|
||
dependsOn project(':ui').tasks.named('assemble')
|
||
shouldRunAfter tasks.named('processResources')
|
||
// 前端产物带 hash 文件名,先清空目标目录避免历史版本残留进 jar
|
||
doFirst {
|
||
delete layout.buildDirectory.dir('resources/main/console')
|
||
}
|
||
}
|
||
|
||
tasks.named('classes') {
|
||
dependsOn tasks.named('processUiResources')
|
||
}
|
||
|
||
tasks.named('generatePluginComponentsIdx') {
|
||
notCompatibleWithConfigurationCache('This task invokes "Task.project" at execution time, which is not supported with configuration cache.')
|
||
}
|
||
|
||
halo {
|
||
version = '2.26.1'
|
||
}
|
||
|
||
// API 客户端生成(官方检查清单第 2 条):UI 的 TS 类型与请求方法一律由
|
||
// generateApiClient 任务生成,禁止手写。管线两步:
|
||
// 1) ./gradlew generateOpenApiDocs —— 从运行中的 Halo(Docker haloServer 或
|
||
// useExistingServer 指向的实例)抓取 /v3/api-docs/extensionApis,按 groupingRules
|
||
// 过滤插件路径,落盘到 openApi.outputDir(每次生成先清空,须为专属目录);
|
||
// 2) ./gradlew generateApiClient —— 读取上一步的规范 JSON,产出 TS 客户端到
|
||
// generator.outputDir(同样先清空;产物入库,UI 经 ui/src/api 封装层调用)。
|
||
haloPlugin {
|
||
openApi {
|
||
// 规范 JSON 落盘目录(generateOpenApiDocs 产物 / generateApiClient 输入;
|
||
// 每次生成先清空,须为专属目录,位于 build/ 下不入库)
|
||
outputDir = file("${projectDir}/build/openapi")
|
||
// 仅覆盖插件自有子资源端点(/-/query、/-/export、/-/test);
|
||
// AuditLog 模型类型经响应 schema 引用一并生成
|
||
groupingRules {
|
||
extensionApis {
|
||
displayName = 'Operation Audit Extension API'
|
||
pathsToMatch = [
|
||
'/apis/audit.guichumo.com/v1alpha1/auditlogs/-/**',
|
||
'/apis/audit.guichumo.com/v1alpha1/alerts/-/**',
|
||
]
|
||
}
|
||
}
|
||
groupedApiMappings = [
|
||
'/v3/api-docs/extensionApis': 'extensionApis.json'
|
||
]
|
||
generator {
|
||
outputDir = file("${projectDir}/ui/src/api/generated")
|
||
additionalProperties = [
|
||
useES6 : 'true',
|
||
useSingleRequestParameter : 'true',
|
||
withSeparateModelsAndApi : 'true',
|
||
apiPackage : 'api',
|
||
modelPackage : 'models',
|
||
]
|
||
typeMappings = [
|
||
set: 'Array'
|
||
]
|
||
}
|
||
}
|
||
}
|