Skip to content

fix(desktop): .deb upgrades no longer remove the AppArmor profile - #40341

Open
juliusmarminge wants to merge 2 commits into
mainfrom
factory/issue-40294-a1795264884
Open

juliusmarminge wants to merge 2 commits into
mainfrom
factory/issue-40294-a1795264884

Conversation

@juliusmarminge

Copy link
Copy Markdown
Member

On Ubuntu 24.04 and later, an in-app .deb update interrupted partway (for example by force-quitting the frozen window) left T3 Code crashing at every launch until sudo dpkg --configure -a was run. The old package's post-remove script deleted and unloaded the AppArmor profile even during an upgrade.

  • apps/desktop/resources/linux/after-remove.tpl replaces electron-builder's stock postrm and only removes the profile and the /usr/bin/t3code link when the package is actually removed or purged.
  • apps/desktop/resources/linux/before-install.sh is a new preinst. On upgrade it adds the same remove/purge guard to the installed release's postrm, which dpkg runs next. This protects the first upgrade from releases that still have the stock script.

Fixes #40294

Reproduction on main

Commit: origin/main 6644126 (packaging unchanged on main; used the published preview .debs built from it). Ubuntu 24.04.4 VM with kernel.apparmor_restrict_unprivileged_userns = 1. (1) sudo dpkg -i T3-Code-0.1.12-preview.20261121.5023-amd64.deb -> dpkg -l shows ii, /etc/apparmor.d/t3code present and the t3code profile loaded (aa-status); launching '/opt/T3 Code (Beta)/t3code' with the Chromium sandbox on, under Xvfb with an isolated HOME, stays running for 15s (label 't3code (unconfined)'). (2) sudo dpkg --unpack T3-Code-0.1.12-preview.20261121.5025-amd64.deb, which matches a dpkg -i interrupted after old-postrm and before configure -> dpkg -l shows iU, /etc/apparmor.d/t3code is gone and the profile is no longer loaded. (3) Launching again exits immediately with code 133 (Trace/breakpoint trap) and '[FATAL:sandbox/linux/suid/client/setuid_sandbox_host.cc:166] The SUID sandbox helper binary was found, but is not configured correctly'; the kernel log shows apparmor="DENIED" operation="capable" profile="unprivileged_userns" comm="t3code" capname="sys_admin", the same as the report. (4) sudo dpkg --configure -a -> ii, profile restored, the app launches normally again. Confirmed that the shipped postrm (dpkg-deb -e) unloads and deletes the profile with no check on $1. Confirmed that electron-updater 6.8.9 DebUpdater.doInstall runs dpkg -i through spawnSyncLog (child_process.spawnSync), so the main thread blocks while the window stays open.

Evidence

Being captured: before and after in the real app. This section is filled in before the pull request can merge.

Tests

  • sudo dpkg -i / dpkg --unpack / dpkg --configure -a / dpkg -P on synthetic packages built from the stock and new scripts: stock->fixed and fixed->fixed interrupted upgrades keep the profile loaded; downgrade and re-upgrade keep it; purge removes it
  • electron-builder's bundled fpm with --before-install: the produced .deb's preinst is identical to before-install.sh
  • vp run check:changed: pass (format, lint, knip, typecheck of 2 packages, 1 test file)

Not in this change

  • electron-updater's DebUpdater runs pkexec dpkg -i through spawnSync on the main thread while app windows stay open until before-quit-for-update, so the window looks frozen during the install.
  • The stock after-install and AppArmor profile templates are still used unchanged.

Who did the work

  • Written by Claude Opus 5.5, in Claude Code
  • Reviewed by GPT-6.1 Sol, in Codex, and by Claude Opus 5.5, each on its own
  • Proof captured by GPT-6.1 Sol and checked by Claude Opus 5.5

Run by the t3code factory in T3 Code.

juliusmarminge and others added 2 commits November 21, 2026 12:53
electron-builder's default postrm unloads and deletes
/etc/apparmor.d/t3code on every invocation, including the old package's
postrm during an upgrade. An upgrade interrupted before the new postinst
left T3 Code crashing at launch with a SUID-sandbox FATAL on Ubuntu 24.04+.
Ship our own after-remove template that only cleans up on remove/purge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… upgrade

The remove/purge guard only applies to postrm scripts of packages built
with it. Upgrading from a release with electron-builder's stock postrm
still ran that unguarded script, so an interrupted upgrade still lost the
AppArmor profile. Add a preinst, which dpkg runs before the old postrm,
that inserts the same guard into the installed postrm on upgrade.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Nov 21, 2026
@coderabbitai

