Skip to content

[WSLC] Add wslc get cli session api#40141

Open
chemwolf6922 wants to merge 5 commits intofeature/wsl-for-appsfrom
user/chemwolf6922/add-wslc-get-cli-session-api
Open

[WSLC] Add wslc get cli session api#40141
chemwolf6922 wants to merge 5 commits intofeature/wsl-for-appsfrom
user/chemwolf6922/add-wslc-get-cli-session-api

Conversation

@chemwolf6922
Copy link
Copy Markdown
Contributor

@chemwolf6922 chemwolf6922 commented Apr 9, 2026

Summary of the Pull Request

  • Add the WslcGetCliSession api.
  • Move wslc default session names to common so both sdk and cli can access them.
  • Fix broken tests

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Add test: WslcSdkTests::GetCliSession

@chemwolf6922 chemwolf6922 requested a review from a team as a code owner April 9, 2026 03:18
Copilot AI review requested due to automatic review settings April 9, 2026 03:18
@chemwolf6922 chemwolf6922 changed the title Add wslc get cli session api [WSLC] Add wslc get cli session api Apr 9, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new WSLC SDK entrypoint to obtain the default “CLI session” and centralizes the default CLI session naming logic so it can be shared by both the SDK and the wslc CLI.

Changes:

  • Added WslcGetCliSession to the WSLC SDK (header + export + implementation) to open the default CLI session by name.
  • Introduced wsl::windows::common::WSLCSessionDefaults (shared defaults for wslc-cli / wslc-cli-admin) and updated CLI/task/model/test code to use it.
  • Added a Windows test validating WslcGetCliSession behavior.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/windows/WslcSdkTests.cpp Adds GetCliSession SDK test and a release-only RAII wrapper for session refs.
test/windows/wslc/e2e/WSLCE2EHelpers.cpp Switches default session name lookup to the new common defaults helper.
src/windows/WslcSDK/wslcsdk.h Declares the new public WslcGetCliSession API.
src/windows/WslcSDK/wslcsdk.def Exports WslcGetCliSession from the SDK DLL.
src/windows/WslcSDK/wslcsdk.cpp Implements WslcGetCliSession by opening the default session by name.
src/windows/wslc/tasks/SessionTasks.cpp Uses the common defaults helper for default session name + default-name checks.
src/windows/wslc/services/SessionModel.h Removes default session naming helpers/constants from SessionOptions.
src/windows/wslc/services/SessionModel.cpp Uses common defaults for display name and storage path selection.
src/windows/common/WslSecurity.h Adds security::IsElevated() declaration.
src/windows/common/WslSecurity.cpp Implements security::IsElevated() using the current access token.
src/windows/common/WSLCSessionDefaults.h New common header encapsulating elevation-aware default session naming.
src/windows/common/CMakeLists.txt Registers the new common header in the common target headers list.

// IsTokenElevated checks if the integrity level is exactly HIGH.
// We must also check for local system because it is above HIGH.
// However, IsTokenLocalSystem() does not work correctly and fails.
// TODO: Add proper handling for system user callers.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is pre-existing and not related to your PR @chemwolf6922, but is the fix in IsTokenElevated() as simple as changing the == to >= for proper handling of system user callers, @benhillis ?
Now that IsElevated is moved to the shared WslSecurity, this bug/limitation could have more exposure

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modifed the IsElevated function to use >=. And renamed it to IsElevatedOrAbove to aboid confusion with the IsTokenElevated fucntion.
I don't think we should modify the IsTokenElevated function though. As that affects other parts of the codebase.

// We must also check for local system because it is above HIGH.
// However, IsTokenLocalSystem() does not work correctly and fails.
// TODO: Add proper handling for system user callers.
return IsTokenElevated(token.get());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, could the issue referenced above mean that a SYSTEM-context caller of WslcGetCliSession would get the wrong session name (wslc-cli instead of wslc-cli-admin), and so it could likely result in a 'not found'?

Copy link
Copy Markdown
Contributor Author

@chemwolf6922 chemwolf6922 Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we assume the user runs cli commands in the same context as the get cli session call. They will always get the same session. No matter if it's the correct one. (local system will get wslc-cli).
For the dev loop scenario, this assumption is true.

@yao-msft
Copy link
Copy Markdown

Just curious about the context of the change, what're the scenarios that an app will need to access a cli session?

@chemwolf6922
Copy link
Copy Markdown
Contributor Author

Just curious about the context of the change, what're the scenarios that an app will need to access a cli session?

Hi @yao-msft , Please refer to the build experience design doc. I'll try to send you internally. In short, this is for the dev loop where the developer builds their image in the cli session and pick it up directly when debugging.

Copilot AI review requested due to automatic review settings April 10, 2026 02:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

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.

4 participants