-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
50 changed files
with
1,240 additions
and
645 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="hboned" type="GoApplicationRunConfiguration" factoryName="Go Application"> | ||
<module name="dmesh" /> | ||
<working_directory value="$PROJECT_DIR$/../ugate/cmd/hboned/testdata" /> | ||
<kind value="PACKAGE" /> | ||
<package value="github.com/costinm/ugate/cmd/hboned" /> | ||
<directory value="$USER_HOME$/work" /> | ||
<filePath value="$PROJECT_DIR$/../ugate/cmd/hboned/hboned.go" /> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,36 +2,32 @@ package main | |
|
||
import ( | ||
"flag" | ||
"io" | ||
"log" | ||
"net/http" | ||
"net" | ||
"os" | ||
|
||
"github.com/costinm/ugate" | ||
"github.com/costinm/ugate/pkg/auth" | ||
"github.com/costinm/ugate/pkg/ugatesvc" | ||
) | ||
|
||
|
||
var ( | ||
// WIP: | ||
// port = flag.Int("l", 0, "local port") | ||
//debugPort = flag.Int("d", 0, "debug/status port") | ||
port = flag.String("l", "", "local port") | ||
tls = flag.Bool("s", false, "mTLS over hbone") | ||
) | ||
|
||
|
||
|
||
var hc *http.Client | ||
|
||
// Create a HBONE tunnel to a given URL. | ||
// | ||
// Current client is authenticated for HBONE using local credentials, or a kube.json file. | ||
// If no kube.json is found, one will be generated. | ||
// Current client is authenticated for HBONE using local credentials, | ||
// or a kube.json file. If no certs or kube.json is found, one will be generated. | ||
// | ||
// Example: | ||
// ssh -v -o ProxyCommand='hbone https://c1.webinf.info:443/dm/PZ5LWHIYFLSUZB7VHNAMGJICH7YVRU2CNFRT4TXFFQSXEITCJUCQ:22' root@PZ5LWHIYFLSUZB7VHNAMGJICH7YVRU2CNFRT4TXFFQSXEITCJUCQ | ||
// ssh -v -o ProxyCommand='hbone https://%h:443/hbone/:22' [email protected] | ||
// | ||
// Note that SSH is converting %h to lowercase - the ID must be in this form | ||
// | ||
// Bug: %h:%p doesn't work, ssh uses lower case and confuses the map. | ||
func main() { | ||
flag.Parse() | ||
|
||
|
@@ -40,47 +36,34 @@ func main() { | |
|
||
ug := ugatesvc.New(config, authz, nil) | ||
|
||
hc = &http.Client{ | ||
Transport: ug, | ||
} | ||
|
||
if len(flag.Args()) == 0 { | ||
log.Fatal("Expecting URL") | ||
} | ||
url := flag.Arg(0) | ||
err := Netcat(ug, url) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
// Netcat copies stdin/stdout to a HBONE stream. | ||
func Netcat(ug *ugatesvc.UGate, s string) error { | ||
i, o := io.Pipe() | ||
r, _ := http.NewRequest("POST", s, i) | ||
res, err := ug.RoundTrip(r) | ||
if err != nil { | ||
return err | ||
} | ||
nc := ugate.NewStreamRequestOut(r, o, res, nil) | ||
go func() { | ||
b1 := make([]byte, 1024) | ||
if *port != "" { | ||
l, err := net.Listen("tcp", *port) | ||
if err != nil { | ||
panic(err) | ||
} | ||
for { | ||
n, err := nc.Read(b1) | ||
a, err := l.Accept() | ||
if err != nil { | ||
log.Fatal("Tun read err", err) | ||
panic(err) | ||
} | ||
os.Stdout.Write(b1[0:n]) | ||
} | ||
}() | ||
b1 := make([]byte, 1024) | ||
for { | ||
n, err := os.Stdin.Read(b1) | ||
if err != nil { | ||
return err | ||
go func() { | ||
err := ugatesvc.HboneCat(ug, url, *tls, a, a) | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
}() | ||
} | ||
nc.Write(b1[0:n]) | ||
} | ||
return nil | ||
|
||
err := ugatesvc.HboneCat(ug, url, *tls, os.Stdin, os.Stdout) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/costinm/ugate" | ||
"github.com/costinm/ugate/pkg/iptables" | ||
"github.com/costinm/ugate/pkg/socks" | ||
"github.com/costinm/ugate/pkg/ugatesvc" | ||
) | ||
|
||
|
||
// | ||
// WIP: | ||
// - Listens as H2C, using certs generated by krun | ||
// - Forwards /hbone/PORT to port | ||
// - Handles /hbone/mtls as mtls and forwards to 8080 as H2C | ||
// - intercepts egress with iptables, forwards to a gate. | ||
// | ||
func main() { | ||
config := ugatesvc.NewConf(".", "./var/lib/dmesh", | ||
"./var/run/secrets/istio.io", "/var/run/secrets/istio.io") | ||
|
||
cfg := &ugate.GateCfg{ | ||
BasePort: 14000, | ||
} | ||
|
||
// Start a Gate. Basic H2 and H2R services enabled. | ||
ug := ugatesvc.New(config, nil, cfg) | ||
|
||
// Inbound path | ||
// TODO: create reverse tunnel to ugate | ||
// go ug.H2Handler.UpdateReverseAccept() | ||
|
||
// Ingress using H2C, for example in CloudRun. | ||
btscAddr := fmt.Sprintf("0.0.0.0:%d", cfg.BasePort+ugate.PORT_BTSC) | ||
ug.StartListener(&ugate.Listener{ | ||
Address: btscAddr, | ||
Protocol: ugate.ProtoBTSC, | ||
}) | ||
|
||
// WIP: egress side | ||
// capture using iptables, socks, port | ||
go iptables.IptablesCapture(ug, fmt.Sprintf("0.0.0.0:%d", cfg.BasePort + 1), false) | ||
go iptables.IptablesCapture(ug, fmt.Sprintf("0.0.0.0:%d", cfg.BasePort + 6), true) | ||
socks.New(ug) | ||
ug.Config.Listeners[":10001"] = &ugate.Listener { | ||
ForwardTo: "localhost:5201", | ||
} | ||
ug.Config.Listeners[":10002"] = &ugate.Listener { | ||
ForwardTo: "localhost:8080", | ||
} | ||
|
||
// | ||
// TODO: get out endpoints using a metadata server ( backed by pilot-agent ) | ||
// or XDS. | ||
// TODO: configure an multi-network gateway, with SNI or BTS | ||
|
||
// VIPs for iptables capture test. Redirect to local host, to bench | ||
// 1-hop iptables capture, in TCP mode | ||
ug.Config.Routes["10.1.1.2:8080"] = &ugate.Route { | ||
ForwardTo: "localhost:8080", | ||
} | ||
ug.Config.Routes[":8081"] = &ugate.Route { | ||
ForwardTo: "localhost:8080", | ||
} | ||
ug.Config.Routes["10.1.1.3:5201"] = &ugate.Route { | ||
ForwardTo: "localhost:5201", | ||
} | ||
|
||
ug.Start() | ||
|
||
select {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.