Skip to content

Commit 335af8f

Browse files
fix(server): browser setup keeps an existing AppArmor profile and only reloads it
An administrator can edit the profile in place, so setup writes the shipped profile only when the file is missing and reloads whatever is on disk. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d0830e5 commit 335af8f

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,35 @@ const runSetupAsRoot = (input: { readonly profile: string | undefined }) => {
104104

105105
const LOAD = `apparmor_parser -r ${PreviewBrowserHost.APPARMOR_PROFILE_PATH}`;
106106

107+
const CUSTOMIZED_PROFILE = PreviewBrowserHost.APPARMOR_PROFILE.replace(
108+
" userns,\n",
109+
" userns,\n deny /tmp/t3-admin-private/** rw,\n",
110+
);
111+
107112
it.effect.each([
108113
{
109114
label: "reloads a profile that is on disk",
110115
profile: PreviewBrowserHost.APPARMOR_PROFILE,
116+
written: PreviewBrowserHost.APPARMOR_PROFILE,
111117
said: "Reloaded the AppArmor profile",
112118
},
113-
{ label: "writes and loads a missing profile", profile: undefined, said: "Wrote and loaded" },
114119
{
115-
label: "rewrites and loads a profile that differs",
116-
profile: "profile old {}\n",
120+
label: "writes and loads a missing profile",
121+
profile: undefined,
122+
written: PreviewBrowserHost.APPARMOR_PROFILE,
117123
said: "Wrote and loaded",
118124
},
125+
{
126+
label: "reloads a customized profile without rewriting it",
127+
profile: CUSTOMIZED_PROFILE,
128+
written: CUSTOMIZED_PROFILE,
129+
said: "Reloaded the AppArmor profile",
130+
},
119131
])("t3 browser setup as root $label", (input) =>
120132
Effect.gen(function* () {
121133
const result = yield* runSetupAsRoot({ profile: input.profile });
122134
expect(result.loads).toEqual([LOAD]);
123-
expect(result.profile).toBe(PreviewBrowserHost.APPARMOR_PROFILE);
135+
expect(result.profile).toBe(input.written);
124136
expect(result.output).toContain(input.said);
125137
expect(result.output).toContain("This host is ready for T3's browser.");
126138
}),

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,11 @@ const browserSetupCommand = Command.make("setup", { baseDir: baseDirFlag }).pipe
170170
}
171171

172172
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-
);
179-
if (!profileCurrent) {
173+
// An existing profile may carry an administrator's edits, so it is reloaded as is.
174+
const profileOnDisk = yield* fs
175+
.exists(PreviewBrowserHost.APPARMOR_PROFILE_PATH)
176+
.pipe(Effect.orElseSucceed(() => false));
177+
if (!profileOnDisk) {
180178
yield* fs
181179
.writeFileString(
182180
PreviewBrowserHost.APPARMOR_PROFILE_PATH,
@@ -197,7 +195,7 @@ const browserSetupCommand = Command.make("setup", { baseDir: baseDirFlag }).pipe
197195
PreviewBrowserHost.APPARMOR_PROFILE_PATH,
198196
]);
199197
yield* Console.log(
200-
profileCurrent
198+
profileOnDisk
201199
? `Reloaded the AppArmor profile at ${PreviewBrowserHost.APPARMOR_PROFILE_PATH} that allows Chrome's sandbox for T3's browser.`
202200
: `Wrote and loaded the AppArmor profile at ${PreviewBrowserHost.APPARMOR_PROFILE_PATH} that allows Chrome's sandbox for T3's browser.`,
203201
);

0 commit comments

Comments
 (0)