nwtgck / go-piping-tunnel

Tunneling from anywhere via Piping Server
MIT License
20 stars 3 forks source link

How to use with piping-server http basic auth? #19

Open m2acgi opened 1 year ago

m2acgi commented 1 year ago

How to use with piping-server http basic auth? Thanks.

nwtgck commented 1 year ago

You can use -H option to specify HTTP header. e.g. -H "Authorization: Basic am9objoxMjM0"

m2acgi commented 1 month ago

Not work, it says ↑ 0B ( 0B/s) | ↓ 0B ( 0B/s)2024/05/28 09:45:30 [ERR] yamux: Failed to read header: invalid content-type: , test on Windows 10 + go-piping-tunnel v0.11.0

nwtgck commented 1 month ago

Did you use only piping-tunnel on both server-host and client-host or a different tool?

m2acgi commented 1 month ago

Both server and client are piping-tunnel

nwtgck commented 1 month ago

I tried it but it worked.

edit: I may drop Content-Type checking in yamux. https://github.com/nwtgck/go-piping-tunnel/blob/add2e220369ee8b36040b9c5de6ebd9755b54063/cmd/client/client.go#L238

m2acgi commented 1 month ago

In my environment, the piping server is behind the Caddy reverse proxy server, the basic auth was provided by the Caddy server

nwtgck commented 1 month ago

Does it work without --yamux flag?

I will release new version avoiding content-type checking.

m2acgi commented 1 month ago

The program exited directly after remove --yamux:

[root@almalinux9-test ~]# ./piping-tunnel server --port 22 -H "Authorization: Basic Z3Vlc3Q6MTIzNDU2" --server https://piping.example.com 1234 4321
[INFO] Hint: Client host (socat + curl)
  curl -NsS https://piping.example.com/4321 | socat TCP-LISTEN:31376 - | curl -NsST - https://piping.example.com/1234
[INFO] Hint: Client host (piping-tunnel)
  piping-tunnel -s https://piping.example.com client -p 31376 1234 4321
↑  0B ( 0B/s) | ↓  0B ( 0B/s)
[INFO] Finished
[root@almalinux9-test ~]#
nwtgck commented 1 month ago

0.12.0 was released for avoiding "invalid content-type" error. https://github.com/nwtgck/go-piping-tunnel/releases/tag/v0.12.0

m2acgi commented 1 month ago

piping-tunnel v0.12.0 server still not work:

server:

[root@almalinux9-test ~]# ./piping-tunnel server --port 22 --yamux -H "Authorization: Basic Z3Vlc3Q6MTIzNDU2" --server https://piping.example.com 1234 4321
[INFO] Hint: Client host (piping-tunnel)
  piping-tunnel -s https://piping.example.com client -p 31376 --yamux 1234 4321
[INFO] Multiplexing with hashicorp/yamux
↑  0B ( 0B/s) | ↓  0B ( 0B/s)[WARN] --yamux flag may be missing in client-host
Error: EOF

client:

root@debian-12-test:~# ./piping-tunnel client --port 2222 --yamux -H "Authorization: Basic Z3Vlc3Q6MTIzNDU2" --server https://piping.example.com 1234 4321
[INFO] Client host listening on 2222 ...
[INFO] Hint: Server host (piping-tunnel)
  piping-tunnel -s https://piping.example.com server -p <YOUR PORT> --yamux 1234 4321
    OR
  piping-tunnel -s https://piping.example.com socks --yamux 1234 4321
[INFO] Multiplexing with hashicorp/yamux
↑  0B ( 0B/s) | ↓  0B ( 0B/s)[INFO] --yamux flag may be missing in server-host
nwtgck commented 1 month ago

Could you check the server supports data streaming? You can use curl like the following video:

https://github.com/nwtgck/go-piping-tunnel/assets/10933561/751e189d-5e09-4661-b612-982175032bb4

# sender
curl -T- https://ppng.io/mytext
# receiver
curl https://ppng.io/mytext

For the port forwarding, the server's streaming feature is necessary.

m2acgi commented 1 month ago

I've checked the feature data streaming after I deploy the piping-server to the prod env.

BTW: After disable the basic auth from Caddy server, the piping-tunnel works well without the -H arg.

nwtgck commented 1 month ago

Have you tried -H flags with curl for streaming check?:

# sender
curl -H "Authorization: Basic ..." -T- https://your.server/mytext
# receiver
curl -H "Authorization: Basic ..." https://your.server/mytext
m2acgi commented 1 month ago

Have you tried -H flags with curl for streaming check?:

# sender
curl -H "Authorization: Basic ..." -T- https://your.server/mytext
# receiver
curl -H "Authorization: Basic ..." https://your.server/mytext

Work fine.

nwtgck commented 1 month ago

Did curl -H "Authorization: ..." work with Basic-auth-enabled Caddy?

m2acgi commented 4 weeks ago

Did curl -H "Authorization: ..." work with Basic-auth-enabled Caddy?

Yes