Skip to content

Route dev-cert install through an elevated window instead of failing (#34)#63

Open
chiaramooney wants to merge 4 commits into
mainfrom
chiaramooney/cert-install-elevation
Open

Route dev-cert install through an elevated window instead of failing (#34)#63
chiaramooney wants to merge 4 commits into
mainfrom
chiaramooney/cert-install-elevation

Conversation

@chiaramooney

Copy link
Copy Markdown
Collaborator

Fixes #34.

Investigation summary

The "Generate and install a development certificate?" flow defaulted to installing, and winapp cert install trusts the cert in the machine store, which requires admin. VS Code isn't elevated by default, and there is no VS Code API to create an elevated integrated terminal (confirmed — it's disallowed by design for security). So the install failed with a red Access denied even though the certificate was successfully generated.

The bundled CLI also has no CurrentUser install option (cert install help: "Trust a certificate on this machine (requires admin)"), so installing to a non-elevated store isn't possible from the extension today.

Fix

Per discussion, the behavior is now elevation-aware:

  • VS Code already elevated → install runs in the normal integrated terminal (unchanged).
  • VS Code not elevated → the command is launched in a separate UAC-elevated PowerShell window via Start-Process -Verb RunAs, with an info message telling the user to approve the prompt. This replaces the guaranteed "Access denied" failure with a working install path.
  • The Generate Certificate quick pick now defaults to "Generate only", so users opt into the admin step instead of hitting it by surprise.

Applies to WinApp: Generate Certificate and WinApp: Install Certificate.

Implementation notes

  • buildElevatedTerminalCommand is extracted into winapp-cli-utils.ts with unit tests (shell-escape.test.ts) covering quote escaping, the RunAs verb, and the working-directory handling.
  • A RunAs-elevated process starts in System32; the elevated shell is pointed back at the project directory with Set-Location (not Start-Process -WorkingDirectory, which is ignored with -Verb on Windows PowerShell 5.1) so cert generate still infers the publisher from the manifest and writes devcert.pfx in the right place.
  • README command table and troubleshooting notes updated.

Out of scope (flagging)

The Create MSIX Package command's --install-cert option has the same elevation trap but is a separate command surface not named in the issue. Left untouched to keep this PR scoped to #34 — happy to do it as a follow-up.

Testing

  • npm run compile-tsc — clean
  • npm run lint — 0 errors (8 pre-existing warnings)
  • npm run test:unit — passing (11 in shell-escape.test.ts, incl. new elevation-command tests)
  • npm run package — build complete

chiaramooney and others added 4 commits July 15, 2026 13:42
Installing a development certificate trusts it in the machine store, which
requires administrator rights. VS Code isn't elevated by default and cannot
create an elevated integrated terminal, so `cert generate --install` and
`cert install` printed a red "Access denied" failure even though the cert was
generated — a scary, misleading first-run experience.

- Detect whether VS Code is elevated (WindowsPrincipal check). When elevated,
  run the install in the normal terminal as before.
- When not elevated, launch the command in a separate UAC-elevated PowerShell
  window via `Start-Process -Verb RunAs`, and show an info message so the user
  knows to approve the prompt. The elevated shell is pointed back at the
  working directory with `Set-Location` (RunAs otherwise starts in System32,
  which would break `cert generate` publisher inference and misplace
  devcert.pfx).
- Default the Generate Certificate quick pick to "Generate only" so users opt
  into the admin step instead of hitting it by surprise.
- Extract `buildElevatedTerminalCommand` into winapp-cli-utils with unit tests
  covering escaping, the RunAs verb, and the working-directory fix.
- Update README command table and troubleshooting notes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5ce7415c-8966-43ec-ad27-59a68e7ed74b
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5ce7415c-8966-43ec-ad27-59a68e7ed74b
…arify launcher terminal (#34)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5ce7415c-8966-43ec-ad27-59a68e7ed74b
… probe and launcher terminal (#34)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5ce7415c-8966-43ec-ad27-59a68e7ed74b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

certGenerate reports 'Access denied' as failure even though the cert is generated (elevation)

1 participant