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

Docker ubuntu 20.04 container OSError: [Errno 18] Invalid cross-device link: '/etc/hosts' -> '/etc/hosts.sbak' #518

Open
bgreenacre opened this issue Sep 5, 2020 · 4 comments

Comments

@bgreenacre
Copy link

I'm trying to build a docker image with ubuntu 20.04 as a base and I always get the Errno 18 when I build it. I've searched here and found a similar issue on #398 which lead me to https://stackoverflow.com/questions/60529231/invoking-iptables-results-in-operation-not-supported-in-docker. So I tried the suggested update-alternatives --set iptables /usr/sbin/iptables-legacy in my Dockerfile but there's no change. I still get the same error.

Here's some verbose output of sshuttle:
I've removed some of it to remove alot of the hosts I end up getting when connected

Starting sshuttle proxy.
firewall manager: Starting firewall with Python version 3.8.2
firewall manager: ready method name nat.
IPv6 enabled: None
UDP enabled: False
DNS enabled: True
User enabled: False
Binding redirector: 12300
TCP redirector listening on ('127.0.0.1', 12300).
TCP redirector listening with <socket.socket fd=5, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('127.0.0.1', 12300)>.
Binding DNS: 12300 12299
DNS listening on ('127.0.0.1', 12299).
DNS listening with <socket.socket fd=7, family=AddressFamily.AF_INET, type=SocketKind.SOCK_DGRAM, proto=0, laddr=('127.0.0.1', 12299)>.
Starting client with Python version 3.8.2
c : connecting to server...
c : executing: ['/usr/bin/ssh', '-oStrictHostKeyChecking=no', '<user>@192.168.1.129', '--', '/bin/sh -c \'P=python3; $P -V 2>/dev/null || P=python; exec "$P" -c \'"\'"\'import sys, os; verbosity=3; sys.stdin = os.fdopen(0, "rb"); exec(compile(sys.stdin.read(1490), "assembler.py", "exec"))\'"\'"\'\'']
c :  > channel=0 cmd=PING len=7 (fullness=0)
Warning: Permanently added '192.168.1.129' (ECDSA) to the list of known hosts.
server: assembling 'sshuttle' (88 bytes)
server: assembling 'sshuttle.cmdline_options' (60 bytes)
server: assembling 'sshuttle.helpers' (892 bytes)
server: assembling 'sshuttle.ssnet' (5789 bytes)
server: assembling 'sshuttle.hostwatch' (2466 bytes)
server: assembling 'sshuttle.server' (3929 bytes)
Starting server with Python version 3.8.2
 s: latency control setting = True
 s:  > channel=0 cmd=PING len=7 (fullness=0)
c : Connected.
c : seed_hosts: []
c :  > channel=0 cmd=HOST_REQ len=0 (fullness=7)
c : Waiting: 3 r=[5, 7, 9] w=[9] x=[] (fullness=7/0)
 s: auto-nets:True
c :   Ready: 3 r=[] w=[9] x=[]
c : mux wrote: 15/15
c : Waiting: 3 r=[5, 7, 9] w=[9] x=[] (fullness=7/0)
c :   Ready: 3 r=[] w=[9] x=[]
c : mux wrote: 8/8
c : Waiting: 3 r=[5, 7, 9] w=[] x=[] (fullness=7/0)
 s: available routes:
 s:   2/169.254.0.0/16
 s:   2/169.254.169.254/32
 s:   2/192.168.1.0/24
 s:   2/192.168.1.1/32
 s:   2/192.168.1.1/32
 s:   2/192.168.1.111/32
 s:   2/192.168.1.129/32
 s:   2/192.168.1.144/32
 s:   2/224.0.0.0/4
 s:   2/224.0.0.251/32
 s:   2/255.255.255.255/32
 s:  > channel=0 cmd=ROUTES len=198 (fullness=7)
 s: Waiting: 1 r=[0] w=[1] x=[] (fullness=205/0)
 s:   Ready: 1 r=[0] w=[1] x=[]
 s: <  channel=0 cmd=PING len=7
 s:  > channel=0 cmd=PONG len=7 (fullness=205)
 s: <  channel=0 cmd=HOST_REQ len=0
c :   Ready: 3 r=[9] w=[] x=[]
c : <  channel=0 cmd=PING len=7
c :  > channel=0 cmd=PONG len=7 (fullness=7)
c : mux wrote: 15/15
c : Waiting: 3 r=[5, 7, 9] w=[] x=[] (fullness=14/0)
 s: mux wrote: 15/15
 s: mux wrote: 206/206
c :   Ready: 3 r=[9] w=[] x=[]
c : <  channel=0 cmd=ROUTES len=198
c : Adding auto net 2/169.254.0.0/16
c : Adding auto net 2/169.254.169.254/32
c : Adding auto net 2/192.168.1.0/24
c : Adding auto net 2/192.168.1.1/32
c : Adding auto net 2/192.168.1.1/32
c : Adding auto net 2/192.168.1.111/32
c : Adding auto net 2/192.168.1.129/32
c : Adding auto net 2/192.168.1.144/32
c : Adding auto net 2/224.0.0.0/4
c : Adding auto net 2/224.0.0.251/32
c : Adding auto net 2/255.255.255.255/32
firewall manager: Got subnets: [(2, 0, False, '0.0.0.0', 0, 0), (2, 16, False, '169.254.0.0', 0, 0), (2, 32, False, '169.254.169.254', 0, 0), (2, 24, False, '192.168.1.0', 0, 0), (2, 32, False, '192.168.1.1', 0, 0), (2, 32, False, '192.168.1.1', 0, 0), (2, 32, False, '192.168.1.111', 0, 0), (2, 32, False, '192.168.1.129', 0, 0), (2, 32, False, '192.168.1.144', 0, 0), (2, 4, False, '224.0.0.0', 0, 0), (2, 32, False, '224.0.0.251', 0, 0), (2, 32, False, '255.255.255.255', 0, 0)]
firewall manager: Got partial nslist: [(2, '127.0.0.11')]
firewall manager: Got nslist: [(2, '127.0.0.11')]
firewall manager: Got ports: 0,12300,0,12299
firewall manager: Got udp: False, user: None
firewall manager: setting up.
firewall manager: setting up IPv4.
>> iptables -t nat -A sshuttle-12300 -j REDIRECT --dest 169.254.169.254/32 -p tcp --to-ports 12300 -m ttl ! --ttl 63
>> iptables -t nat -A sshuttle-12300 -j REDIRECT --dest 192.168.1.1/32 -p tcp --to-ports 12300 -m ttl ! --ttl 63
>> iptables -t nat -A sshuttle-12300 -j REDIRECT --dest 192.168.1.1/32 -p tcp --to-ports 12300 -m ttl ! --ttl 63
>> iptables -t nat -A sshuttle-12300 -j REDIRECT --dest 192.168.1.111/32 -p tcp --to-ports 12300 -m ttl ! --ttl 63
>> iptables -t nat -A sshuttle-12300 -j REDIRECT --dest 192.168.1.129/32 -p tcp --to-ports 12300 -m ttl ! --ttl 63
>> iptables -t nat -A sshuttle-12300 -j REDIRECT --dest 192.168.1.144/32 -p tcp --to-ports 12300 -m ttl ! --ttl 63
>> iptables -t nat -A sshuttle-12300 -j REDIRECT --dest 224.0.0.251/32 -p tcp --to-ports 12300 -m ttl ! --ttl 63
>> iptables -t nat -A sshuttle-12300 -j REDIRECT --dest 255.255.255.255/32 -p tcp --to-ports 12300 -m ttl ! --ttl 63
>> iptables -t nat -A sshuttle-12300 -j REDIRECT --dest 192.168.1.0/24 -p tcp --to-ports 12300 -m ttl ! --ttl 63
>> iptables -t nat -A sshuttle-12300 -j REDIRECT --dest 169.254.0.0/16 -p tcp --to-ports 12300 -m ttl ! --ttl 63
>> iptables -t nat -A sshuttle-12300 -j REDIRECT --dest 224.0.0.0/4 -p tcp --to-ports 12300 -m ttl ! --ttl 63
>> iptables -t nat -A sshuttle-12300 -j REDIRECT --dest 0.0.0.0/0 -p tcp --to-ports 12300 -m ttl ! --ttl 63
>> iptables -t nat -A sshuttle-12300 -j REDIRECT --dest 127.0.0.11/32 -p udp --dport 53 --to-ports 12299 -m ttl ! --ttl 63
firewall manager: setting up /etc/hosts.
firewall manager: undoing changes.
firewall manager: undoing IPv4 changes.
>> iptables -t nat -D OUTPUT -j sshuttle-12300
>> iptables -t nat -D PREROUTING -j sshuttle-12300
>> iptables -t nat -F sshuttle-12300
>> iptables -t nat -X sshuttle-12300
firewall manager: undoing /etc/hosts changes.
firewall manager: ---> Traceback (most recent call last):
firewall manager: --->   File "/usr/local/lib/python3.8/dist-packages/sshuttle-1.0.5.dev9+g19f653d-py3.8.egg/sshuttle/firewall.py", line 239, in main
firewall manager: --->     rewrite_etc_hosts(hostmap, port_v6 or port_v4)
firewall manager: --->   File "/usr/local/lib/python3.8/dist-packages/sshuttle-1.0.5.dev9+g19f653d-py3.8.egg/sshuttle/firewall.py", line 30, in rewrite_etc_hosts
firewall manager: --->     os.link(HOSTSFILE, BAKFILE)
firewall manager: ---> OSError: [Errno 18] Invalid cross-device link: '/etc/hosts' -> '/etc/hosts.sbak'
firewall manager: ---> 
firewall manager: ---> During handling of the above exception, another exception occurred:
firewall manager: ---> 
firewall manager: ---> Traceback (most recent call last):
firewall manager: --->   File "/usr/local/lib/python3.8/dist-packages/sshuttle-1.0.5.dev9+g19f653d-py3.8.egg/sshuttle/firewall.py", line 279, in main
firewall manager: --->     restore_etc_hosts(port_v6 or port_v4)
firewall manager: --->   File "/usr/local/lib/python3.8/dist-packages/sshuttle-1.0.5.dev9+g19f653d-py3.8.egg/sshuttle/firewall.py", line 51, in restore_etc_hosts
firewall manager: --->     rewrite_etc_hosts({}, port)
firewall manager: --->   File "/usr/local/lib/python3.8/dist-packages/sshuttle-1.0.5.dev9+g19f653d-py3.8.egg/sshuttle/firewall.py", line 30, in rewrite_etc_hosts
firewall manager: --->     os.link(HOSTSFILE, BAKFILE)
firewall manager: ---> OSError: [Errno 18] Invalid cross-device link: '/etc/hosts' -> '/etc/hosts.sbak'
@AtzeDeVries
Copy link

i'm also working on this. I did get it to work with adding --net=host to your docker run statement. I don't want this so i'm researching further

@dclong
Copy link

dclong commented Oct 20, 2020

I'm encountering the same issue. @AtzeDeVries , may I ask what does --net=host do? It didn't work me.

@skuhl
Copy link
Contributor

skuhl commented Oct 20, 2020

If you don’t use the —auto-hosts option, the error after “firewall manager: undoing /etc/hosts changes.” should be fixed by pull request #545.

@nikatlas
Copy link
Contributor

nikatlas commented May 18, 2022

Maybe this helps #759
hosts file is mounted on a docker container

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

No branches or pull requests

5 participants