Skip to content
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

Is it safe to ignore the sessionId on a process to detect it as service? #77350

Closed
gillg opened this issue Oct 23, 2022 · 5 comments
Closed

Is it safe to ignore the sessionId on a process to detect it as service? #77350

gillg opened this issue Oct 23, 2022 · 5 comments

Comments

@gillg
Copy link

gillg commented Oct 23, 2022

Hi,

On the legacy method WindowsServiceHelpers.IsWindowsService() the logic is based on SessionID == 0 and parent process services.exe.
Using services.exe seems enough, or in the worst case a OR condition on SessionID 0 or 1, but I guess the session is a safety guard in case of a third party software with an exe named services.exe.

The problem is on a windows container, services.exe has a sessionId = 1 and Golang framework steal the logic from this legacy method. So we experience issues with some Golang softwares hosted in docker and compatibles as cli + service. (Otelcollector, Windows exporter, and any other not launched as host process).

Any advice from the Microsoft team ?

Original code here : https://github.com/dotnet/extensions/blob/f4066026ca06984b07e90e61a6390ac38152ba93/src/Hosting/WindowsServices/src/WindowsServiceHelpers.cs#L31
Some details here : golang/go#56335 (comment)

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Oct 23, 2022
@gillg
Copy link
Author

gillg commented Oct 23, 2022

By the way, other interesting output from a host and container :
Host

> query session
 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
 services                                    0  Disc
>console           my.username            1  Active

Container

> query session
 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
>services                                    1  Disc

Maybe instead of a basic "OR" condition, we should identify the session name "services" instead of testing a session ID.
What de you think ?
What is the good way to retrieve a session name from a session ID ?

@ghost
Copy link

ghost commented Oct 23, 2022

Tagging subscribers to this area: @dotnet/area-extensions-hosting
See info in area-owners.md if you want to be subscribed.

Issue Details

Hi,

On the legacy method WindowsServiceHelpers.IsWindowsService() the logic is based on SessionID == 0 and parent process services.exe.
Using services.exe seems enough, or in the worst case a OR condition on SessionID 0 or 1, but I guess the session is a safety guard in case of a third party software with an exe named services.exe.

The problem is on a windows container, services.exe has a sessionId = 1 and Golang framework steal the logic from this legacy method. So we experience issues with some Golang softwares hosted in docker and compatibles as cli + service. (Otelcollector, Windows exporter, and any other not launched as host process).

Any advice from the Microsoft team ?

Original code here : https://github.com/dotnet/extensions/blob/f4066026ca06984b07e90e61a6390ac38152ba93/src/Hosting/WindowsServices/src/WindowsServiceHelpers.cs#L31
Some details here : golang/go#56335 (comment)

Author: gillg
Assignees: -
Labels:

untriaged, area-Extensions-Hosting

Milestone: -

@jkotas
Copy link
Member

jkotas commented Oct 23, 2022

This is duplicate of #52416 .

SessionId is no longer checked in the current Microsoft.Extensions.Hosting.WindowsServices sources:

return string.Equals("services", parent.ProcessName, StringComparison.OrdinalIgnoreCase);

@jkotas jkotas closed this as completed Oct 23, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Oct 23, 2022
@gillg
Copy link
Author

gillg commented Oct 23, 2022

Awesome! Thanks a lot for your fast answer. I will circle back with the Golang team.

@ghost ghost locked as resolved and limited conversation to collaborators Nov 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants