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 macOS support #11

Merged
merged 12 commits into from
May 26, 2019
Merged

Add macOS support #11

merged 12 commits into from
May 26, 2019

Conversation

gmacon
Copy link
Collaborator

@gmacon gmacon commented Oct 12, 2018

This adds support for macOS as discussed in #5.

@dlenski
Copy link
Owner

dlenski commented Nov 24, 2018

It seems fine to me, although I have no way to test the MacOS functionality. (A test suite will be useful here sooner or later…)

But please fix the unnecessary code formatting changes, as discussed in #5.

@gmacon
Copy link
Collaborator Author

gmacon commented Nov 25, 2018

Sure. I thought I'd fixed them all, and I'm apparently too close to this code to see whatever is left. Can you point me to them (really just one of each type; knowing exactly what to look for will make them easier to find)?

@kalvinwang
Copy link

@dlenski I looked at the latest diff here and don't see any code formatting changes remaining of the type you mentioned (apostrophes and multiline arguments), would you mind merging this branch? It's really helpful for Mac users. Thanks! (and thanks to @gmacon as well!)

@XL64
Copy link

XL64 commented Feb 12, 2019

I would like to have a look and maybe resolve the conflicts from another fork but I don't know how to build it correctly.
I did python3 setup.py build but it only builds a build/lib/vpn_slice with no vpn_slice python file. And when I try to run the main.py it says : "main.py: error: Must be called as vpnc-script, with $reason set".
What did I miss ?

EDIT : OK I didn't use the -s option of openconnect but --script-tun --script instead as for ocproxy.
EDIT2 : SSHing a machine behind the VPN works with the branch from gmacon., Accessing a Lync server failed :s. Neither do kinit login@server.
EDIT3 : I don't know if it's link but for those link/kerberos servers URL I got several IPs populated in /etc/hosts, as far as I understand the first one will be used. correct ?

@gmacon
Copy link
Collaborator Author

gmacon commented Feb 14, 2019

I've rebased my branch on top of the current master.

@XL64: I don't think your error is related to this PR. I think your issue is that vpn-slice does not expect the --script-tun option (which routes all traffic through the command provided by --script). Try it without that option.

@XL64
Copy link

XL64 commented Feb 14, 2019

@gmacon Indeed I had to remove this option, thanks for rebasing :)

@modib
Copy link

modib commented Feb 23, 2019

Tested this on macOS Mojave 10.14.3 and it seems to be working fine so far with basic testing. Will be testing more throughout the week.

cmd used:
sudo openconnect <host> -b -l -q -u <user> --authgroup=<authgroup> -s '/usr/local/bin/vpn-slice x.x.x.x/22'

@modib
Copy link

modib commented Feb 23, 2019

Connection is active but got this exception after macbook went to sleep while it was locked.

Exception while setting reason from environment variable reason='attempt-reconnect'
Traceback (most recent call last):
  File "/usr/local/bin/vpn-slice", line 11, in <module>
    load_entry_point('vpn-slice==0.1', 'console_scripts', 'vpn-slice')()
  File "/usr/local/lib/python3.7/site-packages/vpn_slice-0.1-py3.7.egg/vpn_slice/main.py", line 331, in main
  File "/usr/local/lib/python3.7/site-packages/vpn_slice-0.1-py3.7.egg/vpn_slice/main.py", line 245, in parse_env
  File "/usr/local/lib/python3.7/site-packages/vpn_slice-0.1-py3.7.egg/vpn_slice/main.py", line 218, in <lambda>
  File "/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/enum.py", line 351, in __getitem__
    return cls._member_map_[name]
KeyError: 'attempt_reconnect'

@gmacon
Copy link
Collaborator Author

gmacon commented Feb 24, 2019

@modib, I believe the attempt-reconnect error is a separate issue, so I created #13 to discuss it.

@doomedraven
Copy link
Contributor

confirmed, works on osx 10.14.3 with openconnect 8.02.
@gmacon thanks a lot

@michaelblyons
Copy link

What are the odds that this could be a Homebrew formula?

@doomedraven
Copy link
Contributor

You can install it with pip if that would be merged

@XL64
Copy link

XL64 commented Mar 6, 2019 via email

@doomedraven
Copy link
Contributor

doomedraven commented Mar 6, 2019 via email

@doomedraven
Copy link
Contributor

if that would be useful for someone, vpn-slice + unbound dns server in local
https://github.com/doomedraven/Tools/blob/master/Mac/VPN_split.sh

@XL64
Copy link

XL64 commented Mar 8, 2019 via email

@doomedraven
Copy link
Contributor

you are correct, fixing, yes the dns will handle that dynamically for you, and you don't need use hosts or pass list of domains

@XL64
Copy link

XL64 commented Mar 8, 2019 via email

@doomedraven
Copy link
Contributor

doomedraven commented Mar 8, 2019

you don't need to put .local at the end, just yourcompany.com. <- dot at the end :)

i just updated it as i forgot what i had updated it here so 1 more thing
local-data: "vpn.yourcomapy.com. IN A VPN_IP" <- required to be able to connect to vpn gw as if no, dns will not able to connect to that VPN , see "company.net.", you will need real IP in local-data

    private-domain: "company.net."
    local-data: "vpn.company.net.     IN A IP"
remote-control:
    control-enable: yes
    control-interface: 127.0.0.1
    server-key-file: "/usr/local/etc/unbound/unbound_server.key"
    server-cert-file: "/usr/local/etc/unbound/unbound_server.pem"
    control-key-file: "/usr/local/etc/unbound/unbound_control.key"
    control-cert-file: "/usr/local/etc/unbound/unbound_control.pem"

forward-zone:
   name: "company.net."
   forward-addr: IP
   forward-addr: IP 

forward-zone:
   name: "."
   # forward-ssl-upstream: yes
   forward-addr: 1.1.1.1@53#one.one.one.one
   forward-addr: 8.8.8.8@53#dns.google
   forward-addr: 9.9.9.9@53#dns.quad9.net
   forward-addr: 1.0.0.1@53#one.one.one.one
   forward-addr: 8.8.4.4@53#dns.google
   forward-addr: 149.112.112.112@53#dns.quad9.net

@doomedraven
Copy link
Contributor

ayway let me know if you need help, so i can maybe better explain it

@XL64
Copy link

XL64 commented Mar 8, 2019 via email

@doomedraven
Copy link
Contributor

yes correct, that is the easier one, you was need just to check vpn-slice --help, just add to vpn-slice --dump --verbose

and it will give you all info

@XL64
Copy link

XL64 commented Mar 8, 2019 via email

@doomedraven
Copy link
Contributor

to check your dns do few things

dig @dns_IP some_corp_domain
dig @localhost some_corp_domain

to simplify debug of issue in unbound.conf uncomment

# logfile: "/tmp/unbound.log"
# log-queries: yes
# log-time-ascii: yes

and do tail -f /tmp/unbound.log in another terminal, and exec dig command to see whats going on

@XL64
Copy link

XL64 commented Mar 8, 2019 via email

@XL64
Copy link

XL64 commented Mar 11, 2019 via email

@doomedraven
Copy link
Contributor

hm, i just do this sudo openconnect vpn.company.com -u my_user -s 'vpn-slice 10.0.0.0/8 --verbose --dump'

and it works fine, try maybe cidr 8 instead of 9

@XL64
Copy link

XL64 commented Mar 16, 2019

Finally my kinit issue was not link with that at all, I just had to copy my company krb5.conf in /etc/, all is fine now !

@doomedraven
Copy link
Contributor

glad that works :)

@sjuxax
Copy link

sjuxax commented Apr 26, 2019

Works great for me at gmacon@eb4f7e3. Thanks!

@emulated24
Copy link

Hi gmacon, great job, thanks a lot for the mac port. ;)
Works fine on macOS Mojave 10.14.4 with OpenConnect for Juniper VPN.

dlenski added 6 commits May 25, 2019 17:00
1. Missing `destination` parameter.
2. Inconsistently named `output_start` vs. `start_output`.
3. Parsing the output of iproute is finicky and there's no guarantee that a
   words occur in sensible pairs.
While the BSD `route add` may simply ignore re-addition of existing routes,
`ip route add` does NOT behave in this way. `ip route replace` needs to be
used in this case.

I prefer to keep `RouteProvider.add_route` and `RouteProvider.replace_route`
distinct on platforms where it's easy to do so, since this stricter behavior
helps catch other mistakes in the routing configuration.
…nnel device

So restore that behavior of `reason=pre-init` by creating a
new `TunnelPrepProvider` class.
This leaves `os.environ`, `os.path`, and `os.fork` as the three OS-specific
bits which are not abstracted out into providers.

