Files
Allen Houchins 61064687e4 Add Python 3.13 & 3.14 as Windows FMAs and normalize versions (#46873)
This pull request improves the handling of version comparisons for
Windows application patch policies in the `winget` ingester,
specifically to support installers (like python.org) where the
registry's `DisplayVersion` does not match the package's marketing
version. It introduces a new option to compare against the
`DisplayVersion`, adds robust test coverage for this logic, and onboards
Python 3.13 and 3.14 as maintained apps with correct install/uninstall
scripts.

**Patch policy improvements:**

* Added a `UseDisplayVersionForPatch` field to `inputApp` and supporting
logic in the ingester to optionally compare patch policy versions
against the registry `DisplayVersion` instead of the package version,
with error handling if no display version is found.
[[1]](diffhunk://#diff-eb6c4ae7be41e61a2292c4240de750809d40c0686fb01f80f52df056ebc9c2a8R414-R434)
[[2]](diffhunk://#diff-eb6c4ae7be41e61a2292c4240de750809d40c0686fb01f80f52df056ebc9c2a8R566-R571)
* Introduced the helper function `firstDisplayVersion` and extended the
`appsAndFeaturesEntries` struct to include `DisplayVersion`.
[[1]](diffhunk://#diff-eb6c4ae7be41e61a2292c4240de750809d40c0686fb01f80f52df056ebc9c2a8R448-R458)
[[2]](diffhunk://#diff-eb6c4ae7be41e61a2292c4240de750809d40c0686fb01f80f52df056ebc9c2a8R612)

**Test coverage:**

* Expanded test cases in `ingester_test.go` to cover the new
`UseDisplayVersionForPatch` logic, including both positive and negative
scenarios.
[[1]](diffhunk://#diff-c68f0564df3c6e38ad333d4ca6e1040305eb079eb0d168d29c95b1b250463055R347)
[[2]](diffhunk://#diff-c68f0564df3c6e38ad333d4ca6e1040305eb079eb0d168d29c95b1b250463055R374-R424)
[[3]](diffhunk://#diff-c68f0564df3c6e38ad333d4ca6e1040305eb079eb0d168d29c95b1b250463055L410-R470)
* Updated test server config and fixtures to support `DisplayVersion`
for accurate test simulation.
[[1]](diffhunk://#diff-c68f0564df3c6e38ad333d4ca6e1040305eb079eb0d168d29c95b1b250463055R482)
[[2]](diffhunk://#diff-c68f0564df3c6e38ad333d4ca6e1040305eb079eb0d168d29c95b1b250463055L447-R503)

**New maintained apps:**

* Added onboarding for Python 3.13 and Python 3.14 as maintained apps,
each with a `use_display_version_for_patch` flag, install/uninstall
scripts, and appropriate configuration.
[[1]](diffhunk://#diff-8a640dba0d8cc9ee50cef0397c5efce6655957dde836df94e6d5fb536f422fecR1-R15)
[[2]](diffhunk://#diff-e25e77b6c53c5fcc80a6d7589547873b5007dbcca660decbff3c9579c057b0fbR1-R15)
[[3]](diffhunk://#diff-fca224dfb5a7262b0b4ad68061b06552dc5291aeb8e2409fd5c9c6f8d8022dacR1-R32)
[[4]](diffhunk://#diff-b2bd0383162063c7923532a2be6b7014310a79fe3b0c681d1647bcd0fa6e3fe8R1-R147)

These changes ensure that patch policies correctly flag outdated
installs for apps where the registry version format differs from the
package version, and Python installs are now robustly managed via Fleet.

<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #37326

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.

- [ ] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements), JS
inline code is prevented especially for url redirects, and untrusted
data interpolated into shell scripts/commands is validated against shell
metacharacters.
- [ ] Timeouts are implemented and retries are limited to avoid infinite
loops
- [ ] If paths of existing endpoints are modified without backwards
compatibility, checked the frontend/CLI for any necessary changes

## Testing

- [ ] Added/updated automated tests
- [ ] Where appropriate, [automated tests simulate multiple hosts and
test for host
isolation](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/reference/patterns-backend.md#unit-testing)
(updates to one hosts's records do not affect another)

- [ ] QA'd all new/changed functionality manually

For unreleased bug fixes in a release candidate, one of:

- [ ] Confirmed that the fix is not expected to adversely impact load
test results
- [ ] Alerted the release DRI if additional load testing is needed

## Database migrations

- [ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [ ] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).

## New Fleet configuration settings

- [ ] Setting(s) is/are explicitly excluded from GitOps

If you didn't check the box above, follow this checklist for
GitOps-enabled settings:

- [ ] Verified that the setting is exported via `fleetctl
generate-gitops`
- [ ] Verified the setting is documented in a separate PR to [the GitOps
documentation](https://github.com/fleetdm/fleet/blob/main/docs/Configuration/yaml-files.md#L485)
- [ ] Verified that the setting is cleared on the server if it is not
supplied in a YAML file (or that it is documented as being optional)
- [ ] Verified that any relevant UI is disabled when GitOps mode is
enabled

## fleetd/orbit/Fleet Desktop

- [ ] Verified compatibility with the latest released version of Fleet
(see [Must
rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md))
- [ ] If the change applies to only one platform, confirmed that
`runtime.GOOS` is used as needed to isolate changes
- [ ] Verified that fleetd runs on macOS, Linux and Windows
- [ ] Verified auto-update works from the released version of component
to the new version (see [tools/tuf/test](../tools/tuf/test/README.md))


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added support for Python 3.13 and Python 3.14 on Windows Fleet,
including install/uninstall workflows and manifests
  * Option to use installer-displayed version for patch comparisons

* **Improvements**
* Normalized Windows-reported Python version strings for consistent
inventory and vulnerability matching
  * Added icons for Python 3.13 and 3.14 in the software catalog
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-06-08 10:51:32 -05:00

158 lines
7.1 KiB
PowerShell

# python.org's Windows installer is a WiX "Burn" bundle. A Python 3.13 install
# registers many visible uninstall entries:
# * the bundle: "Python 3.13.<patch> (64-bit)" -> a cached Burn EXE
# * components: "Python 3.13.<patch> Core Interpreter (64-bit)",
# "...Standard Library (64-bit)", "...Executables (64-bit)",
# etc. -> individual MSIs
#
# The component MSIs must be removed in DEPENDENCY ORDER: the feature components
# (Standard Library, Tcl/Tk, pip, docs, etc.) run uninstall custom actions that
# invoke python.exe, so the "Executables" and "Core Interpreter" components that
# provide python.exe must be removed LAST. Removing them first makes the rest
# fail with exit code 1603. This ordering + "REBOOT=ReallySuppress /qn" mirrors
# the documented silentinstallhq.com Python uninstall.
#
# We match on the DisplayName (anchored for the bundle) rather than the Publisher
# string, and scan every hive osquery's "programs" table reads (HKLM +
# Wow6432Node + all HKU) so this works for per-machine (SYSTEM) and per-user
# installs alike.
$pythonNameLike = "Python 3.13.* (64-bit)"
$bundleNamePattern = '^Python 3\.13\.\d+ \(64-bit\)$'
# 0 = success, 1605 = not installed, 1614 = already uninstalled, 1641 = reboot
# initiated, 3010 = reboot required.
$ExpectedExitCodes = @(0, 1605, 1614, 1641, 3010)
$exitCode = 0
function Get-UninstallRoots {
$roots = [System.Collections.Generic.List[string]]::new()
$roots.Add('HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall')
$roots.Add('HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
foreach ($hive in (Get-ChildItem 'Registry::HKEY_USERS' -ErrorAction SilentlyContinue)) {
if ($hive.Name -match '_Classes$') { continue }
$roots.Add("Registry::$($hive.Name)\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")
$roots.Add("Registry::$($hive.Name)\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall")
}
return $roots
}
function Get-PythonEntries {
param([string[]]$Roots)
$list = @()
foreach ($root in $Roots) {
foreach ($sub in (Get-ChildItem -Path $root -ErrorAction SilentlyContinue)) {
$key = Get-ItemProperty $sub.PSPath -ErrorAction SilentlyContinue
if (-not $key.DisplayName) { continue }
if ($key.DisplayName -notlike $pythonNameLike) { continue }
$list += [PSCustomObject]@{
DisplayName = $key.DisplayName
KeyPath = $sub.PSPath
KeyName = $sub.PSChildName
Uninstall = $key.UninstallString
QuietUninstall = $key.QuietUninstallString
}
}
}
return $list
}
# Returns an MSI product code ({GUID}) for an entry, or $null if it isn't an MSI.
function Get-MsiProductCode {
param($Entry)
if ($Entry.Uninstall -match "(?i)MsiExec\.exe\s+/[IX]\s*(\{[0-9A-F-]+\})") { return $Matches[1] }
if ($Entry.KeyName -match "(?i)^\{[0-9A-F-]+\}$") { return $Entry.KeyName }
return $null
}
# Dependency removal order: feature components first (0), then Executables (1),
# then Core Interpreter LAST (2).
function Get-RemovalPriority {
param([string]$Name)
if ($Name -match '(?i)Core Interpreter') { return 2 }
if ($Name -match '(?i)Executables') { return 1 }
return 0
}
function Get-ExePath {
param([string]$Command)
if ($Command -match '^\s*"([^"]+)"') { return $Matches[1] }
if ($Command -match '(?i)^\s*(.+?\.exe)(\s|$)') { return $Matches[1] }
return $null
}
try {
$roots = Get-UninstallRoots
$entries = Get-PythonEntries -Roots $roots
if ($entries.Count -eq 0) {
Write-Host "No Python 3.13 (64-bit) entries found (already removed)."
Exit 0
}
# Stop only running interpreters that belong to THIS Python install so the
# component MSIs aren't locked. We scope the kill to processes whose image
# lives under the version-specific "Python313" directory; matching by image
# base name alone (python.exe/pythonw.exe/...) would also terminate a
# side-by-side 3.12/3.14, Microsoft Store, or Anaconda interpreter -- a
# 3.13 uninstall running as SYSTEM could kill an unrelated long-running
# workload mid-write. The shared "py"/"pyw" launcher lives in C:\Windows and
# is version-agnostic, so it is intentionally left running.
$installDirPattern = '*\Python313\*'
foreach ($proc in @("python", "pythonw", "py", "pyw")) {
Get-Process -Name $proc -ErrorAction SilentlyContinue |
Where-Object { $_.Path -like $installDirPattern } |
Stop-Process -Force -ErrorAction SilentlyContinue
}
# --- Remove component MSIs in dependency order (Core Interpreter last). ---
$components = $entries |
Where-Object { $_.DisplayName -notmatch $bundleNamePattern } |
Sort-Object @{ Expression = { Get-RemovalPriority $_.DisplayName } }
foreach ($e in $components) {
$code = Get-MsiProductCode $e
if (-not $code) { Write-Host "Skipping non-MSI component: '$($e.DisplayName)'"; continue }
Write-Host "Removing component: '$($e.DisplayName)' ($code)"
$p = Start-Process -FilePath "msiexec.exe" `
-ArgumentList "/x $code REBOOT=ReallySuppress /qn /norestart" -PassThru -Wait
Write-Host " Exit code: $($p.ExitCode)"
if (($ExpectedExitCodes -notcontains $p.ExitCode) -and ($exitCode -eq 0)) { $exitCode = $p.ExitCode }
}
# --- Remove the bundle. With its components gone its own uninstall is quick;
# if a registration lingers, delete the orphaned key so detection clears. ---
foreach ($e in (Get-PythonEntries -Roots $roots | Where-Object { $_.DisplayName -match $bundleNamePattern })) {
$command = if ($e.QuietUninstall) { $e.QuietUninstall } else { $e.Uninstall }
$exe = if ($command) { Get-ExePath $command } else { $null }
if ($exe -and (Test-Path -LiteralPath $exe)) {
Write-Host "Uninstalling bundle: '$($e.DisplayName)' via $exe"
$p = Start-Process -FilePath $exe -ArgumentList "/uninstall /quiet /norestart" -PassThru -Wait
Write-Host " Exit code: $($p.ExitCode)"
if (($ExpectedExitCodes -notcontains $p.ExitCode) -and ($exitCode -eq 0)) { $exitCode = $p.ExitCode }
}
$still = Get-ItemProperty $e.KeyPath -ErrorAction SilentlyContinue
if ($still -and $still.DisplayName) {
Write-Host "Removing leftover bundle registration: '$($e.DisplayName)'"
Remove-Item -Path $e.KeyPath -Recurse -Force -ErrorAction SilentlyContinue
}
}
# --- Verify nothing remains in the programs table. ---
$remaining = Get-PythonEntries -Roots $roots
if ($remaining.Count -gt 0) {
Write-Host "WARNING: $($remaining.Count) Python 3.13 entry(ies) still present after uninstall:"
$remaining | ForEach-Object { Write-Host " - $($_.DisplayName) [$($_.KeyPath)]" }
if ($exitCode -eq 0) { $exitCode = 1 }
} else {
Write-Host "All Python 3.13 (64-bit) entries removed."
}
} catch {
Write-Host "Error: $_"
$exitCode = 1
}
if ($ExpectedExitCodes -contains $exitCode) { Exit 0 } else { Exit $exitCode }