-
Couldn't load subscription status.
- Fork 1.5k
Add multi-source per-user distribution lists with file injection #13558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add multi-source per-user distribution lists with file injection #13558
Conversation
This commit implements two related feature requests: Issue microsoft#13098: Use multiple and per-user DistributionListUrls - Add support for HKEY_CURRENT_USER distribution sources (no admin required) - Implement REG_MULTI_SZ support for multiple distribution URLs - Add ReadWideStringSet() function for reading multi-string registry values - Modify GetAvailable() to merge distributions from HKLM, HKCU, and append URLs - User sources take priority over system sources Issue microsoft#13099: Enable using existing distributions from upstream sources - Add file injection capability to distribution manifests - Support inline content and URL-based file injection - Implement SHA256 verification for downloaded files - Inject files during distribution installation via LaunchProcess() - Create parent directories automatically Implementation details: - Extended Distribution.h with InjectedFile struct and Files map - Added MergeDistributionLists() helper for intelligent deduplication - Modified InstallModernDistribution() in WslInstall.cpp for file injection - Uses base64 encoding for safe shell command passing - Maintains full backward compatibility with existing distributions Security features: - SHA256 hash verification for all downloads - No arbitrary code execution (server-side generation recommended) - Registry isolation between users (HKCU vs HKLM) - Secure shell command handling with base64 encoding Fixes microsoft#13098 Fixes microsoft#13099 Signed-off-by: Giovanni Magliocchetti <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements multi-source, per-user distribution lists with automatic file injection capabilities for WSL. It enables users to configure custom distribution sources without administrator privileges and automatically inject configuration files during installation.
Key changes include:
- Added support for per-user distribution sources via HKEY_CURRENT_USER registry keys
- Implemented multi-source distribution loading with REG_MULTI_SZ support
- Added automatic file injection during distribution installation from manifest specifications
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
registry.hpp |
Adds declaration for ReadWideStringSet() to support REG_MULTI_SZ registry values |
registry.cpp |
Implements ReadWideStringSet() function for reading multi-string registry values |
Distribution.h |
Defines InjectedFile struct and adds Files map to DistributionArchive for file injection |
Distribution.cpp |
Implements multi-source manifest loading, HKCU/HKLM priority handling, and manifest merging |
WslInstall.cpp |
Adds file injection logic during distribution installation with inline and URL-based sources |
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
…s to prevent collisions Signed-off-by: Giovanni Magliocchetti <[email protected]>
Summary
This PR implements two highly-requested features that enable users to manage custom WSL distributions without requiring administrator privileges and without needing to repackage existing upstream distributions.
Closes #13098 - Use multiple and per-user DistributionListUrls
Closes #13099 - Enable easily using existing distributions from existing official upstream sources
Motivation
Currently, WSL users face two significant limitations:
Admin-only distribution sources: Users cannot add custom distribution sources without administrator privileges, limiting flexibility in enterprise and shared environments.
Manual repackaging burden: Users must manually repackage upstream distributions to add configuration files, creating maintenance overhead and preventing automatic updates.
This PR addresses both issues by enabling:
HKEY_CURRENT_USER(no admin required)REG_MULTI_SZregistry valuesFeatures Implemented
1. Per-User Distribution Sources (Issue #13098)
Users can now specify distribution sources in
HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxsswithout requiring administrator privileges:Priority order: HKCU > HKLM > Default Microsoft URL
2. Multiple Distribution Sources (Issue #13098)
Support for
REG_MULTI_SZenables unlimited distribution sources:Distributions from all sources are intelligently merged with duplicate detection.
3. Automatic File Injection (Issue #13099)
Distribution manifests can now specify files to inject during installation:
{ "Distributions": [ { "Name": "Alpine-3.22.0", "Version": "3.22.0", "Architecture": "x86_64", "Url": "https://dl-cdn.alpinelinux.org/alpine/v3.22/releases/x86_64/alpine-minirootfs-3.22.0-x86_64.tar.gz", "Sha256": "...", "Files": { "/etc/wsl.conf": { "Source": "inline", "Contents": "[boot]\nsystemd=true\n\n[network]\ngenerateResolvConf=false" }, "/etc/apk/repositories": { "Source": "url", "Url": "https://example.com/alpine-repos.txt", "Sha256": "..." } } } ] }Supported injection methods:
Implementation Details
Modified Files
Distribution.hInjectedFilestruct andFilesmap toDistributionArchiveDistribution.cppregistry.hppReadWideStringSet()declarationregistry.cppReadWideStringSet()implementation forREG_MULTI_SZWslInstall.cppKey Components
1. Registry Reading (
Distribution.cpp)2. Manifest Merging (
MergeDistributionLists())3. File Injection (
WslInstall.cpp)Security Considerations
✅ SHA256 Verification: All downloaded files verified before injection
✅ Base64 Encoding: Prevents shell injection attacks
✅ Registry Isolation: HKCU changes don't affect other users
✅ No Arbitrary Code Execution: Server-side generation recommended
✅ Existing Security Model: Uses existing
LaunchProcess()mechanismsBackward Compatibility
✅ Existing distributions unaffected: No changes to default behavior
✅ Registry compatibility: Existing
REG_SZvalues still work✅ JSON schema additive:
Filesfield is optional✅ No breaking changes: All existing functionality preserved
Testing
Recommended Manual Testing
REG_MULTI_SZfile://URLsRecommended Unit Tests
ReadWideStringSet()with variousREG_MULTI_SZvaluesMergeDistributionLists()with overlapping distributionsGetAvailable()with HKCU/HKLM priorityUse Cases
Individual Developers
file://URLsEnterprise Environments
Distribution Maintainers
Example: Real-World Usage
Scenario: Alpine Linux with Custom Configuration
Result: Alpine Linux installed with systemd enabled and custom repositories configured automatically.
Migration Path
Users currently maintaining custom distribution packages can migrate to this approach:
Before (manual repackaging required):
After (automatic with this PR):
Performance Impact
Future Enhancements
Potential improvements in future PRs:
Checklist
Breaking Changes
None - This PR is fully backward compatible.
Additional Context
This implementation follows WSL's existing patterns:
OpenLxssUserKey()andOpenLxssSystemKey()functionsReadStringSet()→ReadWideStringSet())LaunchProcess()for secure command execution