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

Add Windows compatibility #16

Closed
wants to merge 4 commits into from
Closed

Conversation

presidento
Copy link

Implements #3. Unfortunately privilege escalation is still needed, because in escalated mode the builtin browser did not work for me. But there are quite working sudo implementations in the field, so I kept it this way, because I did not want to increase the complexity.

Máté Farkas added 3 commits May 4, 2020 19:38
Reading from STDIN worked well on Linux,
but on Windows communicating via STDIN
is not available for evelated processes.
As its name says, command_line contains
the command line. During debug it is not
helpful having only one parameter set
by a different way.
Unfortunately the embedded browser did not work
with elevated mode, so it was required to keep the
"sudo" part. In Windows there is no easy way to do
it, but there are many "sudo" implementations, so
this way the source code can be unchanged and
the user can select for themselves any sudo
implementation.
@vlaci
Copy link
Owner

vlaci commented May 4, 2020

I am wondering if bringing in elevate would make privilege elevation simpler as it is a cross platform library.

I don't know how the implementations plays together with async. On the other hand if it is an issue, openconnect could be executed synchronously as there are no other background tasks running at that point.
Edit: never mind, I have thought it does some funky magic to return execution on the point elevate is called. It is not the case so it would need to be an additional helper script to work...

Copy link
Owner

@vlaci vlaci left a comment

Choose a reason for hiding this comment

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

Note that SIGWINCH is not available on windows. You can check my initial experiment with windows compatibilty on the windows branch: f3fd7e3

vlaci
vlaci previously approved these changes May 4, 2020
Also clarify why this magic is needed

Cherry-picked from commit
f3fd7e3
@presidento
Copy link
Author

I have tried elevate as well, but it simply calls the script itself with elevated privileges, and has no magic at all to jump to the execution point. On Windows it is done within a new terminal (which can be hidden or shown). It would be good to do it as the first step (before running the async loop), but unfortunately the built-in browser did not work (at least for me) with elevated privileges, and I did not want to start debugging it.

The other way can be to create a simple wrapper script to run openconnect with elevated privileges, which means to create another sudo implementation... It can be done, but also it would be better to run openconnect directly with elevated privileges on Windows, but I do not know how can we an async way to run windll.shell32.ShellExecuteEx, and at this point I did not want to increase the complexity. (Moreover I have found a sudo implementation for Windows which does not start a new console, but shows the output of the elevated command within the same console, and I was not able to find a solution to do it with Python, so I am happy having only one terminal.)

We can add experimental flag to the Windows section of README if you think.

@vlaci
Copy link
Owner

vlaci commented May 5, 2020

I was thinking about moving privilege elevation to an additional script or call it via multiprocessing in the same way browser is handled. I do not like the idea of elavating the whole process.

On the other hand openconnect binary itself can be marked to require elevation. Won't it work then without sudo?

I am happy with the changes but am curious how could we remove the need of an explicit sudo dependency

@vlaci
Copy link
Owner

vlaci commented May 5, 2020

It is merged into develop branch. Will check on Windows, then I'll merge to master.

@presidento
Copy link
Author

If openconnect binary is marked to run in elevated mode, then Python cannot start it, the error thrown on https://github.com/python/cpython/blob/v3.7.7/Lib/subprocess.py#L1200 is that The requested operation requires elevation.

(I may create an additional script in a separated pull request later to do the elevation and call openconnect.)

@presidento
Copy link
Author

Here is a working-for-me-on-Windows PoC of a wrapper script: presidento@3c1d3f2. You can copy/implement it if you want.

vlaci pushed a commit that referenced this pull request May 7, 2020
@vlaci vlaci added the on-develop PR is still open but merged to develop branch. label Jul 14, 2020
vlaci pushed a commit that referenced this pull request Aug 27, 2020
vlaci pushed a commit that referenced this pull request Sep 6, 2020
vlaci pushed a commit that referenced this pull request Sep 6, 2020
@vlaci
Copy link
Owner

vlaci commented Oct 25, 2020

This feature has been merged to master and is part of v0.6.0

@vlaci vlaci closed this Oct 25, 2020
@vlaci vlaci removed the on-develop PR is still open but merged to develop branch. label Oct 25, 2020
@anishsane
Copy link
Contributor

I created this wrapper over the openconnect-sso.exe:

https://gist.github.com/anishsane/43b72f4fa117dea389b4e971bf6cbc1c

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.

3 participants