-
-
Notifications
You must be signed in to change notification settings - Fork 143
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
Issue: caching with CacheMode = "Auto"
expires too soon in MSYS2 and Cygwin
#348
Comments
I repeated the debug tracing from CMD with 3 consecutive runs of gsudo: C:\Users\saukrs> gsudo -k
Info: All credentials cache were invalidated. First run: C:\Users\saukrs> gsudo --debug fltmc
Debug: Invoking Shell: Cmd
Debug: Command Line: --debug fltmc
Debug: Command to run: "C:\Windows\system32\fltmc.EXE"
Debug: Using Console mode TokenSwitch
Debug: Caller PID: 4480
Debug: Caller SID: S-1-5-21-3533002965-4122658273-1040882531-1006
Debug: Elevating process: C:\ProgramData\scoop\apps\gsudo\2.4.4\gsudo.exe --debug gsudoservice 4480 S-1-5-21-3533002965-4122658273-1040882531-1006 All 00:05:00
Debug: Service process started.
Debug: Connected via Named Pipe ProtectedPrefix\Administrators\gsudo_843F5F48FDA973F21389B11234EB033B58EA49A490BA043B543AB3F4F9DC018B.
Debug: Creating target process: "C:\Windows\system32\fltmc.EXE"
Debug: Process token successfully substituted.
Filter Name Num Instances Altitude Frame
------------------------------ ------------- ------------ -----
OpenZFS <Legacy>
bindflt 1 409800 1
storqosflt 0 244000 1
wcifs 0 189900 1
CldFlt 1 180451 1
FileCrypt 0 141100 0
luafv 1 135000 0
npsvctrig 1 46000 0
Wof 3 40700 0
FileInfo 8 40500 0
Debug: Process exited with code 0 Second run: C:\Users\saukrs> gsudo --debug fltmc
Debug: Invoking Shell: Cmd
Debug: Command Line: --debug fltmc
Debug: Command to run: "C:\Windows\system32\fltmc.EXE"
Debug: Using Console mode TokenSwitch
Debug: Caller PID: 4480
Debug: Connected via Named Pipe ProtectedPrefix\Administrators\gsudo_843F5F48FDA973F21389B11234EB033B58EA49A490BA043B543AB3F4F9DC018B.
Debug: Creating target process: "C:\Windows\system32\fltmc.EXE"
Debug: Process token successfully substituted.
Filter Name Num Instances Altitude Frame
------------------------------ ------------- ------------ -----
OpenZFS <Legacy>
bindflt 1 409800 1
storqosflt 0 244000 1
wcifs 0 189900 1
CldFlt 1 180451 1
FileCrypt 0 141100 0
luafv 1 135000 0
npsvctrig 1 46000 0
Wof 3 40700 0
FileInfo 8 40500 0
Debug: Process exited with code 0 Third run: C:\Users\saukrs> gsudo --debug fltmc
Debug: Invoking Shell: Cmd
Debug: Command Line: --debug fltmc
Debug: Command to run: "C:\Windows\system32\fltmc.EXE"
Debug: Using Console mode TokenSwitch
Debug: Caller PID: 4480
Debug: Connected via Named Pipe ProtectedPrefix\Administrators\gsudo_843F5F48FDA973F21389B11234EB033B58EA49A490BA043B543AB3F4F9DC018B.
Debug: Creating target process: "C:\Windows\system32\fltmc.EXE"
Debug: Process token successfully substituted.
Filter Name Num Instances Altitude Frame
------------------------------ ------------- ------------ -----
OpenZFS <Legacy>
bindflt 1 409800 1
storqosflt 0 244000 1
wcifs 0 189900 1
CldFlt 1 180451 1
FileCrypt 0 141100 0
luafv 1 135000 0
npsvctrig 1 46000 0
Wof 3 40700 0
FileInfo 8 40500 0
Debug: Process exited with code 0 Only the first run pops up the UAC prompt. And only one debug CMD console pops up during the test: Debug: Command Line: --debug gsudoservice 4480 S-1-5-21-3533002965-4122658273-1040882531-1006 All 00:05:00
gsudo v2.4.4 (Branch.tags-v2.4.4.Sha.cf887bf98d5d3d90fc1eebc08c7a277afb50cd19)
Copyright(c) 2019-2022 Gerardo Grignoli and GitHub contributors
Caller Pid: 4480
Running as:
User: DESKTOP-O7JE7JE\saukrs
Sid: S-1-5-21-3533002965-4122658273-1040882531-1006
Is Admin: True
Integrity Level: High (12288)
Credentials Cache:
Mode: Auto
Available for this process: False
Total active cache sessions: 0
Processes attached to the current console:
PID PPID Integrity UserName Name
12792 11808 High DESKTOP-O7JE7JE\saukrs C:\ProgramData\scoop\apps\gsudo\2.4.4\gsudo.exe (this gsudo status)
Info: Service started
Debug: Service will shutdown if idle for 00:05:00
Debug: Listening on named pipe ProtectedPrefix\Administrators\gsudo_843F5F48FDA973F21389B11234EB033B58EA49A490BA043B543AB3F4F9DC018B.
Debug: Access allowed only for ProcessID 4480 and children
Debug: NamedPipeServer listening.
Info: Incoming Connection.
Debug: ElevationRequest length 330
Debug: Process token replaced
Info: Connection Closed.
Debug: NamedPipeServer listening.
Info: Incoming Connection.
Debug: ElevationRequest length 328
Debug: Process token replaced
Info: Connection Closed.
Debug: NamedPipeServer listening.
Info: Incoming Connection.
Debug: ElevationRequest length 329
Debug: Process token replaced
Info: Connection Closed.
Debug: NamedPipeServer listening. ... which stays quite for a while after I have finished my runs. |
CacheMode = Auto
doesn't work in MSYS2 and CygwinCacheMode = "Auto"
expires too soon in MSYS2 and Cygwin
Hi, I'm busy these days with work and life, I'll try to make some progress with limited resources... gsudo cache typically identifies the invoker process as the cache process root, allowing this caller process to elevate again, and also terminating the cache when this process ends. MSYS2 has a behavior that confuses gsudo. When you run a windows console app from MSYS, it starts an intermediate/wrapper process. gsudo should identify the wrapper and select not the parent but the grandfather process as the cache root process. This part is failing. This is evident since each screenshot you pasted of So the offending code is likely here I would need you to tell me:
Thank you! |
btw in the mean time you can also do |
Thanks for all the tips.
No need for promises and hurrying. I just documented the thing that otherwise would be lost in transit :)
I used
Textual output
|
Ahh... I forgot I knew the answer to this one... The And that additional windows pid cache is breaking the cache root process selection: (I'm adding this here for future reference) The workaround is already explained here: https://gerardog.github.io/gsudo/docs/usage/bash-for-windows
|
I may review that code again later and see if I can fix the root selection algorithm.. But If I recall correctly, the problem is that the grandparent process ends immediately by the time gsudo starts., so I can't completely trace our grand-grandparent as the cache root. Will check and let you know |
Thanks for the details and the tip/workaround, @gerardog! What surprises me is the difference that user observes with the PPID value behavior when adding/removing |
Issue Description
Recently I discovered that process elevation credentials could be cached. I set it to
Auto
:This works with CMD and PowerShell, but not in a pretty recent MSYS2 and Cygwin.
In both latter environments every subsequent launch of
gsudo
pops up the UAC window.I expect the caching to work in MSYS2 and Cygwin too.
Steps to Reproduce
gsudo config
to see that all items are defaultgsudo config CacheMode = "Auto"
gsudo config
to see thatCacheMode
setting gotAuto
as the global valuegsudo fltmc
gsudo fltmc
the 2nd timeScreenshots
Here is the result I got by adding
--debug
:Each invocation poped up a new CMD window, I managed to capture only the last one.
Logs:
Reconfiguring
gsudo
:Doing two consecutive runs in ~40 seconds with
--debug
added:To compare text output in Cygwin terminal and the CMD debug console I launched
gsudo
additionally. Otherwise the former (seen in the screenshot) self-desctructs in 15 seconds.So here are both outputs from the new launch. Cygwin terminal:
Debug CMD console:
Context:
Win10 21H2 - English (OS Build 19044.3086)
gsudo v2.4.4 (Branch.tags-v2.4.4.Sha.cf887bf98d5d3d90fc1eebc08c7a277afb50cd19)
saukrs@DESKTOP-O7JE7JE ~ $ uname -a CYGWIN_NT-10.0-19044 DESKTOP-O7JE7JE 3.4.10-1.x86_64 2023-11-29 12:12 UTC x86_64 Cygwin
The text was updated successfully, but these errors were encountered: