Skip to content

Commit c6dc643

Browse files
committed
Allowlist default OpenCLI configuration diagnostics
1 parent 88d4eab commit c6dc643

5 files changed

Lines changed: 63 additions & 2 deletions

File tree

‎openspec/changes/harden-opencli-diagnostics-privacy/tasks.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,9 @@ JDK 17 基线 `0cbb3ee750062675813f1d3389c5f7f14b50345c` 的定向用例在 3
6161
OC-PRIV-001/004。OpenCliProcessPrivacyTest 的新用例在 Java 17 基线复现缺少 correlationId,退出 1。现在本地进程失败时由 SDK 生成随机 UUID,在 DEBUG 日志及返回的异常消息中使用同一值。日志只记录终止原因、退出码和捕获字节数。测试扫描捕获的日志和完整异常栈,同时通过 partialResult 校验 stderr 原值。C03 的 OpenCliErrorEnvelopeTest 覆盖含敏感标记的畸形 YAML,并确认解析器原文不进入默认诊断。
6262

6363
Java 8、17、21 分别用各自 Wrapper 运行 OpenCliProcessPrivacyTest、OpenCliErrorEnvelopeTest 和 OpenCliProcessContractTest,每条线执行 31 项,零失败、零错误、零跳过。报告位于 target/surefire-reports。Java 21 的先前运行曾出现继承管道用例的 JUnit 临时目录清理竞态,本次重跑通过。该竞态需要独立处理。
64+
65+
## SDK 配置对象的默认诊断
66+
67+
OC-PRIV-001/004。Java 17 基线 `58f675a` 的两项回归均失败。输出 `OpenCliProperties` 或 `OpenCliWsAgentConnectionProperties` 时,Lombok 的默认字符串表示包含测试标记。改为显式允许表后,默认字符串只包含受控枚举、开关、字节预算和超时、并发等数值。CDP 地址、本地路径、启动参数、环境变量、WebSocket 地址和节点标签仍可通过各自的配置 API 读取和使用。
68+
69+
实现分别基于 Java 8 `afc6b33`、Java 17 `58f675a`、Java 21 `5cfa937`。三线使用各自 Wrapper 执行 `./mvnw -B -ntp -o clean verify`,分别通过 2,242、2,243、2,242 项。失败、错误、跳过均为 0。两项新增测试记录在 `OpenCliPropertiesTest` 和 `OpenCliWsReverseAgentClientTest` 的 Surefire 报告中。随后同步的 Agent TLS 证据提交只触及 OpenSpec 材料。

‎src/main/java/io/github/easy4j/opencli/OpenCliProperties.java‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,47 @@
1515
* @author <a href="https://github.com/loong10k">Loong Wan</a>
1616
* @since 3.0.0
1717
*/
18+
@ToString(onlyExplicitlyIncluded = true)
1819
@Data
1920
public class OpenCliProperties {
21+
@ToString.Include
2022
private OpenCliExecutionTarget executionTarget = OpenCliExecutionTarget.LOCAL_PROCESS;
2123
/** Root URL of an opencli-admin compatible Agent. */
22-
@ToString.Exclude
2324
private String remoteAgentBaseUrl;
2425
/** Explicit credential header for the configured HTTPS Agent. */
25-
@ToString.Exclude
2626
private OpenCliRemoteAuthentication remoteAuthentication;
2727
private String remoteCollectMode = "cdp";
2828
private String remoteOutputFormat = "json";
2929
private String remoteCdpEndpoint = "";
3030
/** Raw HTTP capture is explicitly opt-in and may contain sensitive business data. */
31+
@ToString.Include
3132
private boolean remoteCaptureRawHttpResponse = false;
3233
/** Maximum decoded HTTP response body bytes accepted from a remote Agent. */
34+
@ToString.Include
3335
private int maxRemoteResponseBytes = 10 * 1024 * 1024;
3436
private String executable = "opencli";
3537
/** Defaults applied when dispatching a schema-validated local command. */
3638
private OpenCliInvocationContext invocationDefaults;
3739
private String workingDirectory;
3840
/** Total local queue and execution budget, or the remote HTTP transport budget. */
41+
@ToString.Include
3942
private long commandTimeoutMillis = 300_000L;
4043
/** Legacy per-stream ceiling; nonpositive values keep the finite stdout/stderr budgets. */
44+
@ToString.Include
4145
private long maxOutputBytes = 10L * 1024 * 1024;
4246
/** Positive per-client capacity, zero for max(2, cores); negative is invalid. Captured at construction. */
47+
@ToString.Include
4348
private int maxConcurrentExecutions = 0;
4449
/** Maximum bytes retained from stdout for one local invocation. */
50+
@ToString.Include
4551
private int maxStdoutBytes = 8 * 1024 * 1024;
4652
/** Maximum bytes retained from stderr for one local invocation. */
53+
@ToString.Include
4754
private int maxStderrBytes = 2 * 1024 * 1024;
4855
/** Independent bounded cleanup grace, in milliseconds. */
56+
@ToString.Include
4957
private long cleanupGraceMillis = 5_000L;
58+
@ToString.Include
5059
private long startupProbeTimeoutMillis = 30_000L;
5160
/** Literal prefix arguments placed before the command identifier. */
5261
private List<String> leadingArguments = new ArrayList<>();

‎src/main/java/io/github/easy4j/opencli/center/ws/OpenCliWsAgentConnectionProperties.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.easy4j.opencli.center.ws;
22

33
import lombok.Data;
4+
import lombok.ToString;
45

56
/**
67
* 边缘 JVM 作为「反向 WebSocket Agent」连入 opencli-admin 中心所需的连接参数。
@@ -9,6 +10,7 @@
910
* {@code register},随后在处理 {@code collect} 时本地执行 opencli,并以 {@code result} 回传。
1011
* </p>
1112
*/
13+
@ToString(onlyExplicitlyIncluded = true)
1214
@Data/**
1315
1416
* Connection parameters for an edge JVM acting as a reverse WebSocket Agent
@@ -41,6 +43,7 @@ public class OpenCliWsAgentConnectionProperties {
4143
/**
4244
* 连接中心的 WebSocket 路径枚举。
4345
*/
46+
@ToString.Include
4447
private OpenCliCenterWebSocketPath webSocketPath = OpenCliCenterWebSocketPath.NODES_WS;
4548

4649
/**
@@ -60,26 +63,32 @@ public class OpenCliWsAgentConnectionProperties {
6063
private String nodeType = "shell";
6164

6265
/** 并行执行的 collect 任务上限,必须为正数。 */
66+
@ToString.Include
6367
private int maxConcurrentCollects = 4;
6468

6569
/** 排队的 collect 任务上限,零表示没有等待队列。 */
70+
@ToString.Include
6671
private int maxPendingCollects = 32;
6772

6873
/** 单条入站 WebSocket 消息的 UTF-8 字节上限,包括分片聚合。 */
74+
@ToString.Include
6975
private int maxInboundMessageBytes = 1024 * 1024;
7076

7177
/**
7278
* 首次 {@code registered} 应答等待上限(毫秒)。
7379
*/
80+
@ToString.Include
7481
private long handshakeTimeoutMillis = 15_000L;
7582

7683
/**
7784
* 断线后最小重连间隔(毫秒)。
7885
*/
86+
@ToString.Include
7987
private long minReconnectDelayMillis = 3_000L;
8088

8189
/**
8290
* 断线后最大重连间隔(毫秒)。
8391
*/
92+
@ToString.Include
8493
private long maxReconnectDelayMillis = 60_000L;
8594
}

