From d1e63fd8e68b1f7897822e2187608a39d6a46b83 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Wed, 31 Aug 2022 14:49:41 -0400 Subject: [PATCH] listen/bind -> frontend/backend (#37) --- cmd/zrok/{httpbind.go => http_backend.go} | 37 +++++++++-------- cmd/zrok/http_frontend.go | 41 +++++++++++++++++++ cmd/zrok/httplisten.go | 40 ------------------ controller/tunnel.go | 2 +- controller/untunnel.go | 2 +- docs/network/ctrl.yml | 10 ++--- endpoints/{bind => backend}/http.go | 2 +- endpoints/{listen => frontend}/http.go | 2 +- etc/ziti-ctrl.yml | 10 ++--- .../operations/identity/create_account.go | 2 +- .../operations/identity/enable.go | 2 +- rest_server_zrok/operations/identity/login.go | 2 +- .../operations/metadata/overview.go | 2 +- .../operations/metadata/version.go | 2 +- rest_server_zrok/operations/tunnel/tunnel.go | 2 +- .../operations/tunnel/untunnel.go | 2 +- rest_server_zrok/server.go | 16 ++++---- 17 files changed, 89 insertions(+), 87 deletions(-) rename cmd/zrok/{httpbind.go => http_backend.go} (82%) create mode 100644 cmd/zrok/http_frontend.go delete mode 100644 cmd/zrok/httplisten.go rename endpoints/{bind => backend}/http.go (99%) rename endpoints/{listen => frontend}/http.go (99%) diff --git a/cmd/zrok/httpbind.go b/cmd/zrok/http_backend.go similarity index 82% rename from cmd/zrok/httpbind.go rename to cmd/zrok/http_backend.go index 882429c3..25eedb44 100644 --- a/cmd/zrok/httpbind.go +++ b/cmd/zrok/http_backend.go @@ -7,7 +7,7 @@ import ( "github.com/go-openapi/runtime" httptransport "github.com/go-openapi/runtime/client" tb "github.com/nsf/termbox-go" - "github.com/openziti-test-kitchen/zrok/endpoints/bind" + "github.com/openziti-test-kitchen/zrok/endpoints/backend" "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/tunnel" @@ -24,30 +24,31 @@ import ( ) func init() { - httpCmd.AddCommand(newHttpBindCommand().cmd) + httpCmd.AddCommand(newHttpBackendCommand().cmd) } -type httpBindCommand struct { - service bool +type httpBackendCommand struct { + quiet bool basicAuth []string cmd *cobra.Command } -func newHttpBindCommand() *httpBindCommand { +func newHttpBackendCommand() *httpBackendCommand { cmd := &cobra.Command{ - Use: "bind ", - Short: "Create an HTTP binding", - Args: cobra.ExactArgs(1), + Use: "backend ", + Aliases: []string{"be"}, + Short: "Create an HTTP binding", + Args: cobra.ExactArgs(1), } - command := &httpBindCommand{cmd: cmd} - cmd.Flags().BoolVarP(&command.service, "service", "s", false, "Disable TUI 'chrome' for service operation") + command := &httpBackendCommand{cmd: cmd} + cmd.Flags().BoolVarP(&command.quiet, "quiet", "q", false, "Disable TUI 'chrome' for quiet operation") cmd.Flags().StringArrayVar(&command.basicAuth, "basic-auth", []string{}, "Basic authentication users (,...") cmd.Run = command.run return command } -func (self *httpBindCommand) run(_ *cobra.Command, args []string) { - if !self.service { +func (self *httpBackendCommand) run(_ *cobra.Command, args []string) { + if !self.quiet { if err := ui.Init(); err != nil { panic(err) } @@ -63,7 +64,7 @@ func (self *httpBindCommand) run(_ *cobra.Command, args []string) { if err != nil { panic(err) } - cfg := &bind.Config{ + cfg := &backend.Config{ IdentityPath: zif, EndpointAddress: args[0], } @@ -102,7 +103,7 @@ func (self *httpBindCommand) run(_ *cobra.Command, args []string) { os.Exit(0) }() - httpProxy, err := bind.NewHTTP(cfg) + httpProxy, err := backend.NewHTTP(cfg) if err != nil { panic(err) } @@ -113,13 +114,13 @@ func (self *httpBindCommand) run(_ *cobra.Command, args []string) { } }() - if !self.service { + if !self.quiet { ui.Clear() w, h := ui.TerminalDimensions() p := widgets.NewParagraph() p.Border = true - p.Title = " access your zrok service " + p.Title = " access your zrok quiet " p.Text = fmt.Sprintf("%v%v", strings.Repeat(" ", (((w-12)-len(resp.Payload.ProxyEndpoint))/2)-1), resp.Payload.ProxyEndpoint) p.TextStyle = ui.Style{Fg: ui.ColorWhite} p.PaddingTop = 1 @@ -175,13 +176,13 @@ func (self *httpBindCommand) run(_ *cobra.Command, args []string) { } } else { for { - logrus.Infof("access your zrok service: %v", resp.Payload.ProxyEndpoint) + logrus.Infof("access your zrok quiet: %v", resp.Payload.ProxyEndpoint) time.Sleep(30 * time.Second) } } } -func (self *httpBindCommand) destroy(id string, cfg *bind.Config, zrok *rest_client_zrok.Zrok, auth runtime.ClientAuthInfoWriter) { +func (self *httpBackendCommand) destroy(id string, cfg *backend.Config, zrok *rest_client_zrok.Zrok, auth runtime.ClientAuthInfoWriter) { logrus.Infof("shutting down '%v'", cfg.Service) req := tunnel.NewUntunnelParams() req.Body = &rest_model_zrok.UntunnelRequest{ diff --git a/cmd/zrok/http_frontend.go b/cmd/zrok/http_frontend.go new file mode 100644 index 00000000..6b48d8a3 --- /dev/null +++ b/cmd/zrok/http_frontend.go @@ -0,0 +1,41 @@ +package main + +import ( + "github.com/openziti-test-kitchen/zrok/endpoints/frontend" + "github.com/spf13/cobra" +) + +func init() { + httpCmd.AddCommand(newHttpFrontendCommand().cmd) +} + +type httpFrontendCommand struct { + endpoint string + cmd *cobra.Command +} + +func newHttpFrontendCommand() *httpFrontendCommand { + cmd := &cobra.Command{ + Use: "frontend ", + Aliases: []string{"fe"}, + Short: "Create an HTTP frontend", + Args: cobra.ExactArgs(1), + } + command := &httpFrontendCommand{cmd: cmd} + cmd.Flags().StringVarP(&command.endpoint, "endpoint", "e", "0.0.0.0:10180", "Bind address for HTTP frontend") + cmd.Run = command.run + return command +} + +func (self *httpFrontendCommand) run(_ *cobra.Command, args []string) { + httpListener, err := frontend.NewHTTP(&frontend.Config{ + IdentityPath: args[0], + Address: self.endpoint, + }) + if err != nil { + panic(err) + } + if err := httpListener.Run(); err != nil { + panic(err) + } +} diff --git a/cmd/zrok/httplisten.go b/cmd/zrok/httplisten.go deleted file mode 100644 index 18951ea6..00000000 --- a/cmd/zrok/httplisten.go +++ /dev/null @@ -1,40 +0,0 @@ -package main - -import ( - "github.com/openziti-test-kitchen/zrok/endpoints/listen" - "github.com/spf13/cobra" -) - -func init() { - httpCmd.AddCommand(newHttpListenCommand().cmd) -} - -type httpListenCommand struct { - endpoint string - cmd *cobra.Command -} - -func newHttpListenCommand() *httpListenCommand { - cmd := &cobra.Command{ - Use: "listen ", - Short: "Create an HTTP listener", - Args: cobra.ExactArgs(1), - } - command := &httpListenCommand{cmd: cmd} - cmd.Flags().StringVarP(&command.endpoint, "endpoint", "e", "0.0.0.0:10111", "Address for HTTP listening endpoint") - cmd.Run = command.run - return command -} - -func (self *httpListenCommand) run(_ *cobra.Command, args []string) { - httpListener, err := listen.NewHTTP(&listen.Config{ - IdentityPath: args[0], - Address: self.endpoint, - }) - if err != nil { - panic(err) - } - if err := httpListener.Run(); err != nil { - panic(err) - } -} diff --git a/controller/tunnel.go b/controller/tunnel.go index f3fc905e..6294a0c4 100644 --- a/controller/tunnel.go +++ b/controller/tunnel.go @@ -168,7 +168,7 @@ func (self *tunnelHandler) createService(name, cfgId string, edge *rest_manageme func (self *tunnelHandler) createServicePolicyBind(svcName, svcId, envId string, edge *rest_management_api_client.ZitiEdgeManagement) error { semantic := rest_model.SemanticAllOf identityRoles := []string{fmt.Sprintf("@%v", envId)} - name := fmt.Sprintf("%v-bind", svcName) + name := fmt.Sprintf("%v-backend", svcName) postureCheckRoles := []string{} serviceRoles := []string{fmt.Sprintf("@%v", svcId)} dialBind := rest_model.DialBindBind diff --git a/controller/untunnel.go b/controller/untunnel.go index 1348dd4e..e2a6190d 100644 --- a/controller/untunnel.go +++ b/controller/untunnel.go @@ -173,7 +173,7 @@ func (_ *untunnelHandler) deleteServiceEdgeRouterPolicy(svcName string, edge *re } func (self *untunnelHandler) deleteServicePolicyBind(svcName string, edge *rest_management_api_client.ZitiEdgeManagement) error { - return self.deleteServicePolicy(fmt.Sprintf("name=\"%v-bind\"", svcName), edge) + return self.deleteServicePolicy(fmt.Sprintf("name=\"%v-backend\"", svcName), edge) } func (self *untunnelHandler) deleteServicePolicyDial(svcName string, edge *rest_management_api_client.ZitiEdgeManagement) error { diff --git a/docs/network/ctrl.yml b/docs/network/ctrl.yml index d681d6b5..da8b4eaf 100644 --- a/docs/network/ctrl.yml +++ b/docs/network/ctrl.yml @@ -152,19 +152,19 @@ edge: # web # Defines webListeners that will be hosted by the controller. Each webListener can host many APIs and be bound to many -# bind points. +# backend points. web: # name - required # Provides a name for this listener, used for logging output. Not required to be unique, but is highly suggested. - name: client-management # bindPoints - required - # One or more bind points are required. A bind point specifies an interface (interface:port string) that defines - # where on the host machine the webListener will listen and the address (host:port) that should be used to + # One or more backend points are required. A backend point specifies an interface (interface:port string) that defines + # where on the host machine the webListener will frontend and the address (host:port) that should be used to # publicly address the webListener(i.e. mydomain.com, localhost, 127.0.0.1). This public address may be used for # incoming address resolution as well as used in responses in the API. bindPoints: #interface - required - # A host:port string on which network interface to listen on. 0.0.0.0 will listen on all interfaces + # A host:port string on which network interface to frontend on. 0.0.0.0 will frontend on all interfaces - interface: 0.0.0.0:1280 # address - required # The public address that external incoming requests will be able to resolve. Used in request processing and @@ -206,7 +206,7 @@ web: # Allows one or more APIs to be bound to this webListener apis: # binding - required - # Specifies an API to bind to this webListener. Built-in APIs are + # Specifies an API to backend to this webListener. Built-in APIs are # - edge-management # - edge-client # - fabric-management diff --git a/endpoints/bind/http.go b/endpoints/backend/http.go similarity index 99% rename from endpoints/bind/http.go rename to endpoints/backend/http.go index 888a83d6..62eb2b66 100644 --- a/endpoints/bind/http.go +++ b/endpoints/backend/http.go @@ -1,4 +1,4 @@ -package bind +package backend import ( "github.com/openziti-test-kitchen/zrok/util" diff --git a/endpoints/listen/http.go b/endpoints/frontend/http.go similarity index 99% rename from endpoints/listen/http.go rename to endpoints/frontend/http.go index 5b863455..900eb87e 100644 --- a/endpoints/listen/http.go +++ b/endpoints/frontend/http.go @@ -1,4 +1,4 @@ -package listen +package frontend import ( "context" diff --git a/etc/ziti-ctrl.yml b/etc/ziti-ctrl.yml index e8bf7c9b..09874bd4 100644 --- a/etc/ziti-ctrl.yml +++ b/etc/ziti-ctrl.yml @@ -152,19 +152,19 @@ edge: # web # Defines webListeners that will be hosted by the controller. Each webListener can host many APIs and be bound to many -# bind points. +# backend points. web: # name - required # Provides a name for this listener, used for logging output. Not required to be unique, but is highly suggested. - name: client-management # bindPoints - required - # One or more bind points are required. A bind point specifies an interface (interface:port string) that defines - # where on the host machine the webListener will listen and the address (host:port) that should be used to + # One or more backend points are required. A backend point specifies an interface (interface:port string) that defines + # where on the host machine the webListener will frontend and the address (host:port) that should be used to # publicly address the webListener(i.e. mydomain.com, localhost, 127.0.0.1). This public address may be used for # incoming address resolution as well as used in responses in the API. bindPoints: #interface - required - # A host:port string on which network interface to listen on. 0.0.0.0 will listen on all interfaces + # A host:port string on which network interface to frontend on. 0.0.0.0 will frontend on all interfaces - interface: 0.0.0.0:1280 # address - required # The public address that external incoming requests will be able to resolve. Used in request processing and @@ -206,7 +206,7 @@ web: # Allows one or more APIs to be bound to this webListener apis: # binding - required - # Specifies an API to bind to this webListener. Built-in APIs are + # Specifies an API to backend to this webListener. Built-in APIs are # - edge-management # - edge-client # - fabric-management diff --git a/rest_server_zrok/operations/identity/create_account.go b/rest_server_zrok/operations/identity/create_account.go index 2f88eea6..ee141d1b 100644 --- a/rest_server_zrok/operations/identity/create_account.go +++ b/rest_server_zrok/operations/identity/create_account.go @@ -45,7 +45,7 @@ func (o *CreateAccount) ServeHTTP(rw http.ResponseWriter, r *http.Request) { *r = *rCtx } var Params = NewCreateAccountParams() - if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // backend params o.Context.Respond(rw, r, route.Produces, route, err) return } diff --git a/rest_server_zrok/operations/identity/enable.go b/rest_server_zrok/operations/identity/enable.go index a6c8a3d2..17e422bc 100644 --- a/rest_server_zrok/operations/identity/enable.go +++ b/rest_server_zrok/operations/identity/enable.go @@ -60,7 +60,7 @@ func (o *Enable) ServeHTTP(rw http.ResponseWriter, r *http.Request) { principal = uprinc.(*rest_model_zrok.Principal) // this is really a rest_model_zrok.Principal, I promise } - if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // backend params o.Context.Respond(rw, r, route.Produces, route, err) return } diff --git a/rest_server_zrok/operations/identity/login.go b/rest_server_zrok/operations/identity/login.go index cfab30bb..e7e9120f 100644 --- a/rest_server_zrok/operations/identity/login.go +++ b/rest_server_zrok/operations/identity/login.go @@ -45,7 +45,7 @@ func (o *Login) ServeHTTP(rw http.ResponseWriter, r *http.Request) { *r = *rCtx } var Params = NewLoginParams() - if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // backend params o.Context.Respond(rw, r, route.Produces, route, err) return } diff --git a/rest_server_zrok/operations/metadata/overview.go b/rest_server_zrok/operations/metadata/overview.go index c2b2e9ac..23cd4a05 100644 --- a/rest_server_zrok/operations/metadata/overview.go +++ b/rest_server_zrok/operations/metadata/overview.go @@ -60,7 +60,7 @@ func (o *Overview) ServeHTTP(rw http.ResponseWriter, r *http.Request) { principal = uprinc.(*rest_model_zrok.Principal) // this is really a rest_model_zrok.Principal, I promise } - if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // backend params o.Context.Respond(rw, r, route.Produces, route, err) return } diff --git a/rest_server_zrok/operations/metadata/version.go b/rest_server_zrok/operations/metadata/version.go index 79808469..9e63ee6f 100644 --- a/rest_server_zrok/operations/metadata/version.go +++ b/rest_server_zrok/operations/metadata/version.go @@ -45,7 +45,7 @@ func (o *Version) ServeHTTP(rw http.ResponseWriter, r *http.Request) { *r = *rCtx } var Params = NewVersionParams() - if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // backend params o.Context.Respond(rw, r, route.Produces, route, err) return } diff --git a/rest_server_zrok/operations/tunnel/tunnel.go b/rest_server_zrok/operations/tunnel/tunnel.go index ccafd0cd..0adced24 100644 --- a/rest_server_zrok/operations/tunnel/tunnel.go +++ b/rest_server_zrok/operations/tunnel/tunnel.go @@ -60,7 +60,7 @@ func (o *Tunnel) ServeHTTP(rw http.ResponseWriter, r *http.Request) { principal = uprinc.(*rest_model_zrok.Principal) // this is really a rest_model_zrok.Principal, I promise } - if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // backend params o.Context.Respond(rw, r, route.Produces, route, err) return } diff --git a/rest_server_zrok/operations/tunnel/untunnel.go b/rest_server_zrok/operations/tunnel/untunnel.go index 1c4f73df..9c2d2570 100644 --- a/rest_server_zrok/operations/tunnel/untunnel.go +++ b/rest_server_zrok/operations/tunnel/untunnel.go @@ -60,7 +60,7 @@ func (o *Untunnel) ServeHTTP(rw http.ResponseWriter, r *http.Request) { principal = uprinc.(*rest_model_zrok.Principal) // this is really a rest_model_zrok.Principal, I promise } - if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // backend params o.Context.Respond(rw, r, route.Produces, route, err) return } diff --git a/rest_server_zrok/server.go b/rest_server_zrok/server.go index 3914daf2..c2099497 100644 --- a/rest_server_zrok/server.go +++ b/rest_server_zrok/server.go @@ -73,23 +73,23 @@ type Server struct { GracefulTimeout time.Duration `long:"graceful-timeout" description:"grace period for which to wait before shutting down the server" default:"15s"` MaxHeaderSize flagext.ByteSize `long:"max-header-size" description:"controls the maximum number of bytes the server will read parsing the request header's keys and values, including the request line. It does not limit the size of the request body." default:"1MiB"` - SocketPath flags.Filename `long:"socket-path" description:"the unix socket to listen on" default:"/var/run/zrok.sock"` + SocketPath flags.Filename `long:"socket-path" description:"the unix socket to frontend on" default:"/var/run/zrok.sock"` domainSocketL net.Listener - Host string `long:"host" description:"the IP to listen on" default:"localhost" env:"HOST"` - Port int `long:"port" description:"the port to listen on for insecure connections, defaults to a random value" env:"PORT"` - ListenLimit int `long:"listen-limit" description:"limit the number of outstanding requests"` + Host string `long:"host" description:"the IP to frontend on" default:"localhost" env:"HOST"` + Port int `long:"port" description:"the port to frontend on for insecure connections, defaults to a random value" env:"PORT"` + ListenLimit int `long:"frontend-limit" description:"limit the number of outstanding requests"` KeepAlive time.Duration `long:"keep-alive" description:"sets the TCP keep-alive timeouts on accepted connections. It prunes dead TCP connections ( e.g. closing laptop mid-download)" default:"3m"` ReadTimeout time.Duration `long:"read-timeout" description:"maximum duration before timing out read of the request" default:"30s"` WriteTimeout time.Duration `long:"write-timeout" description:"maximum duration before timing out write of the response" default:"60s"` httpServerL net.Listener - TLSHost string `long:"tls-host" description:"the IP to listen on for tls, when not specified it's the same as --host" env:"TLS_HOST"` - TLSPort int `long:"tls-port" description:"the port to listen on for secure connections, defaults to a random value" env:"TLS_PORT"` + TLSHost string `long:"tls-host" description:"the IP to frontend on for tls, when not specified it's the same as --host" env:"TLS_HOST"` + TLSPort int `long:"tls-port" description:"the port to frontend on for secure connections, defaults to a random value" env:"TLS_PORT"` TLSCertificate flags.Filename `long:"tls-certificate" description:"the certificate to use for secure connections" env:"TLS_CERTIFICATE"` TLSCertificateKey flags.Filename `long:"tls-key" description:"the private key to use for secure connections" env:"TLS_PRIVATE_KEY"` TLSCACertificate flags.Filename `long:"tls-ca" description:"the certificate authority file to be used with mutual tls auth" env:"TLS_CA_CERTIFICATE"` - TLSListenLimit int `long:"tls-listen-limit" description:"limit the number of outstanding requests"` + TLSListenLimit int `long:"tls-frontend-limit" description:"limit the number of outstanding requests"` TLSKeepAlive time.Duration `long:"tls-keep-alive" description:"sets the TCP keep-alive timeouts on accepted connections. It prunes dead TCP connections ( e.g. closing laptop mid-download)"` TLSReadTimeout time.Duration `long:"tls-read-timeout" description:"maximum duration before timing out read of the request"` TLSWriteTimeout time.Duration `long:"tls-write-timeout" description:"maximum duration before timing out write of the response"` @@ -337,7 +337,7 @@ func (s *Server) Listen() error { if s.TLSHost == "" { s.TLSHost = s.Host } - // Use http listen limit if https listen limit wasn't defined + // Use http frontend limit if https frontend limit wasn't defined if s.TLSListenLimit == 0 { s.TLSListenLimit = s.ListenLimit }