Skip to content

Commit d0830e5

Browse files
refactor(server): read the AppArmor profile only where root rewrites it
Drops the non-root test, which only asserted guidance text. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d72350e commit d0830e5

2 files changed

Lines changed: 9 additions & 19 deletions

File tree

‎apps/server/src/cli/browser.test.ts‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const notFound = (method: string, path: string) =>
2828
});
2929

3030
/** An Ubuntu host with the userns restriction on, the browser installed, and a system font. */
31-
const runSetup = (input: { readonly uid: number; readonly profile: string | undefined }) => {
31+
const runSetupAsRoot = (input: { readonly profile: string | undefined }) => {
3232
const files = new Map([
3333
[USERNS_RESTRICTION, "1\n"],
3434
[BROWSER, ""],
@@ -94,7 +94,7 @@ const runSetup = (input: { readonly uid: number; readonly profile: string | unde
9494
};
9595
}).pipe(
9696
Effect.provideService(HostProcess.Platform, "linux"),
97-
Effect.provideService(HostProcess.UserId, input.uid),
97+
Effect.provideService(HostProcess.UserId, 0),
9898
Effect.provideService(HostProcess.Environment, { SUDO_USER: "me" }),
9999
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
100100
Effect.provideService(FileSystem.FileSystem, fileSystem),
@@ -118,20 +118,10 @@ it.effect.each([
118118
},
119119
])("t3 browser setup as root $label", (input) =>
120120
Effect.gen(function* () {
121-
const result = yield* runSetup({ uid: 0, profile: input.profile });
121+
const result = yield* runSetupAsRoot({ profile: input.profile });
122122
expect(result.loads).toEqual([LOAD]);
123123
expect(result.profile).toBe(PreviewBrowserHost.APPARMOR_PROFILE);
124124
expect(result.output).toContain(input.said);
125125
expect(result.output).toContain("This host is ready for T3's browser.");
126126
}),
127127
);
128-
129-
it.effect("t3 browser setup without root says a profile on disk may not be loaded", () =>
130-
Effect.gen(function* () {
131-
const result = yield* runSetup({ uid: 1000, profile: PreviewBrowserHost.APPARMOR_PROFILE });
132-
expect(result.loads).toEqual([]);
133-
expect(result.output).toContain("is not loaded. To load it, run:");
134-
expect(result.output).toContain("sudo");
135-
expect(result.output).toContain("browser setup --base-dir /home/me/.t3");
136-
}),
137-
);

‎apps/server/src/cli/browser.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,6 @@ const browserSetupCommand = Command.make("setup", { baseDir: baseDirFlag }).pipe
128128
: undefined;
129129

130130
const restricted = yield* PreviewBrowserHost.usernsRestricted;
131-
const profileCurrent =
132-
restricted &&
133-
(yield* fs.readFileString(PreviewBrowserHost.APPARMOR_PROFILE_PATH).pipe(
134-
Effect.map((profile) => profile === PreviewBrowserHost.APPARMOR_PROFILE),
135-
Effect.orElseSucceed(() => false),
136-
));
137131
// The kernel can lack a profile that is on disk, as on a host restored from an image,
138132
// and only root can read the loaded list, so root reloads it on every run.
139133
const needsProfile = isRoot ? restricted : yield* PreviewBrowserHost.sandboxBlocked;
@@ -176,6 +170,12 @@ const browserSetupCommand = Command.make("setup", { baseDir: baseDirFlag }).pipe
176170
}
177171

178172
if (needsProfile) {
173+
const profileCurrent = yield* fs
174+
.readFileString(PreviewBrowserHost.APPARMOR_PROFILE_PATH)
175+
.pipe(
176+
Effect.map((profile) => profile === PreviewBrowserHost.APPARMOR_PROFILE),
177+
Effect.orElseSucceed(() => false),
178+
);
179179
if (!profileCurrent) {
180180
yield* fs
181181
.writeFileString(

0 commit comments

Comments
 (0)