coderabbitai Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Debian package build now registers lifecycle scripts. One inserts a guard into the installed postrm during upgrades. The other removes the executable link and handles the AppArmor profile for remove and purge actions.

Changes: Debian package lifecycle

Layer / File(s) Summary
Lifecycle script behavior
apps/desktop/resources/linux/before-install.sh, apps/desktop/resources/linux/after-remove.tpl
During upgrades, before-install.sh inserts a guard so the installed postrm continues for remove and purge arguments. The after-remove.tpl script removes the executable alternative or /usr/bin link for those actions. If the AppArmor profile exists, it attempts to unload it under the specified conditions and then removes the profile file.
Debian build wiring
scripts/build-desktop-artifact.ts
The Debian FPM configuration registers before-install.sh and after-remove.tpl. The existing metainfo and license mappings remain.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • pingdotgg/t3code#40336: It addresses the same interrupted-upgrade issue by limiting Debian postrm cleanup to removal actions.

Suggested reviewers: macroscopeapp

Merge Risk: Minimal · up to 5b57d

This change guards the Debian package scripts so an interrupted upgrade no longer removes the AppArmor profile. No blocking issue was found. Real-app upgrade evidence was still being captured.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(desktop): .deb upgrades no longer remove the AppArmor profile" states the main change: the desktop package's upgrade path no longer removes the AppArmor profile. The changeset adds afte…
Description check Passed The description follows the template's sections: Problem, Change, Scope, Verification, and the agent attribution line. The Problem section explains the crash after an interrupted .deb upgrade. The Cha…
Linked Issues check Passed Directly linked issue #40294 asks that an interrupted in-app .deb upgrade not leave T3 Code unable to launch. The cause is that the old package's postrm deletes /etc/apparmor.d/t3code and unloads the …
Out of Scope Changes check Passed The changed files are apps/desktop/resources/linux/after-remove.tpl, apps/desktop/resources/linux/before-install.sh, and scripts/build-desktop-artifact.ts. The first two implement the packaging fix in…
Full details: Title check

Explanation

The title "fix(desktop): .deb upgrades no longer remove the AppArmor profile" states the main change: the desktop package's upgrade path no longer removes the AppArmor profile. The changeset adds after-remove.tpl, which limits profile removal to remove or purge, and before-install.sh, which guards the installed postrm during upgrades. The title is specific and follows the conventional commit format. It does not mention the interrupted-upgrade trigger, which is acceptable.

Full details: Description check

Explanation

The description follows the template's sections: Problem, Change, Scope, Verification, and the agent attribution line. The Problem section explains the crash after an interrupted .deb upgrade. The Change section explains both new scripts. Scope links issue #40294 and describes the bug. Verification gives detailed manual dpkg reproduction and test results, and it states that the frozen-window behavior is out of scope. The Evidence section is explicitly still pending, and the template's UI screenshot requirement may not apply because this is a packaging change. The Evidence placeholder is a remaining gap, but the description is otherwise mostly complete.

Full details: Linked Issues check

Explanation

Directly linked issue #40294 asks that an interrupted in-app .deb upgrade not leave T3 Code unable to launch. The cause is that the old package's postrm deletes /etc/apparmor.d/t3code and unloads the profile during upgrade, without checking $1. At head, apps/desktop/resources/linux/after-remove.tpl exits unless $1 is remove or purge, and only then removes the profile and the link. apps/desktop/resources/linux/before-install.sh runs on upgrade and inserts the same guard into the installed release's postrm when the stock script lacks it. Together these keep the profile loaded through an interrupted upgrade from the stock or fixed release. The issue also documents main-thread blocking of dpkg via spawnSync and a frozen window. That behavior is not a stated requested outcome, and the PR explicitly leaves it out of scope, so its absence does not fail this check. The reproduction and synthetic-package test evidence in the PR description was not re-run in this review and is taken as the author's report. Status is PASS on the code evidence.

Full details: Out of Scope Changes check

Explanation

The changed files are apps/desktop/resources/linux/after-remove.tpl, apps/desktop/resources/linux/before-install.sh, and scripts/build-desktop-artifact.ts. The first two implement the packaging fix in #40294. The build script change wires before-install and afterRemove into the FPM configuration, which is required for the scripts to ship in the .deb. The PR does not change the frozen-window or updater code, and it states that the stock after-install and AppArmor profile templates remain unchanged. No unrelated change was found in the summary.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 0775dc4 and 5b57d76.

Files selected for processing: 3

  • apps/desktop/resources/linux/after-remove.tpl
  • apps/desktop/resources/linux/before-install.sh
  • scripts/build-desktop-artifact.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interrupted Linux .deb auto-update leaves AppArmor profile removed and T3 Code unable to launch

1 participant