‎src/test/java/io/github/easy4j/opencli/OpenCliPropertiesTest.java‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,27 @@
66

77
class OpenCliPropertiesTest {
88

9+
@Test
10+
void defaultDiagnosticStringExcludesSensitiveExecutionConfiguration() {
11+
OpenCliProperties properties = new OpenCliProperties();
12+
properties.setRemoteCdpEndpoint("https://browser.example/?token=cdp-canary");
13+
properties.setExecutable("/private/executable-canary/opencli");
14+
properties.setWorkingDirectory("/private/working-directory-canary");
15+
properties.setLeadingArguments(Collections.singletonList("argument-canary"));
16+
properties.setEnvironment(Collections.singletonMap("API_TOKEN", "environment-canary"));
17+
18+
String diagnostic = properties.toString();
19+
assertTrue(diagnostic.contains("executionTarget=LOCAL_PROCESS"));
20+
assertTrue(diagnostic.contains("commandTimeoutMillis="));
21+
for (String canary : Arrays.asList("cdp-canary", "executable-canary", "working-directory-canary",
22+
"argument-canary", "environment-canary")) {
23+
assertFalse(diagnostic.contains(canary), canary);
24+
}
25+
assertEquals("environment-canary", properties.getEnvironment().get("API_TOKEN"));
26+
assertEquals(Collections.singletonList("argument-canary"), properties.getLeadingArguments());
27+
}
28+
29+
930
@Test
1031
void shouldHaveDefaults() {
1132
OpenCliProperties p = new OpenCliProperties();

‎src/test/java/io/github/easy4j/opencli/center/ws/OpenCliWsReverseAgentClientTest.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,22 @@ void shouldAcceptValidConnectionProperties() {
8080
client.close();
8181
}
8282

83+
@Test
84+
void defaultConnectionDiagnosticExcludesAddressesAndLabel() {
85+
OpenCliWsAgentConnectionProperties properties = new OpenCliWsAgentConnectionProperties();
86+
properties.setCentralApiBaseUrl("https://center.example/?token=center-canary");
87+
properties.setAgentAdvertiseUrl("https://agent-canary.example/");
88+
properties.setLabel("label-canary");
89+
90+
String diagnostic = properties.toString();
91+
assertTrue(diagnostic.contains("webSocketPath=NODES_WS"));
92+
assertTrue(diagnostic.contains("maxPendingCollects="));
93+
assertFalse(diagnostic.contains("center-canary"));
94+
assertFalse(diagnostic.contains("agent-canary"));
95+
assertFalse(diagnostic.contains("label-canary"));
96+
assertEquals("https://agent-canary.example/", properties.getAgentAdvertiseUrl());
97+
}
98+
8399
@Test
84100
void failedSessionLogDoesNotEchoConfiguredUrlCanary() throws Exception {
85101
String canary = "wsurlsecret" + UUID.randomUUID().toString().replace("-", "");

0 commit comments

Comments
 (0)