The first two are essentially universal, while `os.fork` will need to be
rethought if anyone ever tries to make this work on Windows.
@dlenski
Copy link
Owner

dlenski commented May 26, 2019

Sorry for the long delay… and many thanks to @gmacon for the excellent, excellent work of abstracting and porting to macOS. 👍 👍 👍

I fixed several bits of ip route handling that were broken in 5ff39ee, a couple things that were made more sloppy than necessary in fd571e7 and b6bea08, and a couple cosmetic nickpicks in ca0e574 and d932ba0. Then I also factored out a couple more OS-specific bits into ProcessProvider in f47a35c.

macOS users, please test and let me know if this is still working for you guys. (It should be… I really didn't change anything of consequence in mac.py.)

With this we should be in a very good position to port to other BSDs, if anyone's interested.

Unfortunately, dig does not correctly handle the specification of multiple
`+domain` arguments, discarding all but the last one.  Therefore we need
to run it multiple times and combine the results if multiple
`search_domains` are specified.

This is a very important use case for me, and several other known users.
@dlenski
Copy link
Owner

dlenski commented May 26, 2019

Turns out the DigProvider was also oversimplified, mishandling the case of multiple search domains. Fixed in 3266a8a.

Being able to do vpn-slice -d corp.com -d alternate.corp.com shorthostname1 shorthostname2 shorthostname3 and have all the hostnames found correctly is a very important use case for me.

@dlenski
Copy link
Owner

dlenski commented May 26, 2019

One last thing for @gmacon: is there a known minimum version of macOS required for this to work?

@doomedraven
Copy link
Contributor

hey @dlenski thanks for start lookin on this, so now with all your changes

Traceback (most recent call last):
  File "/usr/local/bin/vpn-slice", line 11, in <module>
    load_entry_point('vpn-slice', 'console_scripts', 'vpn-slice')()
  File "/private/tmp/vpn-slice/vpn_slice/main.py", line 341, in main
    providers = get_default_providers()
  File "/private/tmp/vpn-slice/vpn_slice/main.py", line 29, in get_default_providers
    from .generic import NoFirewallProvider, NoTunnelPrepProvider
ImportError: cannot import name 'NoTunnelPrepProvider' from 'vpn_slice.generic' (/private/tmp/vpn-slice/vpn_slice/generic.py)

@dlenski
Copy link
Owner

dlenski commented May 26, 2019

@doomedraven, derp derp derp 🤦‍♂️. Fixed in edfa341. Thanks for testing.

@doomedraven
Copy link
Contributor

now works just fine :) thanks a lot

@dlenski
Copy link
Owner

dlenski commented May 26, 2019

I'm gonna merge and assume we can clean up any other leftover bits later as needed. Thanks again to @gmacon for the great work and others, in particular @doomedraven, for testing and refinement.

@dlenski dlenski merged commit 8a061f8 into dlenski:master May 26, 2019
@doomedraven
Copy link
Contributor

amazing, thanks a lot @dlenski and @gmacon . I have updated my script https://github.com/doomedraven/Tools/blob/master/Mac/VPN_split.sh

@gmacon
Copy link
Collaborator Author

gmacon commented May 27, 2019

One last thing for @gmacon: is there a known minimum version of macOS required for this to work?

I don't know what the minimum required version is, but I suspect that it would work on any version of macOS because the tools we're interacting with here were all inherited from FreeBSD.

@gmacon gmacon deleted the feature/macos branch May 27, 2019 15:37
@dlenski
Copy link
Owner

dlenski commented May 28, 2019

I don't know what the minimum required version is, but I suspect that it would work on any version of macOS because the tools we're interacting with here were all inherited from FreeBSD.

Thanks. I googled around some, and that was my impression… the userland interface for routing on macOS doesn't seem to have changed much in the last ~20 years. So I'll just leave the docs as-is unless we find a clear counterexample.

@kalvinwang
Copy link

Thank you @dlenski @gmacon @doomedraven et al!!!

@drewclauson
Copy link

Thanks all, I've got this pulled down and working! 👏🏻👏🏻

@dlenski
Copy link
Owner

dlenski commented May 31, 2019

I'm going to lock this issue, so that if any new issues with Mac support are found… people will open new issues rather than be tempted to pile on this one. 😎

Repository owner locked as resolved and limited conversation to collaborators May 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants