Skip to content

Commit f882de0

Browse files
committed
fix(lab): name the ACL failure code in the publisher key error
Every required publisher-key ACL harden failure reached CI as one fixed string, "public publisher key ACL hardening did not complete". The discriminator existed only on `cause`, which the test reporter does not print, so the three causes that occur on the Windows leg -- ETIMEDOUT (the budget), EACLIDENTITY (the effective-SID lookup) and EICACLS (icacls refusing the path) -- were indistinguishable from a log, and each needs a different fix. Append the bounded errno-shaped code to the message. Only the code crosses that boundary, re-checked for shape here rather than trusted, so a pathname or username component cannot reach a public log through it. A cause without such a code keeps the previous message unchanged. Refs #2152.
1 parent 3c6a452 commit f882de0

2 files changed

Lines changed: 86 additions & 1 deletion

File tree

‎src/lab/public/signature.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ function publisherForPrivateKey(privateKeyPem: string): PublicPublisherV1 {
5252
};
5353
}
5454

55+
/**
56+
* The bounded errno-shaped code from a failed ACL harden, or null when the cause
57+
* carries none.
58+
*
59+
* Only the code is allowed into the message. `hardenSecretPath` already sanitizes
60+
* its own diagnostic prose, but this error is what reaches a CI log, so what
61+
* crosses that boundary is re-checked here rather than trusted: an errno code has
62+
* no separator, no lowercase and a bounded length, and therefore cannot carry the
63+
* key pathname or the username component inside it.
64+
*/
65+
function aclFailureCode(error: unknown): string | null {
66+
if (!(error instanceof Error) || !("code" in error)) return null;
67+
const code = (error as NodeJS.ErrnoException).code;
68+
return typeof code === "string" && /^[A-Z][A-Z0-9_]{1,30}$/.test(code) ? code : null;
69+
}
70+
5571
function requirePublisherKeyAcl(path: string, timeoutMemoKey = path): void {
5672
privateRegularFileSize(path, PRIVATE_KEY_FILE_OPTIONS);
5773
let hardened: { ok: boolean };
@@ -63,9 +79,17 @@ function requirePublisherKeyAcl(path: string, timeoutMemoKey = path): void {
6379
hardened = { ok: false };
6480
}
6581
if (!hardened.ok) {
82+
// Name the cause in the message, not only on `cause`. Every harden failure
83+
// reaches a CI log as this one string, and the three that occur there need
84+
// different fixes: ETIMEDOUT is the budget, EACLIDENTITY is the effective-SID
85+
// lookup, EICACLS is icacls refusing the path. A message identical across all
86+
// three cannot be acted on without a Windows box to re-run it under (#2152).
87+
const code = aclFailureCode(hardeningError);
6688
const failure = new PublicEvidenceValidationError(
6789
"public_publisher_key_unsafe",
68-
"public publisher key ACL hardening did not complete",
90+
code
91+
? `public publisher key ACL hardening did not complete (${code})`
92+
: "public publisher key ACL hardening did not complete",
6993
);
7094
if (hardeningError !== undefined) {
7195
(failure as Error & { cause?: unknown }).cause = hardeningError;

‎tests/lab-public-security-regressions.test.ts‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ import {
1515
setIcaclsRunnerForTests,
1616
setPlatformForTests,
1717
} from "../src/lib/windows-secret-acl";
18+
import { setWindowsPrincipalRunnerForTests } from "../src/lib/windows-user-principal";
1819

1920
const roots: string[] = [];
2021

2122
afterEach(() => {
2223
setIcaclsRunnerForTests(null);
24+
setWindowsPrincipalRunnerForTests(null);
2325
setPlatformForTests(null);
2426
resetHardenedStateForTests();
2527
for (const root of roots.splice(0)) {
@@ -186,3 +188,62 @@ test("publisher key ACL failures preserve their underlying cause", () => {
186188
expect(caught).toBeInstanceOf(Error);
187189
expect((caught as Error & { cause?: unknown }).cause).toBeInstanceOf(Error);
188190
});
191+
192+
function publisherKeyAclFailureMessage(prefix: string): string {
193+
const home = configDir(prefix);
194+
try {
195+
getOrCreatePublicPublisher(home);
196+
} catch (error) {
197+
return (error as Error).message;
198+
}
199+
throw new Error("expected required publisher key ACL hardening to fail");
200+
}
201+
202+
// #2152: on the Windows CI leg every publisher-key harden failure arrived as one
203+
// fixed string. The three causes that occur there need different fixes -- the
204+
// budget, the effective-SID lookup, or icacls itself -- and the code lived only on
205+
// `cause`, which the reporter does not print. Diagnosing it needed a Windows box.
206+
test("a required publisher key ACL timeout names ETIMEDOUT in its message", () => {
207+
resetHardenedStateForTests();
208+
setPlatformForTests("win32");
209+
setIcaclsRunnerForTests(() => ({ success: false, exitCode: null, timedOut: true, stdout: "" }));
210+
211+
expect(publisherKeyAclFailureMessage("ocx-cl10-acl-code-timeout-")).toContain("ETIMEDOUT");
212+
});
213+
214+
test("a required publisher key icacls refusal names EICACLS in its message", () => {
215+
resetHardenedStateForTests();
216+
setPlatformForTests("win32");
217+
setIcaclsRunnerForTests(() => ({ success: false, exitCode: 5, timedOut: false, stdout: "" }));
218+
219+
expect(publisherKeyAclFailureMessage("ocx-cl10-acl-code-icacls-")).toContain("EICACLS");
220+
});
221+
222+
// The identity code is raised by windows-user-principal, one module further out
223+
// than the icacls runner, so this also pins that it survives the hand-off.
224+
test("a required publisher key SID lookup failure names EACLIDENTITY in its message", () => {
225+
resetHardenedStateForTests();
226+
setPlatformForTests("win32");
227+
setIcaclsRunnerForTests(() => ({ success: true, exitCode: 0, timedOut: false, stdout: "" }));
228+
setWindowsPrincipalRunnerForTests(() => ({
229+
success: false,
230+
exitCode: null,
231+
timedOut: true,
232+
stdout: "",
233+
}));
234+
235+
expect(publisherKeyAclFailureMessage("ocx-cl10-acl-code-identity-")).toContain("EACLIDENTITY");
236+
});
237+
238+
// A cause with no errno-shaped code must leave the message alone rather than
239+
// print an empty parenthetical, and nothing but the bounded code may be appended.
240+
test("a publisher key ACL failure without a bounded code keeps the plain message", () => {
241+
resetHardenedStateForTests();
242+
setPlatformForTests("win32");
243+
setIcaclsRunnerForTests(() => {
244+
throw new Error("synthetic icacls runner failure");
245+
});
246+
247+
const message = publisherKeyAclFailureMessage("ocx-cl10-acl-code-plain-");
248+
expect(message).toBe("public publisher key ACL hardening did not complete");
249+
});

0 commit comments

Comments
 (0)