Skip to content
8 changes: 7 additions & 1 deletion src/lib/shields/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1728,7 +1728,13 @@ function unlockAgentConfigUnderMutationLock(
target.configDir,
]);
const [mode, owner] = dirPerms.split(" ");
if (mode !== dirMode) issues.push(`config dir mode=${mode} (expected ${dirMode})`);
// The Hermes dashboard can tighten its mutable home from 03770 to 0700.
// Both postures are sandbox-owned; protected files remain exactly 0640.
const validDirMode = mode === dirMode || (target.agentName === "hermes" && mode === "700");
if (!validDirMode) {
const expectedDirModes = target.agentName === "hermes" ? `700 or ${dirMode}` : dirMode;
issues.push(`config dir mode=${mode} (expected ${expectedDirModes})`);
}
if (owner !== "sandbox:sandbox") {
issues.push(`config dir owner=${owner} (expected sandbox:sandbox)`);
}
Expand Down
28 changes: 26 additions & 2 deletions src/lib/shields/legacy-hermes-compat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe("legacy Hermes shields compatibility", () => {
fs.rmSync(homeDir, { recursive: true, force: true });
});

function installExecResponses(help: string): void {
function installExecResponses(help: string, hermesDirMode = "3770"): void {
dockerExecSpy.mockImplementation((cmd: string[]) => {
switch (true) {
case cmd.includes(HERMES_GUARD) && cmd.includes("--help"):
Expand All @@ -138,7 +138,9 @@ describe("legacy Hermes shields compatibility", () => {
case isGuardAction(cmd, "apply-shields-transition"):
return "shields_mode=mutable chattr_applied=0";
case cmd[0] === "stat":
return cmd.at(-1) === "/sandbox/.hermes" ? "3770 sandbox:sandbox" : "640 sandbox:sandbox";
return cmd.at(-1) === "/sandbox/.hermes"
? `${hermesDirMode} sandbox:sandbox`
: "640 sandbox:sandbox";
case cmd[0] === "lsattr":
return `---------------- ${cmd.at(-1)}`;
default:
Expand Down Expand Up @@ -264,6 +266,28 @@ describe("legacy Hermes shields compatibility", () => {
expect(commands.some(isInlinePython)).toBe(false);
});

it("accepts the dashboard-tightened private Hermes root after a sealed unlock", () => {
installExecResponses(CURRENT_GUARD_HELP, "700");

expect(() =>
shields.unlockAgentConfig("current-hermes", hermesTarget(), true, true),
).not.toThrow();

const commands = dockerExecSpy.mock.calls.map(commandFromCall);
expect(commands.some((cmd) => isGuardAction(cmd, "finish-shields-transition"))).toBe(true);
});

it("rejects other sandbox-owned Hermes root modes before finishing a sealed unlock", () => {
installExecResponses(CURRENT_GUARD_HELP, "750");

expect(() => shields.unlockAgentConfig("current-hermes", hermesTarget(), true, true)).toThrow(
/config dir mode/,
);

const commands = dockerExecSpy.mock.calls.map(commandFromCall);
expect(commands.some((cmd) => isGuardAction(cmd, "finish-shields-transition"))).toBe(false);
});

it("isolates Hermes guard Python and scrubs every privileged shields exec", () => {
installExecResponses(CURRENT_GUARD_HELP);

Expand Down
4 changes: 3 additions & 1 deletion test/e2e/live/hermes-shields-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ async function expectMutablePosture(sandbox: SandboxClient, cycle: number): Prom
);
assertExitZero(result, `inspect Hermes mutable posture after cycle ${cycle}`);
expect(result.stdout).toContain("755 sandbox:sandbox /sandbox");
expect(result.stdout).toContain(`3770 sandbox:sandbox ${HERMES_DIR}`);
expect(result.stdout).toMatch(
new RegExp(`^(?:700|3770) sandbox:sandbox ${HERMES_DIR.replace(".", "\\.")}$`, "m"),
);
expect(result.stdout).toContain(`640 sandbox:sandbox ${CONFIG_PATH}`);
expect(result.stdout).toContain(`640 sandbox:sandbox ${HERMES_DIR}/.env`);
expect(result.stdout).toContain(`640 sandbox:sandbox ${HERMES_DIR}/.config-hash`);
Expand Down
Loading