mirror of
https://github.com/openziti/zrok.git
synced 2024-11-22 16:13:47 +01:00
minor namespacing; docs
This commit is contained in:
parent
2983d16a06
commit
dda920f4df
@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/go-openapi/runtime"
|
"github.com/go-openapi/runtime"
|
||||||
httptransport "github.com/go-openapi/runtime/client"
|
httptransport "github.com/go-openapi/runtime/client"
|
||||||
tb "github.com/nsf/termbox-go"
|
tb "github.com/nsf/termbox-go"
|
||||||
"github.com/openziti-test-kitchen/zrok/http"
|
"github.com/openziti-test-kitchen/zrok/endpoints/bind"
|
||||||
"github.com/openziti-test-kitchen/zrok/model"
|
"github.com/openziti-test-kitchen/zrok/model"
|
||||||
"github.com/openziti-test-kitchen/zrok/rest_client_zrok"
|
"github.com/openziti-test-kitchen/zrok/rest_client_zrok"
|
||||||
"github.com/openziti-test-kitchen/zrok/rest_client_zrok/tunnel"
|
"github.com/openziti-test-kitchen/zrok/rest_client_zrok/tunnel"
|
||||||
@ -59,7 +59,7 @@ func (self *httpCommand) run(_ *cobra.Command, args []string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
cfg := &http.Config{
|
cfg := &bind.Config{
|
||||||
IdentityPath: idCfg,
|
IdentityPath: idCfg,
|
||||||
EndpointAddress: args[0],
|
EndpointAddress: args[0],
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ func (self *httpCommand) run(_ *cobra.Command, args []string) {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
httpProxy, err := http.New(cfg)
|
httpProxy, err := bind.NewHTTP(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -185,7 +185,7 @@ func (self *httpCommand) run(_ *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanupHttp(id string, cfg *http.Config, zrok *rest_client_zrok.Zrok, auth runtime.ClientAuthInfoWriter) {
|
func cleanupHttp(id string, cfg *bind.Config, zrok *rest_client_zrok.Zrok, auth runtime.ClientAuthInfoWriter) {
|
||||||
logrus.Infof("shutting down '%v'", cfg.Service)
|
logrus.Infof("shutting down '%v'", cfg.Service)
|
||||||
req := tunnel.NewUntunnelParams()
|
req := tunnel.NewUntunnelParams()
|
||||||
req.Body = &rest_model_zrok.UntunnelRequest{
|
req.Body = &rest_model_zrok.UntunnelRequest{
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/openziti-test-kitchen/zrok/proxy"
|
"github.com/openziti-test-kitchen/zrok/endpoints/listen"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ var proxyCmd = &cobra.Command{
|
|||||||
Use: "proxy <configPath>",
|
Use: "proxy <configPath>",
|
||||||
Short: "Start a zrok proxy",
|
Short: "Start a zrok proxy",
|
||||||
Run: func(_ *cobra.Command, args []string) {
|
Run: func(_ *cobra.Command, args []string) {
|
||||||
if err := proxy.Run(&proxy.Config{IdentityPath: args[0], Address: "0.0.0.0:10111"}); err != nil {
|
if err := listen.Run(&listen.Config{IdentityPath: args[0], Address: "0.0.0.0:10111"}); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -51,5 +51,5 @@ func Run(cfg *Config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func versionHandler(_ metadata.VersionParams) middleware.Responder {
|
func versionHandler(_ metadata.VersionParams) middleware.Responder {
|
||||||
return metadata.NewVersionOK().WithPayload("v0.0.2")
|
return metadata.NewVersionOK().WithPayload("v0.1.0")
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
<mxfile host="Electron" modified="2022-07-22T01:30:17.968Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/19.0.3 Chrome/102.0.5005.63 Electron/19.0.3 Safari/537.36" etag="_Q9Pn9I-GM7nqiGinaNO" version="19.0.3" type="device"><diagram id="_Ghql2C1og50n_kotsIi" name="overview">7Zldb9sgFIZ/TS5XGeOP5LJJv7R1UtZqWnc1EZslLMR4mDRJf/0gxrENae1maepJuwrngA/w8nDATg+OFutrjtLZZxZj2nOdeN2DFz3XdR0/lD/Ks8k9ALiD3DPlJNa+0nFPnrB2Otq7JDHOag0FY1SQtO6MWJLgSNR8iHO2qjf7yWi91xRNseW4jxC1vd9ILGbaGzpOWXGDyXRWdA2KmgUqWmtHNkMxW1Vc8LIHR5wxkZcW6xGmSr5CmPy5q2dqdyPjOBFtHvh0N3eX/MeXMb29iX9Pvt59ZfEHHeUR0aWe8RMRpOcGVMYcTrgsTVUpwWLF+FzPRGwKfWQXcimkMZTTS5UzomwpexyuZkTg+xRFyrmSeEjfTCyotIAs2qMvhoK5wOuKS8/mGrMFFnwjm+ja0Ovnj2i4fBjk9qqyUoX6s8oi9bUPaTimu9ClfLKgFXyFmq6tJmdzW02B+YIkSDBuCcrZMolxrFV6exEHviGi11LE4K1EhJaIKSePSGBbR5SmlERIEJZ0ikwAAtgxNL2WaKacrdVMMswfiVTovfn0Ydf49C0lUbKxhYwoUbM29StgXC7oeaQSABwqMSTF9BZNMB2zjGx5hhcTJgRbVBqcUzJVFYIZOrOloCTBo90h6BxHfA80iw9PqX1gaW/v+yQ+Vwf/dsOjLCORSgECcWG7KxKWXCvtpGR881A1vivjzC/Mi3W18mLTpLnsf4pF8/7Ece0+Yq9MRXl/j/KFj2Mq0+Jj/Razbzl0D2NGFKy7hTdPhTCoh8jYkkdYP1W9dBiB/LAeKOgbgXJhrEBbOnbTPhyY8OTAnDlhnRmvgZmtNcacyLliXjjXRDzonlS5gp+0ykjKaIQvX6xm+BohBZ2CNDDYCsGBkIauAWlwWkj7Hc9qBYzO2cDp14CE4ctIKsNE+3BM2+ZSt1OYDowbTAgPxHTQf99cOvifS1tA6raEFHYKUgD6R0qmwIUny6ZXv/yH+cchyOZkDNdDMb2fwH2fNPa+6URMwsIoxe//Em5+yfCKz1+neMnZK6L9JaPdXn9+U+/OEL+yDcHLp0eZCLx6HgCH5IFWe/olpP6x+1E/dGpU+SYtrQ8e1wgEjEBvvKPtL0LHgrF2IjTdZUoaQ7+GYwOMz5x/W/cVoY155Gh4duwdc1CnyjsUT98zArXEUy4J2lSapapB9vyAA3PAvm/Qnkc8Kvv2d7sjsQ8OZN99FftybBXEO7MTuvWGAI1EvbNfuxM8I1FD9212gnkg/OVOkGb5N1jevPw7EV7+AQ==</diagram></mxfile>
|
<mxfile host="Electron" modified="2022-08-17T16:49:05.027Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/19.0.3 Chrome/102.0.5005.63 Electron/19.0.3 Safari/537.36" etag="KEv0E0LYOGxieD0rUxZZ" version="19.0.3" type="device"><diagram id="_Ghql2C1og50n_kotsIi" name="overview">7Zldb9owFIZ/DZer4jhfXBZaWm2dxFpN666mkHiJh4mZ4xTor59DnC8HSMqAZtKuiI+dY/s9j48dM4DjxfqOucvwM/URGeiavx7Am4Gu65ppi5/UssksAOjDzBIw7EtbaXjCr0gaNWlNsI/iWkNOKeF4WTd6NIqQx2s2lzG6qjf7SUm916UboIbhyXNJ0/oN+zyUVlvTyop7hIMw7xrkNQs3by0Ncej6dFUxwdsBHDNKefa0WI8RSeXLhcnem+ypLUbGUMS7vPDpca4n7MeXKXm493/Pvj5+pf4H6eXFJYmc8SvmeKBbRPgczZh4CtKnCPEVZXM5E77J9RFdiFCIwkhMb5kaPUIT0eNoFWKOnpaulxpXAg9hC/mCiBIQj83R50NBjKN1xSRnc4foAnG2EU1krW042SsSLhNaWXlViVSuflgJkiNtroQjKFyX8okHqeAb1NSbajI6b6o5w5GPo0A0RZG/pFhIoArLaBL5yJdqnV/MoamIaXQU0zqXmLAhpu+yHWKGnC8PKfmeiAJgwZ4xanRklOCYo6hnlJqwb5SaDTndaLMXUo9gtEPGHMxkQa49Tpl4IdUEi33owZ0hMqWxyMo0Ek1mlHO6qDS4JjhIKzhV5KYJJzhC42Jn1E4TAwO0xwBeMgRWIwTNHBD51+lpYLv43TjGXpoOuMt401yRsMQ71U5IxjbP1cL3tHBl5sWbdbXyZtOmueg/QLx9rSK/dkhpRqaivLlD+dzGEHE5fqkfbXaFQ/YwzdZ8EXh1i7CtuouYJsxD0yJTTPY4Mu26I8tRHGXCNBxt6SimfTww9sWBudLsOjNGCzPb0hQxLOaKWG5cY/4se0qfK/iJUukpLbTClwWrHb5WSEGvILUUtmxwJKS2rkBqXRZSp+dZLYdRuxpqTg1IaB9GMi2oaB+PaddcqvcK06FykLHhkZgOnffNpcP/ubQDpHpHSGGvIAXAOVEyBTq8WDad/DKf5x9HIJ7jKVyPePA0g7vuOXZ+9XhUwEIJEZy897eOer1h5Hdil/jW2Sli83qj21rfv6iLPcSsLENwePcoE4FRzwPgmDzQaU0fQuofOx85tlajylRp6bzx6IojoDg684puXg+dCsbajtB2lilptM0aji0w7tn/tuYJJq155GR49uwbc1inyjgWT9NQHHXEU4TE3VSabe+94v0DttQBm6ZCe+bxpOw37/BOxD44kn39TeyLsVUQ781K6NcXAlQSdVF+60owlEQN9fOsBHVD+MuVIIrlf2NZ8/I/Rnj7Bw==</diagram></mxfile>
|
Binary file not shown.
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 26 KiB |
BIN
docs/images/zrok_v0.1_overview.png
Normal file
BIN
docs/images/zrok_v0.1_overview.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
83
docs/overview-v0.1.md
Normal file
83
docs/overview-v0.1.md
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
# zrok v0.1.x
|
||||||
|
|
||||||
|
## What Is `zrok`?
|
||||||
|
|
||||||
|
`zrok` is a super-lightweight tool for providing on-demand access to dark, unreachable resources. The super-power of `zrok` is its ability to provide a single-step solution to enabling network connectivity. From an end-user perspective, `zrok` is a tool packaged as a single executable, which can be used as a shim to quickly create public endpoints for dark resources.
|
||||||
|
|
||||||
|
`zrok` is also a service (can be self-hosted) and runs on top of an OpenZiti network. The service provides one or more listening endpoints (typically on the public internet), that are designed to dynamically expose endpoints (HTTP-only, as of v0.1.x), as requested by the end-user `zrok` tooling.
|
||||||
|
|
||||||
|
`zrok` listening endpoints, and `zrok` terminating endpoints are typically used together to create the streamlined, simple connectivity solution for dark services. But listening endpoints and the terminating endpoints can be used orthogonally, interoperating with other Ziti SDK clients.
|
||||||
|
|
||||||
|
### The Primary Use Case
|
||||||
|
|
||||||
|
The primary use case for `zrok` is exposing dark resources across the public internet, for a multiplicity of reasons. Consider a developer, who is building a web application and wants to share work in progress with third parties for review. The developer already has signed up for a `zrok` account and has been issued a secret token.
|
||||||
|
|
||||||
|
The developer will have enabled `zrok` capabilities for their shell environment using the `zrok enable` command:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ zrok enable <secret-token>
|
||||||
|
```
|
||||||
|
|
||||||
|
After enabling their environment, the developer can quickly create a publicly available URL for their application like this:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ zrok http http://localhost:3000
|
||||||
|
```
|
||||||
|
|
||||||
|
`zrok` will then give them a public URL, like this:
|
||||||
|
|
||||||
|
```
|
||||||
|
http://d9121e7cdfd2dd2f.zrok.quigley.com:10111/
|
||||||
|
```
|
||||||
|
|
||||||
|
This URL can be shared with anyone, anywhere, allowing access to the developer's application as long as the developer is running the `zrok http` command. Simply ending that process will destroy all of the public access, and clean up the associated resources in the underlying Ziti environment.
|
||||||
|
|
||||||
|
## How Does `zrok` Work?
|
||||||
|
|
||||||
|
At a high level, the `zrok` stack looks like this:
|
||||||
|
|
||||||
|
![zrok v0.1 overview](images/zrok_v0.1_overview.png)
|
||||||
|
|
||||||
|
Let's discuss a couple of the flows through the above use case and talk about what's happening.
|
||||||
|
|
||||||
|
### The `zrok enable` Flow
|
||||||
|
|
||||||
|
When a new `zrok` user signs up for an account, they are issued a "secret token". This secret token is used to enable shell access to `zrok http` from the command line.
|
||||||
|
|
||||||
|
When the user runs `zrok enable` from their shell, here's what happens:
|
||||||
|
|
||||||
|
1. The `zrok enable` client reaches out with an enable request to the `zrok` controller.
|
||||||
|
2. The `zrok` controller creates a new Ziti identity for the environment, enrolls it, and returns the entire SDK configuration back to the `zrok enable` client.
|
||||||
|
3. The `zrok enable` client then stores the Ziti identity a few other housekeeping details in the user's `~/.zrok` folder (we refer to this as `zrokdir`, conceptually in the code).
|
||||||
|
4. With the Ziti identity and configuration details stored in the user's `zrokdir`, the user is then able to create any number of binding endpoints using the `zrok http` command.
|
||||||
|
5. The `zrok` controller creates an edge router policy associating the new Ziti identity with `#all` edge routers.
|
||||||
|
|
||||||
|
### The `zrok http` Flow
|
||||||
|
|
||||||
|
When a `zrok` user issues a `zrok http` command for an endpoint, here's what happens:
|
||||||
|
|
||||||
|
1. The `zrok http` client gathers the necessary identity details from the `zrokdir`.
|
||||||
|
2. The `zrok http` client reaches out to the `zrok` controller with an authenticated `tunnel` request, asking to have a new endpoint binding created.
|
||||||
|
3. The `zrok` controller allocates a new "service name" for the binding.
|
||||||
|
4. The `zrok` controller creates a `zrok.proxy.v1` configuration describing the user's requested authentication details (currently: `none` or `basic`).
|
||||||
|
5. The `zrok` controller creates a new service, associating the service with the configuration.
|
||||||
|
6. The `zrok` controller creates a bind service policy for the user's environment identity and the newly created Ziti service.
|
||||||
|
7. The `zrok` controller creates a dial service policy allowing the configured listening endpoints (ingress proxies) to dial the newly created service.
|
||||||
|
8. The `zrok` controller creates a service edge router policy associating the newly created service with `#all` edge routers.
|
||||||
|
9. The URL for the new `zrok` service is constructed and returned to the `zrok http` client.
|
||||||
|
10. The `zrok http` client then binds the Ziti service with an SDK client, and begins reverse-proxying traffic received from Ziti across to the dark service.
|
||||||
|
|
||||||
|
When the user terminates the `zrok http` client, these resources are removed from the Ziti network.
|
||||||
|
|
||||||
|
### HTTP Client Flow
|
||||||
|
|
||||||
|
When `zrok http` exposes a service and returns a URL, that URL is designed to be sent to a `zrok` listening endpoint (`zrok proxy`, currently). The `zrok proxy` is a stateless SDK client with an HTTP(S) listener exposed to the public internet.
|
||||||
|
|
||||||
|
When an HTTP request arrives as the `zrok proxy` listener, this happens:
|
||||||
|
|
||||||
|
1. The `zrok proxy` parses the `Host` header provided by the client, extracting the `zrok` service name from the URL.
|
||||||
|
2. The service is refreshed (if necessary) and retrieved. The `zrok.proxy.v1` configuration details are retrieved.
|
||||||
|
3. The `zrok.proxy.v1` configuration is used to do authentication processing. If authentication is required, such a response is returned to the client.
|
||||||
|
4. The `zrok proxy` then dials the Ziti service, and the dialed service is used to reverse proxy the request from the end user across Ziti to the binding endpoint, and then dark service.
|
||||||
|
|
||||||
|
The `zrok proxy` does not require any communication with the `zrok` controller, and is stateless. They can be pooled behind a load balancer. It is currently a goal is to maintain this lightweight nature.
|
@ -1,4 +1,4 @@
|
|||||||
package http
|
package bind
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/openziti-test-kitchen/zrok/util"
|
"github.com/openziti-test-kitchen/zrok/util"
|
||||||
@ -19,13 +19,13 @@ type Config struct {
|
|||||||
Service string
|
Service string
|
||||||
}
|
}
|
||||||
|
|
||||||
type httpProxy struct {
|
type httpBind struct {
|
||||||
Requests func() int32
|
Requests func() int32
|
||||||
listener edge.Listener
|
listener edge.Listener
|
||||||
handler http.Handler
|
handler http.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg *Config) (*httpProxy, error) {
|
func NewHTTP(cfg *Config) (*httpBind, error) {
|
||||||
options := ziti.ListenOptions{
|
options := ziti.ListenOptions{
|
||||||
ConnectTimeout: 5 * time.Minute,
|
ConnectTimeout: 5 * time.Minute,
|
||||||
MaxConnections: 64,
|
MaxConnections: 64,
|
||||||
@ -39,27 +39,27 @@ func New(cfg *Config) (*httpProxy, error) {
|
|||||||
return nil, errors.Wrap(err, "error listening")
|
return nil, errors.Wrap(err, "error listening")
|
||||||
}
|
}
|
||||||
|
|
||||||
proxy, err := NewProxy(cfg.EndpointAddress)
|
proxy, err := newReverseProxy(cfg.EndpointAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
handler := util.NewProxyHandler(proxy)
|
handler := util.NewProxyHandler(proxy)
|
||||||
return &httpProxy{
|
return &httpBind{
|
||||||
Requests: handler.Requests,
|
Requests: handler.Requests,
|
||||||
listener: listener,
|
listener: listener,
|
||||||
handler: handler,
|
handler: handler,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *httpProxy) Run() error {
|
func (p *httpBind) Run() error {
|
||||||
if err := http.Serve(p.listener, p.handler); err != nil {
|
if err := http.Serve(p.listener, p.handler); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewProxy(target string) (*httputil.ReverseProxy, error) {
|
func newReverseProxy(target string) (*httputil.ReverseProxy, error) {
|
||||||
targetURL, err := url.Parse(target)
|
targetURL, err := url.Parse(target)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
@ -1,4 +1,4 @@
|
|||||||
package proxy
|
package listen
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
Loading…
Reference in New Issue
Block a user